move responsibility for creating raster-device into pdf

BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2146333004

NOTRY=True
win failure seems unrelated

Review-Url: https://codereview.chromium.org/2146333004
This commit is contained in:
reed 2016-07-15 14:23:29 -07:00 committed by Commit bot
parent 80d46ccb28
commit 7503d60847
3 changed files with 26 additions and 26 deletions

View File

@ -1513,7 +1513,7 @@ private:
SrcRectConstraint);
void internalDrawPaint(const SkPaint& paint);
void internalSaveLayer(const SaveLayerRec&, SaveLayerStrategy);
void internalDrawDevice(SkBaseDevice*, int x, int y, const SkPaint*, bool isBitmapDevice);
void internalDrawDevice(SkBaseDevice*, int x, int y, const SkPaint*);
// shared by save() and saveLayer()
void internalSave();

View File

@ -200,14 +200,12 @@ struct DeviceCM {
const SkMatrix* fMatrix;
SkMatrix fMatrixStorage;
SkMatrix fStashedMatrix; // original CTM; used by imagefilter in saveLayer
const bool fDeviceIsBitmapDevice;
DeviceCM(SkBaseDevice* device, const SkPaint* paint, SkCanvas* canvas,
bool conservativeRasterClip, bool deviceIsBitmapDevice, const SkMatrix& stashed)
bool conservativeRasterClip, const SkMatrix& stashed)
: fNext(nullptr)
, fClip(conservativeRasterClip)
, fStashedMatrix(stashed)
, fDeviceIsBitmapDevice(deviceIsBitmapDevice)
{
if (nullptr != device) {
device->ref();
@ -673,7 +671,7 @@ SkBaseDevice* SkCanvas::init(SkBaseDevice* device, InitFlags flags) {
SkASSERT(sizeof(DeviceCM) <= sizeof(fDeviceCMStorage));
fMCRec->fLayer = (DeviceCM*)fDeviceCMStorage;
new (fDeviceCMStorage) DeviceCM(nullptr, nullptr, nullptr, fConservativeRasterClip, false,
new (fDeviceCMStorage) DeviceCM(nullptr, nullptr, nullptr, fConservativeRasterClip,
fMCRec->fMatrix);
fMCRec->fTopLayer = fMCRec->fLayer;
@ -1280,7 +1278,6 @@ void SkCanvas::internalSaveLayer(const SaveLayerRec& rec, SaveLayerStrategy stra
SkImageInfo info = make_layer_info(device->imageInfo(), ir.width(), ir.height(), isOpaque,
paint);
bool forceSpriteOnRestore = false;
{
const bool preserveLCDText = kOpaque_SkAlphaType == info.alphaType() ||
(saveLayerFlags & kPreserveLCDText_SaveLayerFlag);
@ -1289,15 +1286,9 @@ void SkCanvas::internalSaveLayer(const SaveLayerRec& rec, SaveLayerStrategy stra
preserveLCDText);
SkBaseDevice* newDev = device->onCreateDevice(createInfo, paint);
if (nullptr == newDev) {
// If onCreateDevice didn't succeed, try raster (e.g. PDF couldn't handle the paint)
const SkSurfaceProps surfaceProps(fProps.flags(), createInfo.fPixelGeometry);
newDev = SkBitmapDevice::Create(createInfo.fInfo, surfaceProps);
if (nullptr == newDev) {
SkErrorInternals::SetError(kInternalError_SkError,
"Unable to create device for layer.");
return;
}
forceSpriteOnRestore = true;
SkErrorInternals::SetError(kInternalError_SkError,
"Unable to create device for layer.");
return;
}
device = newDev;
}
@ -1307,8 +1298,7 @@ void SkCanvas::internalSaveLayer(const SaveLayerRec& rec, SaveLayerStrategy stra
draw_filter_into_device(fMCRec->fTopLayer->fDevice, rec.fBackdrop, device, fMCRec->fMatrix);
}
DeviceCM* layer = new DeviceCM(device, paint, this, fConservativeRasterClip,
forceSpriteOnRestore, stashedMatrix);
DeviceCM* layer = new DeviceCM(device, paint, this, fConservativeRasterClip, stashedMatrix);
device->unref();
layer->fNext = fMCRec->fTopLayer;
@ -1351,8 +1341,7 @@ void SkCanvas::internalRestore() {
if (layer) {
if (layer->fNext) {
const SkIPoint& origin = layer->fDevice->getOrigin();
this->internalDrawDevice(layer->fDevice, origin.x(), origin.y(),
layer->fPaint, layer->fDeviceIsBitmapDevice);
this->internalDrawDevice(layer->fDevice, origin.x(), origin.y(), layer->fPaint);
// restore what we smashed in internalSaveLayer
fMCRec->fMatrix = layer->fStashedMatrix;
// reset this, since internalDrawDevice will have set it to true
@ -1457,8 +1446,7 @@ bool SkCanvas::onAccessTopLayerPixels(SkPixmap* pmap) {
/////////////////////////////////////////////////////////////////////////////
void SkCanvas::internalDrawDevice(SkBaseDevice* srcDev, int x, int y,
const SkPaint* paint, bool deviceIsBitmapDevice) {
void SkCanvas::internalDrawDevice(SkBaseDevice* srcDev, int x, int y, const SkPaint* paint) {
SkPaint tmp;
if (nullptr == paint) {
paint = &tmp;
@ -1473,9 +1461,6 @@ void SkCanvas::internalDrawDevice(SkBaseDevice* srcDev, int x, int y,
if (filter) {
const SkBitmap& srcBM = srcDev->accessBitmap(false);
dstDev->drawSpriteWithFilter(iter, srcBM, pos.x(), pos.y(), *paint);
} else if (deviceIsBitmapDevice) {
const SkBitmap& src = static_cast<SkBitmapDevice*>(srcDev)->fBitmap;
dstDev->drawSprite(iter, src, pos.x(), pos.y(), *paint);
} else {
dstDev->drawDevice(iter, srcDev, pos.x(), pos.y(), *paint);
}

View File

@ -6,8 +6,8 @@
*/
#include "SkPDFDevice.h"
#include "SkAnnotationKeys.h"
#include "SkBitmapDevice.h"
#include "SkBitmapKey.h"
#include "SkColor.h"
#include "SkColorFilter.h"
@ -543,7 +543,8 @@ static bool not_supported_for_layers(const SkPaint& layerPaint) {
SkBaseDevice* SkPDFDevice::onCreateDevice(const CreateInfo& cinfo, const SkPaint* layerPaint) {
if (layerPaint && not_supported_for_layers(*layerPaint)) {
return nullptr;
// need to return a raster device, which we will detect in drawDevice()
return SkBitmapDevice::Create(cinfo.fInfo, SkSurfaceProps(0, kUnknown_SkPixelGeometry));
}
SkISize size = SkISize::Make(cinfo.fInfo.width(), cinfo.fInfo.height());
return SkPDFDevice::Create(size, fRasterDpi, fDocument);
@ -1340,6 +1341,20 @@ void SkPDFDevice::drawVertices(const SkDraw& d, SkCanvas::VertexMode,
void SkPDFDevice::drawDevice(const SkDraw& d, SkBaseDevice* device,
int x, int y, const SkPaint& paint) {
// Check if the source device is really a bitmapdevice (because that's what we returned
// from createDevice (likely due to an imagefilter)
SkPixmap pmap;
if (device->peekPixels(&pmap)) {
SkBitmap bitmap;
bitmap.installPixels(pmap);
if (paint.getImageFilter()) {
this->drawSpriteWithFilter(d, bitmap, x, y, paint);
} else {
this->drawSprite(d, bitmap, x, y, paint);
}
return;
}
// our onCreateCompatibleDevice() always creates SkPDFDevice subclasses.
SkPDFDevice* pdfDevice = static_cast<SkPDFDevice*>(device);