caryclark@google.com | 411bb72 | 2012-11-06 21:29:16 +0000 | [diff] [blame] | 1 | /* |
keyar@chromium.org | 451bb9f | 2012-07-26 17:27:57 +0000 | [diff] [blame] | 2 | * 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.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 10 | |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 11 | #include "SkCanvas.h" |
scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 12 | #include "SkCountdown.h" |
caryclark@google.com | a362237 | 2012-11-06 21:26:13 +0000 | [diff] [blame] | 13 | #include "SkDrawFilter.h" |
commit-bot@chromium.org | a3f882c | 2013-12-13 20:52:36 +0000 | [diff] [blame] | 14 | #include "SkJSONCPP.h" |
keyar@chromium.org | f4959ab | 2012-08-23 20:53:25 +0000 | [diff] [blame] | 15 | #include "SkMath.h" |
reed@google.com | ea6a306 | 2012-11-06 22:14:54 +0000 | [diff] [blame] | 16 | #include "SkPaint.h" |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 17 | #include "SkPicture.h" |
scroggo@google.com | acfb30e | 2012-09-18 14:32:35 +0000 | [diff] [blame] | 18 | #include "SkRect.h" |
keyar@chromium.org | 451bb9f | 2012-07-26 17:27:57 +0000 | [diff] [blame] | 19 | #include "SkRefCnt.h" |
scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 20 | #include "SkRunnable.h" |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 21 | #include "SkString.h" |
scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 22 | #include "SkTDArray.h" |
| 23 | #include "SkThreadPool.h" |
junov@chromium.org | 29b19e5 | 2013-02-27 18:35:16 +0000 | [diff] [blame] | 24 | #include "SkTileGridPicture.h" |
scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 25 | #include "SkTypes.h" |
keyar@chromium.org | 451bb9f | 2012-07-26 17:27:57 +0000 | [diff] [blame] | 26 | |
keyar@chromium.org | 0612564 | 2012-08-20 15:03:33 +0000 | [diff] [blame] | 27 | #if SK_SUPPORT_GPU |
| 28 | #include "GrContextFactory.h" |
| 29 | #include "GrContext.h" |
| 30 | #endif |
| 31 | |
keyar@chromium.org | 451bb9f | 2012-07-26 17:27:57 +0000 | [diff] [blame] | 32 | class SkBitmap; |
| 33 | class SkCanvas; |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 34 | class SkGLContextHelper; |
scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 35 | class SkThread; |
keyar@chromium.org | 451bb9f | 2012-07-26 17:27:57 +0000 | [diff] [blame] | 36 | |
| 37 | namespace sk_tools { |
| 38 | |
scroggo@google.com | cbcef70 | 2012-12-13 22:09:28 +0000 | [diff] [blame] | 39 | class TiledPictureRenderer; |
| 40 | |
commit-bot@chromium.org | a3f882c | 2013-12-13 20:52:36 +0000 | [diff] [blame] | 41 | /** |
| 42 | * Class for collecting image results (checksums) as we go. |
| 43 | */ |
| 44 | class ImageResultsSummary { |
| 45 | public: |
| 46 | /** |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 47 | * Adds this bitmap hash to the summary of results. |
| 48 | * |
| 49 | * @param testName name of the test |
| 50 | * @param hash hash to store |
| 51 | */ |
| 52 | void add(const char *testName, uint64_t hash); |
| 53 | |
| 54 | /** |
commit-bot@chromium.org | a3f882c | 2013-12-13 20:52:36 +0000 | [diff] [blame] | 55 | * Adds this bitmap's hash to the summary of results. |
| 56 | * |
| 57 | * @param testName name of the test |
| 58 | * @param bitmap bitmap to store the hash of |
| 59 | */ |
| 60 | void add(const char *testName, const SkBitmap& bitmap); |
| 61 | |
| 62 | /** |
| 63 | * Writes the summary (as constructed so far) to a file. |
| 64 | * |
| 65 | * @param filename path to write the summary to |
| 66 | */ |
| 67 | void writeToFile(const char *filename); |
| 68 | |
| 69 | private: |
| 70 | Json::Value fActualResultsNoComparison; |
| 71 | }; |
| 72 | |
keyar@chromium.org | 451bb9f | 2012-07-26 17:27:57 +0000 | [diff] [blame] | 73 | class PictureRenderer : public SkRefCnt { |
scroggo@google.com | cbcef70 | 2012-12-13 22:09:28 +0000 | [diff] [blame] | 74 | |
keyar@chromium.org | 451bb9f | 2012-07-26 17:27:57 +0000 | [diff] [blame] | 75 | public: |
keyar@chromium.org | c81686c | 2012-08-20 15:04:04 +0000 | [diff] [blame] | 76 | enum SkDeviceTypes { |
scroggo@google.com | 0556ea0 | 2013-02-08 19:38:21 +0000 | [diff] [blame] | 77 | #if SK_ANGLE |
| 78 | kAngle_DeviceType, |
| 79 | #endif |
rmistry@google.com | 6ab9673 | 2014-01-06 18:37:24 +0000 | [diff] [blame] | 80 | #if SK_MESA |
| 81 | kMesa_DeviceType, |
| 82 | #endif |
keyar@chromium.org | c81686c | 2012-08-20 15:04:04 +0000 | [diff] [blame] | 83 | kBitmap_DeviceType, |
| 84 | #if SK_SUPPORT_GPU |
scroggo@google.com | 0556ea0 | 2013-02-08 19:38:21 +0000 | [diff] [blame] | 85 | kGPU_DeviceType, |
commit-bot@chromium.org | 0fd5270 | 2014-03-07 18:41:14 +0000 | [diff] [blame] | 86 | kNVPR_DeviceType, |
keyar@chromium.org | c81686c | 2012-08-20 15:04:04 +0000 | [diff] [blame] | 87 | #endif |
| 88 | }; |
| 89 | |
junov@chromium.org | 9313ca4 | 2012-11-02 18:11:49 +0000 | [diff] [blame] | 90 | enum BBoxHierarchyType { |
| 91 | kNone_BBoxHierarchyType = 0, |
commit-bot@chromium.org | c22d139 | 2014-02-03 18:08:33 +0000 | [diff] [blame] | 92 | kQuadTree_BBoxHierarchyType, |
junov@chromium.org | 9313ca4 | 2012-11-02 18:11:49 +0000 | [diff] [blame] | 93 | kRTree_BBoxHierarchyType, |
junov@chromium.org | 7b53706 | 2012-11-06 18:58:43 +0000 | [diff] [blame] | 94 | kTileGrid_BBoxHierarchyType, |
commit-bot@chromium.org | cdd0f92 | 2014-03-11 17:27:07 +0000 | [diff] [blame] | 95 | |
| 96 | kLast_BBoxHierarchyType = kTileGrid_BBoxHierarchyType, |
junov@chromium.org | 9313ca4 | 2012-11-02 18:11:49 +0000 | [diff] [blame] | 97 | }; |
| 98 | |
caryclark@google.com | a362237 | 2012-11-06 21:26:13 +0000 | [diff] [blame] | 99 | // this uses SkPaint::Flags as a base and adds additional flags |
| 100 | enum DrawFilterFlags { |
| 101 | kNone_DrawFilterFlag = 0, |
reed@google.com | 881b10b | 2013-05-22 14:03:45 +0000 | [diff] [blame] | 102 | kHinting_DrawFilterFlag = 0x10000, // toggles between no hinting and normal hinting |
| 103 | kSlightHinting_DrawFilterFlag = 0x20000, // toggles between slight and normal hinting |
| 104 | kAAClip_DrawFilterFlag = 0x40000, // toggles between soft and hard clip |
humper@google.com | 387db0a | 2013-07-09 14:13:04 +0000 | [diff] [blame] | 105 | kMaskFilter_DrawFilterFlag = 0x80000, // toggles on/off mask filters (e.g., blurs) |
caryclark@google.com | a362237 | 2012-11-06 21:26:13 +0000 | [diff] [blame] | 106 | }; |
| 107 | |
robertphillips@google.com | 4914931 | 2013-07-03 15:34:35 +0000 | [diff] [blame] | 108 | SK_COMPILE_ASSERT(!(kMaskFilter_DrawFilterFlag & SkPaint::kAllFlags), maskfilter_flag_must_be_greater); |
caryclark@google.com | a362237 | 2012-11-06 21:26:13 +0000 | [diff] [blame] | 109 | SK_COMPILE_ASSERT(!(kHinting_DrawFilterFlag & SkPaint::kAllFlags), |
| 110 | hinting_flag_must_be_greater); |
| 111 | SK_COMPILE_ASSERT(!(kSlightHinting_DrawFilterFlag & SkPaint::kAllFlags), |
| 112 | slight_hinting_flag_must_be_greater); |
| 113 | |
scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 114 | /** |
| 115 | * Called with each new SkPicture to render. |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 116 | * |
| 117 | * @param pict The SkPicture to render. |
| 118 | * @param outputDir The output directory within which this renderer should write files, |
| 119 | * or NULL if this renderer should not write files at all. |
| 120 | * @param inputFilename The name of the input file we are rendering. |
| 121 | * @param useChecksumBasedFilenames Whether to use checksum-based filenames when writing |
| 122 | * bitmap images to disk. |
scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 123 | */ |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 124 | virtual void init(SkPicture* pict, const SkString* outputDir, |
| 125 | const SkString* inputFilename, bool useChecksumBasedFilenames); |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 126 | |
| 127 | /** |
scroggo@google.com | c0d5e54 | 2012-12-13 21:40:48 +0000 | [diff] [blame] | 128 | * Set the viewport so that only the portion listed gets drawn. |
| 129 | */ |
| 130 | void setViewport(SkISize size) { fViewport = size; } |
| 131 | |
| 132 | /** |
scroggo@google.com | 82ec0b0 | 2012-12-17 19:25:54 +0000 | [diff] [blame] | 133 | * Set the scale factor at which draw the picture. |
| 134 | */ |
| 135 | void setScaleFactor(SkScalar scale) { fScaleFactor = scale; } |
| 136 | |
| 137 | /** |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 138 | * Perform any setup that should done prior to each iteration of render() which should not be |
| 139 | * timed. |
| 140 | */ |
| 141 | virtual void setup() {} |
| 142 | |
| 143 | /** |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 144 | * Perform the work. If this is being called within the context of bench_pictures, |
| 145 | * this is the step that will be timed. |
| 146 | * |
| 147 | * Typically "the work" is rendering an SkPicture into a bitmap, but in some subclasses |
| 148 | * it is recording the source SkPicture into another SkPicture. |
| 149 | * |
| 150 | * If fOutputDir has been specified, the result of the work will be written to that dir. |
| 151 | * |
| 152 | * @param out If non-null, the implementing subclass MAY allocate an SkBitmap, copy the |
| 153 | * output image into it, and return it here. (Some subclasses ignore this parameter) |
| 154 | * @return bool True if rendering succeeded and, if fOutputDir had been specified, the output |
| 155 | * was successfully written to a file. |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 156 | */ |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 157 | virtual bool render(SkBitmap** out = NULL) = 0; |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 158 | |
scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 159 | /** |
| 160 | * Called once finished with a particular SkPicture, before calling init again, and before |
| 161 | * being done with this Renderer. |
| 162 | */ |
keyar@chromium.org | 9d696c0 | 2012-08-07 17:11:33 +0000 | [diff] [blame] | 163 | virtual void end(); |
scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 164 | |
scroggo@google.com | cbcef70 | 2012-12-13 22:09:28 +0000 | [diff] [blame] | 165 | /** |
| 166 | * If this PictureRenderer is actually a TiledPictureRender, return a pointer to this as a |
| 167 | * TiledPictureRender so its methods can be called. |
| 168 | */ |
| 169 | virtual TiledPictureRenderer* getTiledRenderer() { return NULL; } |
| 170 | |
scroggo@google.com | 08085f8 | 2013-01-28 20:40:24 +0000 | [diff] [blame] | 171 | /** |
| 172 | * Resets the GPU's state. Does nothing if the backing is raster. For a GPU renderer, calls |
commit-bot@chromium.org | 51c040e | 2014-03-11 22:58:00 +0000 | [diff] [blame] | 173 | * flush, swapBuffers and, if callFinish is true, finish. |
scroggo@google.com | 08085f8 | 2013-01-28 20:40:24 +0000 | [diff] [blame] | 174 | * @param callFinish Whether to call finish. |
| 175 | */ |
| 176 | void resetState(bool callFinish); |
keyar@chromium.org | 9d696c0 | 2012-08-07 17:11:33 +0000 | [diff] [blame] | 177 | |
scroggo@google.com | 0556ea0 | 2013-02-08 19:38:21 +0000 | [diff] [blame] | 178 | /** |
robertphillips@google.com | 94d8f1e | 2013-12-18 17:25:33 +0000 | [diff] [blame] | 179 | * Remove all decoded textures from the CPU caches and all uploaded textures |
| 180 | * from the GPU. |
| 181 | */ |
| 182 | void purgeTextures(); |
| 183 | |
| 184 | /** |
scroggo@google.com | 0556ea0 | 2013-02-08 19:38:21 +0000 | [diff] [blame] | 185 | * Set the backend type. Returns true on success and false on failure. |
| 186 | */ |
| 187 | bool setDeviceType(SkDeviceTypes deviceType) { |
keyar@chromium.org | c81686c | 2012-08-20 15:04:04 +0000 | [diff] [blame] | 188 | fDeviceType = deviceType; |
scroggo@google.com | 0556ea0 | 2013-02-08 19:38:21 +0000 | [diff] [blame] | 189 | #if SK_SUPPORT_GPU |
| 190 | // In case this function is called more than once |
| 191 | SkSafeUnref(fGrContext); |
| 192 | fGrContext = NULL; |
| 193 | // Set to Native so it will have an initial value. |
| 194 | GrContextFactory::GLContextType glContextType = GrContextFactory::kNative_GLContextType; |
| 195 | #endif |
| 196 | switch(deviceType) { |
| 197 | case kBitmap_DeviceType: |
| 198 | return true; |
| 199 | #if SK_SUPPORT_GPU |
| 200 | case kGPU_DeviceType: |
| 201 | // Already set to GrContextFactory::kNative_GLContextType, above. |
| 202 | break; |
commit-bot@chromium.org | 0fd5270 | 2014-03-07 18:41:14 +0000 | [diff] [blame] | 203 | case kNVPR_DeviceType: |
| 204 | glContextType = GrContextFactory::kNVPR_GLContextType; |
| 205 | break; |
scroggo@google.com | 0556ea0 | 2013-02-08 19:38:21 +0000 | [diff] [blame] | 206 | #if SK_ANGLE |
| 207 | case kAngle_DeviceType: |
| 208 | glContextType = GrContextFactory::kANGLE_GLContextType; |
| 209 | break; |
| 210 | #endif |
rmistry@google.com | 6ab9673 | 2014-01-06 18:37:24 +0000 | [diff] [blame] | 211 | #if SK_MESA |
| 212 | case kMesa_DeviceType: |
| 213 | glContextType = GrContextFactory::kMESA_GLContextType; |
| 214 | break; |
| 215 | #endif |
scroggo@google.com | 0556ea0 | 2013-02-08 19:38:21 +0000 | [diff] [blame] | 216 | #endif |
| 217 | default: |
| 218 | // Invalid device type. |
| 219 | return false; |
| 220 | } |
| 221 | #if SK_SUPPORT_GPU |
| 222 | fGrContext = fGrContextFactory.get(glContextType); |
| 223 | if (NULL == fGrContext) { |
| 224 | return false; |
| 225 | } else { |
| 226 | fGrContext->ref(); |
| 227 | return true; |
| 228 | } |
| 229 | #endif |
keyar@chromium.org | fe6391a | 2012-08-20 15:03:41 +0000 | [diff] [blame] | 230 | } |
| 231 | |
jvanverth@google.com | f6a9033 | 2013-05-02 12:39:37 +0000 | [diff] [blame] | 232 | #if SK_SUPPORT_GPU |
| 233 | void setSampleCount(int sampleCount) { |
| 234 | fSampleCount = sampleCount; |
| 235 | } |
| 236 | #endif |
| 237 | |
caryclark@google.com | e3e940c | 2012-11-07 16:42:17 +0000 | [diff] [blame] | 238 | void setDrawFilters(DrawFilterFlags const * const filters, const SkString& configName) { |
| 239 | memcpy(fDrawFilters, filters, sizeof(fDrawFilters)); |
caryclark@google.com | a362237 | 2012-11-06 21:26:13 +0000 | [diff] [blame] | 240 | fDrawFiltersConfig = configName; |
| 241 | } |
| 242 | |
junov@chromium.org | 9313ca4 | 2012-11-02 18:11:49 +0000 | [diff] [blame] | 243 | void setBBoxHierarchyType(BBoxHierarchyType bbhType) { |
| 244 | fBBoxHierarchyType = bbhType; |
| 245 | } |
| 246 | |
junov@chromium.org | e286e84 | 2013-03-13 17:27:16 +0000 | [diff] [blame] | 247 | BBoxHierarchyType getBBoxHierarchyType() { return fBBoxHierarchyType; } |
| 248 | |
junov@chromium.org | 7b53706 | 2012-11-06 18:58:43 +0000 | [diff] [blame] | 249 | void setGridSize(int width, int height) { |
junov@chromium.org | 29b19e5 | 2013-02-27 18:35:16 +0000 | [diff] [blame] | 250 | fGridInfo.fTileInterval.set(width, height); |
junov@chromium.org | 7b53706 | 2012-11-06 18:58:43 +0000 | [diff] [blame] | 251 | } |
| 252 | |
commit-bot@chromium.org | a3f882c | 2013-12-13 20:52:36 +0000 | [diff] [blame] | 253 | void setJsonSummaryPtr(ImageResultsSummary* jsonSummaryPtr) { |
| 254 | fJsonSummaryPtr = jsonSummaryPtr; |
| 255 | } |
| 256 | |
keyar@chromium.org | fe6391a | 2012-08-20 15:03:41 +0000 | [diff] [blame] | 257 | bool isUsingBitmapDevice() { |
keyar@chromium.org | 78a35c5 | 2012-08-20 15:03:44 +0000 | [diff] [blame] | 258 | return kBitmap_DeviceType == fDeviceType; |
keyar@chromium.org | 4ea96c5 | 2012-08-20 15:03:29 +0000 | [diff] [blame] | 259 | } |
| 260 | |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 261 | virtual SkString getPerIterTimeFormat() { return SkString("%.2f"); } |
| 262 | |
| 263 | virtual SkString getNormalTimeFormat() { return SkString("%6.2f"); } |
| 264 | |
scroggo@google.com | 0a049b8 | 2012-11-02 22:01:26 +0000 | [diff] [blame] | 265 | /** |
| 266 | * Reports the configuration of this PictureRenderer. |
| 267 | */ |
| 268 | SkString getConfigName() { |
| 269 | SkString config = this->getConfigNameInternal(); |
scroggo@google.com | c4013c1 | 2012-12-13 22:07:08 +0000 | [diff] [blame] | 270 | if (!fViewport.isEmpty()) { |
| 271 | config.appendf("_viewport_%ix%i", fViewport.width(), fViewport.height()); |
| 272 | } |
commit-bot@chromium.org | 9de35eb | 2013-12-20 21:49:33 +0000 | [diff] [blame] | 273 | if (fScaleFactor != SK_Scalar1) { |
| 274 | config.appendf("_scalar_%f", SkScalarToFloat(fScaleFactor)); |
| 275 | } |
scroggo@google.com | 0a049b8 | 2012-11-02 22:01:26 +0000 | [diff] [blame] | 276 | if (kRTree_BBoxHierarchyType == fBBoxHierarchyType) { |
| 277 | config.append("_rtree"); |
commit-bot@chromium.org | c22d139 | 2014-02-03 18:08:33 +0000 | [diff] [blame] | 278 | } else if (kQuadTree_BBoxHierarchyType == fBBoxHierarchyType) { |
| 279 | config.append("_quadtree"); |
junov@chromium.org | 7b53706 | 2012-11-06 18:58:43 +0000 | [diff] [blame] | 280 | } else if (kTileGrid_BBoxHierarchyType == fBBoxHierarchyType) { |
| 281 | config.append("_grid"); |
scroggo@google.com | 0a049b8 | 2012-11-02 22:01:26 +0000 | [diff] [blame] | 282 | } |
| 283 | #if SK_SUPPORT_GPU |
robertphillips@google.com | e8fe4bc | 2013-02-13 13:26:13 +0000 | [diff] [blame] | 284 | switch (fDeviceType) { |
scroggo@google.com | 0556ea0 | 2013-02-08 19:38:21 +0000 | [diff] [blame] | 285 | case kGPU_DeviceType: |
jvanverth@google.com | f6a9033 | 2013-05-02 12:39:37 +0000 | [diff] [blame] | 286 | if (fSampleCount) { |
| 287 | config.appendf("_msaa%d", fSampleCount); |
| 288 | } else { |
| 289 | config.append("_gpu"); |
| 290 | } |
scroggo@google.com | 0556ea0 | 2013-02-08 19:38:21 +0000 | [diff] [blame] | 291 | break; |
commit-bot@chromium.org | 0fd5270 | 2014-03-07 18:41:14 +0000 | [diff] [blame] | 292 | case kNVPR_DeviceType: |
| 293 | config.appendf("_nvprmsaa%d", fSampleCount); |
| 294 | break; |
scroggo@google.com | 0556ea0 | 2013-02-08 19:38:21 +0000 | [diff] [blame] | 295 | #if SK_ANGLE |
| 296 | case kAngle_DeviceType: |
| 297 | config.append("_angle"); |
| 298 | break; |
scroggo@google.com | 0a049b8 | 2012-11-02 22:01:26 +0000 | [diff] [blame] | 299 | #endif |
rmistry@google.com | 6ab9673 | 2014-01-06 18:37:24 +0000 | [diff] [blame] | 300 | #if SK_MESA |
| 301 | case kMesa_DeviceType: |
| 302 | config.append("_mesa"); |
| 303 | break; |
| 304 | #endif |
scroggo@google.com | 0556ea0 | 2013-02-08 19:38:21 +0000 | [diff] [blame] | 305 | default: |
| 306 | // Assume that no extra info means bitmap. |
| 307 | break; |
| 308 | } |
robertphillips@google.com | e8fe4bc | 2013-02-13 13:26:13 +0000 | [diff] [blame] | 309 | #endif |
caryclark@google.com | a362237 | 2012-11-06 21:26:13 +0000 | [diff] [blame] | 310 | config.append(fDrawFiltersConfig.c_str()); |
scroggo@google.com | 0a049b8 | 2012-11-02 22:01:26 +0000 | [diff] [blame] | 311 | return config; |
| 312 | } |
| 313 | |
keyar@chromium.org | 4ea96c5 | 2012-08-20 15:03:29 +0000 | [diff] [blame] | 314 | #if SK_SUPPORT_GPU |
keyar@chromium.org | fe6391a | 2012-08-20 15:03:41 +0000 | [diff] [blame] | 315 | bool isUsingGpuDevice() { |
scroggo@google.com | 0556ea0 | 2013-02-08 19:38:21 +0000 | [diff] [blame] | 316 | switch (fDeviceType) { |
| 317 | case kGPU_DeviceType: |
commit-bot@chromium.org | 0fd5270 | 2014-03-07 18:41:14 +0000 | [diff] [blame] | 318 | case kNVPR_DeviceType: |
scroggo@google.com | 0556ea0 | 2013-02-08 19:38:21 +0000 | [diff] [blame] | 319 | // fall through |
| 320 | #if SK_ANGLE |
| 321 | case kAngle_DeviceType: |
rmistry@google.com | 6ab9673 | 2014-01-06 18:37:24 +0000 | [diff] [blame] | 322 | // fall through |
| 323 | #endif |
| 324 | #if SK_MESA |
| 325 | case kMesa_DeviceType: |
scroggo@google.com | 0556ea0 | 2013-02-08 19:38:21 +0000 | [diff] [blame] | 326 | #endif |
| 327 | return true; |
| 328 | default: |
| 329 | return false; |
| 330 | } |
keyar@chromium.org | fe6391a | 2012-08-20 15:03:41 +0000 | [diff] [blame] | 331 | } |
keyar@chromium.org | 77a5522 | 2012-08-20 15:03:47 +0000 | [diff] [blame] | 332 | |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 333 | SkGLContextHelper* getGLContext() { |
scroggo@google.com | 0556ea0 | 2013-02-08 19:38:21 +0000 | [diff] [blame] | 334 | GrContextFactory::GLContextType glContextType |
| 335 | = GrContextFactory::kNull_GLContextType; |
| 336 | switch(fDeviceType) { |
| 337 | case kGPU_DeviceType: |
| 338 | glContextType = GrContextFactory::kNative_GLContextType; |
| 339 | break; |
commit-bot@chromium.org | 0fd5270 | 2014-03-07 18:41:14 +0000 | [diff] [blame] | 340 | case kNVPR_DeviceType: |
| 341 | glContextType = GrContextFactory::kNVPR_GLContextType; |
| 342 | break; |
scroggo@google.com | 0556ea0 | 2013-02-08 19:38:21 +0000 | [diff] [blame] | 343 | #if SK_ANGLE |
| 344 | case kAngle_DeviceType: |
| 345 | glContextType = GrContextFactory::kANGLE_GLContextType; |
| 346 | break; |
| 347 | #endif |
rmistry@google.com | 6ab9673 | 2014-01-06 18:37:24 +0000 | [diff] [blame] | 348 | #if SK_MESA |
| 349 | case kMesa_DeviceType: |
| 350 | glContextType = GrContextFactory::kMESA_GLContextType; |
| 351 | break; |
| 352 | #endif |
scroggo@google.com | 0556ea0 | 2013-02-08 19:38:21 +0000 | [diff] [blame] | 353 | default: |
| 354 | return NULL; |
keyar@chromium.org | 77a5522 | 2012-08-20 15:03:47 +0000 | [diff] [blame] | 355 | } |
scroggo@google.com | 0556ea0 | 2013-02-08 19:38:21 +0000 | [diff] [blame] | 356 | return fGrContextFactory.getGLContext(glContextType); |
keyar@chromium.org | 77a5522 | 2012-08-20 15:03:47 +0000 | [diff] [blame] | 357 | } |
robertphillips@google.com | 163c84b | 2012-09-13 15:40:37 +0000 | [diff] [blame] | 358 | |
| 359 | GrContext* getGrContext() { |
| 360 | return fGrContext; |
| 361 | } |
keyar@chromium.org | 4ea96c5 | 2012-08-20 15:03:29 +0000 | [diff] [blame] | 362 | #endif |
| 363 | |
commit-bot@chromium.org | 145d1c0 | 2014-03-16 19:46:36 +0000 | [diff] [blame] | 364 | SkCanvas* getCanvas() { |
| 365 | return fCanvas; |
| 366 | } |
| 367 | |
keyar@chromium.org | 02dfb12 | 2012-08-20 15:03:36 +0000 | [diff] [blame] | 368 | PictureRenderer() |
keyar@chromium.org | 0612564 | 2012-08-20 15:03:33 +0000 | [diff] [blame] | 369 | : fPicture(NULL) |
commit-bot@chromium.org | a3f882c | 2013-12-13 20:52:36 +0000 | [diff] [blame] | 370 | , fJsonSummaryPtr(NULL) |
keyar@chromium.org | 0612564 | 2012-08-20 15:03:33 +0000 | [diff] [blame] | 371 | , fDeviceType(kBitmap_DeviceType) |
junov@chromium.org | 50ff9bd | 2012-11-02 19:16:22 +0000 | [diff] [blame] | 372 | , fBBoxHierarchyType(kNone_BBoxHierarchyType) |
scroggo@google.com | 06d6ac6 | 2013-02-08 21:16:19 +0000 | [diff] [blame] | 373 | , fScaleFactor(SK_Scalar1) |
keyar@chromium.org | 0612564 | 2012-08-20 15:03:33 +0000 | [diff] [blame] | 374 | #if SK_SUPPORT_GPU |
scroggo@google.com | 0556ea0 | 2013-02-08 19:38:21 +0000 | [diff] [blame] | 375 | , fGrContext(NULL) |
jvanverth@google.com | f6a9033 | 2013-05-02 12:39:37 +0000 | [diff] [blame] | 376 | , fSampleCount(0) |
keyar@chromium.org | 0612564 | 2012-08-20 15:03:33 +0000 | [diff] [blame] | 377 | #endif |
caryclark@google.com | e3e940c | 2012-11-07 16:42:17 +0000 | [diff] [blame] | 378 | { |
robertphillips@google.com | 7ae918e | 2013-03-02 17:45:27 +0000 | [diff] [blame] | 379 | fGridInfo.fMargin.setEmpty(); |
| 380 | fGridInfo.fOffset.setZero(); |
| 381 | fGridInfo.fTileInterval.set(1, 1); |
caryclark@google.com | e3e940c | 2012-11-07 16:42:17 +0000 | [diff] [blame] | 382 | sk_bzero(fDrawFilters, sizeof(fDrawFilters)); |
scroggo@google.com | c0d5e54 | 2012-12-13 21:40:48 +0000 | [diff] [blame] | 383 | fViewport.set(0, 0); |
caryclark@google.com | e3e940c | 2012-11-07 16:42:17 +0000 | [diff] [blame] | 384 | } |
keyar@chromium.org | 0612564 | 2012-08-20 15:03:33 +0000 | [diff] [blame] | 385 | |
scroggo@google.com | 0556ea0 | 2013-02-08 19:38:21 +0000 | [diff] [blame] | 386 | #if SK_SUPPORT_GPU |
| 387 | virtual ~PictureRenderer() { |
| 388 | SkSafeUnref(fGrContext); |
| 389 | } |
| 390 | #endif |
| 391 | |
keyar@chromium.org | 9d696c0 | 2012-08-07 17:11:33 +0000 | [diff] [blame] | 392 | protected: |
| 393 | SkAutoTUnref<SkCanvas> fCanvas; |
scroggo@google.com | c0d5e54 | 2012-12-13 21:40:48 +0000 | [diff] [blame] | 394 | SkPicture* fPicture; |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 395 | bool fUseChecksumBasedFilenames; |
commit-bot@chromium.org | a3f882c | 2013-12-13 20:52:36 +0000 | [diff] [blame] | 396 | ImageResultsSummary* fJsonSummaryPtr; |
scroggo@google.com | c0d5e54 | 2012-12-13 21:40:48 +0000 | [diff] [blame] | 397 | SkDeviceTypes fDeviceType; |
| 398 | BBoxHierarchyType fBBoxHierarchyType; |
| 399 | DrawFilterFlags fDrawFilters[SkDrawFilter::kTypeCount]; |
| 400 | SkString fDrawFiltersConfig; |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 401 | SkString fOutputDir; |
| 402 | SkString fInputFilename; |
junov@chromium.org | 29b19e5 | 2013-02-27 18:35:16 +0000 | [diff] [blame] | 403 | SkTileGridPicture::TileGridInfo fGridInfo; // used when fBBoxHierarchyType is TileGrid |
keyar@chromium.org | 0612564 | 2012-08-20 15:03:33 +0000 | [diff] [blame] | 404 | |
scroggo@google.com | c0d5e54 | 2012-12-13 21:40:48 +0000 | [diff] [blame] | 405 | void buildBBoxHierarchy(); |
| 406 | |
| 407 | /** |
| 408 | * Return the total width that should be drawn. If the viewport width has been set greater than |
| 409 | * 0, this will be the minimum of the current SkPicture's width and the viewport's width. |
| 410 | */ |
| 411 | int getViewWidth(); |
| 412 | |
| 413 | /** |
| 414 | * Return the total height that should be drawn. If the viewport height has been set greater |
| 415 | * than 0, this will be the minimum of the current SkPicture's height and the viewport's height. |
| 416 | */ |
| 417 | int getViewHeight(); |
| 418 | |
scroggo@google.com | 82ec0b0 | 2012-12-17 19:25:54 +0000 | [diff] [blame] | 419 | /** |
| 420 | * Scales the provided canvas to the scale factor set by setScaleFactor. |
| 421 | */ |
| 422 | void scaleToScaleFactor(SkCanvas*); |
| 423 | |
scroggo@google.com | c0d5e54 | 2012-12-13 21:40:48 +0000 | [diff] [blame] | 424 | SkPicture* createPicture(); |
| 425 | uint32_t recordFlags(); |
| 426 | SkCanvas* setupCanvas(); |
| 427 | virtual SkCanvas* setupCanvas(int width, int height); |
| 428 | |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 429 | /** |
| 430 | * Copy src to dest; if src==NULL, set dest to empty string. |
| 431 | */ |
| 432 | static void CopyString(SkString* dest, const SkString* src); |
| 433 | |
keyar@chromium.org | 9d696c0 | 2012-08-07 17:11:33 +0000 | [diff] [blame] | 434 | private: |
scroggo@google.com | c0d5e54 | 2012-12-13 21:40:48 +0000 | [diff] [blame] | 435 | SkISize fViewport; |
scroggo@google.com | 82ec0b0 | 2012-12-17 19:25:54 +0000 | [diff] [blame] | 436 | SkScalar fScaleFactor; |
scroggo@google.com | 0556ea0 | 2013-02-08 19:38:21 +0000 | [diff] [blame] | 437 | #if SK_SUPPORT_GPU |
| 438 | GrContextFactory fGrContextFactory; |
| 439 | GrContext* fGrContext; |
jvanverth@google.com | f6a9033 | 2013-05-02 12:39:37 +0000 | [diff] [blame] | 440 | int fSampleCount; |
scroggo@google.com | 0556ea0 | 2013-02-08 19:38:21 +0000 | [diff] [blame] | 441 | #endif |
scroggo@google.com | c0d5e54 | 2012-12-13 21:40:48 +0000 | [diff] [blame] | 442 | |
scroggo@google.com | 0a049b8 | 2012-11-02 22:01:26 +0000 | [diff] [blame] | 443 | virtual SkString getConfigNameInternal() = 0; |
| 444 | |
keyar@chromium.org | 9d696c0 | 2012-08-07 17:11:33 +0000 | [diff] [blame] | 445 | typedef SkRefCnt INHERITED; |
keyar@chromium.org | 451bb9f | 2012-07-26 17:27:57 +0000 | [diff] [blame] | 446 | }; |
| 447 | |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 448 | /** |
| 449 | * This class does not do any rendering, but its render function executes recording, which we want |
| 450 | * to time. |
| 451 | */ |
| 452 | class RecordPictureRenderer : public PictureRenderer { |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 453 | virtual bool render(SkBitmap** out = NULL) SK_OVERRIDE; |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 454 | |
| 455 | virtual SkString getPerIterTimeFormat() SK_OVERRIDE { return SkString("%.4f"); } |
| 456 | |
| 457 | virtual SkString getNormalTimeFormat() SK_OVERRIDE { return SkString("%6.4f"); } |
scroggo@google.com | 0a049b8 | 2012-11-02 22:01:26 +0000 | [diff] [blame] | 458 | |
djsollen@google.com | fd9720c | 2012-11-06 16:54:40 +0000 | [diff] [blame] | 459 | protected: |
| 460 | virtual SkCanvas* setupCanvas(int width, int height) SK_OVERRIDE; |
| 461 | |
scroggo@google.com | 0a049b8 | 2012-11-02 22:01:26 +0000 | [diff] [blame] | 462 | private: |
| 463 | virtual SkString getConfigNameInternal() SK_OVERRIDE; |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 464 | }; |
| 465 | |
keyar@chromium.org | 451bb9f | 2012-07-26 17:27:57 +0000 | [diff] [blame] | 466 | class PipePictureRenderer : public PictureRenderer { |
keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 467 | public: |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 468 | virtual bool render(SkBitmap** out = NULL) SK_OVERRIDE; |
keyar@chromium.org | 9d696c0 | 2012-08-07 17:11:33 +0000 | [diff] [blame] | 469 | |
| 470 | private: |
scroggo@google.com | 0a049b8 | 2012-11-02 22:01:26 +0000 | [diff] [blame] | 471 | virtual SkString getConfigNameInternal() SK_OVERRIDE; |
| 472 | |
keyar@chromium.org | 9d696c0 | 2012-08-07 17:11:33 +0000 | [diff] [blame] | 473 | typedef PictureRenderer INHERITED; |
keyar@chromium.org | 451bb9f | 2012-07-26 17:27:57 +0000 | [diff] [blame] | 474 | }; |
| 475 | |
| 476 | class SimplePictureRenderer : public PictureRenderer { |
keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 477 | public: |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 478 | virtual void init(SkPicture* pict, const SkString* outputDir, |
| 479 | const SkString* inputFilename, bool useChecksumBasedFilenames) SK_OVERRIDE; |
junov@chromium.org | 9313ca4 | 2012-11-02 18:11:49 +0000 | [diff] [blame] | 480 | |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 481 | virtual bool render(SkBitmap** out = NULL) SK_OVERRIDE; |
keyar@chromium.org | 9d696c0 | 2012-08-07 17:11:33 +0000 | [diff] [blame] | 482 | |
| 483 | private: |
scroggo@google.com | 0a049b8 | 2012-11-02 22:01:26 +0000 | [diff] [blame] | 484 | virtual SkString getConfigNameInternal() SK_OVERRIDE; |
| 485 | |
keyar@chromium.org | 9d696c0 | 2012-08-07 17:11:33 +0000 | [diff] [blame] | 486 | typedef PictureRenderer INHERITED; |
keyar@chromium.org | 451bb9f | 2012-07-26 17:27:57 +0000 | [diff] [blame] | 487 | }; |
| 488 | |
| 489 | class TiledPictureRenderer : public PictureRenderer { |
| 490 | public: |
| 491 | TiledPictureRenderer(); |
| 492 | |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 493 | virtual void init(SkPicture* pict, const SkString* outputDir, |
| 494 | const SkString* inputFilename, bool useChecksumBasedFilenames) SK_OVERRIDE; |
scroggo@google.com | 81f9d2e | 2012-09-20 14:54:21 +0000 | [diff] [blame] | 495 | |
scroggo@google.com | 81f9d2e | 2012-09-20 14:54:21 +0000 | [diff] [blame] | 496 | /** |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 497 | * Renders to tiles, rather than a single canvas. |
| 498 | * If fOutputDir was provided, a separate file is |
scroggo@google.com | 81f9d2e | 2012-09-20 14:54:21 +0000 | [diff] [blame] | 499 | * created for each tile, named "path0.png", "path1.png", etc. |
| 500 | * Multithreaded mode currently does not support writing to a file. |
| 501 | */ |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 502 | virtual bool render(SkBitmap** out = NULL) SK_OVERRIDE; |
scroggo@google.com | 81f9d2e | 2012-09-20 14:54:21 +0000 | [diff] [blame] | 503 | |
keyar@chromium.org | 9d696c0 | 2012-08-07 17:11:33 +0000 | [diff] [blame] | 504 | virtual void end() SK_OVERRIDE; |
keyar@chromium.org | 451bb9f | 2012-07-26 17:27:57 +0000 | [diff] [blame] | 505 | |
keyar@chromium.org | cc6e5ef | 2012-07-27 20:09:26 +0000 | [diff] [blame] | 506 | void setTileWidth(int width) { |
| 507 | fTileWidth = width; |
| 508 | } |
| 509 | |
| 510 | int getTileWidth() const { |
| 511 | return fTileWidth; |
| 512 | } |
| 513 | |
| 514 | void setTileHeight(int height) { |
| 515 | fTileHeight = height; |
| 516 | } |
| 517 | |
| 518 | int getTileHeight() const { |
| 519 | return fTileHeight; |
| 520 | } |
| 521 | |
| 522 | void setTileWidthPercentage(double percentage) { |
| 523 | fTileWidthPercentage = percentage; |
| 524 | } |
| 525 | |
keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 526 | double getTileWidthPercentage() const { |
keyar@chromium.org | cc6e5ef | 2012-07-27 20:09:26 +0000 | [diff] [blame] | 527 | return fTileWidthPercentage; |
| 528 | } |
| 529 | |
| 530 | void setTileHeightPercentage(double percentage) { |
| 531 | fTileHeightPercentage = percentage; |
| 532 | } |
| 533 | |
keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 534 | double getTileHeightPercentage() const { |
keyar@chromium.org | cc6e5ef | 2012-07-27 20:09:26 +0000 | [diff] [blame] | 535 | return fTileHeightPercentage; |
| 536 | } |
| 537 | |
keyar@chromium.org | f4959ab | 2012-08-23 20:53:25 +0000 | [diff] [blame] | 538 | void setTileMinPowerOf2Width(int width) { |
| 539 | SkASSERT(SkIsPow2(width) && width > 0); |
| 540 | if (!SkIsPow2(width) || width <= 0) { |
| 541 | return; |
| 542 | } |
| 543 | |
| 544 | fTileMinPowerOf2Width = width; |
| 545 | } |
| 546 | |
| 547 | int getTileMinPowerOf2Width() const { |
| 548 | return fTileMinPowerOf2Width; |
| 549 | } |
| 550 | |
scroggo@google.com | cbcef70 | 2012-12-13 22:09:28 +0000 | [diff] [blame] | 551 | virtual TiledPictureRenderer* getTiledRenderer() SK_OVERRIDE { return this; } |
| 552 | |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 553 | virtual bool supportsTimingIndividualTiles() { return true; } |
| 554 | |
scroggo@google.com | cbcef70 | 2012-12-13 22:09:28 +0000 | [diff] [blame] | 555 | /** |
| 556 | * Report the number of tiles in the x and y directions. Must not be called before init. |
| 557 | * @param x Output parameter identifying the number of tiles in the x direction. |
| 558 | * @param y Output parameter identifying the number of tiles in the y direction. |
| 559 | * @return True if the tiles have been set up, and x and y are meaningful. If false, x and y are |
| 560 | * unmodified. |
| 561 | */ |
| 562 | bool tileDimensions(int& x, int&y); |
| 563 | |
| 564 | /** |
| 565 | * Move to the next tile and return its indices. Must be called before calling drawCurrentTile |
| 566 | * for the first time. |
| 567 | * @param i Output parameter identifying the column of the next tile to be drawn on the next |
| 568 | * call to drawNextTile. |
| 569 | * @param j Output parameter identifying the row of the next tile to be drawn on the next call |
| 570 | * to drawNextTile. |
| 571 | * @param True if the tiles have been created and the next tile to be drawn by drawCurrentTile |
| 572 | * is within the range of tiles. If false, i and j are unmodified. |
| 573 | */ |
| 574 | bool nextTile(int& i, int& j); |
| 575 | |
| 576 | /** |
| 577 | * Render one tile. This will draw the same tile each time it is called until nextTile is |
| 578 | * called. The tile rendered will depend on how many calls have been made to nextTile. |
| 579 | * It is an error to call this without first calling nextTile, or if nextTile returns false. |
| 580 | */ |
| 581 | void drawCurrentTile(); |
| 582 | |
scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 583 | protected: |
scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 584 | SkTDArray<SkRect> fTileRects; |
keyar@chromium.org | 451bb9f | 2012-07-26 17:27:57 +0000 | [diff] [blame] | 585 | |
scroggo@google.com | 0a049b8 | 2012-11-02 22:01:26 +0000 | [diff] [blame] | 586 | virtual SkCanvas* setupCanvas(int width, int height) SK_OVERRIDE; |
| 587 | virtual SkString getConfigNameInternal() SK_OVERRIDE; |
| 588 | |
keyar@chromium.org | 451bb9f | 2012-07-26 17:27:57 +0000 | [diff] [blame] | 589 | private: |
scroggo@google.com | cbcef70 | 2012-12-13 22:09:28 +0000 | [diff] [blame] | 590 | int fTileWidth; |
| 591 | int fTileHeight; |
| 592 | double fTileWidthPercentage; |
| 593 | double fTileHeightPercentage; |
| 594 | int fTileMinPowerOf2Width; |
| 595 | |
| 596 | // These variables are only used for timing individual tiles. |
| 597 | // Next tile to draw in fTileRects. |
| 598 | int fCurrentTileOffset; |
| 599 | // Number of tiles in the x direction. |
| 600 | int fTilesX; |
| 601 | // Number of tiles in the y direction. |
| 602 | int fTilesY; |
scroggo@google.com | bcdf2ec | 2012-09-20 14:42:33 +0000 | [diff] [blame] | 603 | |
keyar@chromium.org | 9d696c0 | 2012-08-07 17:11:33 +0000 | [diff] [blame] | 604 | void setupTiles(); |
keyar@chromium.org | f4959ab | 2012-08-23 20:53:25 +0000 | [diff] [blame] | 605 | void setupPowerOf2Tiles(); |
keyar@chromium.org | 9d696c0 | 2012-08-07 17:11:33 +0000 | [diff] [blame] | 606 | |
| 607 | typedef PictureRenderer INHERITED; |
keyar@chromium.org | 451bb9f | 2012-07-26 17:27:57 +0000 | [diff] [blame] | 608 | }; |
| 609 | |
scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 610 | class CloneData; |
| 611 | |
| 612 | class MultiCorePictureRenderer : public TiledPictureRenderer { |
| 613 | public: |
| 614 | explicit MultiCorePictureRenderer(int threadCount); |
| 615 | |
| 616 | ~MultiCorePictureRenderer(); |
| 617 | |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 618 | virtual void init(SkPicture* pict, const SkString* outputDir, |
| 619 | const SkString* inputFilename, bool useChecksumBasedFilenames) SK_OVERRIDE; |
scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 620 | |
| 621 | /** |
| 622 | * Behaves like TiledPictureRenderer::render(), only using multiple threads. |
| 623 | */ |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 624 | virtual bool render(SkBitmap** out = NULL) SK_OVERRIDE; |
scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 625 | |
| 626 | virtual void end() SK_OVERRIDE; |
| 627 | |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 628 | virtual bool supportsTimingIndividualTiles() SK_OVERRIDE { return false; } |
| 629 | |
scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 630 | private: |
scroggo@google.com | 0a049b8 | 2012-11-02 22:01:26 +0000 | [diff] [blame] | 631 | virtual SkString getConfigNameInternal() SK_OVERRIDE; |
| 632 | |
scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 633 | const int fNumThreads; |
| 634 | SkTDArray<SkCanvas*> fCanvasPool; |
| 635 | SkThreadPool fThreadPool; |
| 636 | SkPicture* fPictureClones; |
| 637 | CloneData** fCloneData; |
| 638 | SkCountdown fCountdown; |
| 639 | |
| 640 | typedef TiledPictureRenderer INHERITED; |
| 641 | }; |
| 642 | |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 643 | /** |
| 644 | * This class does not do any rendering, but its render function executes turning an SkPictureRecord |
| 645 | * into an SkPicturePlayback, which we want to time. |
| 646 | */ |
| 647 | class PlaybackCreationRenderer : public PictureRenderer { |
| 648 | public: |
| 649 | virtual void setup() SK_OVERRIDE; |
| 650 | |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 651 | virtual bool render(SkBitmap** out = NULL) SK_OVERRIDE; |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 652 | |
| 653 | virtual SkString getPerIterTimeFormat() SK_OVERRIDE { return SkString("%.4f"); } |
| 654 | |
| 655 | virtual SkString getNormalTimeFormat() SK_OVERRIDE { return SkString("%6.4f"); } |
| 656 | |
| 657 | private: |
junov@chromium.org | 9313ca4 | 2012-11-02 18:11:49 +0000 | [diff] [blame] | 658 | SkAutoTUnref<SkPicture> fReplayer; |
scroggo@google.com | 0a049b8 | 2012-11-02 22:01:26 +0000 | [diff] [blame] | 659 | |
| 660 | virtual SkString getConfigNameInternal() SK_OVERRIDE; |
| 661 | |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 662 | typedef PictureRenderer INHERITED; |
| 663 | }; |
| 664 | |
reed@google.com | fe7b1ed | 2012-11-29 21:00:39 +0000 | [diff] [blame] | 665 | extern PictureRenderer* CreateGatherPixelRefsRenderer(); |
reed@google.com | 5a34fd3 | 2012-12-10 16:05:09 +0000 | [diff] [blame] | 666 | extern PictureRenderer* CreatePictureCloneRenderer(); |
reed@google.com | fe7b1ed | 2012-11-29 21:00:39 +0000 | [diff] [blame] | 667 | |
keyar@chromium.org | 451bb9f | 2012-07-26 17:27:57 +0000 | [diff] [blame] | 668 | } |
| 669 | |
| 670 | #endif // PictureRenderer_DEFINED |