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

Unified Diff: src/utils/SkDeferredCanvas.cpp

Issue 1122643005: Make drawImage a virtual on SkDevice (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: now with Pipe patches Created 5 years, 7 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
« src/gpu/SkGpuDevice.cpp ('K') | « src/pipe/SkGPipeWrite.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/utils/SkDeferredCanvas.cpp
diff --git a/src/utils/SkDeferredCanvas.cpp b/src/utils/SkDeferredCanvas.cpp
index d5cf97bd04df38287faa639f08bd9f7aa4a7c245..5b74d172df675b4936789433b9fbfca64c14d7ff 100644
--- a/src/utils/SkDeferredCanvas.cpp
+++ b/src/utils/SkDeferredCanvas.cpp
@@ -35,7 +35,34 @@ enum PlaybackMode {
static bool should_draw_immediately(const SkBitmap* bitmap, const SkPaint* paint,
size_t bitmapSizeThreshold) {
if (bitmap && ((bitmap->getTexture() && !bitmap->isImmutable()) ||
- (bitmap->getSize() > bitmapSizeThreshold))) {
+ (bitmap->getSize() > bitmapSizeThreshold))) {
+ return true;
+ }
+ if (paint) {
+ SkShader* shader = paint->getShader();
+ // Here we detect the case where the shader is an SkBitmapProcShader
mtklein 2015/05/05 18:50:01 Let's pull out a static function for this bit?
reed1 2015/05/05 19:45:15 Done.
+ // with a gpu texture attached. Checking this without RTTI
+ // requires making the assumption that only gradient shaders
+ // and SkBitmapProcShader implement asABitmap(). The following
+ // code may need to be revised if that assumption is ever broken.
+ if (shader && !shader->asAGradient(NULL)) {
+ SkBitmap bm;
+ if (shader->asABitmap(&bm, NULL, NULL) &&
+ bm.getTexture()) {
+ return true;
+ }
+ }
+ }
+ return false;
+}
+
+static uint64_t image_area(const SkImage* image) {
+ return sk_64_mul(image->width(), image->height());
+}
+
+static bool should_draw_immediately(const SkImage* image, const SkPaint* paint,
+ size_t imageSizeThreshold) {
+ if (image && (image_area(image) > imageSizeThreshold)) {
return true;
}
if (paint) {
@@ -202,6 +229,11 @@ protected:
void drawSprite(const SkDraw&, const SkBitmap& bitmap,
int x, int y, const SkPaint& paint) override
{SkASSERT(0);}
+ void drawImage(const SkDraw&, const SkImage*, SkScalar, SkScalar, const SkPaint&) override
+ {SkASSERT(0);}
+ void drawImageRect(const SkDraw&, const SkImage*, const SkRect*, const SkRect&,
+ const SkPaint&) override
+ {SkASSERT(0);}
void drawText(const SkDraw&, const void* text, size_t len,
SkScalar x, SkScalar y, const SkPaint& paint) override
{SkASSERT(0);}
@@ -483,6 +515,16 @@ public:
const SkPaint* paint) {
this->init(canvas, bitmap, paint);
}
+ AutoImmediateDrawIfNeeded(SkDeferredCanvas& canvas, const SkImage* image,
mtklein 2015/05/05 18:50:01 This seems weirdly asymmetrical. Let's make init
reed1 2015/05/05 19:45:15 Done.
+ const SkPaint* paint) {
+ if (canvas.isDeferredDrawing() &&
+ should_draw_immediately(image, paint, canvas.getBitmapSizeThreshold())) {
+ canvas.setDeferredDrawing(false);
+ fCanvas = &canvas;
+ } else {
+ fCanvas = NULL;
+ }
+ }
AutoImmediateDrawIfNeeded(SkDeferredCanvas& canvas, const SkPaint* paint) {
this->init(canvas, NULL, paint);
@@ -836,6 +878,34 @@ void SkDeferredCanvas::onDrawBitmapRect(const SkBitmap& bitmap, const SkRect* sr
this->recordedDrawCommand();
}
+
+void SkDeferredCanvas::onDrawImage(const SkImage* image, SkScalar x, SkScalar y,
+ const SkPaint* paint) {
+ SkRect bounds = SkRect::MakeXYWH(x, y,
+ SkIntToScalar(image->width()), SkIntToScalar(image->height()));
+ if (fDeferredDrawing &&
+ this->isFullFrame(&bounds, paint) &&
+ isPaintOpaque(paint, image)) {
+ this->getDeferredDevice()->skipPendingCommands();
+ }
+
+ AutoImmediateDrawIfNeeded autoDraw(*this, image, paint);
+ this->drawingCanvas()->drawImage(image, x, y, paint);
+ this->recordedDrawCommand();
+}
+void SkDeferredCanvas::onDrawImageRect(const SkImage* image, const SkRect* src, const SkRect& dst,
+ const SkPaint* paint) {
+ if (fDeferredDrawing &&
+ this->isFullFrame(&dst, paint) &&
+ isPaintOpaque(paint, image)) {
+ this->getDeferredDevice()->skipPendingCommands();
+ }
+
+ AutoImmediateDrawIfNeeded autoDraw(*this, image, paint);
+ this->drawingCanvas()->drawImageRect(image, src, dst, paint);
+ this->recordedDrawCommand();
+}
+
void SkDeferredCanvas::onDrawBitmapNine(const SkBitmap& bitmap,
const SkIRect& center, const SkRect& dst,
const SkPaint* paint) {
« src/gpu/SkGpuDevice.cpp ('K') | « src/pipe/SkGPipeWrite.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698