blob: 72367c0569f19e4de3ffebef43513fcee68d7e67 [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"
junov@chromium.org29b19e52013-02-27 18:35:16 +000022#include "SkTileGridPicture.h"
scroggo@google.coma62da2f2012-11-02 21:28:12 +000023#include "SkTypes.h"
keyar@chromium.org451bb9f2012-07-26 17:27:57 +000024
keyar@chromium.org06125642012-08-20 15:03:33 +000025#if SK_SUPPORT_GPU
26#include "GrContextFactory.h"
27#include "GrContext.h"
28#endif
29
keyar@chromium.org451bb9f2012-07-26 17:27:57 +000030class SkBitmap;
31class SkCanvas;
robertphillips@google.com6177e692013-02-28 20:16:25 +000032class SkGLContextHelper;
scroggo@google.coma62da2f2012-11-02 21:28:12 +000033class SkThread;
keyar@chromium.org451bb9f2012-07-26 17:27:57 +000034
35namespace sk_tools {
36
scroggo@google.comcbcef702012-12-13 22:09:28 +000037class TiledPictureRenderer;
38
keyar@chromium.org451bb9f2012-07-26 17:27:57 +000039class PictureRenderer : public SkRefCnt {
scroggo@google.comcbcef702012-12-13 22:09:28 +000040
keyar@chromium.org451bb9f2012-07-26 17:27:57 +000041public:
keyar@chromium.orgc81686c2012-08-20 15:04:04 +000042 enum SkDeviceTypes {
scroggo@google.com0556ea02013-02-08 19:38:21 +000043#if SK_ANGLE
44 kAngle_DeviceType,
45#endif
keyar@chromium.orgc81686c2012-08-20 15:04:04 +000046 kBitmap_DeviceType,
47#if SK_SUPPORT_GPU
scroggo@google.com0556ea02013-02-08 19:38:21 +000048 kGPU_DeviceType,
keyar@chromium.orgc81686c2012-08-20 15:04:04 +000049#endif
50 };
51
junov@chromium.org9313ca42012-11-02 18:11:49 +000052 enum BBoxHierarchyType {
53 kNone_BBoxHierarchyType = 0,
54 kRTree_BBoxHierarchyType,
junov@chromium.org7b537062012-11-06 18:58:43 +000055 kTileGrid_BBoxHierarchyType,
junov@chromium.org9313ca42012-11-02 18:11:49 +000056 };
57
caryclark@google.coma3622372012-11-06 21:26:13 +000058 // this uses SkPaint::Flags as a base and adds additional flags
59 enum DrawFilterFlags {
60 kNone_DrawFilterFlag = 0,
caryclark@google.come3e940c2012-11-07 16:42:17 +000061 kBlur_DrawFilterFlag = 0x4000, // toggles between blur and no blur
reed@google.com457d8a72012-12-18 18:20:44 +000062 kHinting_DrawFilterFlag = 0x8000, // toggles between no hinting and normal hinting
63 kSlightHinting_DrawFilterFlag = 0x10000, // toggles between slight and normal hinting
64 kAAClip_DrawFilterFlag = 0x20000, // toggles between soft and hard clip
caryclark@google.coma3622372012-11-06 21:26:13 +000065 };
66
67 SK_COMPILE_ASSERT(!(kBlur_DrawFilterFlag & SkPaint::kAllFlags), blur_flag_must_be_greater);
68 SK_COMPILE_ASSERT(!(kHinting_DrawFilterFlag & SkPaint::kAllFlags),
69 hinting_flag_must_be_greater);
70 SK_COMPILE_ASSERT(!(kSlightHinting_DrawFilterFlag & SkPaint::kAllFlags),
71 slight_hinting_flag_must_be_greater);
72
scroggo@google.coma62da2f2012-11-02 21:28:12 +000073 /**
74 * Called with each new SkPicture to render.
75 */
keyar@chromium.org9d696c02012-08-07 17:11:33 +000076 virtual void init(SkPicture* pict);
scroggo@google.com9a412522012-09-07 15:21:18 +000077
78 /**
scroggo@google.comc0d5e542012-12-13 21:40:48 +000079 * Set the viewport so that only the portion listed gets drawn.
80 */
81 void setViewport(SkISize size) { fViewport = size; }
82
83 /**
scroggo@google.com82ec0b02012-12-17 19:25:54 +000084 * Set the scale factor at which draw the picture.
85 */
86 void setScaleFactor(SkScalar scale) { fScaleFactor = scale; }
87
88 /**
scroggo@google.com9a412522012-09-07 15:21:18 +000089 * Perform any setup that should done prior to each iteration of render() which should not be
90 * timed.
91 */
92 virtual void setup() {}
93
94 /**
95 * Perform work that is to be timed. Typically this is rendering, but is also used for recording
96 * and preparing picture for playback by the subclasses which do those.
scroggo@google.com81f9d2e2012-09-20 14:54:21 +000097 * If path is non-null, subclass implementations should call write().
98 * @param path If non-null, also write the output to the file specified by path. path should
99 * have no extension; it will be added by write().
borenet@google.com070d3542012-10-26 13:26:55 +0000100 * @return bool True if rendering succeeded and, if path is non-null, the output was
101 * successfully written to a file.
scroggo@google.com9a412522012-09-07 15:21:18 +0000102 */
edisonn@google.com84f548c2012-12-18 22:24:03 +0000103 virtual bool render(const SkString* path, SkBitmap** out = NULL) = 0;
scroggo@google.com9a412522012-09-07 15:21:18 +0000104
scroggo@google.coma62da2f2012-11-02 21:28:12 +0000105 /**
106 * Called once finished with a particular SkPicture, before calling init again, and before
107 * being done with this Renderer.
108 */
keyar@chromium.org9d696c02012-08-07 17:11:33 +0000109 virtual void end();
scroggo@google.coma62da2f2012-11-02 21:28:12 +0000110
scroggo@google.comcbcef702012-12-13 22:09:28 +0000111 /**
112 * If this PictureRenderer is actually a TiledPictureRender, return a pointer to this as a
113 * TiledPictureRender so its methods can be called.
114 */
115 virtual TiledPictureRenderer* getTiledRenderer() { return NULL; }
116
scroggo@google.com08085f82013-01-28 20:40:24 +0000117 /**
118 * Resets the GPU's state. Does nothing if the backing is raster. For a GPU renderer, calls
119 * flush, and calls finish if callFinish is true.
120 * @param callFinish Whether to call finish.
121 */
122 void resetState(bool callFinish);
keyar@chromium.org9d696c02012-08-07 17:11:33 +0000123
scroggo@google.com0556ea02013-02-08 19:38:21 +0000124 /**
125 * Set the backend type. Returns true on success and false on failure.
126 */
127 bool setDeviceType(SkDeviceTypes deviceType) {
keyar@chromium.orgc81686c2012-08-20 15:04:04 +0000128 fDeviceType = deviceType;
scroggo@google.com0556ea02013-02-08 19:38:21 +0000129#if SK_SUPPORT_GPU
130 // In case this function is called more than once
131 SkSafeUnref(fGrContext);
132 fGrContext = NULL;
133 // Set to Native so it will have an initial value.
134 GrContextFactory::GLContextType glContextType = GrContextFactory::kNative_GLContextType;
135#endif
136 switch(deviceType) {
137 case kBitmap_DeviceType:
138 return true;
139#if SK_SUPPORT_GPU
140 case kGPU_DeviceType:
141 // Already set to GrContextFactory::kNative_GLContextType, above.
142 break;
143#if SK_ANGLE
144 case kAngle_DeviceType:
145 glContextType = GrContextFactory::kANGLE_GLContextType;
146 break;
147#endif
148#endif
149 default:
150 // Invalid device type.
151 return false;
152 }
153#if SK_SUPPORT_GPU
154 fGrContext = fGrContextFactory.get(glContextType);
155 if (NULL == fGrContext) {
156 return false;
157 } else {
158 fGrContext->ref();
159 return true;
160 }
161#endif
keyar@chromium.orgfe6391a2012-08-20 15:03:41 +0000162 }
163
caryclark@google.come3e940c2012-11-07 16:42:17 +0000164 void setDrawFilters(DrawFilterFlags const * const filters, const SkString& configName) {
165 memcpy(fDrawFilters, filters, sizeof(fDrawFilters));
caryclark@google.coma3622372012-11-06 21:26:13 +0000166 fDrawFiltersConfig = configName;
167 }
168
junov@chromium.org9313ca42012-11-02 18:11:49 +0000169 void setBBoxHierarchyType(BBoxHierarchyType bbhType) {
170 fBBoxHierarchyType = bbhType;
171 }
172
junov@chromium.org7b537062012-11-06 18:58:43 +0000173 void setGridSize(int width, int height) {
junov@chromium.org29b19e52013-02-27 18:35:16 +0000174 fGridInfo.fTileInterval.set(width, height);
junov@chromium.org7b537062012-11-06 18:58:43 +0000175 }
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 }
198#if SK_SUPPORT_GPU
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +0000199 switch (fDeviceType) {
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 default:
209 // Assume that no extra info means bitmap.
210 break;
211 }
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +0000212#endif
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
robertphillips@google.com6177e692013-02-28 20:16:25 +0000231 SkGLContextHelper* 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)
scroggo@google.com06d6ac62013-02-08 21:16:19 +0000258 , fScaleFactor(SK_Scalar1)
keyar@chromium.org06125642012-08-20 15:03:33 +0000259#if SK_SUPPORT_GPU
scroggo@google.com0556ea02013-02-08 19:38:21 +0000260 , fGrContext(NULL)
keyar@chromium.org06125642012-08-20 15:03:33 +0000261#endif
caryclark@google.come3e940c2012-11-07 16:42:17 +0000262 {
robertphillips@google.com7ae918e2013-03-02 17:45:27 +0000263 fGridInfo.fMargin.setEmpty();
264 fGridInfo.fOffset.setZero();
265 fGridInfo.fTileInterval.set(1, 1);
caryclark@google.come3e940c2012-11-07 16:42:17 +0000266 sk_bzero(fDrawFilters, sizeof(fDrawFilters));
scroggo@google.comc0d5e542012-12-13 21:40:48 +0000267 fViewport.set(0, 0);
caryclark@google.come3e940c2012-11-07 16:42:17 +0000268 }
keyar@chromium.org06125642012-08-20 15:03:33 +0000269
scroggo@google.com0556ea02013-02-08 19:38:21 +0000270#if SK_SUPPORT_GPU
271 virtual ~PictureRenderer() {
272 SkSafeUnref(fGrContext);
273 }
274#endif
275
keyar@chromium.org9d696c02012-08-07 17:11:33 +0000276protected:
277 SkAutoTUnref<SkCanvas> fCanvas;
scroggo@google.comc0d5e542012-12-13 21:40:48 +0000278 SkPicture* fPicture;
279 SkDeviceTypes fDeviceType;
280 BBoxHierarchyType fBBoxHierarchyType;
281 DrawFilterFlags fDrawFilters[SkDrawFilter::kTypeCount];
282 SkString fDrawFiltersConfig;
junov@chromium.org29b19e52013-02-27 18:35:16 +0000283 SkTileGridPicture::TileGridInfo fGridInfo; // used when fBBoxHierarchyType is TileGrid
keyar@chromium.org06125642012-08-20 15:03:33 +0000284
scroggo@google.comc0d5e542012-12-13 21:40:48 +0000285 void buildBBoxHierarchy();
286
287 /**
288 * Return the total width that should be drawn. If the viewport width has been set greater than
289 * 0, this will be the minimum of the current SkPicture's width and the viewport's width.
290 */
291 int getViewWidth();
292
293 /**
294 * Return the total height that should be drawn. If the viewport height has been set greater
295 * than 0, this will be the minimum of the current SkPicture's height and the viewport's height.
296 */
297 int getViewHeight();
298
scroggo@google.com82ec0b02012-12-17 19:25:54 +0000299 /**
300 * Scales the provided canvas to the scale factor set by setScaleFactor.
301 */
302 void scaleToScaleFactor(SkCanvas*);
303
scroggo@google.comc0d5e542012-12-13 21:40:48 +0000304 SkPicture* createPicture();
305 uint32_t recordFlags();
306 SkCanvas* setupCanvas();
307 virtual SkCanvas* setupCanvas(int width, int height);
308
keyar@chromium.org9d696c02012-08-07 17:11:33 +0000309private:
scroggo@google.comc0d5e542012-12-13 21:40:48 +0000310 SkISize fViewport;
scroggo@google.com82ec0b02012-12-17 19:25:54 +0000311 SkScalar fScaleFactor;
scroggo@google.com0556ea02013-02-08 19:38:21 +0000312#if SK_SUPPORT_GPU
313 GrContextFactory fGrContextFactory;
314 GrContext* fGrContext;
315#endif
scroggo@google.comc0d5e542012-12-13 21:40:48 +0000316
scroggo@google.com0a049b82012-11-02 22:01:26 +0000317 virtual SkString getConfigNameInternal() = 0;
318
keyar@chromium.org9d696c02012-08-07 17:11:33 +0000319 typedef SkRefCnt INHERITED;
keyar@chromium.org451bb9f2012-07-26 17:27:57 +0000320};
321
scroggo@google.com9a412522012-09-07 15:21:18 +0000322/**
323 * This class does not do any rendering, but its render function executes recording, which we want
324 * to time.
325 */
326class RecordPictureRenderer : public PictureRenderer {
edisonn@google.com84f548c2012-12-18 22:24:03 +0000327 virtual bool render(const SkString*, SkBitmap** out = NULL) SK_OVERRIDE;
scroggo@google.com9a412522012-09-07 15:21:18 +0000328
329 virtual SkString getPerIterTimeFormat() SK_OVERRIDE { return SkString("%.4f"); }
330
331 virtual SkString getNormalTimeFormat() SK_OVERRIDE { return SkString("%6.4f"); }
scroggo@google.com0a049b82012-11-02 22:01:26 +0000332
djsollen@google.comfd9720c2012-11-06 16:54:40 +0000333protected:
334 virtual SkCanvas* setupCanvas(int width, int height) SK_OVERRIDE;
335
scroggo@google.com0a049b82012-11-02 22:01:26 +0000336private:
337 virtual SkString getConfigNameInternal() SK_OVERRIDE;
scroggo@google.com9a412522012-09-07 15:21:18 +0000338};
339
keyar@chromium.org451bb9f2012-07-26 17:27:57 +0000340class PipePictureRenderer : public PictureRenderer {
keyar@chromium.org163b5672012-08-01 17:53:29 +0000341public:
edisonn@google.com84f548c2012-12-18 22:24:03 +0000342 virtual bool render(const SkString*, SkBitmap** out = NULL) SK_OVERRIDE;
keyar@chromium.org9d696c02012-08-07 17:11:33 +0000343
344private:
scroggo@google.com0a049b82012-11-02 22:01:26 +0000345 virtual SkString getConfigNameInternal() SK_OVERRIDE;
346
keyar@chromium.org9d696c02012-08-07 17:11:33 +0000347 typedef PictureRenderer INHERITED;
keyar@chromium.org451bb9f2012-07-26 17:27:57 +0000348};
349
350class SimplePictureRenderer : public PictureRenderer {
keyar@chromium.org163b5672012-08-01 17:53:29 +0000351public:
junov@chromium.org9313ca42012-11-02 18:11:49 +0000352 virtual void init(SkPicture* pict) SK_OVERRIDE;
353
edisonn@google.com84f548c2012-12-18 22:24:03 +0000354 virtual bool render(const SkString*, SkBitmap** out = NULL) SK_OVERRIDE;
keyar@chromium.org9d696c02012-08-07 17:11:33 +0000355
356private:
scroggo@google.com0a049b82012-11-02 22:01:26 +0000357 virtual SkString getConfigNameInternal() SK_OVERRIDE;
358
keyar@chromium.org9d696c02012-08-07 17:11:33 +0000359 typedef PictureRenderer INHERITED;
keyar@chromium.org451bb9f2012-07-26 17:27:57 +0000360};
361
362class TiledPictureRenderer : public PictureRenderer {
363public:
364 TiledPictureRenderer();
365
keyar@chromium.org9d696c02012-08-07 17:11:33 +0000366 virtual void init(SkPicture* pict) SK_OVERRIDE;
scroggo@google.com81f9d2e2012-09-20 14:54:21 +0000367
scroggo@google.com81f9d2e2012-09-20 14:54:21 +0000368 /**
369 * Renders to tiles, rather than a single canvas. If a path is provided, a separate file is
370 * created for each tile, named "path0.png", "path1.png", etc.
371 * Multithreaded mode currently does not support writing to a file.
372 */
edisonn@google.com84f548c2012-12-18 22:24:03 +0000373 virtual bool render(const SkString* path, SkBitmap** out = NULL) SK_OVERRIDE;
scroggo@google.com81f9d2e2012-09-20 14:54:21 +0000374
keyar@chromium.org9d696c02012-08-07 17:11:33 +0000375 virtual void end() SK_OVERRIDE;
keyar@chromium.org451bb9f2012-07-26 17:27:57 +0000376
keyar@chromium.orgcc6e5ef2012-07-27 20:09:26 +0000377 void setTileWidth(int width) {
378 fTileWidth = width;
379 }
380
381 int getTileWidth() const {
382 return fTileWidth;
383 }
384
385 void setTileHeight(int height) {
386 fTileHeight = height;
387 }
388
389 int getTileHeight() const {
390 return fTileHeight;
391 }
392
393 void setTileWidthPercentage(double percentage) {
394 fTileWidthPercentage = percentage;
395 }
396
keyar@chromium.org163b5672012-08-01 17:53:29 +0000397 double getTileWidthPercentage() const {
keyar@chromium.orgcc6e5ef2012-07-27 20:09:26 +0000398 return fTileWidthPercentage;
399 }
400
401 void setTileHeightPercentage(double percentage) {
402 fTileHeightPercentage = percentage;
403 }
404
keyar@chromium.org163b5672012-08-01 17:53:29 +0000405 double getTileHeightPercentage() const {
keyar@chromium.orgcc6e5ef2012-07-27 20:09:26 +0000406 return fTileHeightPercentage;
407 }
408
keyar@chromium.orgf4959ab2012-08-23 20:53:25 +0000409 void setTileMinPowerOf2Width(int width) {
410 SkASSERT(SkIsPow2(width) && width > 0);
411 if (!SkIsPow2(width) || width <= 0) {
412 return;
413 }
414
415 fTileMinPowerOf2Width = width;
416 }
417
418 int getTileMinPowerOf2Width() const {
419 return fTileMinPowerOf2Width;
420 }
421
scroggo@google.comcbcef702012-12-13 22:09:28 +0000422 virtual TiledPictureRenderer* getTiledRenderer() SK_OVERRIDE { return this; }
423
424 /**
425 * Report the number of tiles in the x and y directions. Must not be called before init.
426 * @param x Output parameter identifying the number of tiles in the x direction.
427 * @param y Output parameter identifying the number of tiles in the y direction.
428 * @return True if the tiles have been set up, and x and y are meaningful. If false, x and y are
429 * unmodified.
430 */
431 bool tileDimensions(int& x, int&y);
432
433 /**
434 * Move to the next tile and return its indices. Must be called before calling drawCurrentTile
435 * for the first time.
436 * @param i Output parameter identifying the column of the next tile to be drawn on the next
437 * call to drawNextTile.
438 * @param j Output parameter identifying the row of the next tile to be drawn on the next call
439 * to drawNextTile.
440 * @param True if the tiles have been created and the next tile to be drawn by drawCurrentTile
441 * is within the range of tiles. If false, i and j are unmodified.
442 */
443 bool nextTile(int& i, int& j);
444
445 /**
446 * Render one tile. This will draw the same tile each time it is called until nextTile is
447 * called. The tile rendered will depend on how many calls have been made to nextTile.
448 * It is an error to call this without first calling nextTile, or if nextTile returns false.
449 */
450 void drawCurrentTile();
451
scroggo@google.coma62da2f2012-11-02 21:28:12 +0000452protected:
scroggo@google.coma62da2f2012-11-02 21:28:12 +0000453 SkTDArray<SkRect> fTileRects;
keyar@chromium.org451bb9f2012-07-26 17:27:57 +0000454
scroggo@google.com0a049b82012-11-02 22:01:26 +0000455 virtual SkCanvas* setupCanvas(int width, int height) SK_OVERRIDE;
456 virtual SkString getConfigNameInternal() SK_OVERRIDE;
457
keyar@chromium.org451bb9f2012-07-26 17:27:57 +0000458private:
scroggo@google.comcbcef702012-12-13 22:09:28 +0000459 int fTileWidth;
460 int fTileHeight;
461 double fTileWidthPercentage;
462 double fTileHeightPercentage;
463 int fTileMinPowerOf2Width;
464
465 // These variables are only used for timing individual tiles.
466 // Next tile to draw in fTileRects.
467 int fCurrentTileOffset;
468 // Number of tiles in the x direction.
469 int fTilesX;
470 // Number of tiles in the y direction.
471 int fTilesY;
scroggo@google.combcdf2ec2012-09-20 14:42:33 +0000472
keyar@chromium.org9d696c02012-08-07 17:11:33 +0000473 void setupTiles();
keyar@chromium.orgf4959ab2012-08-23 20:53:25 +0000474 void setupPowerOf2Tiles();
keyar@chromium.org9d696c02012-08-07 17:11:33 +0000475
476 typedef PictureRenderer INHERITED;
keyar@chromium.org451bb9f2012-07-26 17:27:57 +0000477};
478
scroggo@google.coma62da2f2012-11-02 21:28:12 +0000479class CloneData;
480
481class MultiCorePictureRenderer : public TiledPictureRenderer {
482public:
483 explicit MultiCorePictureRenderer(int threadCount);
484
485 ~MultiCorePictureRenderer();
486
487 virtual void init(SkPicture* pict) SK_OVERRIDE;
488
489 /**
490 * Behaves like TiledPictureRenderer::render(), only using multiple threads.
491 */
edisonn@google.com84f548c2012-12-18 22:24:03 +0000492 virtual bool render(const SkString* path, SkBitmap** out = NULL) SK_OVERRIDE;
scroggo@google.coma62da2f2012-11-02 21:28:12 +0000493
494 virtual void end() SK_OVERRIDE;
495
496private:
scroggo@google.com0a049b82012-11-02 22:01:26 +0000497 virtual SkString getConfigNameInternal() SK_OVERRIDE;
498
scroggo@google.coma62da2f2012-11-02 21:28:12 +0000499 const int fNumThreads;
500 SkTDArray<SkCanvas*> fCanvasPool;
501 SkThreadPool fThreadPool;
502 SkPicture* fPictureClones;
503 CloneData** fCloneData;
504 SkCountdown fCountdown;
505
506 typedef TiledPictureRenderer INHERITED;
507};
508
scroggo@google.com9a412522012-09-07 15:21:18 +0000509/**
510 * This class does not do any rendering, but its render function executes turning an SkPictureRecord
511 * into an SkPicturePlayback, which we want to time.
512 */
513class PlaybackCreationRenderer : public PictureRenderer {
514public:
515 virtual void setup() SK_OVERRIDE;
516
edisonn@google.com84f548c2012-12-18 22:24:03 +0000517 virtual bool render(const SkString*, SkBitmap** out = NULL) SK_OVERRIDE;
scroggo@google.com9a412522012-09-07 15:21:18 +0000518
519 virtual SkString getPerIterTimeFormat() SK_OVERRIDE { return SkString("%.4f"); }
520
521 virtual SkString getNormalTimeFormat() SK_OVERRIDE { return SkString("%6.4f"); }
522
523private:
junov@chromium.org9313ca42012-11-02 18:11:49 +0000524 SkAutoTUnref<SkPicture> fReplayer;
scroggo@google.com0a049b82012-11-02 22:01:26 +0000525
526 virtual SkString getConfigNameInternal() SK_OVERRIDE;
527
scroggo@google.com9a412522012-09-07 15:21:18 +0000528 typedef PictureRenderer INHERITED;
529};
530
reed@google.comfe7b1ed2012-11-29 21:00:39 +0000531extern PictureRenderer* CreateGatherPixelRefsRenderer();
reed@google.com5a34fd32012-12-10 16:05:09 +0000532extern PictureRenderer* CreatePictureCloneRenderer();
reed@google.comfe7b1ed2012-11-29 21:00:39 +0000533
keyar@chromium.org451bb9f2012-07-26 17:27:57 +0000534}
535
536#endif // PictureRenderer_DEFINED