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