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

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: 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 unified diff | Download patch
« src/gpu/SkGpuDevice.cpp ('K') | « 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 17 matching lines...) Expand all
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 bool should_draw_immediately(const SkBitmap* bitmap, const SkPaint* paint ,
36 size_t bitmapSizeThreshold) { 36 size_t bitmapSizeThreshold) {
37 if (bitmap && ((bitmap->getTexture() && !bitmap->isImmutable()) || 37 if (bitmap && ((bitmap->getTexture() && !bitmap->isImmutable()) ||
38 (bitmap->getSize() > bitmapSizeThreshold))) { 38 (bitmap->getSize() > bitmapSizeThreshold))) {
39 return true; 39 return true;
40 } 40 }
41 if (paint) { 41 if (paint) {
42 SkShader* shader = paint->getShader();
43 // 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.
44 // with a gpu texture attached. Checking this without RTTI
45 // requires making the assumption that only gradient shaders
46 // and SkBitmapProcShader implement asABitmap(). The following
47 // code may need to be revised if that assumption is ever broken.
48 if (shader && !shader->asAGradient(NULL)) {
49 SkBitmap bm;
50 if (shader->asABitmap(&bm, NULL, NULL) &&
51 bm.getTexture()) {
52 return true;
53 }
54 }
55 }
56 return false;
57 }
58
59 static uint64_t image_area(const SkImage* image) {
60 return sk_64_mul(image->width(), image->height());
61 }
62
63 static bool should_draw_immediately(const SkImage* image, const SkPaint* paint,
64 size_t imageSizeThreshold) {
65 if (image && (image_area(image) > imageSizeThreshold)) {
66 return true;
67 }
68 if (paint) {
42 SkShader* shader = paint->getShader(); 69 SkShader* shader = paint->getShader();
43 // Here we detect the case where the shader is an SkBitmapProcShader 70 // Here we detect the case where the shader is an SkBitmapProcShader
44 // with a gpu texture attached. Checking this without RTTI 71 // with a gpu texture attached. Checking this without RTTI
45 // requires making the assumption that only gradient shaders 72 // requires making the assumption that only gradient shaders
46 // and SkBitmapProcShader implement asABitmap(). The following 73 // and SkBitmapProcShader implement asABitmap(). The following
47 // code may need to be revised if that assumption is ever broken. 74 // code may need to be revised if that assumption is ever broken.
48 if (shader && !shader->asAGradient(NULL)) { 75 if (shader && !shader->asAGradient(NULL)) {
49 SkBitmap bm; 76 SkBitmap bm;
50 if (shader->asABitmap(&bm, NULL, NULL) && 77 if (shader->asABitmap(&bm, NULL, NULL) &&
51 bm.getTexture()) { 78 bm.getTexture()) {
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 void drawBitmap(const SkDraw&, const SkBitmap& bitmap, 222 void drawBitmap(const SkDraw&, const SkBitmap& bitmap,
196 const SkMatrix& matrix, const SkPaint& paint) override 223 const SkMatrix& matrix, const SkPaint& paint) override
197 {SkASSERT(0);} 224 {SkASSERT(0);}
198 void drawBitmapRect(const SkDraw&, const SkBitmap&, const SkRect*, 225 void drawBitmapRect(const SkDraw&, const SkBitmap&, const SkRect*,
199 const SkRect&, const SkPaint&, 226 const SkRect&, const SkPaint&,
200 SkCanvas::DrawBitmapRectFlags) override 227 SkCanvas::DrawBitmapRectFlags) override
201 {SkASSERT(0);} 228 {SkASSERT(0);}
202 void drawSprite(const SkDraw&, const SkBitmap& bitmap, 229 void drawSprite(const SkDraw&, const SkBitmap& bitmap,
203 int x, int y, const SkPaint& paint) override 230 int x, int y, const SkPaint& paint) override
204 {SkASSERT(0);} 231 {SkASSERT(0);}
232 void drawImage(const SkDraw&, const SkImage*, SkScalar, SkScalar, const SkPa int&) override
233 {SkASSERT(0);}
234 void drawImageRect(const SkDraw&, const SkImage*, const SkRect*, const SkRec t&,
235 const SkPaint&) override
236 {SkASSERT(0);}
205 void drawText(const SkDraw&, const void* text, size_t len, 237 void drawText(const SkDraw&, const void* text, size_t len,
206 SkScalar x, SkScalar y, const SkPaint& paint) override 238 SkScalar x, SkScalar y, const SkPaint& paint) override
207 {SkASSERT(0);} 239 {SkASSERT(0);}
208 void drawPosText(const SkDraw&, const void* text, size_t len, 240 void drawPosText(const SkDraw&, const void* text, size_t len,
209 const SkScalar pos[], int scalarsPerPos, 241 const SkScalar pos[], int scalarsPerPos,
210 const SkPoint& offset, const SkPaint& paint) override 242 const SkPoint& offset, const SkPaint& paint) override
211 {SkASSERT(0);} 243 {SkASSERT(0);}
212 void drawTextOnPath(const SkDraw&, const void* text, 244 void drawTextOnPath(const SkDraw&, const void* text,
213 size_t len, const SkPath& path, 245 size_t len, const SkPath& path,
214 const SkMatrix* matrix, 246 const SkMatrix* matrix,
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 this->flushPendingCommands(kNormal_PlaybackMode); 508 this->flushPendingCommands(kNormal_PlaybackMode);
477 return fImmediateCanvas->readPixels(info, pixels, rowBytes, x, y); 509 return fImmediateCanvas->readPixels(info, pixels, rowBytes, x, y);
478 } 510 }
479 511
480 class AutoImmediateDrawIfNeeded { 512 class AutoImmediateDrawIfNeeded {
481 public: 513 public:
482 AutoImmediateDrawIfNeeded(SkDeferredCanvas& canvas, const SkBitmap* bitmap, 514 AutoImmediateDrawIfNeeded(SkDeferredCanvas& canvas, const SkBitmap* bitmap,
483 const SkPaint* paint) { 515 const SkPaint* paint) {
484 this->init(canvas, bitmap, paint); 516 this->init(canvas, bitmap, paint);
485 } 517 }
518 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.
519 const SkPaint* paint) {
520 if (canvas.isDeferredDrawing() &&
521 should_draw_immediately(image, paint, canvas.getBitmapSizeThreshold( ))) {
522 canvas.setDeferredDrawing(false);
523 fCanvas = &canvas;
524 } else {
525 fCanvas = NULL;
526 }
527 }
486 528
487 AutoImmediateDrawIfNeeded(SkDeferredCanvas& canvas, const SkPaint* paint) { 529 AutoImmediateDrawIfNeeded(SkDeferredCanvas& canvas, const SkPaint* paint) {
488 this->init(canvas, NULL, paint); 530 this->init(canvas, NULL, paint);
489 } 531 }
490 532
491 ~AutoImmediateDrawIfNeeded() { 533 ~AutoImmediateDrawIfNeeded() {
492 if (fCanvas) { 534 if (fCanvas) {
493 fCanvas->setDeferredDrawing(true); 535 fCanvas->setDeferredDrawing(true);
494 } 536 }
495 } 537 }
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after
829 this->isFullFrame(&dst, paint) && 871 this->isFullFrame(&dst, paint) &&
830 isPaintOpaque(paint, &bitmap)) { 872 isPaintOpaque(paint, &bitmap)) {
831 this->getDeferredDevice()->skipPendingCommands(); 873 this->getDeferredDevice()->skipPendingCommands();
832 } 874 }
833 875
834 AutoImmediateDrawIfNeeded autoDraw(*this, &bitmap, paint); 876 AutoImmediateDrawIfNeeded autoDraw(*this, &bitmap, paint);
835 this->drawingCanvas()->drawBitmapRectToRect(bitmap, src, dst, paint, flags); 877 this->drawingCanvas()->drawBitmapRectToRect(bitmap, src, dst, paint, flags);
836 this->recordedDrawCommand(); 878 this->recordedDrawCommand();
837 } 879 }
838 880
881
882 void SkDeferredCanvas::onDrawImage(const SkImage* image, SkScalar x, SkScalar y,
883 const SkPaint* paint) {
884 SkRect bounds = SkRect::MakeXYWH(x, y,
885 SkIntToScalar(image->width()), SkIntToScala r(image->height()));
886 if (fDeferredDrawing &&
887 this->isFullFrame(&bounds, paint) &&
888 isPaintOpaque(paint, image)) {
889 this->getDeferredDevice()->skipPendingCommands();
890 }
891
892 AutoImmediateDrawIfNeeded autoDraw(*this, image, paint);
893 this->drawingCanvas()->drawImage(image, x, y, paint);
894 this->recordedDrawCommand();
895 }
896 void SkDeferredCanvas::onDrawImageRect(const SkImage* image, const SkRect* src, const SkRect& dst,
897 const SkPaint* paint) {
898 if (fDeferredDrawing &&
899 this->isFullFrame(&dst, paint) &&
900 isPaintOpaque(paint, image)) {
901 this->getDeferredDevice()->skipPendingCommands();
902 }
903
904 AutoImmediateDrawIfNeeded autoDraw(*this, image, paint);
905 this->drawingCanvas()->drawImageRect(image, src, dst, paint);
906 this->recordedDrawCommand();
907 }
908
839 void SkDeferredCanvas::onDrawBitmapNine(const SkBitmap& bitmap, 909 void SkDeferredCanvas::onDrawBitmapNine(const SkBitmap& bitmap,
840 const SkIRect& center, const SkRect& dst , 910 const SkIRect& center, const SkRect& dst ,
841 const SkPaint* paint) { 911 const SkPaint* paint) {
842 // TODO: reset recording canvas if paint+bitmap is opaque and clip rect 912 // TODO: reset recording canvas if paint+bitmap is opaque and clip rect
843 // covers canvas entirely and dst covers canvas entirely 913 // covers canvas entirely and dst covers canvas entirely
844 AutoImmediateDrawIfNeeded autoDraw(*this, &bitmap, paint); 914 AutoImmediateDrawIfNeeded autoDraw(*this, &bitmap, paint);
845 this->drawingCanvas()->drawBitmapNine(bitmap, center, dst, paint); 915 this->drawingCanvas()->drawBitmapNine(bitmap, center, dst, paint);
846 this->recordedDrawCommand(); 916 this->recordedDrawCommand();
847 } 917 }
848 918
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
928 SkDrawFilter* SkDeferredCanvas::setDrawFilter(SkDrawFilter* filter) { 998 SkDrawFilter* SkDeferredCanvas::setDrawFilter(SkDrawFilter* filter) {
929 this->drawingCanvas()->setDrawFilter(filter); 999 this->drawingCanvas()->setDrawFilter(filter);
930 this->INHERITED::setDrawFilter(filter); 1000 this->INHERITED::setDrawFilter(filter);
931 this->recordedDrawCommand(); 1001 this->recordedDrawCommand();
932 return filter; 1002 return filter;
933 } 1003 }
934 1004
935 SkCanvas* SkDeferredCanvas::canvasForDrawIter() { 1005 SkCanvas* SkDeferredCanvas::canvasForDrawIter() {
936 return this->drawingCanvas(); 1006 return this->drawingCanvas();
937 } 1007 }
OLDNEW
« 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