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