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