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