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

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

Issue 12184010: skia::AnalysisCanvas: implementation for IsCheapInRect(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Wrote device boilerplate 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
8 namespace skia {
9
10 AnalysisDevice::AnalysisDevice(const SkBitmap& bm) : SkDevice(bm) { }
11
12 AnalysisCanvas::AnalysisCanvas(SkDevice* device, SkRect clip)
13 : SkCanvas(device)
14 , estimatedCost_(0)
15 , clip_(clip) {
16 SkIRect ir;
17 clip.roundOut(&ir);
18 this->setClipRegion(SkRegion(ir));
19 }
20
21 AnalysisCanvas::~AnalysisCanvas() {
22
23 }
24
25
26 int AnalysisCanvas::save(SkCanvas::SaveFlags) {
Justin Novosad 2013/02/04 22:03:31 Some forward thinking here... In a future iteratio
27 ++estimatedCost_;
28 }
29
30 int AnalysisCanvas::saveLayer(const SkRect*, const SkPaint*,
31 SkCanvas::SaveFlags) {
32 ++estimatedCost_;
Justin Novosad 2013/02/04 22:03:31 In the case of save layer we want to flow-through
Tom Hudson 2013/02/05 17:02:00 Done. I'm not sure about the clipRectBounds, thou
33 }
34
35 void AnalysisCanvas::restore() {
36 ++estimatedCost_;
Justin Novosad 2013/02/04 22:03:31 flow-though
37 }
38
39 bool AnalysisCanvas::clipRect(const SkRect&, SkRegion::Op, bool) {
40 ++estimatedCost_;
Justin Novosad 2013/02/04 22:03:31 You want this to flow-through to base class, force
Tom Hudson 2013/02/05 17:02:00 Done. I'm not sure about forcing AA to false, tho
41 }
42
43 bool AnalysisCanvas::clipRRect(const SkRRect&, SkRegion::Op, bool) {
44 ++estimatedCost_;
Justin Novosad 2013/02/04 22:03:31 We need this to flow-through to base class, but we
45 }
46
47 bool AnalysisCanvas::clipPath(const SkPath&, SkRegion::Op, bool) {
48 ++estimatedCost_;
Justin Novosad 2013/02/04 22:03:31 Same here, redirect to clipRect with path.bounds,
49 }
50
51 bool AnalysisCanvas::clipRegion(const SkRegion&, SkRegion::Op) {
52 ++estimatedCost_;
53 }
54
55 void AnalysisCanvas::clear(SkColor) {
56 ++estimatedCost_;
57 }
58
59 void AnalysisCanvas::drawPaint(const SkPaint&) {
60 ++estimatedCost_;
61 }
62
63 void AnalysisCanvas::drawPoints(PointMode, size_t, const SkPoint [],
64 const SkPaint&) {
65 ++estimatedCost_;
66 }
67
68 void AnalysisCanvas::drawRect(const SkRect&, const SkPaint&) {
69 // FIXME: if there's a pending image decode & resize, more expensive
70 ++estimatedCost_;
71 }
72
73 void AnalysisCanvas::drawOval(const SkRect&, const SkPaint&) {
74 ++estimatedCost_;
75 }
76
77 void AnalysisCanvas::drawRRect(const SkRRect&, const SkPaint&) {
78 ++estimatedCost_;
79 }
80
81 void AnalysisCanvas::drawPath(const SkPath& path, const SkPaint& paint) {
82 char tmpbuf [256];
83 sprintf(tmpbuf, "AnalysisCanvas::drawPath effect %s fill %s", paint.getPathEffec t() ? "true" : "false", paint.getStyle() == SkPaint::kFill_Style ? "true" : "fal se");
84 TRACE_EVENT0("skia", strdup(tmpbuf));
85 // if the path is filled, and there's a mask filter, more expensive
86 // FIXME: this isn't correctly detecting yet; no paths are taking
87 // the branch. See SkDraw::drawPath() for the code we're attempting
88 // to reproduce. Although none of the drawPath calls have a mask filter
89 // attached at analysis time, on entry to SkDraw::drawPath the expensive
90 // ones do!
91 bool doFill = true;
92 if (paint.getPathEffect() || paint.getStyle() != SkPaint::kFill_Style) {
93 TRACE_EVENT0("skia", "Checking fill path...");
94 SkPath tmpPath;
95 doFill = paint.getFillPath(path, &tmpPath, &clip_);
96 }
97 if (doFill && paint.getMaskFilter()) {
Justin Novosad 2013/02/04 22:03:31 The Mask filter should result in the same perf pen
Tom Hudson 2013/02/05 10:23:24 You're correct, but right now I have evidence of s
Tom Hudson 2013/02/05 17:02:00 Done.
98 TRACE_EVENT0("skia", "Found filled masked path; ouch!");
99 estimatedCost_ += 100;
Justin Novosad 2013/02/04 22:03:31 Cost of mask filter does not depend on fill vs. st
100 }
101 if (!paint.getMaskFilter()) {
102 TRACE_EVENT0("skia", "No mask filter.");
103 }
104 ++estimatedCost_;
105
106 }
107
108 void AnalysisCanvas::drawBitmap(const SkBitmap&, SkScalar, SkScalar,
109 const SkPaint&) {
110 ++estimatedCost_;
Justin Novosad 2013/02/04 22:03:31 If you gathered stats in an SkDevice-derived class
Tom Hudson 2013/02/05 17:02:00 Done.
111 }
112
113 void AnalysisCanvas::drawBitmapRectToRect(const SkBitmap&, const SkRect*,
114 const SkRect&, const SkPaint*) {
115 ++estimatedCost_;
116 }
117
118 void AnalysisCanvas::drawBitmapMatrix(const SkBitmap&, const SkMatrix&,
119 const SkPaint*) {
120 ++estimatedCost_;
121 }
122
123 void AnalysisCanvas::drawBitmapNine(const SkBitmap&, const SkIRect&,
124 const SkRect&, const SkPaint*) {
125 ++estimatedCost_;
126 }
127
128 void AnalysisCanvas::drawSprite(const SkBitmap&, int left, int top,
129 const SkPaint*) {
130 ++estimatedCost_;
131 }
132
133 void AnalysisCanvas::drawText(const void*, size_t, SkScalar, SkScalar,
Justin Novosad 2013/02/04 22:03:31 If you gathered stats in an SkDevice-derived class
Tom Hudson 2013/02/05 17:02:00 Done.
134 const SkPaint&) {
135 ++estimatedCost_;
136 }
137
138 void AnalysisCanvas::drawPosText(const void*, size_t, const SkPoint [],
139 const SkPaint&) {
140 // FIXME: sometimes very expensive
141 // NOT proportional to length: we see ~40B inputs taking 10-500 us
142 // The difference seems to be cache misses; every miss adds 10-30 us,
143 // and we might see 8 misses in 52B and spend >200us drawing a string
144 // immediately after drawing a 48B string in 2us (!) with no misses.
145 // https://code.google.com/p/skia/issues/detail?id=1102
146 ++estimatedCost_;
147 }
148
149 void AnalysisCanvas::drawPosTextH(const void*, size_t, const SkScalar [],
150 SkScalar, const SkPaint&) {
151 ++estimatedCost_;
152 }
153
154 void AnalysisCanvas::drawTextOnPath(const void*, size_t, const SkPath&,
155 const SkMatrix*, const SkPaint&) {
156 ++estimatedCost_;
157 }
158
159 void AnalysisCanvas::drawVertices(VertexMode, int, const SkPoint [],
160 const SkPoint [], const SkColor [],
161 SkXfermode*,
162 const uint16_t [], int, const SkPaint&) {
163 ++estimatedCost_;
164 }
165
166 void AnalysisCanvas::drawData(const void*, size_t) {
167 ++estimatedCost_;
168 }
169
170
171 int AnalysisCanvas::getEstimatedCost() const {
172 return estimatedCost_;
173 }
174
175
176 void AnalysisCanvas::reset(SkRect clip) {
177 estimatedCost_ = 0;
178 clip_ = clip;
179 SkIRect ir;
180 clip.roundOut(&ir);
181 this->setClipRegion(SkRegion(ir));
182 }
183
184
185
186 } // namespace skia
187
188
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