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

Side by Side 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: 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 unified diff | Download patch
« no previous file with comments | « src/pipe/SkGPipeWrite.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2013 Google Inc. 3 * Copyright 2013 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 #include "SkDeferredCanvas.h" 9 #include "SkDeferredCanvas.h"
10 10
(...skipping 14 matching lines...) Expand all
25 kDeferredCanvasBitmapSizeThreshold = ~0U, // Disables this feature 25 kDeferredCanvasBitmapSizeThreshold = ~0U, // Disables this feature
26 26
27 kNoSaveLayerIndex = -1, 27 kNoSaveLayerIndex = -1,
28 }; 28 };
29 29
30 enum PlaybackMode { 30 enum PlaybackMode {
31 kNormal_PlaybackMode, 31 kNormal_PlaybackMode,
32 kSilent_PlaybackMode, 32 kSilent_PlaybackMode,
33 }; 33 };
34 34
35 static bool should_draw_immediately(const SkBitmap* bitmap, const SkPaint* paint , 35 static uint64_t image_area(const SkImage* image) {
36 size_t bitmapSizeThreshold) { 36 return sk_64_mul(image->width(), image->height());
37 }
38
39 static bool should_draw_immediately(const SkBitmap* bitmap, const SkImage* image ,
40 const SkPaint* paint, size_t bitmapSizeThres hold) {
37 if (bitmap && ((bitmap->getTexture() && !bitmap->isImmutable()) || 41 if (bitmap && ((bitmap->getTexture() && !bitmap->isImmutable()) ||
38 (bitmap->getSize() > bitmapSizeThreshold))) { 42 (bitmap->getSize() > bitmapSizeThreshold))) {
43 return true;
44 }
45 if (image && (image_area(image) > bitmapSizeThreshold)) {
39 return true; 46 return true;
40 } 47 }
41 if (paint) { 48 if (paint) {
42 SkShader* shader = paint->getShader(); 49 SkShader* shader = paint->getShader();
43 // Here we detect the case where the shader is an SkBitmapProcShader 50 // Here we detect the case where the shader is an SkBitmapProcShader
44 // with a gpu texture attached. Checking this without RTTI 51 // with a gpu texture attached. Checking this without RTTI
45 // requires making the assumption that only gradient shaders 52 // requires making the assumption that only gradient shaders
46 // and SkBitmapProcShader implement asABitmap(). The following 53 // and SkBitmapProcShader implement asABitmap(). The following
47 // code may need to be revised if that assumption is ever broken. 54 // code may need to be revised if that assumption is ever broken.
48 if (shader && !shader->asAGradient(NULL)) { 55 if (shader && !shader->asAGradient(NULL)) {
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 void drawBitmap(const SkDraw&, const SkBitmap& bitmap, 202 void drawBitmap(const SkDraw&, const SkBitmap& bitmap,
196 const SkMatrix& matrix, const SkPaint& paint) override 203 const SkMatrix& matrix, const SkPaint& paint) override
197 {SkASSERT(0);} 204 {SkASSERT(0);}
198 void drawBitmapRect(const SkDraw&, const SkBitmap&, const SkRect*, 205 void drawBitmapRect(const SkDraw&, const SkBitmap&, const SkRect*,
199 const SkRect&, const SkPaint&, 206 const SkRect&, const SkPaint&,
200 SkCanvas::DrawBitmapRectFlags) override 207 SkCanvas::DrawBitmapRectFlags) override
201 {SkASSERT(0);} 208 {SkASSERT(0);}
202 void drawSprite(const SkDraw&, const SkBitmap& bitmap, 209 void drawSprite(const SkDraw&, const SkBitmap& bitmap,
203 int x, int y, const SkPaint& paint) override 210 int x, int y, const SkPaint& paint) override
204 {SkASSERT(0);} 211 {SkASSERT(0);}
212 void drawImage(const SkDraw&, const SkImage*, SkScalar, SkScalar, const SkPa int&) override
213 {SkASSERT(0);}
214 void drawImageRect(const SkDraw&, const SkImage*, const SkRect*, const SkRec t&,
215 const SkPaint&) override
216 {SkASSERT(0);}
205 void drawText(const SkDraw&, const void* text, size_t len, 217 void drawText(const SkDraw&, const void* text, size_t len,
206 SkScalar x, SkScalar y, const SkPaint& paint) override 218 SkScalar x, SkScalar y, const SkPaint& paint) override
207 {SkASSERT(0);} 219 {SkASSERT(0);}
208 void drawPosText(const SkDraw&, const void* text, size_t len, 220 void drawPosText(const SkDraw&, const void* text, size_t len,
209 const SkScalar pos[], int scalarsPerPos, 221 const SkScalar pos[], int scalarsPerPos,
210 const SkPoint& offset, const SkPaint& paint) override 222 const SkPoint& offset, const SkPaint& paint) override
211 {SkASSERT(0);} 223 {SkASSERT(0);}
212 void drawTextOnPath(const SkDraw&, const void* text, 224 void drawTextOnPath(const SkDraw&, const void* text,
213 size_t len, const SkPath& path, 225 size_t len, const SkPath& path,
214 const SkMatrix* matrix, 226 const SkMatrix* matrix,
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 bool SkDeferredDevice::onReadPixels(const SkImageInfo& info, void* pixels, size_ t rowBytes, 486 bool SkDeferredDevice::onReadPixels(const SkImageInfo& info, void* pixels, size_ t rowBytes,
475 int x, int y) { 487 int x, int y) {
476 this->flushPendingCommands(kNormal_PlaybackMode); 488 this->flushPendingCommands(kNormal_PlaybackMode);
477 return fImmediateCanvas->readPixels(info, pixels, rowBytes, x, y); 489 return fImmediateCanvas->readPixels(info, pixels, rowBytes, x, y);
478 } 490 }
479 491
480 class AutoImmediateDrawIfNeeded { 492 class AutoImmediateDrawIfNeeded {
481 public: 493 public:
482 AutoImmediateDrawIfNeeded(SkDeferredCanvas& canvas, const SkBitmap* bitmap, 494 AutoImmediateDrawIfNeeded(SkDeferredCanvas& canvas, const SkBitmap* bitmap,
483 const SkPaint* paint) { 495 const SkPaint* paint) {
484 this->init(canvas, bitmap, paint); 496 this->init(canvas, bitmap, NULL, paint);
497 }
498 AutoImmediateDrawIfNeeded(SkDeferredCanvas& canvas, const SkImage* image,
499 const SkPaint* paint) {
500 this->init(canvas, NULL, image, paint);
485 } 501 }
486 502
487 AutoImmediateDrawIfNeeded(SkDeferredCanvas& canvas, const SkPaint* paint) { 503 AutoImmediateDrawIfNeeded(SkDeferredCanvas& canvas, const SkPaint* paint) {
488 this->init(canvas, NULL, paint); 504 this->init(canvas, NULL, NULL, paint);
489 } 505 }
490 506
491 ~AutoImmediateDrawIfNeeded() { 507 ~AutoImmediateDrawIfNeeded() {
492 if (fCanvas) { 508 if (fCanvas) {
493 fCanvas->setDeferredDrawing(true); 509 fCanvas->setDeferredDrawing(true);
494 } 510 }
495 } 511 }
496 private: 512 private:
497 void init(SkDeferredCanvas& canvas, const SkBitmap* bitmap, const SkPaint* p aint) { 513 void init(SkDeferredCanvas& canvas, const SkBitmap* bitmap, const SkImage* i mage,
514 const SkPaint* paint) {
498 if (canvas.isDeferredDrawing() && 515 if (canvas.isDeferredDrawing() &&
499 should_draw_immediately(bitmap, paint, canvas.getBitmapSizeThreshold ())) { 516 should_draw_immediately(bitmap, image, paint, canvas.getBitmapSizeTh reshold())) {
500 canvas.setDeferredDrawing(false); 517 canvas.setDeferredDrawing(false);
501 fCanvas = &canvas; 518 fCanvas = &canvas;
502 } else { 519 } else {
503 fCanvas = NULL; 520 fCanvas = NULL;
504 } 521 }
505 } 522 }
506 523
507 SkDeferredCanvas* fCanvas; 524 SkDeferredCanvas* fCanvas;
508 }; 525 };
509 526
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
829 this->isFullFrame(&dst, paint) && 846 this->isFullFrame(&dst, paint) &&
830 isPaintOpaque(paint, &bitmap)) { 847 isPaintOpaque(paint, &bitmap)) {
831 this->getDeferredDevice()->skipPendingCommands(); 848 this->getDeferredDevice()->skipPendingCommands();
832 } 849 }
833 850
834 AutoImmediateDrawIfNeeded autoDraw(*this, &bitmap, paint); 851 AutoImmediateDrawIfNeeded autoDraw(*this, &bitmap, paint);
835 this->drawingCanvas()->drawBitmapRectToRect(bitmap, src, dst, paint, flags); 852 this->drawingCanvas()->drawBitmapRectToRect(bitmap, src, dst, paint, flags);
836 this->recordedDrawCommand(); 853 this->recordedDrawCommand();
837 } 854 }
838 855
856
857 void SkDeferredCanvas::onDrawImage(const SkImage* image, SkScalar x, SkScalar y,
858 const SkPaint* paint) {
859 SkRect bounds = SkRect::MakeXYWH(x, y,
860 SkIntToScalar(image->width()), SkIntToScala r(image->height()));
861 if (fDeferredDrawing &&
862 this->isFullFrame(&bounds, paint) &&
863 isPaintOpaque(paint, image)) {
864 this->getDeferredDevice()->skipPendingCommands();
865 }
866
867 AutoImmediateDrawIfNeeded autoDraw(*this, image, paint);
868 this->drawingCanvas()->drawImage(image, x, y, paint);
869 this->recordedDrawCommand();
870 }
871 void SkDeferredCanvas::onDrawImageRect(const SkImage* image, const SkRect* src, const SkRect& dst,
872 const SkPaint* paint) {
873 if (fDeferredDrawing &&
874 this->isFullFrame(&dst, paint) &&
875 isPaintOpaque(paint, image)) {
876 this->getDeferredDevice()->skipPendingCommands();
877 }
878
879 AutoImmediateDrawIfNeeded autoDraw(*this, image, paint);
880 this->drawingCanvas()->drawImageRect(image, src, dst, paint);
881 this->recordedDrawCommand();
882 }
883
839 void SkDeferredCanvas::onDrawBitmapNine(const SkBitmap& bitmap, 884 void SkDeferredCanvas::onDrawBitmapNine(const SkBitmap& bitmap,
840 const SkIRect& center, const SkRect& dst , 885 const SkIRect& center, const SkRect& dst ,
841 const SkPaint* paint) { 886 const SkPaint* paint) {
842 // TODO: reset recording canvas if paint+bitmap is opaque and clip rect 887 // TODO: reset recording canvas if paint+bitmap is opaque and clip rect
843 // covers canvas entirely and dst covers canvas entirely 888 // covers canvas entirely and dst covers canvas entirely
844 AutoImmediateDrawIfNeeded autoDraw(*this, &bitmap, paint); 889 AutoImmediateDrawIfNeeded autoDraw(*this, &bitmap, paint);
845 this->drawingCanvas()->drawBitmapNine(bitmap, center, dst, paint); 890 this->drawingCanvas()->drawBitmapNine(bitmap, center, dst, paint);
846 this->recordedDrawCommand(); 891 this->recordedDrawCommand();
847 } 892 }
848 893
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
928 SkDrawFilter* SkDeferredCanvas::setDrawFilter(SkDrawFilter* filter) { 973 SkDrawFilter* SkDeferredCanvas::setDrawFilter(SkDrawFilter* filter) {
929 this->drawingCanvas()->setDrawFilter(filter); 974 this->drawingCanvas()->setDrawFilter(filter);
930 this->INHERITED::setDrawFilter(filter); 975 this->INHERITED::setDrawFilter(filter);
931 this->recordedDrawCommand(); 976 this->recordedDrawCommand();
932 return filter; 977 return filter;
933 } 978 }
934 979
935 SkCanvas* SkDeferredCanvas::canvasForDrawIter() { 980 SkCanvas* SkDeferredCanvas::canvasForDrawIter() {
936 return this->drawingCanvas(); 981 return this->drawingCanvas();
937 } 982 }
OLDNEW
« no previous file with comments | « src/pipe/SkGPipeWrite.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698