Disable LCD text explicitly in SkPictureImageFilter::onFilterImage()

As an intermediate fix for
https://code.google.com/p/skia/issues/detail?id=3142, we can use a
non-public SkCanvas constructor and force-disable LCD text.

BUG=skia:3142
R=reed@google.com,senorblanco@google.com

Review URL: https://codereview.chromium.org/725243004
This commit is contained in:
fmalita 2014-11-20 10:44:58 -08:00 коммит произвёл Commit bot
Родитель d6ab2a8e45
Коммит 2d97bc139a
8 изменённых файлов: 45 добавлений и 19 удалений

Просмотреть файл

@ -1330,6 +1330,7 @@ private:
friend class SkSurface_Raster; // needs getDevice()
friend class SkRecorder; // InitFlags
friend class SkNoSaveLayerCanvas; // InitFlags
friend class SkPictureImageFilter; // SkCanvas(SkBaseDevice*, SkSurfaceProps*, InitFlags)
enum InitFlags {
kDefault_InitFlags = 0,

Просмотреть файл

@ -16,6 +16,7 @@
class SkBitmap;
class SkColorFilter;
class SkBaseDevice;
class SkSurfaceProps;
struct SkIPoint;
class GrFragmentProcessor;
class GrTexture;
@ -87,6 +88,7 @@ public:
virtual bool filterImage(const SkImageFilter*, const SkBitmap& src,
const Context&,
SkBitmap* result, SkIPoint* offset) = 0;
virtual const SkSurfaceProps* surfaceProps() const = 0;
};
/**

Просмотреть файл

@ -1219,7 +1219,7 @@ void SkCanvas::internalDrawDevice(SkBaseDevice* srcDev, int x, int y,
SkImageFilter* filter = paint->getImageFilter();
SkIPoint pos = { x - iter.getX(), y - iter.getY() };
if (filter && !dstDev->canHandleImageFilter(filter)) {
SkDeviceImageFilterProxy proxy(dstDev);
SkDeviceImageFilterProxy proxy(dstDev, fProps);
SkBitmap dst;
SkIPoint offset = SkIPoint::Make(0, 0);
const SkBitmap& src = srcDev->accessBitmap(false);
@ -1261,7 +1261,7 @@ void SkCanvas::drawSprite(const SkBitmap& bitmap, int x, int y,
SkImageFilter* filter = paint->getImageFilter();
SkIPoint pos = { x - iter.getX(), y - iter.getY() };
if (filter && !iter.fDevice->canHandleImageFilter(filter)) {
SkDeviceImageFilterProxy proxy(iter.fDevice);
SkDeviceImageFilterProxy proxy(iter.fDevice, fProps);
SkBitmap dst;
SkIPoint offset = SkIPoint::Make(0, 0);
SkMatrix matrix = *iter.fMatrix;

Просмотреть файл

@ -8,11 +8,19 @@
#ifndef SkDeviceImageFilterProxy_DEFINED
#define SkDeviceImageFilterProxy_DEFINED
#include "SkDevice.h"
#include "SkImageFilter.h"
#include "SkSurfaceProps.h"
class SkDeviceImageFilterProxy : public SkImageFilter::Proxy {
public:
SkDeviceImageFilterProxy(SkBaseDevice* device) : fDevice(device) {}
SkDeviceImageFilterProxy(SkBaseDevice* device, const SkSurfaceProps& props)
: fDevice(device)
, fProps(props.flags(),
SkBaseDevice::CreateInfo::AdjustGeometry(SkImageInfo(),
SkBaseDevice::kImageFilter_Usage,
props.pixelGeometry()))
{}
virtual SkBaseDevice* createDevice(int w, int h) SK_OVERRIDE {
SkBaseDevice::CreateInfo cinfo(SkImageInfo::MakeN32Premul(w, h),
@ -29,8 +37,13 @@ public:
return fDevice->filterImage(filter, src, ctx, result, offset);
}
virtual const SkSurfaceProps* surfaceProps() const SK_OVERRIDE {
return &fProps;
}
private:
SkBaseDevice* fDevice;
SkBaseDevice* fDevice;
const SkSurfaceProps fProps;
};
#endif

Просмотреть файл

@ -9,6 +9,7 @@
#include "SkDevice.h"
#include "SkCanvas.h"
#include "SkReadBuffer.h"
#include "SkSurfaceProps.h"
#include "SkWriteBuffer.h"
#include "SkValidationUtils.h"
@ -97,8 +98,10 @@ bool SkPictureImageFilter::onFilterImage(Proxy* proxy, const SkBitmap&, const Co
return false;
}
SkCanvas canvas(device.get());
SkPaint paint;
// Pass explicit surface props, as the simplified canvas constructor discards device properties.
// FIXME: switch back to the public constructor (and unfriend) after
// https://code.google.com/p/skia/issues/detail?id=3142 is fixed.
SkCanvas canvas(device.get(), proxy->surfaceProps(), SkCanvas::kDefault_InitFlags);
canvas.translate(-SkIntToScalar(bounds.fLeft), -SkIntToScalar(bounds.fTop));
canvas.concat(ctx.ctm());

Просмотреть файл

@ -1348,12 +1348,15 @@ void SkGpuDevice::internalDrawBitmap(const SkBitmap& bitmap,
fContext->drawRectToRect(grPaint, dstRect, paintRect);
}
static bool filter_texture(SkBaseDevice* device, GrContext* context,
GrTexture* texture, const SkImageFilter* filter,
const SkImageFilter::Context& ctx,
SkBitmap* result, SkIPoint* offset) {
bool SkGpuDevice::filterTexture(GrContext* context, GrTexture* texture,
const SkImageFilter* filter,
const SkImageFilter::Context& ctx,
SkBitmap* result, SkIPoint* offset) {
SkASSERT(filter);
SkDeviceImageFilterProxy proxy(device);
// FIXME: plumb actual surface props such that we don't have to lie about the flags here
// (https://code.google.com/p/skia/issues/detail?id=3148).
SkDeviceImageFilterProxy proxy(this, SkSurfaceProps(0, getLeakyProperties().pixelGeometry()));
if (filter->canFilterImageGPU()) {
// Save the render target and set it to NULL, so we don't accidentally draw to it in the
@ -1395,8 +1398,8 @@ void SkGpuDevice::drawSprite(const SkDraw& draw, const SkBitmap& bitmap,
// This cache is transient, and is freed (along with all its contained
// textures) when it goes out of scope.
SkImageFilter::Context ctx(matrix, clipBounds, cache);
if (filter_texture(this, fContext, texture, filter, ctx, &filteredBitmap,
&offset)) {
if (this->filterTexture(fContext, texture, filter, ctx, &filteredBitmap,
&offset)) {
texture = (GrTexture*) filteredBitmap.getTexture();
w = filteredBitmap.width();
h = filteredBitmap.height();
@ -1506,8 +1509,8 @@ void SkGpuDevice::drawDevice(const SkDraw& draw, SkBaseDevice* device,
// textures) when it goes out of scope.
SkAutoTUnref<SkImageFilter::Cache> cache(getImageFilterCache());
SkImageFilter::Context ctx(matrix, clipBounds, cache);
if (filter_texture(this, fContext, devTex, filter, ctx, &filteredBitmap,
&offset)) {
if (this->filterTexture(fContext, devTex, filter, ctx, &filteredBitmap,
&offset)) {
devTex = filteredBitmap.getTexture();
w = filteredBitmap.width();
h = filteredBitmap.height();
@ -1559,7 +1562,7 @@ bool SkGpuDevice::filterImage(const SkImageFilter* filter, const SkBitmap& src,
// must be pushed upstack.
AutoBitmapTexture abt(fContext, src, NULL, &texture);
return filter_texture(this, fContext, texture, filter, ctx, result, offset);
return this->filterTexture(fContext, texture, filter, ctx, result, offset);
}
///////////////////////////////////////////////////////////////////////////////

Просмотреть файл

@ -202,6 +202,10 @@ private:
bool drawDashLine(const SkPoint pts[2], const SkPaint& paint);
bool filterTexture(GrContext*, GrTexture*, const SkImageFilter*,
const SkImageFilter::Context&,
SkBitmap* result, SkIPoint* offset);
static SkPicture::AccelData::Key ComputeAccelDataKey();
typedef SkBaseDevice INHERITED;

Просмотреть файл

@ -235,7 +235,7 @@ static void test_crop_rects(SkBaseDevice* device, skiatest::Reporter* reporter)
SkBitmap bitmap;
bitmap.allocN32Pixels(100, 100);
bitmap.eraseARGB(0, 0, 0, 0);
SkDeviceImageFilterProxy proxy(device);
SkDeviceImageFilterProxy proxy(device, SkSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType));
SkImageFilter::CropRect inputCropRect(SkRect::MakeXYWH(8, 13, 80, 80));
SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(20, 30, 60, 60));
@ -315,7 +315,7 @@ static void test_negative_blur_sigma(SkBaseDevice* device, skiatest::Reporter* r
// Check that SkBlurImageFilter will accept a negative sigma, either in
// the given arguments or after CTM application.
int width = 32, height = 32;
SkDeviceImageFilterProxy proxy(device);
SkDeviceImageFilterProxy proxy(device, SkSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType));
SkScalar five = SkIntToScalar(5);
SkAutoTUnref<SkBlurImageFilter> positiveFilter(
@ -825,7 +825,7 @@ DEF_TEST(ImageFilterClippedPictureImageFilter, reporter) {
SkBitmap bitmap;
bitmap.allocN32Pixels(2, 2);
SkBitmapDevice device(bitmap);
SkDeviceImageFilterProxy proxy(&device);
SkDeviceImageFilterProxy proxy(&device, SkSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType));
REPORTER_ASSERT(reporter, !imageFilter->filterImage(&proxy, bitmap, ctx, &result, &offset));
}