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