blob: 796162846b71c82aa58678327de96fb95604d241 [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
scroggo@google.com161e1ba2013-03-04 16:41:06 +000011#include "SkCanvas.h"
scroggo@google.coma62da2f2012-11-02 21:28:12 +000012#include "SkCountdown.h"
caryclark@google.coma3622372012-11-06 21:26:13 +000013#include "SkDrawFilter.h"
commit-bot@chromium.orga3f882c2013-12-13 20:52:36 +000014#include "SkJSONCPP.h"
keyar@chromium.orgf4959ab2012-08-23 20:53:25 +000015#include "SkMath.h"
reed@google.comea6a3062012-11-06 22:14:54 +000016#include "SkPaint.h"
scroggo@google.com9a412522012-09-07 15:21:18 +000017#include "SkPicture.h"
robertphillips@google.com770963f2014-04-18 18:04:41 +000018#include "SkPictureRecorder.h"
scroggo@google.comacfb30e2012-09-18 14:32:35 +000019#include "SkRect.h"
keyar@chromium.org451bb9f2012-07-26 17:27:57 +000020#include "SkRefCnt.h"
scroggo@google.coma62da2f2012-11-02 21:28:12 +000021#include "SkRunnable.h"
scroggo@google.com9a412522012-09-07 15:21:18 +000022#include "SkString.h"
scroggo@google.coma62da2f2012-11-02 21:28:12 +000023#include "SkTDArray.h"
24#include "SkThreadPool.h"
25#include "SkTypes.h"
keyar@chromium.org451bb9f2012-07-26 17:27:57 +000026
keyar@chromium.org06125642012-08-20 15:03:33 +000027#if SK_SUPPORT_GPU
28#include "GrContextFactory.h"
29#include "GrContext.h"
30#endif
31
keyar@chromium.org451bb9f2012-07-26 17:27:57 +000032class SkBitmap;
33class SkCanvas;
robertphillips@google.com6177e692013-02-28 20:16:25 +000034class SkGLContextHelper;
scroggo@google.coma62da2f2012-11-02 21:28:12 +000035class SkThread;
keyar@chromium.org451bb9f2012-07-26 17:27:57 +000036
37namespace sk_tools {
38
scroggo@google.comcbcef702012-12-13 22:09:28 +000039class TiledPictureRenderer;
40
commit-bot@chromium.orga3f882c2013-12-13 20:52:36 +000041/**
42 * Class for collecting image results (checksums) as we go.
43 */
44class ImageResultsSummary {
45public:
46 /**
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +000047 * Adds this image to the summary of results.
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +000048 *
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +000049 * @param sourceName name of the source file that generated this result
50 * @param fileName relative path to the image output file on local disk
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +000051 * @param hash hash to store
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +000052 * @param tileNumber if not NULL, ptr to tile number
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +000053 */
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +000054 void add(const char *sourceName, const char *fileName, uint64_t hash,
55 const int *tileNumber=NULL);
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +000056
57 /**
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +000058 * Adds this image to the summary of results.
commit-bot@chromium.orga3f882c2013-12-13 20:52:36 +000059 *
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +000060 * @param sourceName name of the source file that generated this result
61 * @param fileName relative path to the image output file on local disk
commit-bot@chromium.orga3f882c2013-12-13 20:52:36 +000062 * @param bitmap bitmap to store the hash of
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +000063 * @param tileNumber if not NULL, ptr to tile number
commit-bot@chromium.orga3f882c2013-12-13 20:52:36 +000064 */
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +000065 void add(const char *sourceName, const char *fileName, const SkBitmap& bitmap,
66 const int *tileNumber=NULL);
commit-bot@chromium.orga3f882c2013-12-13 20:52:36 +000067
68 /**
69 * Writes the summary (as constructed so far) to a file.
70 *
71 * @param filename path to write the summary to
72 */
73 void writeToFile(const char *filename);
74
75private:
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +000076 Json::Value fActualResults;
commit-bot@chromium.orga3f882c2013-12-13 20:52:36 +000077};
78
keyar@chromium.org451bb9f2012-07-26 17:27:57 +000079class PictureRenderer : public SkRefCnt {
scroggo@google.comcbcef702012-12-13 22:09:28 +000080
keyar@chromium.org451bb9f2012-07-26 17:27:57 +000081public:
keyar@chromium.orgc81686c2012-08-20 15:04:04 +000082 enum SkDeviceTypes {
scroggo@google.com0556ea02013-02-08 19:38:21 +000083#if SK_ANGLE
84 kAngle_DeviceType,
85#endif
rmistry@google.com6ab96732014-01-06 18:37:24 +000086#if SK_MESA
87 kMesa_DeviceType,
88#endif
keyar@chromium.orgc81686c2012-08-20 15:04:04 +000089 kBitmap_DeviceType,
90#if SK_SUPPORT_GPU
scroggo@google.com0556ea02013-02-08 19:38:21 +000091 kGPU_DeviceType,
commit-bot@chromium.org0fd52702014-03-07 18:41:14 +000092 kNVPR_DeviceType,
keyar@chromium.orgc81686c2012-08-20 15:04:04 +000093#endif
94 };
95
junov@chromium.org9313ca42012-11-02 18:11:49 +000096 enum BBoxHierarchyType {
97 kNone_BBoxHierarchyType = 0,
commit-bot@chromium.orgc22d1392014-02-03 18:08:33 +000098 kQuadTree_BBoxHierarchyType,
junov@chromium.org9313ca42012-11-02 18:11:49 +000099 kRTree_BBoxHierarchyType,
junov@chromium.org7b537062012-11-06 18:58:43 +0000100 kTileGrid_BBoxHierarchyType,
commit-bot@chromium.orgcdd0f922014-03-11 17:27:07 +0000101
102 kLast_BBoxHierarchyType = kTileGrid_BBoxHierarchyType,
junov@chromium.org9313ca42012-11-02 18:11:49 +0000103 };
104
caryclark@google.coma3622372012-11-06 21:26:13 +0000105 // this uses SkPaint::Flags as a base and adds additional flags
106 enum DrawFilterFlags {
107 kNone_DrawFilterFlag = 0,
reed@google.com881b10b2013-05-22 14:03:45 +0000108 kHinting_DrawFilterFlag = 0x10000, // toggles between no hinting and normal hinting
109 kSlightHinting_DrawFilterFlag = 0x20000, // toggles between slight and normal hinting
110 kAAClip_DrawFilterFlag = 0x40000, // toggles between soft and hard clip
humper@google.com387db0a2013-07-09 14:13:04 +0000111 kMaskFilter_DrawFilterFlag = 0x80000, // toggles on/off mask filters (e.g., blurs)
caryclark@google.coma3622372012-11-06 21:26:13 +0000112 };
113
robertphillips@google.com49149312013-07-03 15:34:35 +0000114 SK_COMPILE_ASSERT(!(kMaskFilter_DrawFilterFlag & SkPaint::kAllFlags), maskfilter_flag_must_be_greater);
caryclark@google.coma3622372012-11-06 21:26:13 +0000115 SK_COMPILE_ASSERT(!(kHinting_DrawFilterFlag & SkPaint::kAllFlags),
116 hinting_flag_must_be_greater);
117 SK_COMPILE_ASSERT(!(kSlightHinting_DrawFilterFlag & SkPaint::kAllFlags),
118 slight_hinting_flag_must_be_greater);
119
scroggo@google.coma62da2f2012-11-02 21:28:12 +0000120 /**
121 * Called with each new SkPicture to render.
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000122 *
123 * @param pict The SkPicture to render.
124 * @param outputDir The output directory within which this renderer should write files,
125 * or NULL if this renderer should not write files at all.
126 * @param inputFilename The name of the input file we are rendering.
127 * @param useChecksumBasedFilenames Whether to use checksum-based filenames when writing
128 * bitmap images to disk.
scroggo@google.coma62da2f2012-11-02 21:28:12 +0000129 */
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000130 virtual void init(SkPicture* pict, const SkString* outputDir,
131 const SkString* inputFilename, bool useChecksumBasedFilenames);
scroggo@google.com9a412522012-09-07 15:21:18 +0000132
133 /**
scroggo@google.comc0d5e542012-12-13 21:40:48 +0000134 * Set the viewport so that only the portion listed gets drawn.
135 */
136 void setViewport(SkISize size) { fViewport = size; }
137
138 /**
scroggo@google.com82ec0b02012-12-17 19:25:54 +0000139 * Set the scale factor at which draw the picture.
140 */
141 void setScaleFactor(SkScalar scale) { fScaleFactor = scale; }
142
143 /**
scroggo@google.com9a412522012-09-07 15:21:18 +0000144 * Perform any setup that should done prior to each iteration of render() which should not be
145 * timed.
146 */
147 virtual void setup() {}
148
149 /**
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000150 * Perform the work. If this is being called within the context of bench_pictures,
151 * this is the step that will be timed.
152 *
153 * Typically "the work" is rendering an SkPicture into a bitmap, but in some subclasses
154 * it is recording the source SkPicture into another SkPicture.
155 *
156 * If fOutputDir has been specified, the result of the work will be written to that dir.
157 *
158 * @param out If non-null, the implementing subclass MAY allocate an SkBitmap, copy the
159 * output image into it, and return it here. (Some subclasses ignore this parameter)
160 * @return bool True if rendering succeeded and, if fOutputDir had been specified, the output
161 * was successfully written to a file.
scroggo@google.com9a412522012-09-07 15:21:18 +0000162 */
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000163 virtual bool render(SkBitmap** out = NULL) = 0;
scroggo@google.com9a412522012-09-07 15:21:18 +0000164
scroggo@google.coma62da2f2012-11-02 21:28:12 +0000165 /**
166 * Called once finished with a particular SkPicture, before calling init again, and before
167 * being done with this Renderer.
168 */
keyar@chromium.org9d696c02012-08-07 17:11:33 +0000169 virtual void end();
scroggo@google.coma62da2f2012-11-02 21:28:12 +0000170
scroggo@google.comcbcef702012-12-13 22:09:28 +0000171 /**
172 * If this PictureRenderer is actually a TiledPictureRender, return a pointer to this as a
173 * TiledPictureRender so its methods can be called.
174 */
175 virtual TiledPictureRenderer* getTiledRenderer() { return NULL; }
176
scroggo@google.com08085f82013-01-28 20:40:24 +0000177 /**
178 * Resets the GPU's state. Does nothing if the backing is raster. For a GPU renderer, calls
commit-bot@chromium.org51c040e2014-03-11 22:58:00 +0000179 * flush, swapBuffers and, if callFinish is true, finish.
scroggo@google.com08085f82013-01-28 20:40:24 +0000180 * @param callFinish Whether to call finish.
181 */
182 void resetState(bool callFinish);
keyar@chromium.org9d696c02012-08-07 17:11:33 +0000183
scroggo@google.com0556ea02013-02-08 19:38:21 +0000184 /**
robertphillips@google.com94d8f1e2013-12-18 17:25:33 +0000185 * Remove all decoded textures from the CPU caches and all uploaded textures
186 * from the GPU.
187 */
188 void purgeTextures();
189
190 /**
scroggo@google.com0556ea02013-02-08 19:38:21 +0000191 * Set the backend type. Returns true on success and false on failure.
192 */
193 bool setDeviceType(SkDeviceTypes deviceType) {
keyar@chromium.orgc81686c2012-08-20 15:04:04 +0000194 fDeviceType = deviceType;
scroggo@google.com0556ea02013-02-08 19:38:21 +0000195#if SK_SUPPORT_GPU
196 // In case this function is called more than once
197 SkSafeUnref(fGrContext);
198 fGrContext = NULL;
199 // Set to Native so it will have an initial value.
200 GrContextFactory::GLContextType glContextType = GrContextFactory::kNative_GLContextType;
201#endif
202 switch(deviceType) {
203 case kBitmap_DeviceType:
204 return true;
205#if SK_SUPPORT_GPU
206 case kGPU_DeviceType:
207 // Already set to GrContextFactory::kNative_GLContextType, above.
208 break;
commit-bot@chromium.org0fd52702014-03-07 18:41:14 +0000209 case kNVPR_DeviceType:
210 glContextType = GrContextFactory::kNVPR_GLContextType;
211 break;
scroggo@google.com0556ea02013-02-08 19:38:21 +0000212#if SK_ANGLE
213 case kAngle_DeviceType:
214 glContextType = GrContextFactory::kANGLE_GLContextType;
215 break;
216#endif
rmistry@google.com6ab96732014-01-06 18:37:24 +0000217#if SK_MESA
218 case kMesa_DeviceType:
219 glContextType = GrContextFactory::kMESA_GLContextType;
220 break;
221#endif
scroggo@google.com0556ea02013-02-08 19:38:21 +0000222#endif
223 default:
224 // Invalid device type.
225 return false;
226 }
227#if SK_SUPPORT_GPU
228 fGrContext = fGrContextFactory.get(glContextType);
229 if (NULL == fGrContext) {
230 return false;
231 } else {
232 fGrContext->ref();
233 return true;
234 }
235#endif
keyar@chromium.orgfe6391a2012-08-20 15:03:41 +0000236 }
237
jvanverth@google.comf6a90332013-05-02 12:39:37 +0000238#if SK_SUPPORT_GPU
239 void setSampleCount(int sampleCount) {
240 fSampleCount = sampleCount;
241 }
242#endif
243
caryclark@google.come3e940c2012-11-07 16:42:17 +0000244 void setDrawFilters(DrawFilterFlags const * const filters, const SkString& configName) {
245 memcpy(fDrawFilters, filters, sizeof(fDrawFilters));
caryclark@google.coma3622372012-11-06 21:26:13 +0000246 fDrawFiltersConfig = configName;
247 }
248
junov@chromium.org9313ca42012-11-02 18:11:49 +0000249 void setBBoxHierarchyType(BBoxHierarchyType bbhType) {
250 fBBoxHierarchyType = bbhType;
251 }
252
junov@chromium.orge286e842013-03-13 17:27:16 +0000253 BBoxHierarchyType getBBoxHierarchyType() { return fBBoxHierarchyType; }
254
junov@chromium.org7b537062012-11-06 18:58:43 +0000255 void setGridSize(int width, int height) {
junov@chromium.org29b19e52013-02-27 18:35:16 +0000256 fGridInfo.fTileInterval.set(width, height);
junov@chromium.org7b537062012-11-06 18:58:43 +0000257 }
258
commit-bot@chromium.orga3f882c2013-12-13 20:52:36 +0000259 void setJsonSummaryPtr(ImageResultsSummary* jsonSummaryPtr) {
260 fJsonSummaryPtr = jsonSummaryPtr;
261 }
262
keyar@chromium.orgfe6391a2012-08-20 15:03:41 +0000263 bool isUsingBitmapDevice() {
keyar@chromium.org78a35c52012-08-20 15:03:44 +0000264 return kBitmap_DeviceType == fDeviceType;
keyar@chromium.org4ea96c52012-08-20 15:03:29 +0000265 }
266
scroggo@google.com9a412522012-09-07 15:21:18 +0000267 virtual SkString getPerIterTimeFormat() { return SkString("%.2f"); }
268
269 virtual SkString getNormalTimeFormat() { return SkString("%6.2f"); }
270
scroggo@google.com0a049b82012-11-02 22:01:26 +0000271 /**
272 * Reports the configuration of this PictureRenderer.
273 */
274 SkString getConfigName() {
275 SkString config = this->getConfigNameInternal();
scroggo@google.comc4013c12012-12-13 22:07:08 +0000276 if (!fViewport.isEmpty()) {
277 config.appendf("_viewport_%ix%i", fViewport.width(), fViewport.height());
278 }
commit-bot@chromium.org9de35eb2013-12-20 21:49:33 +0000279 if (fScaleFactor != SK_Scalar1) {
280 config.appendf("_scalar_%f", SkScalarToFloat(fScaleFactor));
281 }
scroggo@google.com0a049b82012-11-02 22:01:26 +0000282 if (kRTree_BBoxHierarchyType == fBBoxHierarchyType) {
283 config.append("_rtree");
commit-bot@chromium.orgc22d1392014-02-03 18:08:33 +0000284 } else if (kQuadTree_BBoxHierarchyType == fBBoxHierarchyType) {
285 config.append("_quadtree");
junov@chromium.org7b537062012-11-06 18:58:43 +0000286 } else if (kTileGrid_BBoxHierarchyType == fBBoxHierarchyType) {
287 config.append("_grid");
scroggo@google.com0a049b82012-11-02 22:01:26 +0000288 }
289#if SK_SUPPORT_GPU
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +0000290 switch (fDeviceType) {
scroggo@google.com0556ea02013-02-08 19:38:21 +0000291 case kGPU_DeviceType:
jvanverth@google.comf6a90332013-05-02 12:39:37 +0000292 if (fSampleCount) {
293 config.appendf("_msaa%d", fSampleCount);
294 } else {
295 config.append("_gpu");
296 }
scroggo@google.com0556ea02013-02-08 19:38:21 +0000297 break;
commit-bot@chromium.org0fd52702014-03-07 18:41:14 +0000298 case kNVPR_DeviceType:
299 config.appendf("_nvprmsaa%d", fSampleCount);
300 break;
scroggo@google.com0556ea02013-02-08 19:38:21 +0000301#if SK_ANGLE
302 case kAngle_DeviceType:
303 config.append("_angle");
304 break;
scroggo@google.com0a049b82012-11-02 22:01:26 +0000305#endif
rmistry@google.com6ab96732014-01-06 18:37:24 +0000306#if SK_MESA
307 case kMesa_DeviceType:
308 config.append("_mesa");
309 break;
310#endif
scroggo@google.com0556ea02013-02-08 19:38:21 +0000311 default:
312 // Assume that no extra info means bitmap.
313 break;
314 }
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +0000315#endif
caryclark@google.coma3622372012-11-06 21:26:13 +0000316 config.append(fDrawFiltersConfig.c_str());
scroggo@google.com0a049b82012-11-02 22:01:26 +0000317 return config;
318 }
319
keyar@chromium.org4ea96c52012-08-20 15:03:29 +0000320#if SK_SUPPORT_GPU
keyar@chromium.orgfe6391a2012-08-20 15:03:41 +0000321 bool isUsingGpuDevice() {
scroggo@google.com0556ea02013-02-08 19:38:21 +0000322 switch (fDeviceType) {
323 case kGPU_DeviceType:
commit-bot@chromium.org0fd52702014-03-07 18:41:14 +0000324 case kNVPR_DeviceType:
scroggo@google.com0556ea02013-02-08 19:38:21 +0000325 // fall through
326#if SK_ANGLE
327 case kAngle_DeviceType:
rmistry@google.com6ab96732014-01-06 18:37:24 +0000328 // fall through
329#endif
330#if SK_MESA
331 case kMesa_DeviceType:
scroggo@google.com0556ea02013-02-08 19:38:21 +0000332#endif
333 return true;
334 default:
335 return false;
336 }
keyar@chromium.orgfe6391a2012-08-20 15:03:41 +0000337 }
keyar@chromium.org77a55222012-08-20 15:03:47 +0000338
robertphillips@google.com6177e692013-02-28 20:16:25 +0000339 SkGLContextHelper* getGLContext() {
scroggo@google.com0556ea02013-02-08 19:38:21 +0000340 GrContextFactory::GLContextType glContextType
341 = GrContextFactory::kNull_GLContextType;
342 switch(fDeviceType) {
343 case kGPU_DeviceType:
344 glContextType = GrContextFactory::kNative_GLContextType;
345 break;
commit-bot@chromium.org0fd52702014-03-07 18:41:14 +0000346 case kNVPR_DeviceType:
347 glContextType = GrContextFactory::kNVPR_GLContextType;
348 break;
scroggo@google.com0556ea02013-02-08 19:38:21 +0000349#if SK_ANGLE
350 case kAngle_DeviceType:
351 glContextType = GrContextFactory::kANGLE_GLContextType;
352 break;
353#endif
rmistry@google.com6ab96732014-01-06 18:37:24 +0000354#if SK_MESA
355 case kMesa_DeviceType:
356 glContextType = GrContextFactory::kMESA_GLContextType;
357 break;
358#endif
scroggo@google.com0556ea02013-02-08 19:38:21 +0000359 default:
360 return NULL;
keyar@chromium.org77a55222012-08-20 15:03:47 +0000361 }
scroggo@google.com0556ea02013-02-08 19:38:21 +0000362 return fGrContextFactory.getGLContext(glContextType);
keyar@chromium.org77a55222012-08-20 15:03:47 +0000363 }
robertphillips@google.com163c84b2012-09-13 15:40:37 +0000364
365 GrContext* getGrContext() {
366 return fGrContext;
367 }
keyar@chromium.org4ea96c52012-08-20 15:03:29 +0000368#endif
369
commit-bot@chromium.org145d1c02014-03-16 19:46:36 +0000370 SkCanvas* getCanvas() {
371 return fCanvas;
372 }
373
commit-bot@chromium.org8ddc26b2014-03-31 17:55:12 +0000374 SkPicture* getPicture() {
375 return fPicture;
376 }
377
keyar@chromium.org02dfb122012-08-20 15:03:36 +0000378 PictureRenderer()
robertphillips@google.com84b18c72014-04-13 19:09:42 +0000379 : fJsonSummaryPtr(NULL)
keyar@chromium.org06125642012-08-20 15:03:33 +0000380 , fDeviceType(kBitmap_DeviceType)
junov@chromium.org50ff9bd2012-11-02 19:16:22 +0000381 , fBBoxHierarchyType(kNone_BBoxHierarchyType)
scroggo@google.com06d6ac62013-02-08 21:16:19 +0000382 , fScaleFactor(SK_Scalar1)
keyar@chromium.org06125642012-08-20 15:03:33 +0000383#if SK_SUPPORT_GPU
scroggo@google.com0556ea02013-02-08 19:38:21 +0000384 , fGrContext(NULL)
jvanverth@google.comf6a90332013-05-02 12:39:37 +0000385 , fSampleCount(0)
keyar@chromium.org06125642012-08-20 15:03:33 +0000386#endif
caryclark@google.come3e940c2012-11-07 16:42:17 +0000387 {
robertphillips@google.com7ae918e2013-03-02 17:45:27 +0000388 fGridInfo.fMargin.setEmpty();
389 fGridInfo.fOffset.setZero();
390 fGridInfo.fTileInterval.set(1, 1);
caryclark@google.come3e940c2012-11-07 16:42:17 +0000391 sk_bzero(fDrawFilters, sizeof(fDrawFilters));
scroggo@google.comc0d5e542012-12-13 21:40:48 +0000392 fViewport.set(0, 0);
caryclark@google.come3e940c2012-11-07 16:42:17 +0000393 }
keyar@chromium.org06125642012-08-20 15:03:33 +0000394
scroggo@google.com0556ea02013-02-08 19:38:21 +0000395#if SK_SUPPORT_GPU
396 virtual ~PictureRenderer() {
397 SkSafeUnref(fGrContext);
398 }
399#endif
400
keyar@chromium.org9d696c02012-08-07 17:11:33 +0000401protected:
402 SkAutoTUnref<SkCanvas> fCanvas;
robertphillips@google.com84b18c72014-04-13 19:09:42 +0000403 SkAutoTUnref<SkPicture> fPicture;
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000404 bool fUseChecksumBasedFilenames;
commit-bot@chromium.orga3f882c2013-12-13 20:52:36 +0000405 ImageResultsSummary* fJsonSummaryPtr;
scroggo@google.comc0d5e542012-12-13 21:40:48 +0000406 SkDeviceTypes fDeviceType;
407 BBoxHierarchyType fBBoxHierarchyType;
408 DrawFilterFlags fDrawFilters[SkDrawFilter::kTypeCount];
409 SkString fDrawFiltersConfig;
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000410 SkString fOutputDir;
411 SkString fInputFilename;
commit-bot@chromium.org5fb2ce32014-04-17 23:35:06 +0000412 SkTileGridFactory::TileGridInfo fGridInfo; // used when fBBoxHierarchyType is TileGrid
keyar@chromium.org06125642012-08-20 15:03:33 +0000413
scroggo@google.comc0d5e542012-12-13 21:40:48 +0000414 void buildBBoxHierarchy();
415
416 /**
417 * Return the total width that should be drawn. If the viewport width has been set greater than
418 * 0, this will be the minimum of the current SkPicture's width and the viewport's width.
419 */
420 int getViewWidth();
421
422 /**
423 * Return the total height that should be drawn. If the viewport height has been set greater
424 * than 0, this will be the minimum of the current SkPicture's height and the viewport's height.
425 */
426 int getViewHeight();
427
scroggo@google.com82ec0b02012-12-17 19:25:54 +0000428 /**
429 * Scales the provided canvas to the scale factor set by setScaleFactor.
430 */
431 void scaleToScaleFactor(SkCanvas*);
432
commit-bot@chromium.org5fb2ce32014-04-17 23:35:06 +0000433 SkBBHFactory* getFactory();
scroggo@google.comc0d5e542012-12-13 21:40:48 +0000434 uint32_t recordFlags();
435 SkCanvas* setupCanvas();
436 virtual SkCanvas* setupCanvas(int width, int height);
437
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000438 /**
439 * Copy src to dest; if src==NULL, set dest to empty string.
440 */
441 static void CopyString(SkString* dest, const SkString* src);
442
keyar@chromium.org9d696c02012-08-07 17:11:33 +0000443private:
scroggo@google.comc0d5e542012-12-13 21:40:48 +0000444 SkISize fViewport;
scroggo@google.com82ec0b02012-12-17 19:25:54 +0000445 SkScalar fScaleFactor;
scroggo@google.com0556ea02013-02-08 19:38:21 +0000446#if SK_SUPPORT_GPU
447 GrContextFactory fGrContextFactory;
448 GrContext* fGrContext;
jvanverth@google.comf6a90332013-05-02 12:39:37 +0000449 int fSampleCount;
scroggo@google.com0556ea02013-02-08 19:38:21 +0000450#endif
scroggo@google.comc0d5e542012-12-13 21:40:48 +0000451
scroggo@google.com0a049b82012-11-02 22:01:26 +0000452 virtual SkString getConfigNameInternal() = 0;
453
keyar@chromium.org9d696c02012-08-07 17:11:33 +0000454 typedef SkRefCnt INHERITED;
keyar@chromium.org451bb9f2012-07-26 17:27:57 +0000455};
456
scroggo@google.com9a412522012-09-07 15:21:18 +0000457/**
458 * This class does not do any rendering, but its render function executes recording, which we want
459 * to time.
460 */
461class RecordPictureRenderer : public PictureRenderer {
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000462 virtual bool render(SkBitmap** out = NULL) SK_OVERRIDE;
scroggo@google.com9a412522012-09-07 15:21:18 +0000463
464 virtual SkString getPerIterTimeFormat() SK_OVERRIDE { return SkString("%.4f"); }
465
466 virtual SkString getNormalTimeFormat() SK_OVERRIDE { return SkString("%6.4f"); }
scroggo@google.com0a049b82012-11-02 22:01:26 +0000467
djsollen@google.comfd9720c2012-11-06 16:54:40 +0000468protected:
469 virtual SkCanvas* setupCanvas(int width, int height) SK_OVERRIDE;
470
scroggo@google.com0a049b82012-11-02 22:01:26 +0000471private:
472 virtual SkString getConfigNameInternal() SK_OVERRIDE;
scroggo@google.com9a412522012-09-07 15:21:18 +0000473};
474
keyar@chromium.org451bb9f2012-07-26 17:27:57 +0000475class PipePictureRenderer : public PictureRenderer {
keyar@chromium.org163b5672012-08-01 17:53:29 +0000476public:
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000477 virtual bool render(SkBitmap** out = NULL) SK_OVERRIDE;
keyar@chromium.org9d696c02012-08-07 17:11:33 +0000478
479private:
scroggo@google.com0a049b82012-11-02 22:01:26 +0000480 virtual SkString getConfigNameInternal() SK_OVERRIDE;
481
keyar@chromium.org9d696c02012-08-07 17:11:33 +0000482 typedef PictureRenderer INHERITED;
keyar@chromium.org451bb9f2012-07-26 17:27:57 +0000483};
484
485class SimplePictureRenderer : public PictureRenderer {
keyar@chromium.org163b5672012-08-01 17:53:29 +0000486public:
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000487 virtual void init(SkPicture* pict, const SkString* outputDir,
488 const SkString* inputFilename, bool useChecksumBasedFilenames) SK_OVERRIDE;
junov@chromium.org9313ca42012-11-02 18:11:49 +0000489
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000490 virtual bool render(SkBitmap** out = NULL) SK_OVERRIDE;
keyar@chromium.org9d696c02012-08-07 17:11:33 +0000491
492private:
scroggo@google.com0a049b82012-11-02 22:01:26 +0000493 virtual SkString getConfigNameInternal() SK_OVERRIDE;
494
keyar@chromium.org9d696c02012-08-07 17:11:33 +0000495 typedef PictureRenderer INHERITED;
keyar@chromium.org451bb9f2012-07-26 17:27:57 +0000496};
497
498class TiledPictureRenderer : public PictureRenderer {
499public:
500 TiledPictureRenderer();
501
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000502 virtual void init(SkPicture* pict, const SkString* outputDir,
503 const SkString* inputFilename, bool useChecksumBasedFilenames) SK_OVERRIDE;
scroggo@google.com81f9d2e2012-09-20 14:54:21 +0000504
scroggo@google.com81f9d2e2012-09-20 14:54:21 +0000505 /**
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000506 * Renders to tiles, rather than a single canvas.
507 * If fOutputDir was provided, a separate file is
scroggo@google.com81f9d2e2012-09-20 14:54:21 +0000508 * created for each tile, named "path0.png", "path1.png", etc.
509 * Multithreaded mode currently does not support writing to a file.
510 */
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000511 virtual bool render(SkBitmap** out = NULL) SK_OVERRIDE;
scroggo@google.com81f9d2e2012-09-20 14:54:21 +0000512
keyar@chromium.org9d696c02012-08-07 17:11:33 +0000513 virtual void end() SK_OVERRIDE;
keyar@chromium.org451bb9f2012-07-26 17:27:57 +0000514
keyar@chromium.orgcc6e5ef2012-07-27 20:09:26 +0000515 void setTileWidth(int width) {
516 fTileWidth = width;
517 }
518
519 int getTileWidth() const {
520 return fTileWidth;
521 }
522
523 void setTileHeight(int height) {
524 fTileHeight = height;
525 }
526
527 int getTileHeight() const {
528 return fTileHeight;
529 }
530
531 void setTileWidthPercentage(double percentage) {
532 fTileWidthPercentage = percentage;
533 }
534
keyar@chromium.org163b5672012-08-01 17:53:29 +0000535 double getTileWidthPercentage() const {
keyar@chromium.orgcc6e5ef2012-07-27 20:09:26 +0000536 return fTileWidthPercentage;
537 }
538
539 void setTileHeightPercentage(double percentage) {
540 fTileHeightPercentage = percentage;
541 }
542
keyar@chromium.org163b5672012-08-01 17:53:29 +0000543 double getTileHeightPercentage() const {
keyar@chromium.orgcc6e5ef2012-07-27 20:09:26 +0000544 return fTileHeightPercentage;
545 }
546
keyar@chromium.orgf4959ab2012-08-23 20:53:25 +0000547 void setTileMinPowerOf2Width(int width) {
548 SkASSERT(SkIsPow2(width) && width > 0);
549 if (!SkIsPow2(width) || width <= 0) {
550 return;
551 }
552
553 fTileMinPowerOf2Width = width;
554 }
555
556 int getTileMinPowerOf2Width() const {
557 return fTileMinPowerOf2Width;
558 }
559
scroggo@google.comcbcef702012-12-13 22:09:28 +0000560 virtual TiledPictureRenderer* getTiledRenderer() SK_OVERRIDE { return this; }
561
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000562 virtual bool supportsTimingIndividualTiles() { return true; }
563
scroggo@google.comcbcef702012-12-13 22:09:28 +0000564 /**
565 * Report the number of tiles in the x and y directions. Must not be called before init.
566 * @param x Output parameter identifying the number of tiles in the x direction.
567 * @param y Output parameter identifying the number of tiles in the y direction.
568 * @return True if the tiles have been set up, and x and y are meaningful. If false, x and y are
569 * unmodified.
570 */
571 bool tileDimensions(int& x, int&y);
572
573 /**
574 * Move to the next tile and return its indices. Must be called before calling drawCurrentTile
575 * for the first time.
576 * @param i Output parameter identifying the column of the next tile to be drawn on the next
577 * call to drawNextTile.
578 * @param j Output parameter identifying the row of the next tile to be drawn on the next call
579 * to drawNextTile.
580 * @param True if the tiles have been created and the next tile to be drawn by drawCurrentTile
581 * is within the range of tiles. If false, i and j are unmodified.
582 */
583 bool nextTile(int& i, int& j);
584
585 /**
586 * Render one tile. This will draw the same tile each time it is called until nextTile is
587 * called. The tile rendered will depend on how many calls have been made to nextTile.
588 * It is an error to call this without first calling nextTile, or if nextTile returns false.
589 */
590 void drawCurrentTile();
591
scroggo@google.coma62da2f2012-11-02 21:28:12 +0000592protected:
scroggo@google.coma62da2f2012-11-02 21:28:12 +0000593 SkTDArray<SkRect> fTileRects;
keyar@chromium.org451bb9f2012-07-26 17:27:57 +0000594
scroggo@google.com0a049b82012-11-02 22:01:26 +0000595 virtual SkCanvas* setupCanvas(int width, int height) SK_OVERRIDE;
596 virtual SkString getConfigNameInternal() SK_OVERRIDE;
597
keyar@chromium.org451bb9f2012-07-26 17:27:57 +0000598private:
scroggo@google.comcbcef702012-12-13 22:09:28 +0000599 int fTileWidth;
600 int fTileHeight;
601 double fTileWidthPercentage;
602 double fTileHeightPercentage;
603 int fTileMinPowerOf2Width;
604
605 // These variables are only used for timing individual tiles.
606 // Next tile to draw in fTileRects.
607 int fCurrentTileOffset;
608 // Number of tiles in the x direction.
609 int fTilesX;
610 // Number of tiles in the y direction.
611 int fTilesY;
scroggo@google.combcdf2ec2012-09-20 14:42:33 +0000612
keyar@chromium.org9d696c02012-08-07 17:11:33 +0000613 void setupTiles();
keyar@chromium.orgf4959ab2012-08-23 20:53:25 +0000614 void setupPowerOf2Tiles();
keyar@chromium.org9d696c02012-08-07 17:11:33 +0000615
616 typedef PictureRenderer INHERITED;
keyar@chromium.org451bb9f2012-07-26 17:27:57 +0000617};
618
scroggo@google.coma62da2f2012-11-02 21:28:12 +0000619class CloneData;
620
621class MultiCorePictureRenderer : public TiledPictureRenderer {
622public:
623 explicit MultiCorePictureRenderer(int threadCount);
624
625 ~MultiCorePictureRenderer();
626
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000627 virtual void init(SkPicture* pict, const SkString* outputDir,
628 const SkString* inputFilename, bool useChecksumBasedFilenames) SK_OVERRIDE;
scroggo@google.coma62da2f2012-11-02 21:28:12 +0000629
630 /**
631 * Behaves like TiledPictureRenderer::render(), only using multiple threads.
632 */
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000633 virtual bool render(SkBitmap** out = NULL) SK_OVERRIDE;
scroggo@google.coma62da2f2012-11-02 21:28:12 +0000634
635 virtual void end() SK_OVERRIDE;
636
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000637 virtual bool supportsTimingIndividualTiles() SK_OVERRIDE { return false; }
638
scroggo@google.coma62da2f2012-11-02 21:28:12 +0000639private:
scroggo@google.com0a049b82012-11-02 22:01:26 +0000640 virtual SkString getConfigNameInternal() SK_OVERRIDE;
641
scroggo@google.coma62da2f2012-11-02 21:28:12 +0000642 const int fNumThreads;
643 SkTDArray<SkCanvas*> fCanvasPool;
644 SkThreadPool fThreadPool;
645 SkPicture* fPictureClones;
646 CloneData** fCloneData;
647 SkCountdown fCountdown;
648
649 typedef TiledPictureRenderer INHERITED;
650};
651
scroggo@google.com9a412522012-09-07 15:21:18 +0000652/**
653 * This class does not do any rendering, but its render function executes turning an SkPictureRecord
654 * into an SkPicturePlayback, which we want to time.
655 */
656class PlaybackCreationRenderer : public PictureRenderer {
657public:
658 virtual void setup() SK_OVERRIDE;
659
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000660 virtual bool render(SkBitmap** out = NULL) SK_OVERRIDE;
scroggo@google.com9a412522012-09-07 15:21:18 +0000661
662 virtual SkString getPerIterTimeFormat() SK_OVERRIDE { return SkString("%.4f"); }
663
664 virtual SkString getNormalTimeFormat() SK_OVERRIDE { return SkString("%6.4f"); }
665
666private:
robertphillips@google.com84b18c72014-04-13 19:09:42 +0000667 SkAutoTDelete<SkPictureRecorder> fRecorder;
scroggo@google.com0a049b82012-11-02 22:01:26 +0000668
669 virtual SkString getConfigNameInternal() SK_OVERRIDE;
670
scroggo@google.com9a412522012-09-07 15:21:18 +0000671 typedef PictureRenderer INHERITED;
672};
673
reed@google.comfe7b1ed2012-11-29 21:00:39 +0000674extern PictureRenderer* CreateGatherPixelRefsRenderer();
reed@google.com5a34fd32012-12-10 16:05:09 +0000675extern PictureRenderer* CreatePictureCloneRenderer();
reed@google.comfe7b1ed2012-11-29 21:00:39 +0000676
keyar@chromium.org451bb9f2012-07-26 17:27:57 +0000677}
678
679#endif // PictureRenderer_DEFINED