Skip to content

Commit

Permalink
Use an alpha type that matches the color type in Android software ren…
Browse files Browse the repository at this point in the history
  • Loading branch information
jason-simmons authored Feb 15, 2018
1 parent 19e8d9b commit a8bda71
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
24 changes: 15 additions & 9 deletions shell/platform/android/android_surface_software.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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);

Expand All @@ -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,
Expand Down Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions shell/platform/android/android_surface_software.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand Down

0 comments on commit a8bda71

Please sign in to comment.