Reland "remove SkCanvas::kIsOpaque_SaveLayerFlag"

This reverts the revert 9ff8c8c073.

Original:

    This is a performance-only hint that no one but fuzzers
    is using.  It's even explicitly filtered out in Android.

    The fuzzers have noticed they can trick us into allocating
    uninitialized memory and treating it as opaque, blending
    uninitialized pixels, etc.

    Since no one's using this, we can just kill the bit.

    Bug: skia:7566, chromium:808830

Docs-Preview: https://skia.org/?cl=105282
Change-Id: I4326c663f777aa373ff7ec9f319519da9729350d
Reviewed-on: https://skia-review.googlesource.com/105282
Reviewed-by: Mike Klein <mtklein@chromium.org>
Commit-Queue: Mike Klein <mtklein@chromium.org>
This commit is contained in:
Mike Klein 2018-02-07 12:54:27 -05:00 committed by Skia Commit-Bot
parent 4043702b9a
commit e083f7c9f2
8 changed files with 8 additions and 39 deletions

View File

@ -1682,7 +1682,6 @@ documentation purposes, this enum is named rather than anonymous
#Line # sets SaveLayerRec options ##
#Code
enum {
kIsOpaque_SaveLayerFlag = 1 << 0,
kPreserveLCDText_SaveLayerFlag = 1 << 1,
kInitWithPrevious_SaveLayerFlag = 1 << 2,
kDontClipToLayer_Legacy_SaveLayerFlag = kDontClipToLayer_PrivateSaveLayerFlag,
@ -1692,11 +1691,6 @@ documentation purposes, this enum is named rather than anonymous
SaveLayerFlags provides options that may be used in any combination in SaveLayerRec,
defining how Layer allocated by saveLayer operates.
#Const kIsOpaque_SaveLayerFlag 1
Creates Layer without transparency. Flag is ignored if Layer Paint contains
Image_Filter or Color_Filter.
##
#Const kPreserveLCDText_SaveLayerFlag 2
Creates Layer for LCD text. Flag is ignored if Layer Paint contains
Image_Filter or Color_Filter.
@ -1824,8 +1818,8 @@ Sets fBounds, fPaint, and fBackdrop to nullptr. Clears fSaveLayerFlags.
#Example
SkCanvas::SaveLayerRec rec1;
rec1.fSaveLayerFlags = SkCanvas::kIsOpaque_SaveLayerFlag;
SkCanvas::SaveLayerRec rec2(nullptr, nullptr, SkCanvas::kIsOpaque_SaveLayerFlag);
rec1.fSaveLayerFlags = SkCanvas::kPreserveLCDText_SaveLayerFlag;
SkCanvas::SaveLayerRec rec2(nullptr, nullptr, SkCanvas::kPreserveLCDText_SaveLayerFlag);
SkDebugf("rec1 %c= rec2\n", rec1.fBounds == rec2.fBounds
&& rec1.fPaint == rec2.fPaint
&& rec1.fBackdrop == rec2.fBackdrop

View File

@ -1150,9 +1150,6 @@ static void fuzz_canvas(Fuzz* fuzz, SkCanvas* canvas, int depth = 9) {
}
// _DumpCanvas can't handle this.
// if (make_fuzz_t<bool>(fuzz)) {
// saveLayerRec.fSaveLayerFlags |= SkCanvas::kIsOpaque_SaveLayerFlag;
// }
// if (make_fuzz_t<bool>(fuzz)) {
// saveLayerRec.fSaveLayerFlags |= SkCanvas::kPreserveLCDText_SaveLayerFlag;
// }

View File

@ -605,11 +605,6 @@ public:
defining how layer allocated by saveLayer() operates.
*/
enum {
/** Creates layer without transparency. Flag is ignored if layer SkPaint contains
SkImageFilter or SkColorFilter.
*/
kIsOpaque_SaveLayerFlag = 1 << 0,
/** Creates layer for LCD text. Flag is ignored if layer SkPaint contains
SkImageFilter or SkColorFilter.
*/

View File

@ -1693,7 +1693,6 @@ depth of saved stack
<pre style="padding: 1em 1em 1em 1em;width: 62.5em; background-color: #f0f0f0">
enum {
<a href="#SkCanvas_kIsOpaque_SaveLayerFlag">kIsOpaque SaveLayerFlag</a> = 1 << 0,
<a href="#SkCanvas_kPreserveLCDText_SaveLayerFlag">kPreserveLCDText SaveLayerFlag</a> = 1 << 1,
<a href="#SkCanvas_kInitWithPrevious_SaveLayerFlag">kInitWithPrevious SaveLayerFlag</a> = 1 << 2,
<a href="#SkCanvas_kDontClipToLayer_Legacy_SaveLayerFlag">kDontClipToLayer Legacy SaveLayerFlag</a> = kDontClipToLayer_PrivateSaveLayerFlag,
@ -1705,10 +1704,6 @@ defining how <a href="#Layer">Layer</a> allocated by <a href="#SkCanvas_saveLaye
### Constants
<table>
<tr>
<td><a name="SkCanvas_kIsOpaque_SaveLayerFlag"> <code><strong>SkCanvas::kIsOpaque_SaveLayerFlag </strong></code> </a></td><td>1</td><td>Creates <a href="#Layer">Layer</a> without transparency. Flag is ignored if <a href="#Layer">Layer</a> <a href="SkPaint_Reference#Paint">Paint</a> contains
<a href="undocumented#Image_Filter">Image Filter</a> or <a href="undocumented#Color_Filter">Color Filter</a>.</td>
</tr>
<tr>
<td><a name="SkCanvas_kPreserveLCDText_SaveLayerFlag"> <code><strong>SkCanvas::kPreserveLCDText_SaveLayerFlag </strong></code> </a></td><td>2</td><td>Creates <a href="#Layer">Layer</a> for LCD text. Flag is ignored if <a href="#Layer">Layer</a> <a href="SkPaint_Reference#Paint">Paint</a> contains
<a href="undocumented#Image_Filter">Image Filter</a> or <a href="undocumented#Color_Filter">Color Filter</a>.</td>

View File

@ -372,7 +372,7 @@
"stdout": "---\\n-x-\\n---\\n"
},
"SkCanvas_SaveLayerRec_SaveLayerRec": {
"code": "void draw(SkCanvas* canvas) {\n SkCanvas::SaveLayerRec rec1;\n rec1.fSaveLayerFlags = SkCanvas::kIsOpaque_SaveLayerFlag;\n SkCanvas::SaveLayerRec rec2(nullptr, nullptr, SkCanvas::kIsOpaque_SaveLayerFlag);\n SkDebugf(\"rec1 %c= rec2\\n\", rec1.fBounds == rec2.fBounds\n && rec1.fPaint == rec2.fPaint\n && rec1.fBackdrop == rec2.fBackdrop\n && rec1.fSaveLayerFlags == rec2.fSaveLayerFlags ? '=' : '!');\n}",
"code": "void draw(SkCanvas* canvas) {\n SkCanvas::SaveLayerRec rec1;\n rec1.fSaveLayerFlags = SkCanvas::kPreserveLCDText_SaveLayerFlag;\n SkCanvas::SaveLayerRec rec2(nullptr, nullptr, SkCanvas::kPreserveLCDText_SaveLayerFlag);\n SkDebugf(\"rec1 %c= rec2\\n\", rec1.fBounds == rec2.fBounds\n && rec1.fPaint == rec2.fPaint\n && rec1.fBackdrop == rec2.fBackdrop\n && rec1.fSaveLayerFlags == rec2.fSaveLayerFlags ? '=' : '!');\n}",
"hash": "ac7c834dce2eac6ef49c15e820e94003",
"file": "SkCanvas_Reference",
"name": "SkCanvas::SaveLayerRec::SaveLayerRec",
@ -7231,4 +7231,4 @@ onclick="handleMouseClick()"
></canvas >
</body>
</html>

View File

@ -1036,20 +1036,18 @@ void SkCanvas::DrawDeviceWithFilter(SkBaseDevice* src, const SkImageFilter* filt
}
}
static SkImageInfo make_layer_info(const SkImageInfo& prev, int w, int h, bool isOpaque,
const SkPaint* paint) {
static SkImageInfo make_layer_info(const SkImageInfo& prev, int w, int h, const SkPaint* paint) {
// need to force L32 for now if we have an image filter. Once filters support other colortypes
// e.g. sRGB or F16, we can remove this check
// SRGBTODO: Can we remove this check now?
const bool hasImageFilter = paint && paint->getImageFilter();
SkAlphaType alphaType = isOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType;
if ((prev.bytesPerPixel() < 4) || hasImageFilter) {
// force to L32
return SkImageInfo::MakeN32(w, h, alphaType);
return SkImageInfo::MakeN32Premul(w, h);
} else {
// keep the same characteristics as the prev
return SkImageInfo::Make(w, h, prev.colorType(), alphaType, prev.refColorSpace());
return SkImageInfo::Make(w, h, prev.colorType(), kPremul_SkAlphaType, prev.refColorSpace());
}
}
@ -1107,12 +1105,10 @@ void SkCanvas::internalSaveLayer(const SaveLayerRec& rec, SaveLayerStrategy stra
return;
}
bool isOpaque = SkToBool(saveLayerFlags & kIsOpaque_SaveLayerFlag);
SkPixelGeometry geo = fProps.pixelGeometry();
if (paint) {
// TODO: perhaps add a query to filters so we might preserve opaqueness...
if (paint->getImageFilter() || paint->getColorFilter()) {
isOpaque = false;
geo = kUnknown_SkPixelGeometry;
}
}
@ -1123,8 +1119,7 @@ void SkCanvas::internalSaveLayer(const SaveLayerRec& rec, SaveLayerStrategy stra
return;
}
SkImageInfo info = make_layer_info(priorDevice->imageInfo(), ir.width(), ir.height(), isOpaque,
paint);
SkImageInfo info = make_layer_info(priorDevice->imageInfo(), ir.width(), ir.height(), paint);
sk_sp<SkBaseDevice> newDevice;
{

View File

@ -22,7 +22,6 @@
// matches old SkCanvas::SaveFlags
enum LegacySaveFlags {
kHasAlphaLayer_LegacySaveFlags = 0x04,
kClipToLayer_LegacySaveFlags = 0x10,
};
@ -32,9 +31,6 @@ SkCanvas::SaveLayerFlags SkCanvas::LegacySaveFlagsToSaveLayerFlags(uint32_t flag
if (0 == (flags & kClipToLayer_LegacySaveFlags)) {
layerFlags |= SkCanvas::kDontClipToLayer_PrivateSaveLayerFlag;
}
if (0 == (flags & kHasAlphaLayer_LegacySaveFlags)) {
layerFlags |= kIsOpaque_SaveLayerFlag;
}
return layerFlags;
}

View File

@ -349,9 +349,6 @@ SkString* SkObjectParser::RegionToString(const SkRegion& region) {
SkString* SkObjectParser::SaveLayerFlagsToString(SkCanvas::SaveLayerFlags saveLayerFlags) {
SkString* mFlags = new SkString("SkCanvas::SaveFlags: ");
if (saveLayerFlags & SkCanvas::kIsOpaque_SaveLayerFlag) {
mFlags->append("kIsOpaque_SaveLayerFlag ");
}
if (saveLayerFlags & SkCanvas::kPreserveLCDText_SaveLayerFlag) {
mFlags->append("kPreserveLCDText_SaveLayerFlag ");
}