Use an alpha type that matches the color type in Android software rendering (#4681)

Fixes https://github.com/flutter/flutter/issues/14709
This commit is contained in:
Jason Simmons 2018-02-15 13:00:57 -08:00 committed by GitHub
parent 19e8d9b2bf
commit a8bda71e62
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 9 deletions

View File

@ -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<SkSurface> 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<SkCanvas> 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;
}

View File

@ -44,6 +44,7 @@ class AndroidSurfaceSoftware : public AndroidSurface,
fxl::RefPtr<AndroidNativeWindow> native_window_;
SkColorType target_color_type_;
SkAlphaType target_alpha_type_;
FXL_DISALLOW_COPY_AND_ASSIGN(AndroidSurfaceSoftware);
};