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