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

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 junov's comments, add missing SK_API 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
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 int gPictureCostThreshold = 1000;
Sami 2013/02/06 17:41:47 This could be a const (kPictureCostThreshold), rig
Tom Hudson 2013/02/06 17:53:36 Done.
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 //TRACE_EVENT0("skia", "Who was that masked rect?");
Sami 2013/02/06 17:41:47 Did you mean to leave this in?
Tom Hudson 2013/02/06 17:53:36 Done.
56 estimatedCost_ += 300;
57 }
58 ++estimatedCost_;
59 }
60
61 void AnalysisDevice::drawOval(const SkDraw&, const SkRect& oval,
62 const SkPaint& paint) {
63 ++estimatedCost_;
64 }
65
66 void AnalysisDevice::drawPath(const SkDraw&, const SkPath& path,
67 const SkPaint& paint,
68 const SkMatrix* prePathMatrix ,
69 bool pathIsMutable ) {
70 // On Z620, every antialiased path costs us about 300us.
71 // We've only seen this in practice on filled paths, but
72 // we expect it to apply to all path stroking modes.
73 if (paint.getMaskFilter()) {
74 //TRACE_EVENT0("skia", "Who was that masked path?");
Sami 2013/02/06 17:41:47 Ditto.
Tom Hudson 2013/02/06 17:53:36 Done.
75 estimatedCost_ += 300;
76 }
77 ++estimatedCost_;
78 }
79
80 void AnalysisDevice::drawBitmap(const SkDraw&, const SkBitmap& bitmap,
81 const SkIRect* srcRectOrNull,
82 const SkMatrix& matrix, const SkPaint& paint)
83 {
84 ++estimatedCost_;
85 }
86
87 void AnalysisDevice::drawSprite(const SkDraw&, const SkBitmap& bitmap,
88 int x, int y, const SkPaint& paint) {
89 ++estimatedCost_;
90 }
91
92 void AnalysisDevice::drawBitmapRect(const SkDraw&, const SkBitmap&,
93 const SkRect* srcOrNull, const SkRect& dst,
94 const SkPaint& paint) {
95 ++estimatedCost_;
96 }
97
98
99 void AnalysisDevice::drawText(const SkDraw&, const void* text, size_t len,
100 SkScalar x, SkScalar y, const SkPaint& paint)
101 {
102 ++estimatedCost_;
103 }
104
105 void AnalysisDevice::drawPosText(const SkDraw& draw, const void* text, size_t le n,
106 const SkScalar pos[], SkScalar constY,
107 int scalarsPerPos, const SkPaint& paint) {
108 // FIXME: On Z620, every glyph cache miss costs us about 10us.
109 // We don't have a good mechanism for predicting glyph cache misses.
110 ++estimatedCost_;
111 }
112
113 void AnalysisDevice::drawTextOnPath(const SkDraw&, const void* text, size_t len,
114 const SkPath& path, const SkMatrix* matrix,
115 const SkPaint& paint) {
116 ++estimatedCost_;
117 }
118
119 #ifdef SK_BUILD_FOR_ANDROID
120 void AnalysisDevice::drawPosTextOnPath(const SkDraw& draw, const void* text,
121 size_t len,
122 const SkPoint pos[], const SkPaint& paint,
123 const SkPath& path, const SkMatrix* matrix)
124 {
125 ++estimatedCost_;
126 }
127 #endif
128
129 void AnalysisDevice::drawVertices(const SkDraw&, SkCanvas::VertexMode,
130 int vertexCount,
131 const SkPoint verts[], const SkPoint texs[],
132 const SkColor colors[], SkXfermode* xmode,
133 const uint16_t indices[], int indexCount,
134 const SkPaint& paint) {
135 ++estimatedCost_;
136 }
137
138 void AnalysisDevice::drawDevice(const SkDraw&, SkDevice*, int x, int y,
139 const SkPaint&) {
140 ++estimatedCost_;
141 }
142
143
144
145
146 AnalysisCanvas::AnalysisCanvas(AnalysisDevice* device)
147 : INHERITED(device) {
148
149 }
150
151 AnalysisCanvas::~AnalysisCanvas() {
152 }
153
154
155 bool AnalysisCanvas::isCheap() const {
156 return getEstimatedCost() < gPictureCostThreshold;
157 }
158
159 int AnalysisCanvas::getEstimatedCost() const {
160 return ((AnalysisDevice*)getDevice())->getEstimatedCost();
Sami 2013/02/06 17:41:47 static_cast<> maybe?
Tom Hudson 2013/02/06 17:53:36 Done.
161 }
162
163
164 bool AnalysisCanvas::clipRect(const SkRect& rect, SkRegion::Op op,
165 bool doAA) {
166 return INHERITED::clipRect(rect, op, doAA);
167 }
168
169 bool AnalysisCanvas::clipPath(const SkPath& path, SkRegion::Op op,
170 bool doAA) {
171 return INHERITED::clipRect(path.getBounds(), op, doAA);
172 }
173
174 bool AnalysisCanvas::clipRRect(const SkRRect& rrect, SkRegion::Op op,
175 bool doAA) {
176 return INHERITED::clipRect(rrect.getBounds(), op, doAA);
177 }
178
179 int AnalysisCanvas::saveLayer(const SkRect* bounds, const SkPaint*,
180 SkCanvas::SaveFlags flags) {
181 // Actually saving a layer here could cause a new bitmap to be created
182 // and real rendering to occur.
183 int count = SkCanvas::save(flags);
184 if (bounds) {
185 INHERITED::clipRectBounds(bounds, flags, NULL);
186 }
187 return count;
188 }
189
190 } // namespace skia
191
192
OLDNEW
« skia/ext/analysis_canvas.h ('K') | « skia/ext/analysis_canvas.h ('k') | skia/skia.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698