Index: src/utils/SkDeferredCanvas.cpp |
diff --git a/src/utils/SkDeferredCanvas.cpp b/src/utils/SkDeferredCanvas.cpp |
index 49c5a82c149a12e33d9e8ccee65b635e9fcc64e6..7ba3051a276ab6431eaa9a240e8d04030c124c2e 100644 |
--- a/src/utils/SkDeferredCanvas.cpp |
+++ b/src/utils/SkDeferredCanvas.cpp |
@@ -13,6 +13,7 @@ |
#include "SkColorFilter.h" |
#include "SkDrawFilter.h" |
#include "SkGPipe.h" |
+#include "SkImage_Base.h" |
#include "SkPaint.h" |
#include "SkPaintPriv.h" |
#include "SkRRect.h" |
@@ -32,12 +33,7 @@ enum PlaybackMode { |
kSilent_PlaybackMode, |
}; |
-static bool should_draw_immediately(const SkBitmap* bitmap, const SkPaint* paint, |
- size_t bitmapSizeThreshold) { |
- if (bitmap && ((bitmap->getTexture() && !bitmap->isImmutable()) || |
- (bitmap->getSize() > bitmapSizeThreshold))) { |
- return true; |
- } |
+static bool should_draw_immediately(const SkPaint* paint) { |
if (paint) { |
SkShader* shader = paint->getShader(); |
// Here we detect the case where the shader is an SkBitmapProcShader |
@@ -56,6 +52,25 @@ static bool should_draw_immediately(const SkBitmap* bitmap, const SkPaint* paint |
return false; |
} |
+static bool should_draw_immediately(const SkBitmap* bitmap, const SkPaint* paint, |
+ size_t bitmapSizeThreshold) { |
+ if ((bitmap->getTexture() && !bitmap->isImmutable()) || |
+ (bitmap->getSize() > bitmapSizeThreshold)) { |
+ return true; |
+ } |
+ return should_draw_immediately(paint); |
+} |
+ |
+static bool should_draw_immediately(const SkImage* image, const SkPaint* paint, |
+ size_t bitmapSizeThreshold) { |
+ SkASSERT(image); |
+ if (as_IB(image)->getSize() > bitmapSizeThreshold) { |
+ return true; |
+ } |
+ return should_draw_immediately(paint); |
+} |
+ |
+ |
//----------------------------------------------------------------------------- |
// DeferredPipeController |
//----------------------------------------------------------------------------- |
@@ -202,6 +217,9 @@ protected: |
virtual void drawSprite(const SkDraw&, const SkBitmap& bitmap, |
int x, int y, const SkPaint& paint) SK_OVERRIDE |
{SkASSERT(0);} |
+ virtual void drawSprite(const SkDraw&, const SkImage& image, |
+ int x, int y, const SkPaint& paint) SK_OVERRIDE |
+ {SkASSERT(0);} |
virtual void drawText(const SkDraw&, const void* text, size_t len, |
SkScalar x, SkScalar y, const SkPaint& paint) SK_OVERRIDE |
{SkASSERT(0);} |
@@ -237,8 +255,9 @@ protected: |
bool canHandleImageFilter(const SkImageFilter*) SK_OVERRIDE { |
return false; |
} |
- virtual bool filterImage(const SkImageFilter*, const SkBitmap&, |
- const SkImageFilter::Context&, SkBitmap*, SkIPoint*) SK_OVERRIDE { |
+ virtual bool filterImage(const SkImageFilter*, const SkImage*, |
+ const SkImageFilter::Context&, |
+ SkAutoTUnref<const SkImage>&, SkIPoint*) SK_OVERRIDE { |
return false; |
} |
@@ -480,12 +499,31 @@ bool SkDeferredDevice::onReadPixels(const SkImageInfo& info, void* pixels, size_ |
class AutoImmediateDrawIfNeeded { |
public: |
AutoImmediateDrawIfNeeded(SkDeferredCanvas& canvas, const SkBitmap* bitmap, |
- const SkPaint* paint) { |
- this->init(canvas, bitmap, paint); |
+ const SkPaint* paint) |
+ : fCanvas(NULL) { |
+ if (canvas.isDeferredDrawing() && |
+ should_draw_immediately(bitmap, paint, canvas.getBitmapSizeThreshold())) { |
+ fCanvas = &canvas; |
+ } |
+ this->init(); |
} |
- AutoImmediateDrawIfNeeded(SkDeferredCanvas& canvas, const SkPaint* paint) { |
- this->init(canvas, NULL, paint); |
+ AutoImmediateDrawIfNeeded(SkDeferredCanvas& canvas, const SkImage* image, |
+ const SkPaint* paint) |
+ : fCanvas(NULL) { |
+ if (canvas.isDeferredDrawing() && |
+ should_draw_immediately(image, paint, canvas.getBitmapSizeThreshold())) { |
+ fCanvas = &canvas; |
+ } |
+ this->init(); |
+ } |
+ |
+ AutoImmediateDrawIfNeeded(SkDeferredCanvas& canvas, const SkPaint* paint) |
+ : fCanvas(NULL) { |
+ if (canvas.isDeferredDrawing() && should_draw_immediately(paint)) { |
+ fCanvas = &canvas; |
+ } |
+ this->init(); |
} |
~AutoImmediateDrawIfNeeded() { |
@@ -494,13 +532,9 @@ public: |
} |
} |
private: |
- void init(SkDeferredCanvas& canvas, const SkBitmap* bitmap, const SkPaint* paint) { |
- if (canvas.isDeferredDrawing() && |
- should_draw_immediately(bitmap, paint, canvas.getBitmapSizeThreshold())) { |
- canvas.setDeferredDrawing(false); |
- fCanvas = &canvas; |
- } else { |
- fCanvas = NULL; |
+ void init() { |
+ if (fCanvas) { |
+ fCanvas->setDeferredDrawing(false); |
} |
} |
@@ -864,6 +898,24 @@ void SkDeferredCanvas::onDrawSprite(const SkBitmap& bitmap, int left, int top, |
this->recordedDrawCommand(); |
} |
+void SkDeferredCanvas::onDrawSprite(const SkImage& image, int left, int top, |
+ const SkPaint* paint) { |
+ SkRect imageRect = SkRect::MakeXYWH( |
+ SkIntToScalar(left), |
+ SkIntToScalar(top), |
+ SkIntToScalar(image.width()), |
+ SkIntToScalar(image.height())); |
+ if (fDeferredDrawing && |
+ this->isFullFrame(&imageRect, paint) && |
+ isPaintOpaque(paint, &image)) { |
+ this->getDeferredDevice()->skipPendingCommands(); |
+ } |
+ |
+ AutoImmediateDrawIfNeeded autoDraw(*this, &image, paint); |
+ this->drawingCanvas()->drawSprite(image, left, top, paint); |
+ this->recordedDrawCommand(); |
+} |
+ |
void SkDeferredCanvas::onDrawText(const void* text, size_t byteLength, SkScalar x, SkScalar y, |
const SkPaint& paint) { |
AutoImmediateDrawIfNeeded autoDraw(*this, &paint); |