try adding flag to allow lcd text even in a layer

BUG=skia:

Review URL: https://codereview.chromium.org/1513513002
This commit is contained in:
reed 2015-12-10 13:44:45 -08:00 committed by Commit bot
parent 96f16e835e
commit 70ee31b2fa
6 changed files with 68 additions and 8 deletions

View File

@ -126,6 +126,33 @@ protected:
private:
typedef skiagm::GM INHERITED;
};
DEF_GM( return new LcdTextGM; )
DEF_GM( return new LcdTextSizeGM; )
///////////////////////////////////////////////////////////////////////////////////////////////////
DEF_SIMPLE_GM(savelayer_lcdtext, canvas, 620, 260) {
SkPaint paint;
paint.setAntiAlias(true);
paint.setLCDRenderText(true);
paint.setTextSize(20);
canvas->drawText("Hamburgefons", 12, 30, 30, paint);
const bool gPreserveLCDText[] = { false, true };
canvas->translate(0, 20);
for (auto preserve : gPreserveLCDText) {
preserve ? canvas->saveLayerPreserveLCDTextRequests(nullptr, nullptr)
: canvas->saveLayer(nullptr, nullptr);
canvas->drawText("Hamburgefons", 12, 30, 60, paint);
SkPaint p;
p.setColor(0xFFCCCCCC);
canvas->drawRect(SkRect::MakeLTRB(25, 70, 200, 100), p);
canvas->drawText("Hamburgefons", 12, 30, 90, paint);
canvas->restore();
canvas->translate(0, 80);
}
}

View File

@ -336,6 +336,13 @@ public:
return this->saveLayer(&bounds, paint);
}
/**
* Temporary name.
* Will allow any requests for LCD text to be respected, so the caller must be careful to
* only draw on top of opaque sections of the layer to get good results.
*/
int saveLayerPreserveLCDTextRequests(const SkRect* bounds, const SkPaint* paint);
/** DEPRECATED - use saveLayer(const SkRect*, const SkPaint*) instead.
This behaves the same as saveLayer(const SkRect*, const SkPaint*),
@ -1316,6 +1323,11 @@ protected:
const SkImageFilter* imageFilter = NULL);
private:
enum PrivateSaveFlags {
// These must not overlap the public flags.
kPreserveLCDText_PrivateSaveFlag = 1 << 5,
};
enum ShaderOverrideOpacity {
kNone_ShaderOverrideOpacity, //!< there is no overriding shader (bitmap or image)
kOpaque_ShaderOverrideOpacity, //!< the overriding shader is opaque

View File

@ -333,16 +333,26 @@ protected:
const SkPaint*);
struct CreateInfo {
static SkPixelGeometry AdjustGeometry(const SkImageInfo&, TileUsage, SkPixelGeometry);
static SkPixelGeometry AdjustGeometry(const SkImageInfo&, TileUsage, SkPixelGeometry,
bool preserveLCDText);
// The constructor may change the pixel geometry based on other parameters.
CreateInfo(const SkImageInfo& info,
TileUsage tileUsage,
SkPixelGeometry geo,
bool forImageFilter = false)
SkPixelGeometry geo)
: fInfo(info)
, fTileUsage(tileUsage)
, fPixelGeometry(AdjustGeometry(info, tileUsage, geo))
, fPixelGeometry(AdjustGeometry(info, tileUsage, geo, false))
, fForImageFilter(false) {}
CreateInfo(const SkImageInfo& info,
TileUsage tileUsage,
SkPixelGeometry geo,
bool preserveLCDText,
bool forImageFilter)
: fInfo(info)
, fTileUsage(tileUsage)
, fPixelGeometry(AdjustGeometry(info, tileUsage, geo, preserveLCDText))
, fForImageFilter(forImageFilter) {}
const SkImageInfo fInfo;

View File

@ -1140,6 +1140,12 @@ int SkCanvas::saveLayer(const SkRect* bounds, const SkPaint* paint, SaveFlags fl
return this->getSaveCount() - 1;
}
int SkCanvas::saveLayerPreserveLCDTextRequests(const SkRect* bounds, const SkPaint* paint) {
unsigned flags = kARGB_ClipLayer_SaveFlag | kPreserveLCDText_PrivateSaveFlag;
return this->saveLayer(bounds, paint, (SaveFlags)flags);
}
void SkCanvas::internalSaveLayer(const SkRect* bounds, const SkPaint* paint, SaveFlags flags,
SaveLayerStrategy strategy) {
#ifndef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG
@ -1183,8 +1189,11 @@ void SkCanvas::internalSaveLayer(const SkRect* bounds, const SkPaint* paint, Sav
bool forceSpriteOnRestore = false;
{
const bool preserveLCDText = kOpaque_SkAlphaType == info.alphaType() ||
SkToBool(flags & kPreserveLCDText_PrivateSaveFlag);
const SkBaseDevice::TileUsage usage = SkBaseDevice::kNever_TileUsage;
const SkBaseDevice::CreateInfo createInfo = SkBaseDevice::CreateInfo(info, usage, geo);
const SkBaseDevice::CreateInfo createInfo = SkBaseDevice::CreateInfo(info, usage, geo,
preserveLCDText, false);
SkBaseDevice* newDev = device->onCreateDevice(createInfo, paint);
if (nullptr == newDev) {
// If onCreateDevice didn't succeed, try raster (e.g. PDF couldn't handle the paint)

View File

@ -55,7 +55,8 @@ const SkBitmap& SkBaseDevice::accessBitmap(bool changePixels) {
SkPixelGeometry SkBaseDevice::CreateInfo::AdjustGeometry(const SkImageInfo& info,
TileUsage tileUsage,
SkPixelGeometry geo) {
SkPixelGeometry geo,
bool preserveLCDText) {
switch (tileUsage) {
case kPossible_TileUsage:
// (we think) for compatibility with old clients, we assume this layer can support LCD
@ -63,7 +64,7 @@ SkPixelGeometry SkBaseDevice::CreateInfo::AdjustGeometry(const SkImageInfo& info
// our callers (reed/robertphilips).
break;
case kNever_TileUsage:
if (info.alphaType() != kOpaque_SkAlphaType) {
if (!preserveLCDText) {
geo = kUnknown_SkPixelGeometry;
}
break;

View File

@ -658,6 +658,7 @@ SkBaseDevice* SkImageFilter::DeviceProxy::createDevice(int w, int h) {
SkBaseDevice::CreateInfo cinfo(SkImageInfo::MakeN32Premul(w, h),
SkBaseDevice::kNever_TileUsage,
kUnknown_SkPixelGeometry,
false, /* preserveLCDText */
true /*forImageFilter*/);
SkBaseDevice* dev = fDevice->onCreateDevice(cinfo, nullptr);
if (nullptr == dev) {