зеркало из https://github.com/mozilla/moz-skia.git
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
This commit is contained in:
Родитель
3c10a0871b
Коммит
b55deeb1c7
|
@ -309,10 +309,19 @@ protected:
|
|||
virtual void lockPixels();
|
||||
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,
|
||||
|
|
|
@ -144,6 +144,8 @@ protected:
|
|||
int y,
|
||||
SkCanvas::Config8888) SK_OVERRIDE;
|
||||
|
||||
virtual bool allowImageFilter(SkImageFilter*) SK_OVERRIDE;
|
||||
|
||||
private:
|
||||
class TypefaceUse : ::SkNoncopyable {
|
||||
public:
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -1535,3 +1535,8 @@ bool SkPDFDevice::onReadPixels(const SkBitmap& bitmap, int x, int y,
|
|||
SkCanvas::Config8888) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool SkPDFDevice::allowImageFilter(SkImageFilter*) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче