diff --git a/shell/platform/android/android_surface_software.cc b/shell/platform/android/android_surface_software.cc index 7b3135a564823..68bf99b27ba56 100644 --- a/shell/platform/android/android_surface_software.cc +++ b/shell/platform/android/android_surface_software.cc @@ -18,13 +18,17 @@ namespace shell { namespace { -bool GetSkColorType(int32_t buffer_format, SkColorType* color_type) { +bool GetSkColorType(int32_t buffer_format, + SkColorType* color_type, + SkAlphaType* alpha_type) { switch (buffer_format) { case WINDOW_FORMAT_RGB_565: *color_type = kRGB_565_SkColorType; + *alpha_type = kOpaque_SkAlphaType; return true; case WINDOW_FORMAT_RGBA_8888: *color_type = kRGBA_8888_SkColorType; + *alpha_type = kPremul_SkAlphaType; return true; default: return false; @@ -33,8 +37,10 @@ bool GetSkColorType(int32_t buffer_format, SkColorType* color_type) { } // anonymous namespace -AndroidSurfaceSoftware::AndroidSurfaceSoftware() - : AndroidSurface(), target_color_type_(kRGBA_8888_SkColorType) {} +AndroidSurfaceSoftware::AndroidSurfaceSoftware() { + GetSkColorType(WINDOW_FORMAT_RGBA_8888, &target_color_type_, + &target_alpha_type_); +} AndroidSurfaceSoftware::~AndroidSurfaceSoftware() = default; @@ -75,7 +81,7 @@ sk_sp AndroidSurfaceSoftware::AcquireBackingStore( } SkImageInfo image_info = SkImageInfo::Make( - size.fWidth, size.fHeight, target_color_type_, kPremul_SkAlphaType); + size.fWidth, size.fHeight, target_color_type_, target_alpha_type_); sk_surface_ = SkSurface::MakeRaster(image_info); @@ -100,10 +106,10 @@ bool AndroidSurfaceSoftware::PresentBackingStore( } SkColorType color_type; - if (GetSkColorType(native_buffer.format, &color_type)) { - SkImageInfo native_image_info = - SkImageInfo::Make(native_buffer.width, native_buffer.height, color_type, - kPremul_SkAlphaType); + SkAlphaType alpha_type; + if (GetSkColorType(native_buffer.format, &color_type, &alpha_type)) { + SkImageInfo native_image_info = SkImageInfo::Make( + native_buffer.width, native_buffer.height, color_type, alpha_type); std::unique_ptr canvas = SkCanvas::MakeRasterDirect( native_image_info, native_buffer.bits, @@ -143,7 +149,7 @@ bool AndroidSurfaceSoftware::SetNativeWindow( int32_t window_format = ANativeWindow_getFormat(native_window_->handle()); if (window_format < 0) return false; - if (!GetSkColorType(window_format, &target_color_type_)) + if (!GetSkColorType(window_format, &target_color_type_, &target_alpha_type_)) return false; return true; } diff --git a/shell/platform/android/android_surface_software.h b/shell/platform/android/android_surface_software.h index d9675d2361c4e..76184b707cf74 100644 --- a/shell/platform/android/android_surface_software.h +++ b/shell/platform/android/android_surface_software.h @@ -44,6 +44,7 @@ class AndroidSurfaceSoftware : public AndroidSurface, fxl::RefPtr native_window_; SkColorType target_color_type_; + SkAlphaType target_alpha_type_; FXL_DISALLOW_COPY_AND_ASSIGN(AndroidSurfaceSoftware); };