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

Unified Diff: src/pipe/SkGPipeWrite.cpp

Issue 613673005: Override SkCanvas::drawImage() in SkDeferredCanvas and SkGPipe (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Rebase master Created 6 years, 2 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
« no previous file with comments | « src/pipe/SkGPipeRead.cpp ('k') | src/utils/SkDeferredCanvas.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/pipe/SkGPipeWrite.cpp
diff --git a/src/pipe/SkGPipeWrite.cpp b/src/pipe/SkGPipeWrite.cpp
index 41b02344805ffceb09c1797367a78355024a7e1d..a1e7dc2872405f5e26ab630a537276ff7956b12b 100644
--- a/src/pipe/SkGPipeWrite.cpp
+++ b/src/pipe/SkGPipeWrite.cpp
@@ -250,6 +250,11 @@ public:
const SkPaint*) SK_OVERRIDE;
virtual void drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center,
const SkRect& dst, const SkPaint* paint = NULL) SK_OVERRIDE;
+ virtual void drawImage(const SkImage* image, SkScalar left, SkScalar top,
+ const SkPaint* paint) SK_OVERRIDE;
+ virtual void drawImageRect(const SkImage* image, const SkRect* src,
+ const SkRect& dst,
+ const SkPaint* paint) SK_OVERRIDE;
virtual void drawSprite(const SkBitmap&, int left, int top,
const SkPaint*) SK_OVERRIDE;
virtual void drawVertices(VertexMode, int vertexCount,
@@ -359,6 +364,9 @@ private:
bool commonDrawBitmap(const SkBitmap& bm, DrawOps op, unsigned flags,
size_t opBytesNeeded, const SkPaint* paint);
+ bool commonDrawImage(const SkImage* image, DrawOps op, unsigned flags,
+ size_t opBytesNeeded, const SkPaint* paint);
+
SkPaint fPaint;
void writePaint(const SkPaint&);
@@ -471,6 +479,7 @@ SkGPipeCanvas::SkGPipeCanvas(SkGPipeController* controller,
}
}
fFlattenableHeap.setBitmapStorage(fBitmapHeap);
+
this->doNotify();
}
@@ -799,6 +808,79 @@ bool SkGPipeCanvas::commonDrawBitmap(const SkBitmap& bm, DrawOps op,
return false;
}
+bool SkGPipeCanvas::commonDrawImage(const SkImage* image, DrawOps op,
+ unsigned flags,
+ size_t opBytesNeeded,
+ const SkPaint* paint) {
+ if (fDone) {
+ return false;
+ }
+
+ if (paint != NULL) {
+ flags |= kDrawBitmap_HasPaint_DrawOpFlag;
+ this->writePaint(*paint);
+ }
+
+ opBytesNeeded += sizeof (SkImage*);
+
+ if (this->needOpBytes(opBytesNeeded)) {
+ this->writeOp(op, flags, 0);
+
+ image->ref(); // The SkGPipeReader will have to call unref()
+ fWriter.writePtr(static_cast<void*>(const_cast<SkImage*>(image)));
+
+ return true;
+ }
+ return false;
+}
+
+void SkGPipeCanvas::drawImage(const SkImage* image, SkScalar left, SkScalar top,
+ const SkPaint* paint) {
+ if (is_cross_process(fFlags)){
+ // If the SkGPipe is cross-process, we will have to flatten the data in the SkImage, so
+ // fallback to the default implementation in SkCanvas (which calls SkImage::draw())
+ // https://code.google.com//p/skia/issues/detail?id=2985
+ this->INHERITED::drawImage(image, left, top, paint);
+ } else {
+ NOTIFY_SETUP(this);
+ size_t opBytesNeeded = sizeof(SkScalar) * 2;
+
+ if (this->commonDrawImage(image, kDrawImage_DrawOp, 0, opBytesNeeded, paint)) {
+ fWriter.writeScalar(left);
+ fWriter.writeScalar(top);
+ }
+ }
+}
+
+void SkGPipeCanvas::drawImageRect(const SkImage* image, const SkRect* src,
+ const SkRect& dst,
+ const SkPaint* paint) {
+ if (is_cross_process(fFlags)){
+ // If the SkGPipe is cross-process, we will have to flatten the data in the SkImage, so
+ // fallback to the default implementation in SkCanvas (which calls SkImage::drawRect())
+ // https://code.google.com//p/skia/issues/detail?id=2985
+ this->INHERITED::drawImageRect(image, src, dst, paint);
+ } else {
+ NOTIFY_SETUP(this);
+ size_t opBytesNeeded = sizeof (SkRect);
+ bool hasSrc = src != NULL;
+ unsigned flags;
+ if (hasSrc) {
+ flags = kDrawImage_HasSrcRect_DrawOpFlag;
+ opBytesNeeded += sizeof (SkRect);
+ } else {
+ flags = 0;
+ }
+
+ if (this->commonDrawImage(image, kDrawImageRect_DrawOp, flags, opBytesNeeded, paint)) {
+ if (hasSrc) {
+ fWriter.writeRect(*src);
+ }
+ fWriter.writeRect(dst);
+ }
+ }
+}
+
void SkGPipeCanvas::drawBitmap(const SkBitmap& bm, SkScalar left, SkScalar top,
const SkPaint* paint) {
NOTIFY_SETUP(this);
@@ -1090,7 +1172,7 @@ void SkGPipeCanvas::onDrawPatch(const SkPoint cubics[12], const SkColor colors[4
const SkPoint texCoords[4], SkXfermode* xmode,
const SkPaint& paint) {
NOTIFY_SETUP(this);
-
+
size_t size = SkPatchUtils::kNumCtrlPts * sizeof(SkPoint);
unsigned flags = 0;
if (colors) {
@@ -1108,21 +1190,21 @@ void SkGPipeCanvas::onDrawPatch(const SkPoint cubics[12], const SkColor colors[4
size += sizeof(int32_t);
}
}
-
+
this->writePaint(paint);
if (this->needOpBytes(size)) {
this->writeOp(kDrawPatch_DrawOp, flags, 0);
-
+
fWriter.write(cubics, SkPatchUtils::kNumCtrlPts * sizeof(SkPoint));
-
+
if (colors) {
fWriter.write(colors, SkPatchUtils::kNumCorners * sizeof(SkColor));
}
-
+
if (texCoords) {
fWriter.write(texCoords, SkPatchUtils::kNumCorners * sizeof(SkPoint));
}
-
+
if (flags & kDrawVertices_HasXfermode_DrawOpFlag) {
SkXfermode::Mode mode = SkXfermode::kModulate_Mode;
SkAssertResult(xmode->asMode(&mode));
« no previous file with comments | « src/pipe/SkGPipeRead.cpp ('k') | src/utils/SkDeferredCanvas.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698