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