diff options
author | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-01-06 14:43:09 +0000 |
---|---|---|
committer | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-01-06 14:43:09 +0000 |
commit | b55deeb1c7c692023603639a9b29c0e3de124eac (patch) | |
tree | 700cd48c2047c233ab2a8ed27331b48eff2e517f | |
parent | 3c10a0871b1a664441ff53df9a8c57005e247116 (diff) |
add allowImageFilter() so a device can allow/disallow filters
(esp. for printing)
git-svn-id: http://skia.googlecode.com/svn/trunk@2981 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r-- | include/core/SkDevice.h | 11 | ||||
-rw-r--r-- | include/device/xps/SkXPSDevice.h | 2 | ||||
-rw-r--r-- | include/pdf/SkPDFDevice.h | 2 | ||||
-rw-r--r-- | src/core/SkCanvas.cpp | 21 | ||||
-rw-r--r-- | src/core/SkDevice.cpp | 4 | ||||
-rw-r--r-- | src/device/xps/SkXPSDevice.cpp | 6 | ||||
-rw-r--r-- | src/pdf/SkPDFDevice.cpp | 5 |
7 files changed, 45 insertions, 6 deletions
diff --git a/include/core/SkDevice.h b/include/core/SkDevice.h index 8c351f9e51..c026a4b493 100644 --- a/include/core/SkDevice.h +++ b/include/core/SkDevice.h @@ -310,9 +310,18 @@ protected: virtual void unlockPixels(); /** + * Returns true if the device allows processing of this imagefilter. If + * false is returned, then the filter is ignored. This may happen for + * some subclasses that do not support pixel manipulations after drawing + * has occurred (e.g. printing). The default implementation returns true. + */ + virtual bool allowImageFilter(SkImageFilter*); + + /** * Override and return true for filters that the device handles * intrinsically. Returning false means call the filter. - * Default impl returns false. + * Default impl returns false. This will only be called if allowImageFilter() + * returned true. */ virtual bool filterImage(SkImageFilter*, const SkBitmap& src, const SkMatrix& ctm, diff --git a/include/device/xps/SkXPSDevice.h b/include/device/xps/SkXPSDevice.h index c948a902fb..686e1687ec 100644 --- a/include/device/xps/SkXPSDevice.h +++ b/include/device/xps/SkXPSDevice.h @@ -144,6 +144,8 @@ protected: int y, SkCanvas::Config8888) SK_OVERRIDE; + virtual bool allowImageFilter(SkImageFilter*) SK_OVERRIDE; + private: class TypefaceUse : ::SkNoncopyable { public: diff --git a/include/pdf/SkPDFDevice.h b/include/pdf/SkPDFDevice.h index 006994e304..45511495c4 100644 --- a/include/pdf/SkPDFDevice.h +++ b/include/pdf/SkPDFDevice.h @@ -161,6 +161,8 @@ protected: virtual bool onReadPixels(const SkBitmap& bitmap, int x, int y, SkCanvas::Config8888) SK_OVERRIDE; + virtual bool allowImageFilter(SkImageFilter*) SK_OVERRIDE; + private: // TODO(vandebo): push most of SkPDFDevice's state into a core object in // order to get the right access levels without using friend. diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp index e9fcb57f01..87da90ad9f 100644 --- a/src/core/SkCanvas.cpp +++ b/src/core/SkCanvas.cpp @@ -732,6 +732,16 @@ int SkCanvas::saveLayer(const SkRect* bounds, const SkPaint* paint, return count; } + // Kill the imagefilter if our device doesn't allow it + SkLazyPaint lazyP; + if (paint && paint->getImageFilter()) { + if (!this->getTopDevice()->allowImageFilter(paint->getImageFilter())) { + SkPaint* p = lazyP.set(*paint); + p->setImageFilter(NULL); + paint = p; + } + } + bool isOpaque; SkBitmap::Config config = resolve_config(this, ir, flags, &isOpaque); @@ -889,7 +899,7 @@ bool DeviceImageFilterProxy::filterImage(SkImageFilter* filter, return fDevice->filterImage(filter, src, ctm, result, offset); } -void SkCanvas::drawDevice(SkDevice* device, int x, int y, +void SkCanvas::drawDevice(SkDevice* srcDev, int x, int y, const SkPaint* paint) { SkPaint tmp; if (NULL == paint) { @@ -899,20 +909,21 @@ void SkCanvas::drawDevice(SkDevice* device, int x, int y, LOOPER_BEGIN(*paint, SkDrawFilter::kBitmap_Type) while (iter.next()) { + SkDevice* dstDev = iter.fDevice; paint = &looper.paint(); SkImageFilter* filter = paint->getImageFilter(); SkIPoint pos = { x - iter.getX(), y - iter.getY() }; if (filter) { - DeviceImageFilterProxy proxy(device); + DeviceImageFilterProxy proxy(dstDev); SkBitmap dst; - const SkBitmap& src = device->accessBitmap(false); + const SkBitmap& src = srcDev->accessBitmap(false); if (filter->filterImage(&proxy, src, *iter.fMatrix, &dst, &pos)) { SkPaint tmp(*paint); tmp.setImageFilter(NULL); - iter.fDevice->drawSprite(iter, dst, pos.x(), pos.y(), tmp); + dstDev->drawSprite(iter, dst, pos.x(), pos.y(), tmp); } } else { - iter.fDevice->drawDevice(iter, device, pos.x(), pos.y(), *paint); + dstDev->drawDevice(iter, srcDev, pos.x(), pos.y(), *paint); } } LOOPER_END diff --git a/src/core/SkDevice.cpp b/src/core/SkDevice.cpp index 578d0c88eb..aaafb14fd1 100644 --- a/src/core/SkDevice.cpp +++ b/src/core/SkDevice.cpp @@ -107,6 +107,10 @@ bool SkDevice::filterImage(SkImageFilter*, const SkBitmap& src, return false; } +bool SkDevice::allowImageFilter(SkImageFilter*) { + return true; +} + /////////////////////////////////////////////////////////////////////////////// bool SkDevice::readPixels(SkBitmap* bitmap, int x, int y, diff --git a/src/device/xps/SkXPSDevice.cpp b/src/device/xps/SkXPSDevice.cpp index a32eb26adc..e2e23fa1ab 100644 --- a/src/device/xps/SkXPSDevice.cpp +++ b/src/device/xps/SkXPSDevice.cpp @@ -2384,6 +2384,7 @@ SkDevice* SkXPSDevice::onCreateCompatibleDevice(SkBitmap::Config config, bool isOpaque, Usage usage) { if (SkDevice::kGeneral_Usage == usage) { + return NULL; SK_CRASH(); //To what stream do we write? //SkXPSDevice* dev = new SkXPSDevice(this); @@ -2409,3 +2410,8 @@ SkXPSDevice::SkXPSDevice(IXpsOMObjectFactory* xpsFactory) HRVM(this->fXpsFactory->CreateCanvas(&this->fCurrentXpsCanvas), "Could not create canvas for layer."); } + +bool SkXPSDevice::allowImageFilter(SkImageFilter*) { + return false; +} + diff --git a/src/pdf/SkPDFDevice.cpp b/src/pdf/SkPDFDevice.cpp index ced3107363..ba889567bb 100644 --- a/src/pdf/SkPDFDevice.cpp +++ b/src/pdf/SkPDFDevice.cpp @@ -1535,3 +1535,8 @@ bool SkPDFDevice::onReadPixels(const SkBitmap& bitmap, int x, int y, SkCanvas::Config8888) { return false; } + +bool SkPDFDevice::allowImageFilter(SkImageFilter*) { + return false; +} + |