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