Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(199)

Unified Diff: src/effects/SkLayerDrawLooper.cpp

Issue 155513012: [WIP] Add Context to SkDrawLooper. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: static allocation of DrawContext; update rest of code. Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/effects/SkLayerDrawLooper.cpp
diff --git a/src/effects/SkLayerDrawLooper.cpp b/src/effects/SkLayerDrawLooper.cpp
index 6c7c3cef0cb04f2529fc3e21fd5688d3a7b19fed..464976ef38060db27dcf6c766a0f48ce47691038 100644
--- a/src/effects/SkLayerDrawLooper.cpp
+++ b/src/effects/SkLayerDrawLooper.cpp
@@ -12,6 +12,7 @@
#include "SkLayerDrawLooper.h"
#include "SkString.h"
#include "SkStringUtils.h"
+#include "SkTemplatesPriv.h"
#include "SkUnPreMultiply.h"
SkLayerDrawLooper::LayerInfo::LayerInfo() {
@@ -25,8 +26,7 @@ SkLayerDrawLooper::LayerInfo::LayerInfo() {
SkLayerDrawLooper::SkLayerDrawLooper()
: fRecs(NULL),
fTopRec(NULL),
- fCount(0),
- fCurrRec(NULL) {
+ fCount(0) {
}
SkLayerDrawLooper::~SkLayerDrawLooper() {
@@ -76,9 +76,13 @@ SkPaint* SkLayerDrawLooper::addLayerOnTop(const LayerInfo& info) {
return &rec->fPaint;
}
-void SkLayerDrawLooper::init(SkCanvas* canvas) {
- fCurrRec = fRecs;
+SkLayerDrawLooper::DrawContext* SkLayerDrawLooper::init(
+ SkCanvas* canvas, void* storage, size_t storageSize) const {
+ LayerDrawLooperContext* context;
+ SK_PLACEMENT_NEW_ARGS(context, LayerDrawLooperContext, storage,
+ storageSize, (this));
canvas->save(SkCanvas::kMatrix_SaveFlag);
+ return context;
}
static SkColor xferColor(SkColor src, SkColor dst, SkXfermode::Mode mode) {
@@ -99,8 +103,8 @@ static SkColor xferColor(SkColor src, SkColor dst, SkXfermode::Mode mode) {
// Even with kEntirePaint_Bits, we always ensure that the master paint's
// text-encoding is respected, since that controls how we interpret the
// text/length parameters of a draw[Pos]Text call.
-void SkLayerDrawLooper::ApplyInfo(SkPaint* dst, const SkPaint& src,
- const LayerInfo& info) {
+void SkLayerDrawLooper::LayerDrawLooperContext::ApplyInfo(
+ SkPaint* dst, const SkPaint& src, const LayerInfo& info) {
uint32_t mask = info.fFlagsMask;
dst->setFlags((dst->getFlags() & ~mask) | (src.getFlags() & mask));
@@ -170,7 +174,11 @@ static void postTranslate(SkCanvas* canvas, SkScalar dx, SkScalar dy) {
canvas->setMatrix(m);
}
-bool SkLayerDrawLooper::next(SkCanvas* canvas, SkPaint* paint) {
+SkLayerDrawLooper::LayerDrawLooperContext::LayerDrawLooperContext(
+ const SkLayerDrawLooper* looper) : fCurrRec(looper->fRecs) {}
+
+bool SkLayerDrawLooper::LayerDrawLooperContext::next(SkCanvas* canvas,
+ SkPaint* paint) {
canvas->restore();
if (NULL == fCurrRec) {
return false;
@@ -183,7 +191,8 @@ bool SkLayerDrawLooper::next(SkCanvas* canvas, SkPaint* paint) {
postTranslate(canvas, fCurrRec->fInfo.fOffset.fX,
fCurrRec->fInfo.fOffset.fY);
} else {
- canvas->translate(fCurrRec->fInfo.fOffset.fX, fCurrRec->fInfo.fOffset.fY);
+ canvas->translate(fCurrRec->fInfo.fOffset.fX,
+ fCurrRec->fInfo.fOffset.fY);
}
fCurrRec = fCurrRec->fNext;
@@ -225,8 +234,7 @@ SkLayerDrawLooper::SkLayerDrawLooper(SkReadBuffer& buffer)
: INHERITED(buffer),
fRecs(NULL),
fTopRec(NULL),
- fCount(0),
- fCurrRec(NULL) {
+ fCount(0) {
int count = buffer.readInt();
for (int i = 0; i < count; i++) {

Powered by Google App Engine
This is Rietveld 408576698