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" |
| 22 | #include "SkTypes.h" |
keyar@chromium.org | 451bb9f | 2012-07-26 17:27:57 +0000 | [diff] [blame] | 23 | |
keyar@chromium.org | 0612564 | 2012-08-20 15:03:33 +0000 | [diff] [blame] | 24 | #if SK_SUPPORT_GPU |
| 25 | #include "GrContextFactory.h" |
| 26 | #include "GrContext.h" |
| 27 | #endif |
| 28 | |
keyar@chromium.org | 451bb9f | 2012-07-26 17:27:57 +0000 | [diff] [blame] | 29 | class SkBitmap; |
| 30 | class SkCanvas; |
keyar@chromium.org | 4ea96c5 | 2012-08-20 15:03:29 +0000 | [diff] [blame] | 31 | class SkGLContext; |
scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 32 | class SkThread; |
keyar@chromium.org | 451bb9f | 2012-07-26 17:27:57 +0000 | [diff] [blame] | 33 | |
| 34 | namespace sk_tools { |
| 35 | |
| 36 | class PictureRenderer : public SkRefCnt { |
| 37 | public: |
keyar@chromium.org | c81686c | 2012-08-20 15:04:04 +0000 | [diff] [blame] | 38 | enum SkDeviceTypes { |
| 39 | kBitmap_DeviceType, |
| 40 | #if SK_SUPPORT_GPU |
| 41 | kGPU_DeviceType |
| 42 | #endif |
| 43 | }; |
| 44 | |
junov@chromium.org | 9313ca4 | 2012-11-02 18:11:49 +0000 | [diff] [blame] | 45 | enum BBoxHierarchyType { |
| 46 | kNone_BBoxHierarchyType = 0, |
| 47 | kRTree_BBoxHierarchyType, |
junov@chromium.org | 7b53706 | 2012-11-06 18:58:43 +0000 | [diff] [blame] | 48 | kTileGrid_BBoxHierarchyType, |
junov@chromium.org | 9313ca4 | 2012-11-02 18:11:49 +0000 | [diff] [blame] | 49 | }; |
| 50 | |
caryclark@google.com | a362237 | 2012-11-06 21:26:13 +0000 | [diff] [blame] | 51 | // this uses SkPaint::Flags as a base and adds additional flags |
| 52 | enum DrawFilterFlags { |
| 53 | kNone_DrawFilterFlag = 0, |
caryclark@google.com | e3e940c | 2012-11-07 16:42:17 +0000 | [diff] [blame] | 54 | kBlur_DrawFilterFlag = 0x4000, // toggles between blur and no blur |
| 55 | kLowBlur_DrawFilterFlag = 0x8000, // toggles between low and high quality blur |
| 56 | kHinting_DrawFilterFlag = 0x10000, // toggles between no hinting and normal hinting |
| 57 | kSlightHinting_DrawFilterFlag = 0x20000, // toggles between slight and normal hinting |
| 58 | kAAClip_DrawFilterFlag = 0x40000, // toggles between soft and hard clip |
caryclark@google.com | a362237 | 2012-11-06 21:26:13 +0000 | [diff] [blame] | 59 | }; |
| 60 | |
| 61 | SK_COMPILE_ASSERT(!(kBlur_DrawFilterFlag & SkPaint::kAllFlags), blur_flag_must_be_greater); |
| 62 | SK_COMPILE_ASSERT(!(kHinting_DrawFilterFlag & SkPaint::kAllFlags), |
| 63 | hinting_flag_must_be_greater); |
| 64 | SK_COMPILE_ASSERT(!(kSlightHinting_DrawFilterFlag & SkPaint::kAllFlags), |
| 65 | slight_hinting_flag_must_be_greater); |
| 66 | |
scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 67 | /** |
| 68 | * Called with each new SkPicture to render. |
| 69 | */ |
keyar@chromium.org | 9d696c0 | 2012-08-07 17:11:33 +0000 | [diff] [blame] | 70 | virtual void init(SkPicture* pict); |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 71 | |
| 72 | /** |
scroggo@google.com | c0d5e54 | 2012-12-13 21:40:48 +0000 | [diff] [blame^] | 73 | * Set the viewport so that only the portion listed gets drawn. |
| 74 | */ |
| 75 | void setViewport(SkISize size) { fViewport = size; } |
| 76 | |
| 77 | /** |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 78 | * Perform any setup that should done prior to each iteration of render() which should not be |
| 79 | * timed. |
| 80 | */ |
| 81 | virtual void setup() {} |
| 82 | |
| 83 | /** |
| 84 | * Perform work that is to be timed. Typically this is rendering, but is also used for recording |
| 85 | * and preparing picture for playback by the subclasses which do those. |
scroggo@google.com | 81f9d2e | 2012-09-20 14:54:21 +0000 | [diff] [blame] | 86 | * If path is non-null, subclass implementations should call write(). |
| 87 | * @param path If non-null, also write the output to the file specified by path. path should |
| 88 | * have no extension; it will be added by write(). |
borenet@google.com | 070d354 | 2012-10-26 13:26:55 +0000 | [diff] [blame] | 89 | * @return bool True if rendering succeeded and, if path is non-null, the output was |
| 90 | * successfully written to a file. |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 91 | */ |
scroggo@google.com | 81f9d2e | 2012-09-20 14:54:21 +0000 | [diff] [blame] | 92 | virtual bool render(const SkString* path) = 0; |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 93 | |
scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 94 | /** |
| 95 | * Called once finished with a particular SkPicture, before calling init again, and before |
| 96 | * being done with this Renderer. |
| 97 | */ |
keyar@chromium.org | 9d696c0 | 2012-08-07 17:11:33 +0000 | [diff] [blame] | 98 | virtual void end(); |
scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 99 | |
keyar@chromium.org | 28136b3 | 2012-08-20 15:04:15 +0000 | [diff] [blame] | 100 | void resetState(); |
keyar@chromium.org | 9d696c0 | 2012-08-07 17:11:33 +0000 | [diff] [blame] | 101 | |
keyar@chromium.org | c81686c | 2012-08-20 15:04:04 +0000 | [diff] [blame] | 102 | void setDeviceType(SkDeviceTypes deviceType) { |
| 103 | fDeviceType = deviceType; |
keyar@chromium.org | fe6391a | 2012-08-20 15:03:41 +0000 | [diff] [blame] | 104 | } |
| 105 | |
caryclark@google.com | e3e940c | 2012-11-07 16:42:17 +0000 | [diff] [blame] | 106 | void setDrawFilters(DrawFilterFlags const * const filters, const SkString& configName) { |
| 107 | memcpy(fDrawFilters, filters, sizeof(fDrawFilters)); |
caryclark@google.com | a362237 | 2012-11-06 21:26:13 +0000 | [diff] [blame] | 108 | fDrawFiltersConfig = configName; |
| 109 | } |
| 110 | |
junov@chromium.org | 9313ca4 | 2012-11-02 18:11:49 +0000 | [diff] [blame] | 111 | void setBBoxHierarchyType(BBoxHierarchyType bbhType) { |
| 112 | fBBoxHierarchyType = bbhType; |
| 113 | } |
| 114 | |
junov@chromium.org | 7b53706 | 2012-11-06 18:58:43 +0000 | [diff] [blame] | 115 | void setGridSize(int width, int height) { |
| 116 | fGridWidth = width; |
| 117 | fGridHeight = height; |
| 118 | } |
| 119 | |
keyar@chromium.org | fe6391a | 2012-08-20 15:03:41 +0000 | [diff] [blame] | 120 | bool isUsingBitmapDevice() { |
keyar@chromium.org | 78a35c5 | 2012-08-20 15:03:44 +0000 | [diff] [blame] | 121 | return kBitmap_DeviceType == fDeviceType; |
keyar@chromium.org | 4ea96c5 | 2012-08-20 15:03:29 +0000 | [diff] [blame] | 122 | } |
| 123 | |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 124 | virtual SkString getPerIterTimeFormat() { return SkString("%.2f"); } |
| 125 | |
| 126 | virtual SkString getNormalTimeFormat() { return SkString("%6.2f"); } |
| 127 | |
scroggo@google.com | 0a049b8 | 2012-11-02 22:01:26 +0000 | [diff] [blame] | 128 | /** |
| 129 | * Reports the configuration of this PictureRenderer. |
| 130 | */ |
| 131 | SkString getConfigName() { |
| 132 | SkString config = this->getConfigNameInternal(); |
| 133 | if (kRTree_BBoxHierarchyType == fBBoxHierarchyType) { |
| 134 | config.append("_rtree"); |
junov@chromium.org | 7b53706 | 2012-11-06 18:58:43 +0000 | [diff] [blame] | 135 | } else if (kTileGrid_BBoxHierarchyType == fBBoxHierarchyType) { |
| 136 | config.append("_grid"); |
scroggo@google.com | 0a049b8 | 2012-11-02 22:01:26 +0000 | [diff] [blame] | 137 | } |
| 138 | #if SK_SUPPORT_GPU |
| 139 | if (this->isUsingGpuDevice()) { |
| 140 | config.append("_gpu"); |
| 141 | } |
| 142 | #endif |
caryclark@google.com | a362237 | 2012-11-06 21:26:13 +0000 | [diff] [blame] | 143 | config.append(fDrawFiltersConfig.c_str()); |
scroggo@google.com | 0a049b8 | 2012-11-02 22:01:26 +0000 | [diff] [blame] | 144 | return config; |
| 145 | } |
| 146 | |
keyar@chromium.org | 4ea96c5 | 2012-08-20 15:03:29 +0000 | [diff] [blame] | 147 | #if SK_SUPPORT_GPU |
keyar@chromium.org | fe6391a | 2012-08-20 15:03:41 +0000 | [diff] [blame] | 148 | bool isUsingGpuDevice() { |
keyar@chromium.org | 78a35c5 | 2012-08-20 15:03:44 +0000 | [diff] [blame] | 149 | return kGPU_DeviceType == fDeviceType; |
keyar@chromium.org | fe6391a | 2012-08-20 15:03:41 +0000 | [diff] [blame] | 150 | } |
keyar@chromium.org | 77a5522 | 2012-08-20 15:03:47 +0000 | [diff] [blame] | 151 | |
| 152 | SkGLContext* getGLContext() { |
| 153 | if (this->isUsingGpuDevice()) { |
| 154 | return fGrContextFactory.getGLContext(GrContextFactory::kNative_GLContextType); |
| 155 | } else { |
| 156 | return NULL; |
| 157 | } |
| 158 | } |
robertphillips@google.com | 163c84b | 2012-09-13 15:40:37 +0000 | [diff] [blame] | 159 | |
| 160 | GrContext* getGrContext() { |
| 161 | return fGrContext; |
| 162 | } |
keyar@chromium.org | 4ea96c5 | 2012-08-20 15:03:29 +0000 | [diff] [blame] | 163 | #endif |
| 164 | |
keyar@chromium.org | 02dfb12 | 2012-08-20 15:03:36 +0000 | [diff] [blame] | 165 | PictureRenderer() |
keyar@chromium.org | 0612564 | 2012-08-20 15:03:33 +0000 | [diff] [blame] | 166 | : fPicture(NULL) |
| 167 | , fDeviceType(kBitmap_DeviceType) |
junov@chromium.org | 50ff9bd | 2012-11-02 19:16:22 +0000 | [diff] [blame] | 168 | , fBBoxHierarchyType(kNone_BBoxHierarchyType) |
junov@chromium.org | 7b53706 | 2012-11-06 18:58:43 +0000 | [diff] [blame] | 169 | , fGridWidth(0) |
| 170 | , fGridHeight(0) |
keyar@chromium.org | 0612564 | 2012-08-20 15:03:33 +0000 | [diff] [blame] | 171 | #if SK_SUPPORT_GPU |
| 172 | , fGrContext(fGrContextFactory.get(GrContextFactory::kNative_GLContextType)) |
| 173 | #endif |
caryclark@google.com | e3e940c | 2012-11-07 16:42:17 +0000 | [diff] [blame] | 174 | { |
| 175 | sk_bzero(fDrawFilters, sizeof(fDrawFilters)); |
scroggo@google.com | c0d5e54 | 2012-12-13 21:40:48 +0000 | [diff] [blame^] | 176 | fViewport.set(0, 0); |
caryclark@google.com | e3e940c | 2012-11-07 16:42:17 +0000 | [diff] [blame] | 177 | } |
keyar@chromium.org | 0612564 | 2012-08-20 15:03:33 +0000 | [diff] [blame] | 178 | |
keyar@chromium.org | 9d696c0 | 2012-08-07 17:11:33 +0000 | [diff] [blame] | 179 | protected: |
| 180 | SkAutoTUnref<SkCanvas> fCanvas; |
scroggo@google.com | c0d5e54 | 2012-12-13 21:40:48 +0000 | [diff] [blame^] | 181 | SkPicture* fPicture; |
| 182 | SkDeviceTypes fDeviceType; |
| 183 | BBoxHierarchyType fBBoxHierarchyType; |
| 184 | DrawFilterFlags fDrawFilters[SkDrawFilter::kTypeCount]; |
| 185 | SkString fDrawFiltersConfig; |
| 186 | int fGridWidth, fGridHeight; // used when fBBoxHierarchyType is TileGrid |
keyar@chromium.org | 0612564 | 2012-08-20 15:03:33 +0000 | [diff] [blame] | 187 | |
| 188 | #if SK_SUPPORT_GPU |
| 189 | GrContextFactory fGrContextFactory; |
| 190 | GrContext* fGrContext; |
| 191 | #endif |
keyar@chromium.org | 9d696c0 | 2012-08-07 17:11:33 +0000 | [diff] [blame] | 192 | |
scroggo@google.com | c0d5e54 | 2012-12-13 21:40:48 +0000 | [diff] [blame^] | 193 | void buildBBoxHierarchy(); |
| 194 | |
| 195 | /** |
| 196 | * Return the total width that should be drawn. If the viewport width has been set greater than |
| 197 | * 0, this will be the minimum of the current SkPicture's width and the viewport's width. |
| 198 | */ |
| 199 | int getViewWidth(); |
| 200 | |
| 201 | /** |
| 202 | * Return the total height that should be drawn. If the viewport height has been set greater |
| 203 | * than 0, this will be the minimum of the current SkPicture's height and the viewport's height. |
| 204 | */ |
| 205 | int getViewHeight(); |
| 206 | |
| 207 | SkPicture* createPicture(); |
| 208 | uint32_t recordFlags(); |
| 209 | SkCanvas* setupCanvas(); |
| 210 | virtual SkCanvas* setupCanvas(int width, int height); |
| 211 | |
keyar@chromium.org | 9d696c0 | 2012-08-07 17:11:33 +0000 | [diff] [blame] | 212 | private: |
scroggo@google.com | c0d5e54 | 2012-12-13 21:40:48 +0000 | [diff] [blame^] | 213 | SkISize fViewport; |
| 214 | |
scroggo@google.com | 0a049b8 | 2012-11-02 22:01:26 +0000 | [diff] [blame] | 215 | virtual SkString getConfigNameInternal() = 0; |
| 216 | |
keyar@chromium.org | 9d696c0 | 2012-08-07 17:11:33 +0000 | [diff] [blame] | 217 | typedef SkRefCnt INHERITED; |
keyar@chromium.org | 451bb9f | 2012-07-26 17:27:57 +0000 | [diff] [blame] | 218 | }; |
| 219 | |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 220 | /** |
| 221 | * This class does not do any rendering, but its render function executes recording, which we want |
| 222 | * to time. |
| 223 | */ |
| 224 | class RecordPictureRenderer : public PictureRenderer { |
scroggo@google.com | 81f9d2e | 2012-09-20 14:54:21 +0000 | [diff] [blame] | 225 | virtual bool render(const SkString*) SK_OVERRIDE; |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 226 | |
| 227 | virtual SkString getPerIterTimeFormat() SK_OVERRIDE { return SkString("%.4f"); } |
| 228 | |
| 229 | virtual SkString getNormalTimeFormat() SK_OVERRIDE { return SkString("%6.4f"); } |
scroggo@google.com | 0a049b8 | 2012-11-02 22:01:26 +0000 | [diff] [blame] | 230 | |
djsollen@google.com | fd9720c | 2012-11-06 16:54:40 +0000 | [diff] [blame] | 231 | protected: |
| 232 | virtual SkCanvas* setupCanvas(int width, int height) SK_OVERRIDE; |
| 233 | |
scroggo@google.com | 0a049b8 | 2012-11-02 22:01:26 +0000 | [diff] [blame] | 234 | private: |
| 235 | virtual SkString getConfigNameInternal() SK_OVERRIDE; |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 236 | }; |
| 237 | |
keyar@chromium.org | 451bb9f | 2012-07-26 17:27:57 +0000 | [diff] [blame] | 238 | class PipePictureRenderer : public PictureRenderer { |
keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 239 | public: |
scroggo@google.com | 81f9d2e | 2012-09-20 14:54:21 +0000 | [diff] [blame] | 240 | virtual bool render(const SkString*) SK_OVERRIDE; |
keyar@chromium.org | 9d696c0 | 2012-08-07 17:11:33 +0000 | [diff] [blame] | 241 | |
| 242 | private: |
scroggo@google.com | 0a049b8 | 2012-11-02 22:01:26 +0000 | [diff] [blame] | 243 | virtual SkString getConfigNameInternal() SK_OVERRIDE; |
| 244 | |
keyar@chromium.org | 9d696c0 | 2012-08-07 17:11:33 +0000 | [diff] [blame] | 245 | typedef PictureRenderer INHERITED; |
keyar@chromium.org | 451bb9f | 2012-07-26 17:27:57 +0000 | [diff] [blame] | 246 | }; |
| 247 | |
| 248 | class SimplePictureRenderer : public PictureRenderer { |
keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 249 | public: |
junov@chromium.org | 9313ca4 | 2012-11-02 18:11:49 +0000 | [diff] [blame] | 250 | virtual void init(SkPicture* pict) SK_OVERRIDE; |
| 251 | |
scroggo@google.com | 81f9d2e | 2012-09-20 14:54:21 +0000 | [diff] [blame] | 252 | virtual bool render(const SkString*) SK_OVERRIDE; |
keyar@chromium.org | 9d696c0 | 2012-08-07 17:11:33 +0000 | [diff] [blame] | 253 | |
| 254 | private: |
scroggo@google.com | 0a049b8 | 2012-11-02 22:01:26 +0000 | [diff] [blame] | 255 | virtual SkString getConfigNameInternal() SK_OVERRIDE; |
| 256 | |
keyar@chromium.org | 9d696c0 | 2012-08-07 17:11:33 +0000 | [diff] [blame] | 257 | typedef PictureRenderer INHERITED; |
keyar@chromium.org | 451bb9f | 2012-07-26 17:27:57 +0000 | [diff] [blame] | 258 | }; |
| 259 | |
| 260 | class TiledPictureRenderer : public PictureRenderer { |
| 261 | public: |
| 262 | TiledPictureRenderer(); |
| 263 | |
keyar@chromium.org | 9d696c0 | 2012-08-07 17:11:33 +0000 | [diff] [blame] | 264 | virtual void init(SkPicture* pict) SK_OVERRIDE; |
scroggo@google.com | 81f9d2e | 2012-09-20 14:54:21 +0000 | [diff] [blame] | 265 | |
scroggo@google.com | 81f9d2e | 2012-09-20 14:54:21 +0000 | [diff] [blame] | 266 | /** |
| 267 | * Renders to tiles, rather than a single canvas. If a path is provided, a separate file is |
| 268 | * created for each tile, named "path0.png", "path1.png", etc. |
| 269 | * Multithreaded mode currently does not support writing to a file. |
| 270 | */ |
| 271 | virtual bool render(const SkString* path) SK_OVERRIDE; |
| 272 | |
keyar@chromium.org | 9d696c0 | 2012-08-07 17:11:33 +0000 | [diff] [blame] | 273 | virtual void end() SK_OVERRIDE; |
keyar@chromium.org | 451bb9f | 2012-07-26 17:27:57 +0000 | [diff] [blame] | 274 | |
keyar@chromium.org | cc6e5ef | 2012-07-27 20:09:26 +0000 | [diff] [blame] | 275 | void setTileWidth(int width) { |
| 276 | fTileWidth = width; |
| 277 | } |
| 278 | |
| 279 | int getTileWidth() const { |
| 280 | return fTileWidth; |
| 281 | } |
| 282 | |
| 283 | void setTileHeight(int height) { |
| 284 | fTileHeight = height; |
| 285 | } |
| 286 | |
| 287 | int getTileHeight() const { |
| 288 | return fTileHeight; |
| 289 | } |
| 290 | |
| 291 | void setTileWidthPercentage(double percentage) { |
| 292 | fTileWidthPercentage = percentage; |
| 293 | } |
| 294 | |
keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 295 | double getTileWidthPercentage() const { |
keyar@chromium.org | cc6e5ef | 2012-07-27 20:09:26 +0000 | [diff] [blame] | 296 | return fTileWidthPercentage; |
| 297 | } |
| 298 | |
| 299 | void setTileHeightPercentage(double percentage) { |
| 300 | fTileHeightPercentage = percentage; |
| 301 | } |
| 302 | |
keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 303 | double getTileHeightPercentage() const { |
keyar@chromium.org | cc6e5ef | 2012-07-27 20:09:26 +0000 | [diff] [blame] | 304 | return fTileHeightPercentage; |
| 305 | } |
| 306 | |
keyar@chromium.org | f4959ab | 2012-08-23 20:53:25 +0000 | [diff] [blame] | 307 | void setTileMinPowerOf2Width(int width) { |
| 308 | SkASSERT(SkIsPow2(width) && width > 0); |
| 309 | if (!SkIsPow2(width) || width <= 0) { |
| 310 | return; |
| 311 | } |
| 312 | |
| 313 | fTileMinPowerOf2Width = width; |
| 314 | } |
| 315 | |
| 316 | int getTileMinPowerOf2Width() const { |
| 317 | return fTileMinPowerOf2Width; |
| 318 | } |
| 319 | |
scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 320 | protected: |
scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 321 | SkTDArray<SkRect> fTileRects; |
keyar@chromium.org | 451bb9f | 2012-07-26 17:27:57 +0000 | [diff] [blame] | 322 | |
scroggo@google.com | 0a049b8 | 2012-11-02 22:01:26 +0000 | [diff] [blame] | 323 | virtual SkCanvas* setupCanvas(int width, int height) SK_OVERRIDE; |
| 324 | virtual SkString getConfigNameInternal() SK_OVERRIDE; |
| 325 | |
keyar@chromium.org | 451bb9f | 2012-07-26 17:27:57 +0000 | [diff] [blame] | 326 | private: |
scroggo@google.com | bcdf2ec | 2012-09-20 14:42:33 +0000 | [diff] [blame] | 327 | int fTileWidth; |
| 328 | int fTileHeight; |
| 329 | double fTileWidthPercentage; |
| 330 | double fTileHeightPercentage; |
| 331 | int fTileMinPowerOf2Width; |
scroggo@google.com | bcdf2ec | 2012-09-20 14:42:33 +0000 | [diff] [blame] | 332 | |
keyar@chromium.org | 9d696c0 | 2012-08-07 17:11:33 +0000 | [diff] [blame] | 333 | void setupTiles(); |
keyar@chromium.org | f4959ab | 2012-08-23 20:53:25 +0000 | [diff] [blame] | 334 | void setupPowerOf2Tiles(); |
keyar@chromium.org | 9d696c0 | 2012-08-07 17:11:33 +0000 | [diff] [blame] | 335 | |
| 336 | typedef PictureRenderer INHERITED; |
keyar@chromium.org | 451bb9f | 2012-07-26 17:27:57 +0000 | [diff] [blame] | 337 | }; |
| 338 | |
scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 339 | class CloneData; |
| 340 | |
| 341 | class MultiCorePictureRenderer : public TiledPictureRenderer { |
| 342 | public: |
| 343 | explicit MultiCorePictureRenderer(int threadCount); |
| 344 | |
| 345 | ~MultiCorePictureRenderer(); |
| 346 | |
| 347 | virtual void init(SkPicture* pict) SK_OVERRIDE; |
| 348 | |
| 349 | /** |
| 350 | * Behaves like TiledPictureRenderer::render(), only using multiple threads. |
| 351 | */ |
| 352 | virtual bool render(const SkString* path) SK_OVERRIDE; |
| 353 | |
| 354 | virtual void end() SK_OVERRIDE; |
| 355 | |
| 356 | private: |
scroggo@google.com | 0a049b8 | 2012-11-02 22:01:26 +0000 | [diff] [blame] | 357 | virtual SkString getConfigNameInternal() SK_OVERRIDE; |
| 358 | |
scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 359 | const int fNumThreads; |
| 360 | SkTDArray<SkCanvas*> fCanvasPool; |
| 361 | SkThreadPool fThreadPool; |
| 362 | SkPicture* fPictureClones; |
| 363 | CloneData** fCloneData; |
| 364 | SkCountdown fCountdown; |
| 365 | |
| 366 | typedef TiledPictureRenderer INHERITED; |
| 367 | }; |
| 368 | |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 369 | /** |
| 370 | * This class does not do any rendering, but its render function executes turning an SkPictureRecord |
| 371 | * into an SkPicturePlayback, which we want to time. |
| 372 | */ |
| 373 | class PlaybackCreationRenderer : public PictureRenderer { |
| 374 | public: |
| 375 | virtual void setup() SK_OVERRIDE; |
| 376 | |
scroggo@google.com | 81f9d2e | 2012-09-20 14:54:21 +0000 | [diff] [blame] | 377 | virtual bool render(const SkString*) SK_OVERRIDE; |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 378 | |
| 379 | virtual SkString getPerIterTimeFormat() SK_OVERRIDE { return SkString("%.4f"); } |
| 380 | |
| 381 | virtual SkString getNormalTimeFormat() SK_OVERRIDE { return SkString("%6.4f"); } |
| 382 | |
| 383 | private: |
junov@chromium.org | 9313ca4 | 2012-11-02 18:11:49 +0000 | [diff] [blame] | 384 | SkAutoTUnref<SkPicture> fReplayer; |
scroggo@google.com | 0a049b8 | 2012-11-02 22:01:26 +0000 | [diff] [blame] | 385 | |
| 386 | virtual SkString getConfigNameInternal() SK_OVERRIDE; |
| 387 | |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 388 | typedef PictureRenderer INHERITED; |
| 389 | }; |
| 390 | |
reed@google.com | fe7b1ed | 2012-11-29 21:00:39 +0000 | [diff] [blame] | 391 | extern PictureRenderer* CreateGatherPixelRefsRenderer(); |
reed@google.com | 5a34fd3 | 2012-12-10 16:05:09 +0000 | [diff] [blame] | 392 | extern PictureRenderer* CreatePictureCloneRenderer(); |
reed@google.com | fe7b1ed | 2012-11-29 21:00:39 +0000 | [diff] [blame] | 393 | |
keyar@chromium.org | 451bb9f | 2012-07-26 17:27:57 +0000 | [diff] [blame] | 394 | } |
| 395 | |
| 396 | #endif // PictureRenderer_DEFINED |