7

My app's main screen is rendered via SKCanvasView. The colors accurately reflect the values I specified in code.

If I swap-in SKGLView (hardware-accelerated version), changing no other code, the result is 60% darker:

    <!--<skia:SKCanvasView PaintSurface="OnCanvasViewPaintSurface" />-->
    <skia:SKGLView PaintSurface="OnCanvasViewPaintSurface" />

Why is this happening and how do I fix it?

Mud
  • 28,277
  • 11
  • 59
  • 92
  • What you are seeing makes total sense to me as `SKGLView` is based upon OpenGL and thus geometry lighting comes into play. BUT while there is a rendering loop exposed on SKGLView, I do not see where in the "Sharp" version you can control the light source, the ambient light value, which direction the "default light source is from, etc.... What does it look like if you rotate the world by 180 degrees? – SushiHangover Sep 14 '17 at 23:04
  • As far as battery usage, that can greatly vary based upon the device, it CPU vs. GPU, what and how much is moving and whether here are simple object translations in GL, vs. the painting and double buffering, etc.. of a canvas. Remember on all modern versions of Android, canvas painting is hardware accelerated, the same is true for iOS UIViews, CoreGraphics and UIKit drawing are accelerated. Now the layout of those views are not accelerated as each OS has their own layout manager (and Forms has its own on top of that). – SushiHangover Sep 14 '17 at 23:15
  • For battery testing, use Battery Stats for Android, simple Docker based setup. Run a normal usage test for awhile using the Canvas and store the results in the historian and run it again in GL and you can compare the runs: https://developer.android.com/studio/profile/battery-historian.html – SushiHangover Sep 14 '17 at 23:18
  • "What does it look like if you rotate the world by 180 degrees?" I don't even know what that means in the context of SkiaSharp. It's a 2D drawing library. I'm given a canvas object with methods like `DrawRect`, `DrawCircle`, etc. You supply arguments for things like color and line thickness. With `SKCanvasView`, the color values I supply are what show up on screen. With `SKGLView` everything is... much darker. If it's a function of camera angle and/or lighting, that's an implementation detail of the library over which -- as far as I know -- I have no control. – Mud Sep 15 '17 at 00:08

1 Answers1

2

The answer can be found here: https://github.com/mono/SkiaSharp/issues/299#issuecomment-331990904

I found the solution to the problem. There is a specific attribute that is set in the splash screen style, but is not unset (for some reason) when the style is changed.

In the splashscreen style, note this:

<item name="android:backgroundDimEnabled">true</item>

Docs: https://developer.xamarin.com/api/field/Android.Resource+Attribute.BackgroundDimEnabled

This is not unset when the style is switched. So, to fix this, just set it to false:

<item name="android:backgroundDimEnabled">false</item>

Here is a repository that demonstrates this: https://github.com/mattleibow/AndroidGLSurfaceViewTests

Matthew
  • 4,832
  • 2
  • 29
  • 55