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

Side by Side Diff: src/core/SkPictureCommon.h

Issue 1319723002: Have SkPicture::willPlayBackBitmaps() count SkImages too. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 3 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 | « no previous file | tests/PictureTest.cpp » ('j') | tests/PictureTest.cpp » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 // Some shared code used by both SkBigPicture and SkMiniPicture. 8 // Some shared code used by both SkBigPicture and SkMiniPicture.
9 // SkTextHunter -- SkRecord visitor that returns true when the op draws text . 9 // SkTextHunter -- SkRecord visitor that returns true when the op draws text .
10 // SkBitmapHunter -- SkRecord visitor that returns true when the op draws a bi tmap. 10 // SkBitmapHunter -- SkRecord visitor that returns true when the op draws a bi tmap or image.
11 // SkPathCounter -- SkRecord visitor that counts paths that draw slowly on th e GPU. 11 // SkPathCounter -- SkRecord visitor that counts paths that draw slowly on th e GPU.
12 12
13 #include "SkPathEffect.h" 13 #include "SkPathEffect.h"
14 #include "SkRecords.h" 14 #include "SkRecords.h"
15 #include "SkTLogic.h" 15 #include "SkTLogic.h"
16 16
17 struct SkTextHunter { 17 struct SkTextHunter {
18 // Most ops never have text. Some always do. Subpictures know themeselves. 18 // Most ops never have text. Some always do. Subpictures know themeselves.
19 template <typename T> bool operator()(const T&) { return false; } 19 template <typename T> bool operator()(const T&) { return false; }
20 bool operator()(const SkRecords::DrawPosText&) { return true; } 20 bool operator()(const SkRecords::DrawPosText&) { return true; }
21 bool operator()(const SkRecords::DrawPosTextH&) { return true; } 21 bool operator()(const SkRecords::DrawPosTextH&) { return true; }
22 bool operator()(const SkRecords::DrawText&) { return true; } 22 bool operator()(const SkRecords::DrawText&) { return true; }
23 bool operator()(const SkRecords::DrawTextBlob&) { return true; } 23 bool operator()(const SkRecords::DrawTextBlob&) { return true; }
24 bool operator()(const SkRecords::DrawTextOnPath&) { return true; } 24 bool operator()(const SkRecords::DrawTextOnPath&) { return true; }
25 bool operator()(const SkRecords::DrawPicture& op) { return op.picture->hasTe xt(); } 25 bool operator()(const SkRecords::DrawPicture& op) { return op.picture->hasTe xt(); }
26 }; 26 };
27 27
28 28
29 // N.B. This name is slightly historical: hunting season is now open for SkImage s too.
29 struct SkBitmapHunter { 30 struct SkBitmapHunter {
30 // Helpers. These create HasMember_bitmap and HasMember_paint. 31 // Helpers. These let us detect the presence of struct members with particu lar names.
31 SK_CREATE_MEMBER_DETECTOR(bitmap); 32 SK_CREATE_MEMBER_DETECTOR(bitmap);
33 SK_CREATE_MEMBER_DETECTOR(image);
32 SK_CREATE_MEMBER_DETECTOR(paint); 34 SK_CREATE_MEMBER_DETECTOR(paint);
33 35
36 template <typename T>
37 struct HasMember_bitmap_or_image {
38 static const bool value = HasMember_bitmap<T>::value || HasMember_image< T>::value;
39 };
40
34 // Some ops have a paint, some have an optional paint. Either way, get back a pointer. 41 // Some ops have a paint, some have an optional paint. Either way, get back a pointer.
35 static const SkPaint* AsPtr(const SkPaint& p) { return &p; } 42 static const SkPaint* AsPtr(const SkPaint& p) { return &p; }
36 static const SkPaint* AsPtr(const SkRecords::Optional<SkPaint>& p) { return p; } 43 static const SkPaint* AsPtr(const SkRecords::Optional<SkPaint>& p) { return p; }
37 44
38 // Main entry for visitor: 45 // Main entry for visitor:
39 // If the op is a DrawPicture, recurse. 46 // If the op is a DrawPicture, recurse.
40 // If the op has a bitmap directly, return true. 47 // If the op has a bitmap or image directly, return true.
41 // If the op has a paint and the paint has a bitmap, return true. 48 // If the op has a paint and the paint has a bitmap, return true.
42 // Otherwise, return false. 49 // Otherwise, return false.
43 bool operator()(const SkRecords::DrawPicture& op) { return op.picture->willP layBackBitmaps(); } 50 bool operator()(const SkRecords::DrawPicture& op) { return op.picture->willP layBackBitmaps(); }
44 51
45 template <typename T> 52 template <typename T>
46 bool operator()(const T& r) { return CheckBitmap(r); } 53 bool operator()(const T& r) { return CheckBitmap(r); }
47 54
48 // If the op has a bitmap, of course we're going to play back bitmaps. 55 // If the op has a bitmap, of course we're going to play back bitmaps.
49 template <typename T> 56 template <typename T>
50 static SK_WHEN(HasMember_bitmap<T>, bool) CheckBitmap(const T&) { return tru e; } 57 static SK_WHEN(HasMember_bitmap_or_image<T>, bool) CheckBitmap(const T&) {
58 return true;
59 }
51 60
52 // If not, look for one in its paint (if it has a paint). 61 // If not, look for one in its paint (if it has a paint).
53 template <typename T> 62 template <typename T>
54 static SK_WHEN(!HasMember_bitmap<T>, bool) CheckBitmap(const T& r) { return CheckPaint(r); } 63 static SK_WHEN(!HasMember_bitmap_or_image<T>, bool) CheckBitmap(const T& r) {
64 return CheckPaint(r);
65 }
55 66
56 // If we have a paint, dig down into the effects looking for a bitmap. 67 // If we have a paint, dig down into the effects looking for a bitmap.
57 template <typename T> 68 template <typename T>
58 static SK_WHEN(HasMember_paint<T>, bool) CheckPaint(const T& r) { 69 static SK_WHEN(HasMember_paint<T>, bool) CheckPaint(const T& r) {
59 const SkPaint* paint = AsPtr(r.paint); 70 const SkPaint* paint = AsPtr(r.paint);
60 if (paint) { 71 if (paint) {
61 const SkShader* shader = paint->getShader(); 72 const SkShader* shader = paint->getShader();
62 if (shader && shader->isABitmap()) { 73 if (shader && shader->isABitmap()) {
63 return true; 74 return true;
64 } 75 }
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 template <typename T> 137 template <typename T>
127 SK_WHEN(HasMember_paint<T>, void) operator()(const T& op) { 138 SK_WHEN(HasMember_paint<T>, void) operator()(const T& op) {
128 this->checkPaint(AsPtr(op.paint)); 139 this->checkPaint(AsPtr(op.paint));
129 } 140 }
130 141
131 template <typename T> 142 template <typename T>
132 SK_WHEN(!HasMember_paint<T>, void) operator()(const T& op) { /* do nothing * / } 143 SK_WHEN(!HasMember_paint<T>, void) operator()(const T& op) { /* do nothing * / }
133 144
134 int fNumSlowPathsAndDashEffects; 145 int fNumSlowPathsAndDashEffects;
135 }; 146 };
OLDNEW
« no previous file with comments | « no previous file | tests/PictureTest.cpp » ('j') | tests/PictureTest.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698