blob: 0e4134fa939a37d99d54d3112204367dd5d9052a [file] [log] [blame]
caryclark@google.com411bb722012-11-06 21:29:16 +00001/*
keyar@chromium.org451bb9f2012-07-26 17:27:57 +00002 * Copyright 2012 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#ifndef PictureRenderer_DEFINED
9#define PictureRenderer_DEFINED
scroggo@google.coma62da2f2012-11-02 21:28:12 +000010
11#include "SkCountdown.h"
caryclark@google.coma3622372012-11-06 21:26:13 +000012#include "SkDrawFilter.h"
keyar@chromium.orgf4959ab2012-08-23 20:53:25 +000013#include "SkMath.h"
reed@google.comea6a3062012-11-06 22:14:54 +000014#include "SkPaint.h"
scroggo@google.com9a412522012-09-07 15:21:18 +000015#include "SkPicture.h"
scroggo@google.comacfb30e2012-09-18 14:32:35 +000016#include "SkRect.h"
keyar@chromium.org451bb9f2012-07-26 17:27:57 +000017#include "SkRefCnt.h"
scroggo@google.coma62da2f2012-11-02 21:28:12 +000018#include "SkRunnable.h"
scroggo@google.com9a412522012-09-07 15:21:18 +000019#include "SkString.h"
scroggo@google.coma62da2f2012-11-02 21:28:12 +000020#include "SkTDArray.h"
21#include "SkThreadPool.h"
22#include "SkTypes.h"
keyar@chromium.org451bb9f2012-07-26 17:27:57 +000023
keyar@chromium.org06125642012-08-20 15:03:33 +000024#if SK_SUPPORT_GPU
25#include "GrContextFactory.h"
26#include "GrContext.h"
27#endif
28
keyar@chromium.org451bb9f2012-07-26 17:27:57 +000029class SkBitmap;
30class SkCanvas;
keyar@chromium.org4ea96c52012-08-20 15:03:29 +000031class SkGLContext;
scroggo@google.coma62da2f2012-11-02 21:28:12 +000032class SkThread;
keyar@chromium.org451bb9f2012-07-26 17:27:57 +000033
34namespace sk_tools {
35
scroggo@google.comcbcef702012-12-13 22:09:28 +000036class TiledPictureRenderer;
37
keyar@chromium.org451bb9f2012-07-26 17:27:57 +000038class PictureRenderer : public SkRefCnt {
scroggo@google.comcbcef702012-12-13 22:09:28 +000039
keyar@chromium.org451bb9f2012-07-26 17:27:57 +000040public:
keyar@chromium.orgc81686c2012-08-20 15:04:04 +000041 enum SkDeviceTypes {
scroggo@google.com0556ea02013-02-08 19:38:21 +000042#if SK_ANGLE
43 kAngle_DeviceType,
44#endif
keyar@chromium.orgc81686c2012-08-20 15:04:04 +000045 kBitmap_DeviceType,
46#if SK_SUPPORT_GPU
scroggo@google.com0556ea02013-02-08 19:38:21 +000047 kGPU_DeviceType,
keyar@chromium.orgc81686c2012-08-20 15:04:04 +000048#endif
49 };
50
junov@chromium.org9313ca42012-11-02 18:11:49 +000051 enum BBoxHierarchyType {
52 kNone_BBoxHierarchyType = 0,
53 kRTree_BBoxHierarchyType,
junov@chromium.org7b537062012-11-06 18:58:43 +000054 kTileGrid_BBoxHierarchyType,
junov@chromium.org9313ca42012-11-02 18:11:49 +000055 };
56
caryclark@google.coma3622372012-11-06 21:26:13 +000057 // this uses SkPaint::Flags as a base and adds additional flags
58 enum DrawFilterFlags {
59 kNone_DrawFilterFlag = 0,
caryclark@google.come3e940c2012-11-07 16:42:17 +000060 kBlur_DrawFilterFlag = 0x4000, // toggles between blur and no blur
reed@google.com457d8a72012-12-18 18:20:44 +000061 kHinting_DrawFilterFlag = 0x8000, // toggles between no hinting and normal hinting
62 kSlightHinting_DrawFilterFlag = 0x10000, // toggles between slight and normal hinting
63 kAAClip_DrawFilterFlag = 0x20000, // toggles between soft and hard clip
caryclark@google.coma3622372012-11-06 21:26:13 +000064 };
65
66 SK_COMPILE_ASSERT(!(kBlur_DrawFilterFlag & SkPaint::kAllFlags), blur_flag_must_be_greater);
67 SK_COMPILE_ASSERT(!(kHinting_DrawFilterFlag & SkPaint::kAllFlags),
68 hinting_flag_must_be_greater);
69 SK_COMPILE_ASSERT(!(kSlightHinting_DrawFilterFlag & SkPaint::kAllFlags),
70 slight_hinting_flag_must_be_greater);
71
scroggo@google.coma62da2f2012-11-02 21:28:12 +000072 /**
73 * Called with each new SkPicture to render.
74 */
keyar@chromium.org9d696c02012-08-07 17:11:33 +000075 virtual void init(SkPicture* pict);
scroggo@google.com9a412522012-09-07 15:21:18 +000076
77 /**
scroggo@google.comc0d5e542012-12-13 21:40:48 +000078 * Set the viewport so that only the portion listed gets drawn.
79 */
80 void setViewport(SkISize size) { fViewport = size; }
81
82 /**
scroggo@google.com82ec0b02012-12-17 19:25:54 +000083 * Set the scale factor at which draw the picture.
84 */
85 void setScaleFactor(SkScalar scale) { fScaleFactor = scale; }
86
87 /**
scroggo@google.com9a412522012-09-07 15:21:18 +000088 * Perform any setup that should done prior to each iteration of render() which should not be
89 * timed.
90 */
91 virtual void setup() {}
92
93 /**
94 * Perform work that is to be timed. Typically this is rendering, but is also used for recording
95 * and preparing picture for playback by the subclasses which do those.
scroggo@google.com81f9d2e2012-09-20 14:54:21 +000096 * If path is non-null, subclass implementations should call write().
97 * @param path If non-null, also write the output to the file specified by path. path should
98 * have no extension; it will be added by write().
borenet@google.com070d3542012-10-26 13:26:55 +000099 * @return bool True if rendering succeeded and, if path is non-null, the output was
100 * successfully written to a file.
scroggo@google.com9a412522012-09-07 15:21:18 +0000101 */
edisonn@google.com84f548c2012-12-18 22:24:03 +0000102 virtual bool render(const SkString* path, SkBitmap** out = NULL) = 0;
scroggo@google.com9a412522012-09-07 15:21:18 +0000103
scroggo@google.coma62da2f2012-11-02 21:28:12 +0000104 /**
105 * Called once finished with a particular SkPicture, before calling init again, and before
106 * being done with this Renderer.
107 */
keyar@chromium.org9d696c02012-08-07 17:11:33 +0000108 virtual void end();
scroggo@google.coma62da2f2012-11-02 21:28:12 +0000109
scroggo@google.comcbcef702012-12-13 22:09:28 +0000110 /**
111 * If this PictureRenderer is actually a TiledPictureRender, return a pointer to this as a
112 * TiledPictureRender so its methods can be called.
113 */
114 virtual TiledPictureRenderer* getTiledRenderer() { return NULL; }
115
scroggo@google.com08085f82013-01-28 20:40:24 +0000116 /**
117 * Resets the GPU's state. Does nothing if the backing is raster. For a GPU renderer, calls
118 * flush, and calls finish if callFinish is true.
119 * @param callFinish Whether to call finish.
120 */
121 void resetState(bool callFinish);
keyar@chromium.org9d696c02012-08-07 17:11:33 +0000122
scroggo@google.com0556ea02013-02-08 19:38:21 +0000123 /**
124 * Set the backend type. Returns true on success and false on failure.
125 */
126 bool setDeviceType(SkDeviceTypes deviceType) {
keyar@chromium.orgc81686c2012-08-20 15:04:04 +0000127 fDeviceType = deviceType;
scroggo@google.com0556ea02013-02-08 19:38:21 +0000128#if SK_SUPPORT_GPU
129 // In case this function is called more than once
130 SkSafeUnref(fGrContext);
131 fGrContext = NULL;
132 // Set to Native so it will have an initial value.
133 GrContextFactory::GLContextType glContextType = GrContextFactory::kNative_GLContextType;
134#endif
135 switch(deviceType) {
136 case kBitmap_DeviceType:
137 return true;
138#if SK_SUPPORT_GPU
139 case kGPU_DeviceType:
140 // Already set to GrContextFactory::kNative_GLContextType, above.
141 break;
142#if SK_ANGLE
143 case kAngle_DeviceType:
144 glContextType = GrContextFactory::kANGLE_GLContextType;
145 break;
146#endif
147#endif
148 default:
149 // Invalid device type.
150 return false;
151 }
152#if SK_SUPPORT_GPU
153 fGrContext = fGrContextFactory.get(glContextType);
154 if (NULL == fGrContext) {
155 return false;
156 } else {
157 fGrContext->ref();
158 return true;
159 }
160#endif
keyar@chromium.orgfe6391a2012-08-20 15:03:41 +0000161 }
162
caryclark@google.come3e940c2012-11-07 16:42:17 +0000163 void setDrawFilters(DrawFilterFlags const * const filters, const SkString& configName) {
164 memcpy(fDrawFilters, filters, sizeof(fDrawFilters));
caryclark@google.coma3622372012-11-06 21:26:13 +0000165 fDrawFiltersConfig = configName;
166 }
167
junov@chromium.org9313ca42012-11-02 18:11:49 +0000168 void setBBoxHierarchyType(BBoxHierarchyType bbhType) {
169 fBBoxHierarchyType = bbhType;
170 }
171
junov@chromium.org7b537062012-11-06 18:58:43 +0000172 void setGridSize(int width, int height) {
173 fGridWidth = width;
174 fGridHeight = height;
175 }
176
keyar@chromium.orgfe6391a2012-08-20 15:03:41 +0000177 bool isUsingBitmapDevice() {
keyar@chromium.org78a35c52012-08-20 15:03:44 +0000178 return kBitmap_DeviceType == fDeviceType;
keyar@chromium.org4ea96c52012-08-20 15:03:29 +0000179 }
180
scroggo@google.com9a412522012-09-07 15:21:18 +0000181 virtual SkString getPerIterTimeFormat() { return SkString("%.2f"); }
182
183 virtual SkString getNormalTimeFormat() { return SkString("%6.2f"); }
184
scroggo@google.com0a049b82012-11-02 22:01:26 +0000185 /**
186 * Reports the configuration of this PictureRenderer.
187 */
188 SkString getConfigName() {
189 SkString config = this->getConfigNameInternal();
scroggo@google.comc4013c12012-12-13 22:07:08 +0000190 if (!fViewport.isEmpty()) {
191 config.appendf("_viewport_%ix%i", fViewport.width(), fViewport.height());
192 }
scroggo@google.com0a049b82012-11-02 22:01:26 +0000193 if (kRTree_BBoxHierarchyType == fBBoxHierarchyType) {
194 config.append("_rtree");
junov@chromium.org7b537062012-11-06 18:58:43 +0000195 } else if (kTileGrid_BBoxHierarchyType == fBBoxHierarchyType) {
196 config.append("_grid");
scroggo@google.com0a049b82012-11-02 22:01:26 +0000197 }
scroggo@google.com0556ea02013-02-08 19:38:21 +0000198 switch (fDeviceType) {
scroggo@google.com0a049b82012-11-02 22:01:26 +0000199#if SK_SUPPORT_GPU
scroggo@google.com0556ea02013-02-08 19:38:21 +0000200 case kGPU_DeviceType:
201 config.append("_gpu");
202 break;
203#if SK_ANGLE
204 case kAngle_DeviceType:
205 config.append("_angle");
206 break;
scroggo@google.com0a049b82012-11-02 22:01:26 +0000207#endif
scroggo@google.com0556ea02013-02-08 19:38:21 +0000208#endif
209 default:
210 // Assume that no extra info means bitmap.
211 break;
212 }
caryclark@google.coma3622372012-11-06 21:26:13 +0000213 config.append(fDrawFiltersConfig.c_str());
scroggo@google.com0a049b82012-11-02 22:01:26 +0000214 return config;
215 }
216
keyar@chromium.org4ea96c52012-08-20 15:03:29 +0000217#if SK_SUPPORT_GPU
keyar@chromium.orgfe6391a2012-08-20 15:03:41 +0000218 bool isUsingGpuDevice() {
scroggo@google.com0556ea02013-02-08 19:38:21 +0000219 switch (fDeviceType) {
220 case kGPU_DeviceType:
221 // fall through
222#if SK_ANGLE
223 case kAngle_DeviceType:
224#endif
225 return true;
226 default:
227 return false;
228 }
keyar@chromium.orgfe6391a2012-08-20 15:03:41 +0000229 }
keyar@chromium.org77a55222012-08-20 15:03:47 +0000230
231 SkGLContext* getGLContext() {
scroggo@google.com0556ea02013-02-08 19:38:21 +0000232 GrContextFactory::GLContextType glContextType
233 = GrContextFactory::kNull_GLContextType;
234 switch(fDeviceType) {
235 case kGPU_DeviceType:
236 glContextType = GrContextFactory::kNative_GLContextType;
237 break;
238#if SK_ANGLE
239 case kAngle_DeviceType:
240 glContextType = GrContextFactory::kANGLE_GLContextType;
241 break;
242#endif
243 default:
244 return NULL;
keyar@chromium.org77a55222012-08-20 15:03:47 +0000245 }
scroggo@google.com0556ea02013-02-08 19:38:21 +0000246 return fGrContextFactory.getGLContext(glContextType);
keyar@chromium.org77a55222012-08-20 15:03:47 +0000247 }
robertphillips@google.com163c84b2012-09-13 15:40:37 +0000248
249 GrContext* getGrContext() {
250 return fGrContext;
251 }
keyar@chromium.org4ea96c52012-08-20 15:03:29 +0000252#endif
253
keyar@chromium.org02dfb122012-08-20 15:03:36 +0000254 PictureRenderer()
keyar@chromium.org06125642012-08-20 15:03:33 +0000255 : fPicture(NULL)
256 , fDeviceType(kBitmap_DeviceType)
junov@chromium.org50ff9bd2012-11-02 19:16:22 +0000257 , fBBoxHierarchyType(kNone_BBoxHierarchyType)
junov@chromium.org7b537062012-11-06 18:58:43 +0000258 , fGridWidth(0)
259 , fGridHeight(0)
scroggo@google.com06d6ac62013-02-08 21:16:19 +0000260 , fScaleFactor(SK_Scalar1)
keyar@chromium.org06125642012-08-20 15:03:33 +0000261#if SK_SUPPORT_GPU
scroggo@google.com0556ea02013-02-08 19:38:21 +0000262 , fGrContext(NULL)
keyar@chromium.org06125642012-08-20 15:03:33 +0000263#endif
caryclark@google.come3e940c2012-11-07 16:42:17 +0000264 {
265 sk_bzero(fDrawFilters, sizeof(fDrawFilters));
scroggo@google.comc0d5e542012-12-13 21:40:48 +0000266 fViewport.set(0, 0);
caryclark@google.come3e940c2012-11-07 16:42:17 +0000267 }
keyar@chromium.org06125642012-08-20 15:03:33 +0000268
scroggo@google.com0556ea02013-02-08 19:38:21 +0000269#if SK_SUPPORT_GPU
270 virtual ~PictureRenderer() {
271 SkSafeUnref(fGrContext);
272 }
273#endif
274
keyar@chromium.org9d696c02012-08-07 17:11:33 +0000275protected:
276 SkAutoTUnref<SkCanvas> fCanvas;
scroggo@google.comc0d5e542012-12-13 21:40:48 +0000277 SkPicture* fPicture;
278 SkDeviceTypes fDeviceType;
279 BBoxHierarchyType fBBoxHierarchyType;
280 DrawFilterFlags fDrawFilters[SkDrawFilter::kTypeCount];
281 SkString fDrawFiltersConfig;
282 int fGridWidth, fGridHeight; // used when fBBoxHierarchyType is TileGrid
keyar@chromium.org06125642012-08-20 15:03:33 +0000283
scroggo@google.comc0d5e542012-12-13 21:40:48 +0000284 void buildBBoxHierarchy();
285
286 /**
287 * Return the total width that should be drawn. If the viewport width has been set greater than
288 * 0, this will be the minimum of the current SkPicture's width and the viewport's width.
289 */
290 int getViewWidth();
291
292 /**
293 * Return the total height that should be drawn. If the viewport height has been set greater
294 * than 0, this will be the minimum of the current SkPicture's height and the viewport's height.
295 */
296 int getViewHeight();
297
scroggo@google.com82ec0b02012-12-17 19:25:54 +0000298 /**
299 * Scales the provided canvas to the scale factor set by setScaleFactor.
300 */
301 void scaleToScaleFactor(SkCanvas*);
302
scroggo@google.comc0d5e542012-12-13 21:40:48 +0000303 SkPicture* createPicture();
304 uint32_t recordFlags();
305 SkCanvas* setupCanvas();
306 virtual SkCanvas* setupCanvas(int width, int height);
307
keyar@chromium.org9d696c02012-08-07 17:11:33 +0000308private:
scroggo@google.comc0d5e542012-12-13 21:40:48 +0000309 SkISize fViewport;
scroggo@google.com82ec0b02012-12-17 19:25:54 +0000310 SkScalar fScaleFactor;
scroggo@google.com0556ea02013-02-08 19:38:21 +0000311#if SK_SUPPORT_GPU
312 GrContextFactory fGrContextFactory;
313 GrContext* fGrContext;
314#endif
scroggo@google.comc0d5e542012-12-13 21:40:48 +0000315
scroggo@google.com0a049b82012-11-02 22:01:26 +0000316 virtual SkString getConfigNameInternal() = 0;
317
keyar@chromium.org9d696c02012-08-07 17:11:33 +0000318 typedef SkRefCnt INHERITED;
keyar@chromium.org451bb9f2012-07-26 17:27:57 +0000319};
320
scroggo@google.com9a412522012-09-07 15:21:18 +0000321/**
322 * This class does not do any rendering, but its render function executes recording, which we want
323 * to time.
324 */
325class RecordPictureRenderer : public PictureRenderer {
edisonn@google.com84f548c2012-12-18 22:24:03 +0000326 virtual bool render(const SkString*, SkBitmap** out = NULL) SK_OVERRIDE;
scroggo@google.com9a412522012-09-07 15:21:18 +0000327
328 virtual SkString getPerIterTimeFormat() SK_OVERRIDE { return SkString("%.4f"); }
329
330 virtual SkString getNormalTimeFormat() SK_OVERRIDE { return SkString("%6.4f"); }
scroggo@google.com0a049b82012-11-02 22:01:26 +0000331
djsollen@google.comfd9720c2012-11-06 16:54:40 +0000332protected:
333 virtual SkCanvas* setupCanvas(int width, int height) SK_OVERRIDE;
334
scroggo@google.com0a049b82012-11-02 22:01:26 +0000335private:
336 virtual SkString getConfigNameInternal() SK_OVERRIDE;
scroggo@google.com9a412522012-09-07 15:21:18 +0000337};
338
keyar@chromium.org451bb9f2012-07-26 17:27:57 +0000339class PipePictureRenderer : public PictureRenderer {
keyar@chromium.org163b5672012-08-01 17:53:29 +0000340public:
edisonn@google.com84f548c2012-12-18 22:24:03 +0000341 virtual bool render(const SkString*, SkBitmap** out = NULL) SK_OVERRIDE;
keyar@chromium.org9d696c02012-08-07 17:11:33 +0000342
343private:
scroggo@google.com0a049b82012-11-02 22:01:26 +0000344 virtual SkString getConfigNameInternal() SK_OVERRIDE;
345
keyar@chromium.org9d696c02012-08-07 17:11:33 +0000346 typedef PictureRenderer INHERITED;
keyar@chromium.org451bb9f2012-07-26 17:27:57 +0000347};
348
349class SimplePictureRenderer : public PictureRenderer {
keyar@chromium.org163b5672012-08-01 17:53:29 +0000350public:
junov@chromium.org9313ca42012-11-02 18:11:49 +0000351 virtual void init(SkPicture* pict) SK_OVERRIDE;
352
edisonn@google.com84f548c2012-12-18 22:24:03 +0000353 virtual bool render(const SkString*, SkBitmap** out = NULL) SK_OVERRIDE;
keyar@chromium.org9d696c02012-08-07 17:11:33 +0000354
355private:
scroggo@google.com0a049b82012-11-02 22:01:26 +0000356 virtual SkString getConfigNameInternal() SK_OVERRIDE;
357
keyar@chromium.org9d696c02012-08-07 17:11:33 +0000358 typedef PictureRenderer INHERITED;
keyar@chromium.org451bb9f2012-07-26 17:27:57 +0000359};
360
361class TiledPictureRenderer : public PictureRenderer {
362public:
363 TiledPictureRenderer();
364
keyar@chromium.org9d696c02012-08-07 17:11:33 +0000365 virtual void init(SkPicture* pict) SK_OVERRIDE;
scroggo@google.com81f9d2e2012-09-20 14:54:21 +0000366
scroggo@google.com81f9d2e2012-09-20 14:54:21 +0000367 /**
368 * Renders to tiles, rather than a single canvas. If a path is provided, a separate file is
369 * created for each tile, named "path0.png", "path1.png", etc.
370 * Multithreaded mode currently does not support writing to a file.
371 */
edisonn@google.com84f548c2012-12-18 22:24:03 +0000372 virtual bool render(const SkString* path, SkBitmap** out = NULL) SK_OVERRIDE;
scroggo@google.com81f9d2e2012-09-20 14:54:21 +0000373
keyar@chromium.org9d696c02012-08-07 17:11:33 +0000374 virtual void end() SK_OVERRIDE;
keyar@chromium.org451bb9f2012-07-26 17:27:57 +0000375
keyar@chromium.orgcc6e5ef2012-07-27 20:09:26 +0000376 void setTileWidth(int width) {
377 fTileWidth = width;
378 }
379
380 int getTileWidth() const {
381 return fTileWidth;
382 }
383
384 void setTileHeight(int height) {
385 fTileHeight = height;
386 }
387
388 int getTileHeight() const {
389 return fTileHeight;
390 }
391
392 void setTileWidthPercentage(double percentage) {
393 fTileWidthPercentage = percentage;
394 }
395
keyar@chromium.org163b5672012-08-01 17:53:29 +0000396 double getTileWidthPercentage() const {
keyar@chromium.orgcc6e5ef2012-07-27 20:09:26 +0000397 return fTileWidthPercentage;
398 }
399
400 void setTileHeightPercentage(double percentage) {
401 fTileHeightPercentage = percentage;
402 }
403
keyar@chromium.org163b5672012-08-01 17:53:29 +0000404 double getTileHeightPercentage() const {
keyar@chromium.orgcc6e5ef2012-07-27 20:09:26 +0000405 return fTileHeightPercentage;
406 }
407
keyar@chromium.orgf4959ab2012-08-23 20:53:25 +0000408 void setTileMinPowerOf2Width(int width) {
409 SkASSERT(SkIsPow2(width) && width > 0);
410 if (!SkIsPow2(width) || width <= 0) {
411 return;
412 }
413
414 fTileMinPowerOf2Width = width;
415 }
416
417 int getTileMinPowerOf2Width() const {
418 return fTileMinPowerOf2Width;
419 }
420
scroggo@google.comcbcef702012-12-13 22:09:28 +0000421 virtual TiledPictureRenderer* getTiledRenderer() SK_OVERRIDE { return this; }
422
423 /**
424 * Report the number of tiles in the x and y directions. Must not be called before init.
425 * @param x Output parameter identifying the number of tiles in the x direction.
426 * @param y Output parameter identifying the number of tiles in the y direction.
427 * @return True if the tiles have been set up, and x and y are meaningful. If false, x and y are
428 * unmodified.
429 */
430 bool tileDimensions(int& x, int&y);
431
432 /**
433 * Move to the next tile and return its indices. Must be called before calling drawCurrentTile
434 * for the first time.
435 * @param i Output parameter identifying the column of the next tile to be drawn on the next
436 * call to drawNextTile.
437 * @param j Output parameter identifying the row of the next tile to be drawn on the next call
438 * to drawNextTile.
439 * @param True if the tiles have been created and the next tile to be drawn by drawCurrentTile
440 * is within the range of tiles. If false, i and j are unmodified.
441 */
442 bool nextTile(int& i, int& j);
443
444 /**
445 * Render one tile. This will draw the same tile each time it is called until nextTile is
446 * called. The tile rendered will depend on how many calls have been made to nextTile.
447 * It is an error to call this without first calling nextTile, or if nextTile returns false.
448 */
449 void drawCurrentTile();
450
scroggo@google.coma62da2f2012-11-02 21:28:12 +0000451protected:
scroggo@google.coma62da2f2012-11-02 21:28:12 +0000452 SkTDArray<SkRect> fTileRects;
keyar@chromium.org451bb9f2012-07-26 17:27:57 +0000453
scroggo@google.com0a049b82012-11-02 22:01:26 +0000454 virtual SkCanvas* setupCanvas(int width, int height) SK_OVERRIDE;
455 virtual SkString getConfigNameInternal() SK_OVERRIDE;
456
keyar@chromium.org451bb9f2012-07-26 17:27:57 +0000457private:
scroggo@google.comcbcef702012-12-13 22:09:28 +0000458 int fTileWidth;
459 int fTileHeight;
460 double fTileWidthPercentage;
461 double fTileHeightPercentage;
462 int fTileMinPowerOf2Width;
463
464 // These variables are only used for timing individual tiles.
465 // Next tile to draw in fTileRects.
466 int fCurrentTileOffset;
467 // Number of tiles in the x direction.
468 int fTilesX;
469 // Number of tiles in the y direction.
470 int fTilesY;
scroggo@google.combcdf2ec2012-09-20 14:42:33 +0000471
keyar@chromium.org9d696c02012-08-07 17:11:33 +0000472 void setupTiles();
keyar@chromium.orgf4959ab2012-08-23 20:53:25 +0000473 void setupPowerOf2Tiles();
keyar@chromium.org9d696c02012-08-07 17:11:33 +0000474
475 typedef PictureRenderer INHERITED;
keyar@chromium.org451bb9f2012-07-26 17:27:57 +0000476};
477
scroggo@google.coma62da2f2012-11-02 21:28:12 +0000478class CloneData;
479
480class MultiCorePictureRenderer : public TiledPictureRenderer {
481public:
482 explicit MultiCorePictureRenderer(int threadCount);
483
484 ~MultiCorePictureRenderer();
485
486 virtual void init(SkPicture* pict) SK_OVERRIDE;
487
488 /**
489 * Behaves like TiledPictureRenderer::render(), only using multiple threads.
490 */
edisonn@google.com84f548c2012-12-18 22:24:03 +0000491 virtual bool render(const SkString* path, SkBitmap** out = NULL) SK_OVERRIDE;
scroggo@google.coma62da2f2012-11-02 21:28:12 +0000492
493 virtual void end() SK_OVERRIDE;
494
495private:
scroggo@google.com0a049b82012-11-02 22:01:26 +0000496 virtual SkString getConfigNameInternal() SK_OVERRIDE;
497
scroggo@google.coma62da2f2012-11-02 21:28:12 +0000498 const int fNumThreads;
499 SkTDArray<SkCanvas*> fCanvasPool;
500 SkThreadPool fThreadPool;
501 SkPicture* fPictureClones;
502 CloneData** fCloneData;
503 SkCountdown fCountdown;
504
505 typedef TiledPictureRenderer INHERITED;
506};
507
scroggo@google.com9a412522012-09-07 15:21:18 +0000508/**
509 * This class does not do any rendering, but its render function executes turning an SkPictureRecord
510 * into an SkPicturePlayback, which we want to time.
511 */
512class PlaybackCreationRenderer : public PictureRenderer {
513public:
514 virtual void setup() SK_OVERRIDE;
515
edisonn@google.com84f548c2012-12-18 22:24:03 +0000516 virtual bool render(const SkString*, SkBitmap** out = NULL) SK_OVERRIDE;
scroggo@google.com9a412522012-09-07 15:21:18 +0000517
518 virtual SkString getPerIterTimeFormat() SK_OVERRIDE { return SkString("%.4f"); }
519
520 virtual SkString getNormalTimeFormat() SK_OVERRIDE { return SkString("%6.4f"); }
521
522private:
junov@chromium.org9313ca42012-11-02 18:11:49 +0000523 SkAutoTUnref<SkPicture> fReplayer;
scroggo@google.com0a049b82012-11-02 22:01:26 +0000524
525 virtual SkString getConfigNameInternal() SK_OVERRIDE;
526
scroggo@google.com9a412522012-09-07 15:21:18 +0000527 typedef PictureRenderer INHERITED;
528};
529
reed@google.comfe7b1ed2012-11-29 21:00:39 +0000530extern PictureRenderer* CreateGatherPixelRefsRenderer();
reed@google.com5a34fd32012-12-10 16:05:09 +0000531extern PictureRenderer* CreatePictureCloneRenderer();
reed@google.comfe7b1ed2012-11-29 21:00:39 +0000532
keyar@chromium.org451bb9f2012-07-26 17:27:57 +0000533}
534
535#endif // PictureRenderer_DEFINED