• Home
  • History
  • Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2013 Google Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
8  *     * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *     * Redistributions in binary form must reproduce the above
11  * copyright notice, this list of conditions and the following disclaimer
12  * in the documentation and/or other materials provided with the
13  * distribution.
14  *     * Neither the name of Google Inc. nor the names of its
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 #include "config.h"
32 #include "platform/graphics/ProfilingCanvas.h"
33 
34 #include "wtf/CurrentTime.h"
35 
36 namespace blink {
37 
38 class AutoStamper {
39 public:
40     explicit AutoStamper(ProfilingCanvas*);
41     ~AutoStamper();
42 
43 private:
44     ProfilingCanvas* m_profilingCanvas;
45     double m_startTime;
46 };
47 
AutoStamper(ProfilingCanvas * profilingCanvas)48 AutoStamper::AutoStamper(ProfilingCanvas* profilingCanvas) : m_profilingCanvas(profilingCanvas)
49 {
50     profilingCanvas->m_depthCount++;
51     m_startTime = WTF::monotonicallyIncreasingTime();
52 }
53 
~AutoStamper()54 AutoStamper::~AutoStamper()
55 {
56     m_profilingCanvas->m_depthCount--;
57     if (m_profilingCanvas->m_depthCount)
58         return;
59     double delta = WTF::monotonicallyIncreasingTime() - m_startTime;
60     m_profilingCanvas->m_timings->append(delta);
61 }
62 
ProfilingCanvas(SkBitmap bitmap)63 ProfilingCanvas::ProfilingCanvas(SkBitmap bitmap) : InterceptingCanvas(bitmap)
64 {
65 }
66 
setTimings(Vector<double> * timings)67 void ProfilingCanvas::setTimings(Vector<double>* timings)
68 {
69     m_timings = timings;
70 }
71 
clear(SkColor color)72 void ProfilingCanvas::clear(SkColor color)
73 {
74     AutoStamper stamper(this);
75     this->SkCanvas::clear(color);
76 }
77 
drawPaint(const SkPaint & paint)78 void ProfilingCanvas::drawPaint(const SkPaint& paint)
79 {
80     AutoStamper stamper(this);
81     this->SkCanvas::drawPaint(paint);
82 }
83 
drawPoints(PointMode mode,size_t count,const SkPoint pts[],const SkPaint & paint)84 void ProfilingCanvas::drawPoints(PointMode mode, size_t count, const SkPoint pts[], const SkPaint& paint)
85 {
86     AutoStamper stamper(this);
87     this->SkCanvas::drawPoints(mode, count, pts, paint);
88 }
89 
drawRect(const SkRect & rect,const SkPaint & paint)90 void ProfilingCanvas::drawRect(const SkRect& rect, const SkPaint& paint)
91 {
92     AutoStamper stamper(this);
93     this->SkCanvas::drawRect(rect, paint);
94 }
95 
drawOval(const SkRect & rect,const SkPaint & paint)96 void ProfilingCanvas::drawOval(const SkRect& rect, const SkPaint& paint)
97 {
98     AutoStamper stamper(this);
99     this->SkCanvas::drawOval(rect, paint);
100 }
101 
drawRRect(const SkRRect & rrect,const SkPaint & paint)102 void ProfilingCanvas::drawRRect(const SkRRect& rrect, const SkPaint& paint)
103 {
104     AutoStamper stamper(this);
105     this->SkCanvas::drawRRect(rrect, paint);
106 }
107 
drawPath(const SkPath & path,const SkPaint & paint)108 void ProfilingCanvas::drawPath(const SkPath& path, const SkPaint& paint)
109 {
110     AutoStamper stamper(this);
111     this->SkCanvas::drawPath(path, paint);
112 }
113 
drawBitmap(const SkBitmap & bitmap,SkScalar left,SkScalar top,const SkPaint * paint)114 void ProfilingCanvas::drawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top, const SkPaint* paint)
115 {
116     AutoStamper stamper(this);
117     this->SkCanvas::drawBitmap(bitmap, left, top, paint);
118 }
119 
drawBitmapRectToRect(const SkBitmap & bitmap,const SkRect * src,const SkRect & dst,const SkPaint * paint,DrawBitmapRectFlags flags)120 void ProfilingCanvas::drawBitmapRectToRect(const SkBitmap& bitmap, const SkRect* src, const SkRect& dst,
121     const SkPaint* paint, DrawBitmapRectFlags flags)
122 {
123     AutoStamper stamper(this);
124     this->SkCanvas::drawBitmapRectToRect(bitmap, src, dst, paint, flags);
125 }
126 
drawBitmapMatrix(const SkBitmap & bitmap,const SkMatrix & m,const SkPaint * paint)127 void ProfilingCanvas::drawBitmapMatrix(const SkBitmap& bitmap, const SkMatrix& m, const SkPaint* paint)
128 {
129     AutoStamper stamper(this);
130     this->SkCanvas::drawBitmapMatrix(bitmap, m, paint);
131 }
132 
drawBitmapNine(const SkBitmap & bitmap,const SkIRect & center,const SkRect & dst,const SkPaint * paint)133 void ProfilingCanvas::drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, const SkRect& dst, const SkPaint* paint)
134 {
135     AutoStamper stamper(this);
136     this->SkCanvas::drawBitmapNine(bitmap, center, dst, paint);
137 }
138 
drawSprite(const SkBitmap & bitmap,int left,int top,const SkPaint * paint)139 void ProfilingCanvas::drawSprite(const SkBitmap& bitmap, int left, int top, const SkPaint* paint)
140 {
141     AutoStamper stamper(this);
142     this->SkCanvas::drawSprite(bitmap, left, top, paint);
143 }
144 
drawVertices(VertexMode vmode,int vertexCount,const SkPoint vertices[],const SkPoint texs[],const SkColor colors[],SkXfermode * xmode,const uint16_t indices[],int indexCount,const SkPaint & paint)145 void ProfilingCanvas::drawVertices(VertexMode vmode, int vertexCount, const SkPoint vertices[], const SkPoint texs[],
146     const SkColor colors[], SkXfermode* xmode, const uint16_t indices[], int indexCount, const SkPaint& paint)
147 {
148     AutoStamper stamper(this);
149     this->SkCanvas::drawVertices(vmode, vertexCount, vertices, texs, colors, xmode, indices, indexCount, paint);
150 }
151 
drawData(const void * data,size_t length)152 void ProfilingCanvas::drawData(const void* data, size_t length)
153 {
154     AutoStamper stamper(this);
155     this->SkCanvas::drawData(data, length);
156 }
157 
beginCommentGroup(const char * description)158 void ProfilingCanvas::beginCommentGroup(const char* description)
159 {
160     AutoStamper stamper(this);
161     this->SkCanvas::beginCommentGroup(description);
162 }
163 
addComment(const char * keyword,const char * value)164 void ProfilingCanvas::addComment(const char* keyword, const char* value)
165 {
166     AutoStamper stamper(this);
167     this->SkCanvas::addComment(keyword, value);
168 }
169 
endCommentGroup()170 void ProfilingCanvas::endCommentGroup()
171 {
172     AutoStamper stamper(this);
173     this->SkCanvas::endCommentGroup();
174 }
175 
onDrawDRRect(const SkRRect & outer,const SkRRect & inner,const SkPaint & paint)176 void ProfilingCanvas::onDrawDRRect(const SkRRect& outer, const SkRRect& inner, const SkPaint& paint)
177 {
178     AutoStamper stamper(this);
179     this->SkCanvas::onDrawDRRect(outer, inner, paint);
180 }
181 
onDrawText(const void * text,size_t byteLength,SkScalar x,SkScalar y,const SkPaint & paint)182 void ProfilingCanvas::onDrawText(const void* text, size_t byteLength, SkScalar x, SkScalar y, const SkPaint& paint)
183 {
184     AutoStamper stamper(this);
185     this->SkCanvas::onDrawText(text, byteLength, x, y, paint);
186 }
187 
onDrawPosText(const void * text,size_t byteLength,const SkPoint pos[],const SkPaint & paint)188 void ProfilingCanvas::onDrawPosText(const void* text, size_t byteLength, const SkPoint pos[], const SkPaint& paint)
189 {
190     AutoStamper stamper(this);
191     this->SkCanvas::onDrawPosText(text, byteLength, pos, paint);
192 }
193 
onDrawPosTextH(const void * text,size_t byteLength,const SkScalar xpos[],SkScalar constY,const SkPaint & paint)194 void ProfilingCanvas::onDrawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[], SkScalar constY, const SkPaint& paint)
195 {
196     AutoStamper stamper(this);
197     this->SkCanvas::onDrawPosTextH(text, byteLength, xpos, constY, paint);
198 }
199 
onDrawTextOnPath(const void * text,size_t byteLength,const SkPath & path,const SkMatrix * matrix,const SkPaint & paint)200 void ProfilingCanvas::onDrawTextOnPath(const void* text, size_t byteLength, const SkPath& path, const SkMatrix* matrix, const SkPaint& paint)
201 {
202     AutoStamper stamper(this);
203     this->SkCanvas::onDrawTextOnPath(text, byteLength, path, matrix, paint);
204 }
205 
onPushCull(const SkRect & cullRect)206 void ProfilingCanvas::onPushCull(const SkRect& cullRect)
207 {
208     AutoStamper stamper(this);
209     this->SkCanvas::onPushCull(cullRect);
210 }
211 
onPopCull()212 void ProfilingCanvas::onPopCull()
213 {
214     AutoStamper stamper(this);
215     this->SkCanvas::onPopCull();
216 }
217 
onClipRect(const SkRect & rect,SkRegion::Op op,ClipEdgeStyle edgeStyle)218 void ProfilingCanvas::onClipRect(const SkRect& rect, SkRegion::Op op, ClipEdgeStyle edgeStyle)
219 {
220     AutoStamper stamper(this);
221     this->SkCanvas::onClipRect(rect, op, edgeStyle);
222 }
223 
onClipRRect(const SkRRect & rrect,SkRegion::Op op,ClipEdgeStyle edgeStyle)224 void ProfilingCanvas::onClipRRect(const SkRRect& rrect, SkRegion::Op op, ClipEdgeStyle edgeStyle)
225 {
226     AutoStamper stamper(this);
227     this->SkCanvas::onClipRRect(rrect, op, edgeStyle);
228 }
229 
onClipPath(const SkPath & path,SkRegion::Op op,ClipEdgeStyle edgeStyle)230 void ProfilingCanvas::onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeStyle edgeStyle)
231 {
232     AutoStamper stamper(this);
233     this->SkCanvas::onClipPath(path, op, edgeStyle);
234 }
235 
onClipRegion(const SkRegion & region,SkRegion::Op op)236 void ProfilingCanvas::onClipRegion(const SkRegion& region, SkRegion::Op op)
237 {
238     AutoStamper stamper(this);
239     this->SkCanvas::onClipRegion(region, op);
240 }
241 
onDrawPicture(const SkPicture * picture,const SkMatrix * matrix,const SkPaint * paint)242 void ProfilingCanvas::onDrawPicture(const SkPicture* picture, const SkMatrix* matrix, const SkPaint* paint)
243 {
244     AutoStamper stamper(this);
245     this->SkCanvas::onDrawPicture(picture, matrix, paint);
246 }
247 
didSetMatrix(const SkMatrix & matrix)248 void ProfilingCanvas::didSetMatrix(const SkMatrix& matrix)
249 {
250     AutoStamper stamper(this);
251     this->SkCanvas::didSetMatrix(matrix);
252 }
253 
didConcat(const SkMatrix & matrix)254 void ProfilingCanvas::didConcat(const SkMatrix& matrix)
255 {
256     AutoStamper stamper(this);
257     this->SkCanvas::didConcat(matrix);
258 }
259 
willSave()260 void ProfilingCanvas::willSave()
261 {
262     AutoStamper stamper(this);
263     this->SkCanvas::willSave();
264 }
265 
willSaveLayer(const SkRect * bounds,const SkPaint * paint,SaveFlags flags)266 SkCanvas::SaveLayerStrategy ProfilingCanvas::willSaveLayer(const SkRect* bounds, const SkPaint* paint, SaveFlags flags)
267 {
268     AutoStamper stamper(this);
269     return this->SkCanvas::willSaveLayer(bounds, paint, flags);
270 }
271 
willRestore()272 void ProfilingCanvas::willRestore()
273 {
274     AutoStamper stamper(this);
275     this->SkCanvas::willRestore();
276 }
277 
278 } // namespace blink
279