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

Side by Side Diff: skia/ext/analysis_canvas.cc

Issue 12213018: Implementation for cc::Picture::IsCheapInRect(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 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 | Annotate | Revision Log
« cc/picture.cc ('K') | « skia/ext/analysis_canvas.h ('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 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/debug/trace_event.h" 5 #include "base/debug/trace_event.h"
6 #include "skia/ext/analysis_canvas.h" 6 #include "skia/ext/analysis_canvas.h"
7 #include "third_party/skia/include/core/SkDevice.h"
8 #include "third_party/skia/include/core/SkDraw.h"
9 #include "third_party/skia/include/core/SkRRect.h"
10 #include "ui/gfx/rect_conversions.h"
7 11
8 namespace { 12 namespace {
9 13
10 // FIXME: Arbitrary number. Requires tuning & experimentation. 14 // FIXME: Arbitrary number. Requires tuning & experimentation.
11 // Probably requires per-platform tuning; N10 average draw call takes 15 // Probably requires per-platform tuning; N10 average draw call takes
12 // 25x as long as Z620. 16 // 25x as long as Z620.
13 int gPictureCostThreshold = 100; 17 int gPictureCostThreshold = 1000;
14 18
15 } 19 }
16 20
17 namespace skia { 21 namespace skia {
18 22
19 AnalysisDevice::AnalysisDevice(const SkBitmap& bm) : SkDevice(bm) { } 23 AnalysisDevice::AnalysisDevice(const SkBitmap& bm)
24 : SkDevice(bm)
25 , estimatedCost_(0) {
20 26
21 AnalysisCanvas::AnalysisCanvas(SkDevice* device, SkRect clip)
22 : SkCanvas(device)
23 , estimatedCost_(0)
24 , clip_(clip) {
25 SkIRect ir;
26 clip.roundOut(&ir);
27 this->setClipRegion(SkRegion(ir));
28 } 27 }
29 28
29 AnalysisDevice::~AnalysisDevice() {
30
31 }
32
33 int AnalysisDevice::getEstimatedCost() const {
34 return estimatedCost_;
35 }
36
37 void AnalysisDevice::clear(SkColor color) {
38 ++estimatedCost_;
39 }
40
41 void AnalysisDevice::drawPaint(const SkDraw&, const SkPaint& paint) {
42 ++estimatedCost_;
43 }
44
45 void AnalysisDevice::drawPoints(const SkDraw&, SkCanvas::PointMode mode,
46 size_t count, const SkPoint[],
47 const SkPaint& paint) {
48 ++estimatedCost_;
49 }
50
51 void AnalysisDevice::drawRect(const SkDraw&, const SkRect& r,
52 const SkPaint& paint) {
53 // FIXME: if there's a pending image decode & resize, more expensive
54 ++estimatedCost_;
55 }
56
57 void AnalysisDevice::drawOval(const SkDraw&, const SkRect& oval,
58 const SkPaint& paint) {
59 ++estimatedCost_;
60 }
61
62 void AnalysisDevice::drawPath(const SkDraw&, const SkPath& path,
63 const SkPaint& paint,
64 const SkMatrix* prePathMatrix ,
65 bool pathIsMutable ) {
66 // On Z620, every antialiased path costs us about 300us.
67 // We've only seen this in practice on filled paths, but
68 // we expect it to apply to all path stroking modes.
69 if (paint.getMaskFilter()) {
70 estimatedCost_ += 300;
71 }
72 ++estimatedCost_;
73 }
74
75 void AnalysisDevice::drawBitmap(const SkDraw&, const SkBitmap& bitmap,
76 const SkIRect* srcRectOrNull,
77 const SkMatrix& matrix, const SkPaint& paint)
78 {
79 ++estimatedCost_;
80 }
81
82 void AnalysisDevice::drawSprite(const SkDraw&, const SkBitmap& bitmap,
83 int x, int y, const SkPaint& paint) {
84 ++estimatedCost_;
85 }
86
87 void AnalysisDevice::drawBitmapRect(const SkDraw&, const SkBitmap&,
88 const SkRect* srcOrNull, const SkRect& dst,
89 const SkPaint& paint) {
90 ++estimatedCost_;
91 }
92
93
94 void AnalysisDevice::drawText(const SkDraw&, const void* text, size_t len,
95 SkScalar x, SkScalar y, const SkPaint& paint)
96 {
97 ++estimatedCost_;
98 }
99
100 void AnalysisDevice::drawPosText(const SkDraw& draw, const void* text, size_t le n,
101 const SkScalar pos[], SkScalar constY,
102 int scalarsPerPos, const SkPaint& paint) {
103 // FIXME: On Z620, every glyph cache miss costs us about 10us.
104 // We don't have a good mechanism for predicting glyph cache misses.
105 ++estimatedCost_;
106 }
107
108 void AnalysisDevice::drawTextOnPath(const SkDraw&, const void* text, size_t len,
109 const SkPath& path, const SkMatrix* matrix,
110 const SkPaint& paint) {
111 ++estimatedCost_;
112 }
113
114 #ifdef SK_BUILD_FOR_ANDROID
115 void AnalysisDevice::drawPosTextOnPath(const SkDraw& draw, const void* text,
116 size_t len,
117 const SkPoint pos[], const SkPaint& paint,
118 const SkPath& path, const SkMatrix* matrix)
119 {
120 ++estimatedCost_;
121 }
122 #endif
123
124 void AnalysisDevice::drawVertices(const SkDraw&, SkCanvas::VertexMode,
125 int vertexCount,
126 const SkPoint verts[], const SkPoint texs[],
127 const SkColor colors[], SkXfermode* xmode,
128 const uint16_t indices[], int indexCount,
129 const SkPaint& paint) {
130 ++estimatedCost_;
131 }
132
133 void AnalysisDevice::drawDevice(const SkDraw&, SkDevice*, int x, int y,
134 const SkPaint&) {
135 ++estimatedCost_;
136 }
137
138
139 AnalysisCanvas::AnalysisCanvas(AnalysisDevice* device)
140 : SkCanvas(device) {
141
142 }
143
30 AnalysisCanvas::~AnalysisCanvas() { 144 AnalysisCanvas::~AnalysisCanvas() {
31 145
32 } 146 }
33 147
34
35 int AnalysisCanvas::save(SkCanvas::SaveFlags) {
36 ++estimatedCost_;
37 }
38
39 int AnalysisCanvas::saveLayer(const SkRect*, const SkPaint*,
40 SkCanvas::SaveFlags) {
41 ++estimatedCost_;
42 }
43
44 void AnalysisCanvas::restore() {
45 ++estimatedCost_;
46 }
47
48 bool AnalysisCanvas::clipRect(const SkRect&, SkRegion::Op, bool) {
49 ++estimatedCost_;
50 }
51
52 bool AnalysisCanvas::clipRRect(const SkRRect&, SkRegion::Op, bool) {
53 ++estimatedCost_;
54 }
55
56 bool AnalysisCanvas::clipPath(const SkPath&, SkRegion::Op, bool) {
57 ++estimatedCost_;
58 }
59
60 bool AnalysisCanvas::clipRegion(const SkRegion&, SkRegion::Op) {
61 ++estimatedCost_;
62 }
63
64 void AnalysisCanvas::clear(SkColor) {
65 ++estimatedCost_;
66 }
67
68 void AnalysisCanvas::drawPaint(const SkPaint&) {
69 ++estimatedCost_;
70 }
71
72 void AnalysisCanvas::drawPoints(PointMode, size_t, const SkPoint [],
73 const SkPaint&) {
74 ++estimatedCost_;
75 }
76
77 void AnalysisCanvas::drawRect(const SkRect&, const SkPaint&) {
78 // FIXME: if there's a pending image decode & resize, more expensive
79 ++estimatedCost_;
80 }
81
82 void AnalysisCanvas::drawOval(const SkRect&, const SkPaint&) {
83 ++estimatedCost_;
84 }
85
86 void AnalysisCanvas::drawRRect(const SkRRect&, const SkPaint&) {
87 ++estimatedCost_;
88 }
89
90 void AnalysisCanvas::drawPath(const SkPath& path, const SkPaint& paint) {
91 char tmpbuf [256];
92 sprintf(tmpbuf, "AnalysisCanvas::drawPath effect %s fill %s", paint.getPathEffec t() ? "true" : "false", paint.getStyle() == SkPaint::kFill_Style ? "true" : "fal se");
93 TRACE_EVENT0("skia", strdup(tmpbuf));
94 // if the path is filled, and there's a mask filter, more expensive
95 // FIXME: this isn't correctly detecting yet; no paths are taking
96 // the branch. See SkDraw::drawPath() for the code we're attempting
97 // to reproduce.
98 bool doFill = true;
99 if (paint.getPathEffect() || paint.getStyle() != SkPaint::kFill_Style) {
100 TRACE_EVENT0("skia", "Checking fill path...");
101 SkPath tmpPath;
102 doFill = paint.getFillPath(path, &tmpPath, &clip_);
103 }
104 if (doFill && paint.getMaskFilter()) {
105 TRACE_EVENT0("skia", "Found filled masked path; ouch!");
106 estimatedCost_ += 100;
107 }
108 if (!paint.getMaskFilter()) {
109 TRACE_EVENT0("skia", "No mask filter.");
110 }
111 ++estimatedCost_;
112
113 }
114
115 void AnalysisCanvas::drawBitmap(const SkBitmap&, SkScalar, SkScalar,
116 const SkPaint&) {
117 ++estimatedCost_;
118 }
119
120 void AnalysisCanvas::drawBitmapRectToRect(const SkBitmap&, const SkRect*,
121 const SkRect&, const SkPaint*) {
122 ++estimatedCost_;
123 }
124
125 void AnalysisCanvas::drawBitmapMatrix(const SkBitmap&, const SkMatrix&,
126 const SkPaint*) {
127 ++estimatedCost_;
128 }
129
130 void AnalysisCanvas::drawBitmapNine(const SkBitmap&, const SkIRect&,
131 const SkRect&, const SkPaint*) {
132 ++estimatedCost_;
133 }
134
135 void AnalysisCanvas::drawSprite(const SkBitmap&, int left, int top,
136 const SkPaint*) {
137 ++estimatedCost_;
138 }
139
140 void AnalysisCanvas::drawText(const void*, size_t, SkScalar, SkScalar,
141 const SkPaint&) {
142 ++estimatedCost_;
143 }
144
145 void AnalysisCanvas::drawPosText(const void*, size_t, const SkPoint [],
146 const SkPaint&) {
147 // FIXME: sometimes very expensive
148 // NOT proportional to length: we see ~40B inputs taking 10-500 us
149 // The difference seems to be cache misses; every miss adds 10-30 us,
150 // and we might see 8 misses in 52B and spend >200us drawing a string
151 // immediately after drawing a 48B string in 2us (!) with no misses.
152 // https://code.google.com/p/skia/issues/detail?id=1102
153 ++estimatedCost_;
154 }
155
156 void AnalysisCanvas::drawPosTextH(const void*, size_t, const SkScalar [],
157 SkScalar, const SkPaint&) {
158 ++estimatedCost_;
159 }
160
161 void AnalysisCanvas::drawTextOnPath(const void*, size_t, const SkPath&,
162 const SkMatrix*, const SkPaint&) {
163 ++estimatedCost_;
164 }
165
166 void AnalysisCanvas::drawVertices(VertexMode, int, const SkPoint [],
167 const SkPoint [], const SkColor [],
168 SkXfermode*,
169 const uint16_t [], int, const SkPaint&) {
170 ++estimatedCost_;
171 }
172
173 void AnalysisCanvas::drawData(const void*, size_t) {
174 ++estimatedCost_;
175 }
176
177 bool AnalysisCanvas::isCheap() const { 148 bool AnalysisCanvas::isCheap() const {
178 return estimatedCost_ < gPictureCostThreshold; 149 return getEstimatedCost() < gPictureCostThreshold;
179 } 150 }
180 151
181 int AnalysisCanvas::getEstimatedCost() const { 152 int AnalysisCanvas::getEstimatedCost() const {
182 return estimatedCost_; 153 return ((AnalysisDevice*)getDevice())->getEstimatedCost();
183 } 154 }
184 155
185 156 bool AnalysisCanvas::clipRect(const SkRect& rect, SkRegion::Op op,
186 void AnalysisCanvas::reset(SkRect clip) { 157 bool doAA) {
187 estimatedCost_ = 0; 158 return SkCanvas::clipRect(rect, op, doAA);
188 clip_ = clip;
189 SkIRect ir;
190 clip.roundOut(&ir);
191 this->setClipRegion(SkRegion(ir));
192 } 159 }
193 160
161 bool AnalysisCanvas::clipPath(const SkPath& path, SkRegion::Op op,
162 bool doAA) {
163 return SkCanvas::clipPath(path, op, doAA);
164 }
194 165
166 bool AnalysisCanvas::clipRRect(const SkRRect& rrect, SkRegion::Op op,
167 bool doAA) {
168 return SkCanvas::clipRect(rrect.getBounds(), op, doAA);
169 }
195 170
171 int AnalysisCanvas::saveLayer(const SkRect* bounds, const SkPaint*,
172 SkCanvas::SaveFlags flags) {
173 int count = SkCanvas::save(flags);
174 if (bounds) {
175 SkCanvas::clipRectBounds(bounds, flags, NULL);
176 }
177 return count;
178 }
179
180
196 } // namespace skia 181 } // namespace skia
197 182
198 183
OLDNEW
« cc/picture.cc ('K') | « skia/ext/analysis_canvas.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698