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

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: Respond to skyostil's comments 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
« no previous file with comments | « skia/ext/analysis_canvas.h ('k') | skia/skia.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "base/debug/trace_event.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"
11
12 namespace {
13
14 // FIXME: Arbitrary number. Requires tuning & experimentation.
15 // Probably requires per-platform tuning; N10 average draw call takes
16 // 25x as long as Z620.
17 const int gPictureCostThreshold = 1000;
18
19 }
20
21 namespace skia {
22
23 AnalysisDevice::AnalysisDevice(const SkBitmap& bm)
24 : INHERITED(bm)
25 , estimatedCost_(0) {
26
27 }
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 if (paint.getMaskFilter()) {
55 estimatedCost_ += 300;
56 }
57 ++estimatedCost_;
58 }
59
60 void AnalysisDevice::drawOval(const SkDraw&, const SkRect& oval,
61 const SkPaint& paint) {
62 ++estimatedCost_;
63 }
64
65 void AnalysisDevice::drawPath(const SkDraw&, const SkPath& path,
66 const SkPaint& paint,
67 const SkMatrix* prePathMatrix ,
68 bool pathIsMutable ) {
69 // On Z620, every antialiased path costs us about 300us.
70 // We've only seen this in practice on filled paths, but
71 // we expect it to apply to all path stroking modes.
72 if (paint.getMaskFilter()) {
73 estimatedCost_ += 300;
74 }
75 ++estimatedCost_;
76 }
77
78 void AnalysisDevice::drawBitmap(const SkDraw&, const SkBitmap& bitmap,
79 const SkIRect* srcRectOrNull,
80 const SkMatrix& matrix, const SkPaint& paint)
81 {
82 ++estimatedCost_;
83 }
84
85 void AnalysisDevice::drawSprite(const SkDraw&, const SkBitmap& bitmap,
86 int x, int y, const SkPaint& paint) {
87 ++estimatedCost_;
88 }
89
90 void AnalysisDevice::drawBitmapRect(const SkDraw&, const SkBitmap&,
91 const SkRect* srcOrNull, const SkRect& dst,
92 const SkPaint& paint) {
93 ++estimatedCost_;
94 }
95
96
97 void AnalysisDevice::drawText(const SkDraw&, const void* text, size_t len,
98 SkScalar x, SkScalar y, const SkPaint& paint)
99 {
100 ++estimatedCost_;
101 }
102
103 void AnalysisDevice::drawPosText(const SkDraw& draw, const void* text, size_t le n,
104 const SkScalar pos[], SkScalar constY,
105 int scalarsPerPos, const SkPaint& paint) {
106 // FIXME: On Z620, every glyph cache miss costs us about 10us.
107 // We don't have a good mechanism for predicting glyph cache misses.
108 ++estimatedCost_;
109 }
110
111 void AnalysisDevice::drawTextOnPath(const SkDraw&, const void* text, size_t len,
112 const SkPath& path, const SkMatrix* matrix,
113 const SkPaint& paint) {
114 ++estimatedCost_;
115 }
116
117 #ifdef SK_BUILD_FOR_ANDROID
118 void AnalysisDevice::drawPosTextOnPath(const SkDraw& draw, const void* text,
119 size_t len,
120 const SkPoint pos[], const SkPaint& paint,
121 const SkPath& path, const SkMatrix* matrix)
122 {
123 ++estimatedCost_;
124 }
125 #endif
126
127 void AnalysisDevice::drawVertices(const SkDraw&, SkCanvas::VertexMode,
128 int vertexCount,
129 const SkPoint verts[], const SkPoint texs[],
130 const SkColor colors[], SkXfermode* xmode,
131 const uint16_t indices[], int indexCount,
132 const SkPaint& paint) {
133 ++estimatedCost_;
134 }
135
136 void AnalysisDevice::drawDevice(const SkDraw&, SkDevice*, int x, int y,
137 const SkPaint&) {
138 ++estimatedCost_;
139 }
140
141
142
143
144 AnalysisCanvas::AnalysisCanvas(AnalysisDevice* device)
145 : INHERITED(device) {
146
147 }
148
149 AnalysisCanvas::~AnalysisCanvas() {
150 }
151
152
153 bool AnalysisCanvas::isCheap() const {
154 return getEstimatedCost() < gPictureCostThreshold;
155 }
156
157 int AnalysisCanvas::getEstimatedCost() const {
158 return (static_cast<AnalysisDevice*>(getDevice()))->getEstimatedCost();
159 }
160
161
162 bool AnalysisCanvas::clipRect(const SkRect& rect, SkRegion::Op op,
163 bool doAA) {
164 return INHERITED::clipRect(rect, op, doAA);
165 }
166
167 bool AnalysisCanvas::clipPath(const SkPath& path, SkRegion::Op op,
168 bool doAA) {
169 return INHERITED::clipRect(path.getBounds(), op, doAA);
170 }
171
172 bool AnalysisCanvas::clipRRect(const SkRRect& rrect, SkRegion::Op op,
173 bool doAA) {
174 return INHERITED::clipRect(rrect.getBounds(), op, doAA);
175 }
176
177 int AnalysisCanvas::saveLayer(const SkRect* bounds, const SkPaint*,
178 SkCanvas::SaveFlags flags) {
179 // Actually saving a layer here could cause a new bitmap to be created
180 // and real rendering to occur.
181 int count = SkCanvas::save(flags);
182 if (bounds) {
183 INHERITED::clipRectBounds(bounds, flags, NULL);
184 }
185 return count;
186 }
187
188 } // namespace skia
189
190
OLDNEW
« no previous file with comments | « skia/ext/analysis_canvas.h ('k') | skia/skia.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698