Remove SkCanvas::isDrawingToLayer
BUG=3245 Review URL: https://codereview.chromium.org/803913005
This commit is contained in:
parent
41c9cbe0ce
commit
3fcc125c77
@ -26,7 +26,6 @@ public:
|
||||
explicit SkNulCanvas(const SkBitmap& bitmap) : SkCanvas(bitmap) {}
|
||||
virtual ~SkNulCanvas() {}
|
||||
|
||||
virtual bool isDrawingToLayer() const SK_OVERRIDE {return false;}
|
||||
virtual void drawPaint(const SkPaint& paint) SK_OVERRIDE {}
|
||||
virtual void drawPoints(PointMode mode, size_t count, const SkPoint pts[],
|
||||
const SkPaint& paint) SK_OVERRIDE {}
|
||||
|
@ -398,11 +398,6 @@ public:
|
||||
*/
|
||||
void restoreToCount(int saveCount);
|
||||
|
||||
/** Returns true if drawing is currently going to a layer (from saveLayer)
|
||||
* rather than to the root device.
|
||||
*/
|
||||
virtual bool isDrawingToLayer() const;
|
||||
|
||||
/** Preconcat the current matrix with the specified translation
|
||||
@param dx The distance to translate in X
|
||||
@param dy The distance to translate in Y
|
||||
@ -1250,7 +1245,6 @@ private:
|
||||
const SkSurfaceProps fProps;
|
||||
|
||||
int fSaveCount; // value returned by getSaveCount()
|
||||
int fSaveLayerCount; // number of successful saveLayer calls
|
||||
|
||||
SkMetaData* fMetaData;
|
||||
|
||||
|
@ -144,7 +144,6 @@ public:
|
||||
void silentFlush();
|
||||
|
||||
// Overrides of the SkCanvas interface
|
||||
virtual bool isDrawingToLayer() const SK_OVERRIDE;
|
||||
virtual void drawPaint(const SkPaint& paint) SK_OVERRIDE;
|
||||
virtual void drawPoints(PointMode mode, size_t count, const SkPoint pts[],
|
||||
const SkPaint& paint) SK_OVERRIDE;
|
||||
@ -248,6 +247,9 @@ private:
|
||||
void validate() const;
|
||||
void init();
|
||||
|
||||
|
||||
int fSaveLevel;
|
||||
int fFirstSaveLayerIndex;
|
||||
size_t fBitmapSizeThreshold;
|
||||
bool fDeferredDrawing;
|
||||
|
||||
|
@ -416,7 +416,6 @@ SkBaseDevice* SkCanvas::init(SkBaseDevice* device, InitFlags flags) {
|
||||
fAllowSimplifyClip = false;
|
||||
fDeviceCMDirty = true;
|
||||
fSaveCount = 1;
|
||||
fSaveLayerCount = 0;
|
||||
fMetaData = NULL;
|
||||
|
||||
fMCRec = (MCRec*)fMCStack.push_back();
|
||||
@ -527,7 +526,6 @@ SkCanvas::SkCanvas(const SkBitmap& bitmap)
|
||||
SkCanvas::~SkCanvas() {
|
||||
// free up the contents of our deque
|
||||
this->restoreToCount(1); // restore everything but the last
|
||||
SkASSERT(0 == fSaveLayerCount);
|
||||
|
||||
this->internalRestore(); // restore the last, since we're going away
|
||||
|
||||
@ -990,8 +988,6 @@ void SkCanvas::internalSaveLayer(const SkRect* bounds, const SkPaint* paint, Sav
|
||||
layer->fNext = fMCRec->fTopLayer;
|
||||
fMCRec->fLayer = layer;
|
||||
fMCRec->fTopLayer = layer; // this field is NOT an owner of layer
|
||||
|
||||
fSaveLayerCount += 1;
|
||||
}
|
||||
|
||||
int SkCanvas::saveLayerAlpha(const SkRect* bounds, U8CPU alpha) {
|
||||
@ -1038,18 +1034,11 @@ void SkCanvas::internalRestore() {
|
||||
layer->fPaint);
|
||||
// reset this, since internalDrawDevice will have set it to true
|
||||
fDeviceCMDirty = true;
|
||||
|
||||
SkASSERT(fSaveLayerCount > 0);
|
||||
fSaveLayerCount -= 1;
|
||||
}
|
||||
SkDELETE(layer);
|
||||
}
|
||||
}
|
||||
|
||||
bool SkCanvas::isDrawingToLayer() const {
|
||||
return fSaveLayerCount > 0;
|
||||
}
|
||||
|
||||
SkSurface* SkCanvas::newSurface(const SkImageInfo& info, const SkSurfaceProps* props) {
|
||||
if (NULL == props) {
|
||||
props = &fProps;
|
||||
|
@ -31,7 +31,6 @@ static const uint32_t kSaveLayerWithBoundsSize = 4 * kUInt32Size + sizeof(SkRect
|
||||
|
||||
SkPictureRecord::SkPictureRecord(const SkISize& dimensions, uint32_t flags)
|
||||
: INHERITED(dimensions.width(), dimensions.height())
|
||||
, fFirstSavedLayerIndex(kNoSavedLayerIndex)
|
||||
, fRecordFlags(flags)
|
||||
, fInitialSaveCount(kNoInitialSave) {
|
||||
}
|
||||
@ -151,9 +150,6 @@ SkCanvas::SaveLayerStrategy SkPictureRecord::willSaveLayer(const SkRect* bounds,
|
||||
// from a clip entry.
|
||||
fRestoreOffsetStack.push(-(int32_t)fWriter.bytesWritten());
|
||||
this->recordSaveLayer(bounds, paint, flags);
|
||||
if (kNoSavedLayerIndex == fFirstSavedLayerIndex) {
|
||||
fFirstSavedLayerIndex = fRestoreOffsetStack.count();
|
||||
}
|
||||
|
||||
this->INHERITED::willSaveLayer(bounds, paint, flags);
|
||||
/* No need for a (potentially very big) layer which we don't actually need
|
||||
@ -187,10 +183,6 @@ void SkPictureRecord::recordSaveLayer(const SkRect* bounds, const SkPaint* paint
|
||||
this->validate(initialOffset, size);
|
||||
}
|
||||
|
||||
bool SkPictureRecord::isDrawingToLayer() const {
|
||||
return fFirstSavedLayerIndex != kNoSavedLayerIndex;
|
||||
}
|
||||
|
||||
#ifdef SK_DEBUG
|
||||
/*
|
||||
* Read the op code from 'offset' in 'writer' and extract the size too.
|
||||
@ -221,10 +213,6 @@ void SkPictureRecord::willRestore() {
|
||||
return;
|
||||
}
|
||||
|
||||
if (fRestoreOffsetStack.count() == fFirstSavedLayerIndex) {
|
||||
fFirstSavedLayerIndex = kNoSavedLayerIndex;
|
||||
}
|
||||
|
||||
this->recordRestore();
|
||||
|
||||
fRestoreOffsetStack.pop();
|
||||
|
@ -54,7 +54,6 @@ public:
|
||||
virtual void beginCommentGroup(const char* description) SK_OVERRIDE;
|
||||
virtual void addComment(const char* kywd, const char* value) SK_OVERRIDE;
|
||||
virtual void endCommentGroup() SK_OVERRIDE;
|
||||
virtual bool isDrawingToLayer() const SK_OVERRIDE;
|
||||
|
||||
const SkTDArray<const SkPicture* >& getPictureRefs() const {
|
||||
return fPictureRefs;
|
||||
@ -102,10 +101,6 @@ private:
|
||||
void fillRestoreOffsetPlaceholdersForCurrentStackLevel(uint32_t restoreOffset);
|
||||
|
||||
SkTDArray<int32_t> fRestoreOffsetStack;
|
||||
int fFirstSavedLayerIndex;
|
||||
enum {
|
||||
kNoSavedLayerIndex = -1
|
||||
};
|
||||
|
||||
SkTDArray<uint32_t> fCullOffsetStack;
|
||||
|
||||
|
@ -33,13 +33,11 @@ void SkCanvasDrawableList::append(SkCanvasDrawable* drawable) {
|
||||
|
||||
SkRecorder::SkRecorder(SkRecord* record, int width, int height)
|
||||
: SkCanvas(SkIRect::MakeWH(width, height), SkCanvas::kConservativeRasterClip_InitFlag)
|
||||
, fRecord(record)
|
||||
, fSaveLayerCount(0) {}
|
||||
, fRecord(record) {}
|
||||
|
||||
SkRecorder::SkRecorder(SkRecord* record, const SkRect& bounds)
|
||||
: SkCanvas(bounds.roundOut(), SkCanvas::kConservativeRasterClip_InitFlag)
|
||||
, fRecord(record)
|
||||
, fSaveLayerCount(0) {}
|
||||
, fRecord(record) {}
|
||||
|
||||
void SkRecorder::forgetRecord() {
|
||||
fDrawableList.reset(NULL);
|
||||
@ -273,25 +271,17 @@ void SkRecorder::onDrawPatch(const SkPoint cubics[12], const SkColor colors[4],
|
||||
}
|
||||
|
||||
void SkRecorder::willSave() {
|
||||
fSaveIsSaveLayer.push(false);
|
||||
APPEND(Save);
|
||||
}
|
||||
|
||||
SkCanvas::SaveLayerStrategy SkRecorder::willSaveLayer(const SkRect* bounds,
|
||||
const SkPaint* paint,
|
||||
SkCanvas::SaveFlags flags) {
|
||||
fSaveLayerCount++;
|
||||
fSaveIsSaveLayer.push(true);
|
||||
APPEND(SaveLayer, this->copy(bounds), this->copy(paint), flags);
|
||||
return SkCanvas::kNoLayer_SaveLayerStrategy;
|
||||
}
|
||||
|
||||
void SkRecorder::didRestore() {
|
||||
SkBool8 saveLayer;
|
||||
fSaveIsSaveLayer.pop(&saveLayer);
|
||||
if (saveLayer) {
|
||||
fSaveLayerCount--;
|
||||
}
|
||||
APPEND(Restore, this->devBounds(), this->getTotalMatrix());
|
||||
}
|
||||
|
||||
@ -343,10 +333,6 @@ void SkRecorder::endCommentGroup() {
|
||||
APPEND(EndCommentGroup);
|
||||
}
|
||||
|
||||
bool SkRecorder::isDrawingToLayer() const {
|
||||
return fSaveLayerCount > 0;
|
||||
}
|
||||
|
||||
void SkRecorder::drawData(const void* data, size_t length) {
|
||||
APPEND(DrawData, copy((const char*)data), length);
|
||||
}
|
||||
|
@ -135,7 +135,6 @@ public:
|
||||
void endCommentGroup() SK_OVERRIDE;
|
||||
void drawData(const void*, size_t) SK_OVERRIDE;
|
||||
|
||||
bool isDrawingToLayer() const SK_OVERRIDE;
|
||||
SkSurface* onNewSurface(const SkImageInfo&, const SkSurfaceProps&) SK_OVERRIDE { return NULL; }
|
||||
|
||||
private:
|
||||
@ -153,8 +152,6 @@ private:
|
||||
|
||||
SkRecord* fRecord;
|
||||
|
||||
int fSaveLayerCount;
|
||||
SkTDArray<SkBool8> fSaveIsSaveLayer;
|
||||
SkAutoTDelete<SkCanvasDrawableList> fDrawableList;
|
||||
};
|
||||
|
||||
|
@ -232,7 +232,6 @@ public:
|
||||
}
|
||||
|
||||
// overrides from SkCanvas
|
||||
virtual bool isDrawingToLayer() const SK_OVERRIDE;
|
||||
virtual void drawPaint(const SkPaint& paint) SK_OVERRIDE;
|
||||
virtual void drawPoints(PointMode, size_t count, const SkPoint pts[],
|
||||
const SkPaint&) SK_OVERRIDE;
|
||||
@ -299,11 +298,7 @@ private:
|
||||
void recordScale(const SkMatrix&);
|
||||
void recordConcat(const SkMatrix&);
|
||||
|
||||
enum {
|
||||
kNoSaveLayer = -1,
|
||||
};
|
||||
SkNamedFactorySet* fFactorySet;
|
||||
int fFirstSaveLayerStackLevel;
|
||||
SkBitmapHeap* fBitmapHeap;
|
||||
SkGPipeController* fController;
|
||||
SkWriter32& fWriter;
|
||||
@ -448,7 +443,6 @@ SkGPipeCanvas::SkGPipeCanvas(SkGPipeController* controller,
|
||||
fDone = false;
|
||||
fBlockSize = 0; // need first block from controller
|
||||
fBytesNotified = 0;
|
||||
fFirstSaveLayerStackLevel = kNoSaveLayer;
|
||||
sk_bzero(fCurrFlatIndex, sizeof(fCurrFlatIndex));
|
||||
|
||||
// Tell the reader the appropriate flags to use.
|
||||
@ -556,10 +550,6 @@ SkCanvas::SaveLayerStrategy SkGPipeCanvas::willSaveLayer(const SkRect* bounds, c
|
||||
}
|
||||
}
|
||||
|
||||
if (kNoSaveLayer == fFirstSaveLayerStackLevel){
|
||||
fFirstSaveLayerStackLevel = this->getSaveCount();
|
||||
}
|
||||
|
||||
this->INHERITED::willSaveLayer(bounds, paint, saveFlags);
|
||||
// we don't create a layer
|
||||
return kNoLayer_SaveLayerStrategy;
|
||||
@ -571,17 +561,9 @@ void SkGPipeCanvas::willRestore() {
|
||||
this->writeOp(kRestore_DrawOp);
|
||||
}
|
||||
|
||||
if (this->getSaveCount() - 1 == fFirstSaveLayerStackLevel){
|
||||
fFirstSaveLayerStackLevel = kNoSaveLayer;
|
||||
}
|
||||
|
||||
this->INHERITED::willRestore();
|
||||
}
|
||||
|
||||
bool SkGPipeCanvas::isDrawingToLayer() const {
|
||||
return kNoSaveLayer != fFirstSaveLayerStackLevel;
|
||||
}
|
||||
|
||||
void SkGPipeCanvas::recordTranslate(const SkMatrix& m) {
|
||||
if (this->needOpBytes(2 * sizeof(SkScalar))) {
|
||||
this->writeOp(kTranslate_DrawOp);
|
||||
|
@ -23,6 +23,8 @@ enum {
|
||||
// Deferred canvas will auto-flush when recording reaches this limit
|
||||
kDefaultMaxRecordingStorageBytes = 64*1024*1024,
|
||||
kDeferredCanvasBitmapSizeThreshold = ~0U, // Disables this feature
|
||||
|
||||
kNoSaveLayerIndex = -1,
|
||||
};
|
||||
|
||||
enum PlaybackMode {
|
||||
@ -154,6 +156,7 @@ public:
|
||||
void skipPendingCommands();
|
||||
void setMaxRecordingStorage(size_t);
|
||||
void recordedDrawCommand();
|
||||
void setIsDrawingToLayer(bool value) {fIsDrawingToLayer = value;}
|
||||
|
||||
virtual SkImageInfo imageInfo() const SK_OVERRIDE;
|
||||
|
||||
@ -256,6 +259,7 @@ private:
|
||||
SkDeferredCanvas::NotificationClient* fNotificationClient;
|
||||
bool fFreshFrame;
|
||||
bool fCanDiscardCanvasContents;
|
||||
bool fIsDrawingToLayer;
|
||||
size_t fMaxRecordingStorageBytes;
|
||||
size_t fPreviousStorageAllocated;
|
||||
};
|
||||
@ -278,6 +282,7 @@ void SkDeferredDevice::setSurface(SkSurface* surface) {
|
||||
void SkDeferredDevice::init() {
|
||||
fRecordingCanvas = NULL;
|
||||
fFreshFrame = true;
|
||||
fIsDrawingToLayer = false;
|
||||
fCanDiscardCanvasContents = false;
|
||||
fPreviousStorageAllocated = 0;
|
||||
fMaxRecordingStorageBytes = kDefaultMaxRecordingStorageBytes;
|
||||
@ -308,7 +313,7 @@ void SkDeferredDevice::setNotificationClient(
|
||||
}
|
||||
|
||||
void SkDeferredDevice::skipPendingCommands() {
|
||||
if (!fRecordingCanvas->isDrawingToLayer()) {
|
||||
if (!fIsDrawingToLayer) {
|
||||
fCanDiscardCanvasContents = true;
|
||||
if (fPipeController.hasPendingCommands()) {
|
||||
fFreshFrame = true;
|
||||
@ -522,6 +527,8 @@ void SkDeferredCanvas::init() {
|
||||
fDeferredDrawing = true; // On by default
|
||||
fCachedCanvasSize.setEmpty();
|
||||
fCachedCanvasSizeDirty = true;
|
||||
fSaveLevel = 0;
|
||||
fFirstSaveLayerIndex = kNoSaveLayerIndex;
|
||||
}
|
||||
|
||||
void SkDeferredCanvas::setMaxRecordingStorage(size_t maxStorage) {
|
||||
@ -673,6 +680,7 @@ bool SkDeferredCanvas::isFullFrame(const SkRect* rect,
|
||||
}
|
||||
|
||||
void SkDeferredCanvas::willSave() {
|
||||
fSaveLevel++;
|
||||
this->drawingCanvas()->save();
|
||||
this->recordedDrawCommand();
|
||||
this->INHERITED::willSave();
|
||||
@ -680,6 +688,11 @@ void SkDeferredCanvas::willSave() {
|
||||
|
||||
SkCanvas::SaveLayerStrategy SkDeferredCanvas::willSaveLayer(const SkRect* bounds,
|
||||
const SkPaint* paint, SaveFlags flags) {
|
||||
fSaveLevel++;
|
||||
if (fFirstSaveLayerIndex == kNoSaveLayerIndex) {
|
||||
fFirstSaveLayerIndex = fSaveLevel;
|
||||
this->getDeferredDevice()->setIsDrawingToLayer(true);
|
||||
}
|
||||
this->drawingCanvas()->saveLayer(bounds, paint, flags);
|
||||
this->recordedDrawCommand();
|
||||
this->INHERITED::willSaveLayer(bounds, paint, flags);
|
||||
@ -688,15 +701,17 @@ SkCanvas::SaveLayerStrategy SkDeferredCanvas::willSaveLayer(const SkRect* bounds
|
||||
}
|
||||
|
||||
void SkDeferredCanvas::willRestore() {
|
||||
SkASSERT(fFirstSaveLayerIndex == kNoSaveLayerIndex || fFirstSaveLayerIndex <= fSaveLevel);
|
||||
if (fFirstSaveLayerIndex == fSaveLevel) {
|
||||
fFirstSaveLayerIndex = kNoSaveLayerIndex;
|
||||
this->getDeferredDevice()->setIsDrawingToLayer(false);
|
||||
}
|
||||
fSaveLevel--;
|
||||
this->drawingCanvas()->restore();
|
||||
this->recordedDrawCommand();
|
||||
this->INHERITED::willRestore();
|
||||
}
|
||||
|
||||
bool SkDeferredCanvas::isDrawingToLayer() const {
|
||||
return this->drawingCanvas()->isDrawingToLayer();
|
||||
}
|
||||
|
||||
void SkDeferredCanvas::didConcat(const SkMatrix& matrix) {
|
||||
this->drawingCanvas()->concat(matrix);
|
||||
this->recordedDrawCommand();
|
||||
|
@ -471,39 +471,6 @@ static void SaveRestoreTestStep(SkCanvas* canvas, const TestData& d,
|
||||
}
|
||||
TEST_STEP(SaveRestore, SaveRestoreTestStep);
|
||||
|
||||
static void DrawLayerTestStep(SkCanvas* canvas, const TestData& d,
|
||||
skiatest::Reporter* reporter, CanvasTestStep* testStep) {
|
||||
REPORTER_ASSERT_MESSAGE(reporter, !canvas->isDrawingToLayer(),
|
||||
testStep->assertMessage());
|
||||
canvas->save();
|
||||
REPORTER_ASSERT_MESSAGE(reporter, !canvas->isDrawingToLayer(),
|
||||
testStep->assertMessage());
|
||||
canvas->restore();
|
||||
|
||||
const SkRect* bounds = NULL; // null means include entire bounds
|
||||
const SkPaint* paint = NULL;
|
||||
|
||||
canvas->saveLayer(bounds, paint);
|
||||
REPORTER_ASSERT_MESSAGE(reporter, canvas->isDrawingToLayer(),
|
||||
testStep->assertMessage());
|
||||
canvas->restore();
|
||||
REPORTER_ASSERT_MESSAGE(reporter, !canvas->isDrawingToLayer(),
|
||||
testStep->assertMessage());
|
||||
|
||||
canvas->saveLayer(bounds, paint);
|
||||
canvas->saveLayer(bounds, paint);
|
||||
REPORTER_ASSERT_MESSAGE(reporter, canvas->isDrawingToLayer(),
|
||||
testStep->assertMessage());
|
||||
canvas->restore();
|
||||
REPORTER_ASSERT_MESSAGE(reporter, canvas->isDrawingToLayer(),
|
||||
testStep->assertMessage());
|
||||
canvas->restore();
|
||||
// now layer count should be 0
|
||||
REPORTER_ASSERT_MESSAGE(reporter, !canvas->isDrawingToLayer(),
|
||||
testStep->assertMessage());
|
||||
}
|
||||
TEST_STEP(DrawLayer, DrawLayerTestStep);
|
||||
|
||||
static void NestedSaveRestoreWithSolidPaintTestStep(SkCanvas* canvas, const TestData& d,
|
||||
skiatest::Reporter*, CanvasTestStep*) {
|
||||
// This test step challenges the TestDeferredCanvasStateConsistency
|
||||
@ -551,8 +518,6 @@ static void AssertCanvasStatesEqual(skiatest::Reporter* reporter, const TestData
|
||||
canvas2->getDeviceSize(), testStep->assertMessage());
|
||||
REPORTER_ASSERT_MESSAGE(reporter, canvas1->getSaveCount() ==
|
||||
canvas2->getSaveCount(), testStep->assertMessage());
|
||||
REPORTER_ASSERT_MESSAGE(reporter, canvas1->isDrawingToLayer() ==
|
||||
canvas2->isDrawingToLayer(), testStep->assertMessage());
|
||||
|
||||
SkRect bounds1, bounds2;
|
||||
REPORTER_ASSERT_MESSAGE(reporter,
|
||||
|
@ -125,32 +125,6 @@ DEF_TEST(Recorder_RefPictures, r) {
|
||||
REPORTER_ASSERT(r, pic->unique());
|
||||
}
|
||||
|
||||
DEF_TEST(Recorder_IsDrawingToLayer, r) {
|
||||
SkRecord record;
|
||||
SkRecorder recorder(&record, 100, 100);
|
||||
|
||||
// We'll save, saveLayer, save, and saveLayer, then restore them all,
|
||||
// checking that isDrawingToLayer() is correct at each step.
|
||||
|
||||
REPORTER_ASSERT(r, !recorder.isDrawingToLayer());
|
||||
recorder.save();
|
||||
REPORTER_ASSERT(r, !recorder.isDrawingToLayer());
|
||||
recorder.saveLayer(NULL, NULL);
|
||||
REPORTER_ASSERT(r, recorder.isDrawingToLayer());
|
||||
recorder.save();
|
||||
REPORTER_ASSERT(r, recorder.isDrawingToLayer());
|
||||
recorder.saveLayer(NULL, NULL);
|
||||
REPORTER_ASSERT(r, recorder.isDrawingToLayer());
|
||||
recorder.restore();
|
||||
REPORTER_ASSERT(r, recorder.isDrawingToLayer());
|
||||
recorder.restore();
|
||||
REPORTER_ASSERT(r, recorder.isDrawingToLayer());
|
||||
recorder.restore();
|
||||
REPORTER_ASSERT(r, !recorder.isDrawingToLayer());
|
||||
recorder.restore();
|
||||
REPORTER_ASSERT(r, !recorder.isDrawingToLayer());
|
||||
}
|
||||
|
||||
DEF_TEST(Recorder_drawImage_takeReference, reporter) {
|
||||
|
||||
SkAutoTUnref<SkImage> image;
|
||||
|
Loading…
Reference in New Issue
Block a user