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