add helper to know when a colortype is always opaque
Now that surface creation is more picky about its imageinfo, we need to allow clients to know when they should clean-up their alphatype (like our own gm) Bug: skia: Change-Id: Ic110c75769e0154a8343d7e2160d3351f02cf48f Reviewed-on: https://skia-review.googlesource.com/106320 Reviewed-by: Mike Reed <reed@google.com> Commit-Queue: Mike Reed <reed@google.com>
This commit is contained in:
parent
e1053eaca2
commit
1617899b67
@ -89,7 +89,7 @@ private:
|
||||
// Create a 'width' x 'height' SkSurface that matches the colorType of 'canvas' as
|
||||
// best we can
|
||||
static sk_sp<SkSurface> make_color_matching_surface(SkCanvas* canvas, int width, int height,
|
||||
SkAlphaType alphaType) {
|
||||
SkAlphaType at) {
|
||||
|
||||
SkColorType ct = canvas->imageInfo().colorType();
|
||||
sk_sp<SkColorSpace> cs(canvas->imageInfo().refColorSpace());
|
||||
@ -98,9 +98,11 @@ static sk_sp<SkSurface> make_color_matching_surface(SkCanvas* canvas, int width,
|
||||
// For backends that aren't yet color-space aware we just fallback to N32.
|
||||
ct = kN32_SkColorType;
|
||||
cs = nullptr;
|
||||
} else if (SkColorTypeIsAlwaysOpaque(ct)) {
|
||||
at = kOpaque_SkAlphaType;
|
||||
}
|
||||
|
||||
SkImageInfo info = SkImageInfo::Make(width, height, ct, alphaType, std::move(cs));
|
||||
SkImageInfo info = SkImageInfo::Make(width, height, ct, at, std::move(cs));
|
||||
|
||||
return sk_tool_utils::makeSurface(canvas, info);
|
||||
}
|
||||
|
@ -93,6 +93,11 @@ enum SkColorType {
|
||||
*/
|
||||
SK_API int SkColorTypeBytesPerPixel(SkColorType ct);
|
||||
|
||||
/**
|
||||
* Returns true iff the colortype is always considered opaque (i.e. does not store alpha).
|
||||
*/
|
||||
SK_API bool SkColorTypeIsAlwaysOpaque(SkColorType ct);
|
||||
|
||||
/**
|
||||
* Tries to validate the colortype, alphatype pair. In all cases if it returns true, it
|
||||
* will set canonical to the "canonical" answer if it is non-null, and ignore the parameter if
|
||||
@ -110,8 +115,8 @@ SK_API int SkColorTypeBytesPerPixel(SkColorType ct);
|
||||
* one of them (e.g. kUnknown_SkAlphaType is not valid for any colortype except
|
||||
* kUnknown_SkColorType), then the function returns false, and canonical's value is undefined.
|
||||
*/
|
||||
bool SkColorTypeValidateAlphaType(SkColorType colorType, SkAlphaType alphaType,
|
||||
SkAlphaType* canonical = nullptr);
|
||||
SK_API bool SkColorTypeValidateAlphaType(SkColorType colorType, SkAlphaType alphaType,
|
||||
SkAlphaType* canonical = nullptr);
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -79,6 +79,19 @@ static SkColorType stored_to_live(unsigned stored) {
|
||||
return kUnknown_SkColorType;
|
||||
}
|
||||
|
||||
bool SkColorTypeIsAlwaysOpaque(SkColorType ct) {
|
||||
switch (ct) {
|
||||
case kRGB_565_SkColorType:
|
||||
case kRGB_888x_SkColorType:
|
||||
case kRGB_101010x_SkColorType:
|
||||
case kGray_8_SkColorType:
|
||||
return true;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int SkImageInfo::bytesPerPixel() const { return SkColorTypeBytesPerPixel(fColorType); }
|
||||
|
Loading…
Reference in New Issue
Block a user