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 | |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 11 | #include "SkCanvas.h" |
scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 12 | #include "SkCountdown.h" |
caryclark@google.com | a362237 | 2012-11-06 21:26:13 +0000 | [diff] [blame] | 13 | #include "SkDrawFilter.h" |
commit-bot@chromium.org | a3f882c | 2013-12-13 20:52:36 +0000 | [diff] [blame] | 14 | #include "SkJSONCPP.h" |
keyar@chromium.org | f4959ab | 2012-08-23 20:53:25 +0000 | [diff] [blame] | 15 | #include "SkMath.h" |
reed@google.com | ea6a306 | 2012-11-06 22:14:54 +0000 | [diff] [blame] | 16 | #include "SkPaint.h" |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 17 | #include "SkPicture.h" |
robertphillips@google.com | 770963f | 2014-04-18 18:04:41 +0000 | [diff] [blame] | 18 | #include "SkPictureRecorder.h" |
scroggo@google.com | acfb30e | 2012-09-18 14:32:35 +0000 | [diff] [blame] | 19 | #include "SkRect.h" |
keyar@chromium.org | 451bb9f | 2012-07-26 17:27:57 +0000 | [diff] [blame] | 20 | #include "SkRefCnt.h" |
scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 21 | #include "SkRunnable.h" |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 22 | #include "SkString.h" |
scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 23 | #include "SkTDArray.h" |
| 24 | #include "SkThreadPool.h" |
| 25 | #include "SkTypes.h" |
keyar@chromium.org | 451bb9f | 2012-07-26 17:27:57 +0000 | [diff] [blame] | 26 | |
keyar@chromium.org | 0612564 | 2012-08-20 15:03:33 +0000 | [diff] [blame] | 27 | #if SK_SUPPORT_GPU |
| 28 | #include "GrContextFactory.h" |
| 29 | #include "GrContext.h" |
| 30 | #endif |
| 31 | |
keyar@chromium.org | 451bb9f | 2012-07-26 17:27:57 +0000 | [diff] [blame] | 32 | class SkBitmap; |
| 33 | class SkCanvas; |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 34 | class SkGLContextHelper; |
scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 35 | class SkThread; |
keyar@chromium.org | 451bb9f | 2012-07-26 17:27:57 +0000 | [diff] [blame] | 36 | |
| 37 | namespace sk_tools { |
| 38 | |
scroggo@google.com | cbcef70 | 2012-12-13 22:09:28 +0000 | [diff] [blame] | 39 | class TiledPictureRenderer; |
| 40 | |
commit-bot@chromium.org | a3f882c | 2013-12-13 20:52:36 +0000 | [diff] [blame] | 41 | /** |
| 42 | * Class for collecting image results (checksums) as we go. |
| 43 | */ |
| 44 | class ImageResultsSummary { |
| 45 | public: |
| 46 | /** |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 47 | * Adds this image to the summary of results. |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 48 | * |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 49 | * @param sourceName name of the source file that generated this result |
| 50 | * @param fileName relative path to the image output file on local disk |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 51 | * @param hash hash to store |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 52 | * @param tileNumber if not NULL, ptr to tile number |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 53 | */ |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 54 | void add(const char *sourceName, const char *fileName, uint64_t hash, |
| 55 | const int *tileNumber=NULL); |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 56 | |
| 57 | /** |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 58 | * Adds this image to the summary of results. |
commit-bot@chromium.org | a3f882c | 2013-12-13 20:52:36 +0000 | [diff] [blame] | 59 | * |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 60 | * @param sourceName name of the source file that generated this result |
| 61 | * @param fileName relative path to the image output file on local disk |
commit-bot@chromium.org | a3f882c | 2013-12-13 20:52:36 +0000 | [diff] [blame] | 62 | * @param bitmap bitmap to store the hash of |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 63 | * @param tileNumber if not NULL, ptr to tile number |
commit-bot@chromium.org | a3f882c | 2013-12-13 20:52:36 +0000 | [diff] [blame] | 64 | */ |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 65 | void add(const char *sourceName, const char *fileName, const SkBitmap& bitmap, |
| 66 | const int *tileNumber=NULL); |
commit-bot@chromium.org | a3f882c | 2013-12-13 20:52:36 +0000 | [diff] [blame] | 67 | |
| 68 | /** |
| 69 | * Writes the summary (as constructed so far) to a file. |
| 70 | * |
| 71 | * @param filename path to write the summary to |
| 72 | */ |
| 73 | void writeToFile(const char *filename); |
| 74 | |
| 75 | private: |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 76 | Json::Value fActualResults; |
commit-bot@chromium.org | a3f882c | 2013-12-13 20:52:36 +0000 | [diff] [blame] | 77 | }; |
| 78 | |
keyar@chromium.org | 451bb9f | 2012-07-26 17:27:57 +0000 | [diff] [blame] | 79 | class PictureRenderer : public SkRefCnt { |
scroggo@google.com | cbcef70 | 2012-12-13 22:09:28 +0000 | [diff] [blame] | 80 | |
keyar@chromium.org | 451bb9f | 2012-07-26 17:27:57 +0000 | [diff] [blame] | 81 | public: |
keyar@chromium.org | c81686c | 2012-08-20 15:04:04 +0000 | [diff] [blame] | 82 | enum SkDeviceTypes { |
scroggo@google.com | 0556ea0 | 2013-02-08 19:38:21 +0000 | [diff] [blame] | 83 | #if SK_ANGLE |
| 84 | kAngle_DeviceType, |
| 85 | #endif |
rmistry@google.com | 6ab9673 | 2014-01-06 18:37:24 +0000 | [diff] [blame] | 86 | #if SK_MESA |
| 87 | kMesa_DeviceType, |
| 88 | #endif |
keyar@chromium.org | c81686c | 2012-08-20 15:04:04 +0000 | [diff] [blame] | 89 | kBitmap_DeviceType, |
| 90 | #if SK_SUPPORT_GPU |
scroggo@google.com | 0556ea0 | 2013-02-08 19:38:21 +0000 | [diff] [blame] | 91 | kGPU_DeviceType, |
commit-bot@chromium.org | 0fd5270 | 2014-03-07 18:41:14 +0000 | [diff] [blame] | 92 | kNVPR_DeviceType, |
keyar@chromium.org | c81686c | 2012-08-20 15:04:04 +0000 | [diff] [blame] | 93 | #endif |
| 94 | }; |
| 95 | |
junov@chromium.org | 9313ca4 | 2012-11-02 18:11:49 +0000 | [diff] [blame] | 96 | enum BBoxHierarchyType { |
| 97 | kNone_BBoxHierarchyType = 0, |
commit-bot@chromium.org | c22d139 | 2014-02-03 18:08:33 +0000 | [diff] [blame] | 98 | kQuadTree_BBoxHierarchyType, |
junov@chromium.org | 9313ca4 | 2012-11-02 18:11:49 +0000 | [diff] [blame] | 99 | kRTree_BBoxHierarchyType, |
junov@chromium.org | 7b53706 | 2012-11-06 18:58:43 +0000 | [diff] [blame] | 100 | kTileGrid_BBoxHierarchyType, |
commit-bot@chromium.org | cdd0f92 | 2014-03-11 17:27:07 +0000 | [diff] [blame] | 101 | |
| 102 | kLast_BBoxHierarchyType = kTileGrid_BBoxHierarchyType, |
junov@chromium.org | 9313ca4 | 2012-11-02 18:11:49 +0000 | [diff] [blame] | 103 | }; |
| 104 | |
caryclark@google.com | a362237 | 2012-11-06 21:26:13 +0000 | [diff] [blame] | 105 | // this uses SkPaint::Flags as a base and adds additional flags |
| 106 | enum DrawFilterFlags { |
| 107 | kNone_DrawFilterFlag = 0, |
reed@google.com | 881b10b | 2013-05-22 14:03:45 +0000 | [diff] [blame] | 108 | kHinting_DrawFilterFlag = 0x10000, // toggles between no hinting and normal hinting |
| 109 | kSlightHinting_DrawFilterFlag = 0x20000, // toggles between slight and normal hinting |
| 110 | kAAClip_DrawFilterFlag = 0x40000, // toggles between soft and hard clip |
humper@google.com | 387db0a | 2013-07-09 14:13:04 +0000 | [diff] [blame] | 111 | kMaskFilter_DrawFilterFlag = 0x80000, // toggles on/off mask filters (e.g., blurs) |
caryclark@google.com | a362237 | 2012-11-06 21:26:13 +0000 | [diff] [blame] | 112 | }; |
| 113 | |
robertphillips@google.com | 4914931 | 2013-07-03 15:34:35 +0000 | [diff] [blame] | 114 | SK_COMPILE_ASSERT(!(kMaskFilter_DrawFilterFlag & SkPaint::kAllFlags), maskfilter_flag_must_be_greater); |
caryclark@google.com | a362237 | 2012-11-06 21:26:13 +0000 | [diff] [blame] | 115 | SK_COMPILE_ASSERT(!(kHinting_DrawFilterFlag & SkPaint::kAllFlags), |
| 116 | hinting_flag_must_be_greater); |
| 117 | SK_COMPILE_ASSERT(!(kSlightHinting_DrawFilterFlag & SkPaint::kAllFlags), |
| 118 | slight_hinting_flag_must_be_greater); |
| 119 | |
scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 120 | /** |
| 121 | * Called with each new SkPicture to render. |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 122 | * |
| 123 | * @param pict The SkPicture to render. |
| 124 | * @param outputDir The output directory within which this renderer should write files, |
| 125 | * or NULL if this renderer should not write files at all. |
| 126 | * @param inputFilename The name of the input file we are rendering. |
| 127 | * @param useChecksumBasedFilenames Whether to use checksum-based filenames when writing |
| 128 | * bitmap images to disk. |
scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 129 | */ |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 130 | virtual void init(SkPicture* pict, const SkString* outputDir, |
| 131 | const SkString* inputFilename, bool useChecksumBasedFilenames); |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 132 | |
| 133 | /** |
scroggo@google.com | c0d5e54 | 2012-12-13 21:40:48 +0000 | [diff] [blame] | 134 | * Set the viewport so that only the portion listed gets drawn. |
| 135 | */ |
| 136 | void setViewport(SkISize size) { fViewport = size; } |
| 137 | |
| 138 | /** |
scroggo@google.com | 82ec0b0 | 2012-12-17 19:25:54 +0000 | [diff] [blame] | 139 | * Set the scale factor at which draw the picture. |
| 140 | */ |
| 141 | void setScaleFactor(SkScalar scale) { fScaleFactor = scale; } |
| 142 | |
| 143 | /** |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 144 | * Perform any setup that should done prior to each iteration of render() which should not be |
| 145 | * timed. |
| 146 | */ |
| 147 | virtual void setup() {} |
| 148 | |
| 149 | /** |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 150 | * Perform the work. If this is being called within the context of bench_pictures, |
| 151 | * this is the step that will be timed. |
| 152 | * |
| 153 | * Typically "the work" is rendering an SkPicture into a bitmap, but in some subclasses |
| 154 | * it is recording the source SkPicture into another SkPicture. |
| 155 | * |
| 156 | * If fOutputDir has been specified, the result of the work will be written to that dir. |
| 157 | * |
| 158 | * @param out If non-null, the implementing subclass MAY allocate an SkBitmap, copy the |
| 159 | * output image into it, and return it here. (Some subclasses ignore this parameter) |
| 160 | * @return bool True if rendering succeeded and, if fOutputDir had been specified, the output |
| 161 | * was successfully written to a file. |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 162 | */ |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 163 | virtual bool render(SkBitmap** out = NULL) = 0; |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 164 | |
scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 165 | /** |
| 166 | * Called once finished with a particular SkPicture, before calling init again, and before |
| 167 | * being done with this Renderer. |
| 168 | */ |
keyar@chromium.org | 9d696c0 | 2012-08-07 17:11:33 +0000 | [diff] [blame] | 169 | virtual void end(); |
scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 170 | |
scroggo@google.com | cbcef70 | 2012-12-13 22:09:28 +0000 | [diff] [blame] | 171 | /** |
| 172 | * If this PictureRenderer is actually a TiledPictureRender, return a pointer to this as a |
| 173 | * TiledPictureRender so its methods can be called. |
| 174 | */ |
| 175 | virtual TiledPictureRenderer* getTiledRenderer() { return NULL; } |
| 176 | |
scroggo@google.com | 08085f8 | 2013-01-28 20:40:24 +0000 | [diff] [blame] | 177 | /** |
| 178 | * Resets the GPU's state. Does nothing if the backing is raster. For a GPU renderer, calls |
commit-bot@chromium.org | 51c040e | 2014-03-11 22:58:00 +0000 | [diff] [blame] | 179 | * flush, swapBuffers and, if callFinish is true, finish. |
scroggo@google.com | 08085f8 | 2013-01-28 20:40:24 +0000 | [diff] [blame] | 180 | * @param callFinish Whether to call finish. |
| 181 | */ |
| 182 | void resetState(bool callFinish); |
keyar@chromium.org | 9d696c0 | 2012-08-07 17:11:33 +0000 | [diff] [blame] | 183 | |
scroggo@google.com | 0556ea0 | 2013-02-08 19:38:21 +0000 | [diff] [blame] | 184 | /** |
robertphillips@google.com | 94d8f1e | 2013-12-18 17:25:33 +0000 | [diff] [blame] | 185 | * Remove all decoded textures from the CPU caches and all uploaded textures |
| 186 | * from the GPU. |
| 187 | */ |
| 188 | void purgeTextures(); |
| 189 | |
| 190 | /** |
scroggo@google.com | 0556ea0 | 2013-02-08 19:38:21 +0000 | [diff] [blame] | 191 | * Set the backend type. Returns true on success and false on failure. |
| 192 | */ |
| 193 | bool setDeviceType(SkDeviceTypes deviceType) { |
keyar@chromium.org | c81686c | 2012-08-20 15:04:04 +0000 | [diff] [blame] | 194 | fDeviceType = deviceType; |
scroggo@google.com | 0556ea0 | 2013-02-08 19:38:21 +0000 | [diff] [blame] | 195 | #if SK_SUPPORT_GPU |
| 196 | // In case this function is called more than once |
| 197 | SkSafeUnref(fGrContext); |
| 198 | fGrContext = NULL; |
| 199 | // Set to Native so it will have an initial value. |
| 200 | GrContextFactory::GLContextType glContextType = GrContextFactory::kNative_GLContextType; |
| 201 | #endif |
| 202 | switch(deviceType) { |
| 203 | case kBitmap_DeviceType: |
| 204 | return true; |
| 205 | #if SK_SUPPORT_GPU |
| 206 | case kGPU_DeviceType: |
| 207 | // Already set to GrContextFactory::kNative_GLContextType, above. |
| 208 | break; |
commit-bot@chromium.org | 0fd5270 | 2014-03-07 18:41:14 +0000 | [diff] [blame] | 209 | case kNVPR_DeviceType: |
| 210 | glContextType = GrContextFactory::kNVPR_GLContextType; |
| 211 | break; |
scroggo@google.com | 0556ea0 | 2013-02-08 19:38:21 +0000 | [diff] [blame] | 212 | #if SK_ANGLE |
| 213 | case kAngle_DeviceType: |
| 214 | glContextType = GrContextFactory::kANGLE_GLContextType; |
| 215 | break; |
| 216 | #endif |
rmistry@google.com | 6ab9673 | 2014-01-06 18:37:24 +0000 | [diff] [blame] | 217 | #if SK_MESA |
| 218 | case kMesa_DeviceType: |
| 219 | glContextType = GrContextFactory::kMESA_GLContextType; |
| 220 | break; |
| 221 | #endif |
scroggo@google.com | 0556ea0 | 2013-02-08 19:38:21 +0000 | [diff] [blame] | 222 | #endif |
| 223 | default: |
| 224 | // Invalid device type. |
| 225 | return false; |
| 226 | } |
| 227 | #if SK_SUPPORT_GPU |
| 228 | fGrContext = fGrContextFactory.get(glContextType); |
| 229 | if (NULL == fGrContext) { |
| 230 | return false; |
| 231 | } else { |
| 232 | fGrContext->ref(); |
| 233 | return true; |
| 234 | } |
| 235 | #endif |
keyar@chromium.org | fe6391a | 2012-08-20 15:03:41 +0000 | [diff] [blame] | 236 | } |
| 237 | |
jvanverth@google.com | f6a9033 | 2013-05-02 12:39:37 +0000 | [diff] [blame] | 238 | #if SK_SUPPORT_GPU |
| 239 | void setSampleCount(int sampleCount) { |
| 240 | fSampleCount = sampleCount; |
| 241 | } |
| 242 | #endif |
| 243 | |
caryclark@google.com | e3e940c | 2012-11-07 16:42:17 +0000 | [diff] [blame] | 244 | void setDrawFilters(DrawFilterFlags const * const filters, const SkString& configName) { |
| 245 | memcpy(fDrawFilters, filters, sizeof(fDrawFilters)); |
caryclark@google.com | a362237 | 2012-11-06 21:26:13 +0000 | [diff] [blame] | 246 | fDrawFiltersConfig = configName; |
| 247 | } |
| 248 | |
junov@chromium.org | 9313ca4 | 2012-11-02 18:11:49 +0000 | [diff] [blame] | 249 | void setBBoxHierarchyType(BBoxHierarchyType bbhType) { |
| 250 | fBBoxHierarchyType = bbhType; |
| 251 | } |
| 252 | |
junov@chromium.org | e286e84 | 2013-03-13 17:27:16 +0000 | [diff] [blame] | 253 | BBoxHierarchyType getBBoxHierarchyType() { return fBBoxHierarchyType; } |
| 254 | |
junov@chromium.org | 7b53706 | 2012-11-06 18:58:43 +0000 | [diff] [blame] | 255 | void setGridSize(int width, int height) { |
junov@chromium.org | 29b19e5 | 2013-02-27 18:35:16 +0000 | [diff] [blame] | 256 | fGridInfo.fTileInterval.set(width, height); |
junov@chromium.org | 7b53706 | 2012-11-06 18:58:43 +0000 | [diff] [blame] | 257 | } |
| 258 | |
commit-bot@chromium.org | a3f882c | 2013-12-13 20:52:36 +0000 | [diff] [blame] | 259 | void setJsonSummaryPtr(ImageResultsSummary* jsonSummaryPtr) { |
| 260 | fJsonSummaryPtr = jsonSummaryPtr; |
| 261 | } |
| 262 | |
keyar@chromium.org | fe6391a | 2012-08-20 15:03:41 +0000 | [diff] [blame] | 263 | bool isUsingBitmapDevice() { |
keyar@chromium.org | 78a35c5 | 2012-08-20 15:03:44 +0000 | [diff] [blame] | 264 | return kBitmap_DeviceType == fDeviceType; |
keyar@chromium.org | 4ea96c5 | 2012-08-20 15:03:29 +0000 | [diff] [blame] | 265 | } |
| 266 | |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 267 | virtual SkString getPerIterTimeFormat() { return SkString("%.2f"); } |
| 268 | |
| 269 | virtual SkString getNormalTimeFormat() { return SkString("%6.2f"); } |
| 270 | |
scroggo@google.com | 0a049b8 | 2012-11-02 22:01:26 +0000 | [diff] [blame] | 271 | /** |
| 272 | * Reports the configuration of this PictureRenderer. |
| 273 | */ |
| 274 | SkString getConfigName() { |
| 275 | SkString config = this->getConfigNameInternal(); |
scroggo@google.com | c4013c1 | 2012-12-13 22:07:08 +0000 | [diff] [blame] | 276 | if (!fViewport.isEmpty()) { |
| 277 | config.appendf("_viewport_%ix%i", fViewport.width(), fViewport.height()); |
| 278 | } |
commit-bot@chromium.org | 9de35eb | 2013-12-20 21:49:33 +0000 | [diff] [blame] | 279 | if (fScaleFactor != SK_Scalar1) { |
| 280 | config.appendf("_scalar_%f", SkScalarToFloat(fScaleFactor)); |
| 281 | } |
scroggo@google.com | 0a049b8 | 2012-11-02 22:01:26 +0000 | [diff] [blame] | 282 | if (kRTree_BBoxHierarchyType == fBBoxHierarchyType) { |
| 283 | config.append("_rtree"); |
commit-bot@chromium.org | c22d139 | 2014-02-03 18:08:33 +0000 | [diff] [blame] | 284 | } else if (kQuadTree_BBoxHierarchyType == fBBoxHierarchyType) { |
| 285 | config.append("_quadtree"); |
junov@chromium.org | 7b53706 | 2012-11-06 18:58:43 +0000 | [diff] [blame] | 286 | } else if (kTileGrid_BBoxHierarchyType == fBBoxHierarchyType) { |
| 287 | config.append("_grid"); |
scroggo@google.com | 0a049b8 | 2012-11-02 22:01:26 +0000 | [diff] [blame] | 288 | } |
| 289 | #if SK_SUPPORT_GPU |
robertphillips@google.com | e8fe4bc | 2013-02-13 13:26:13 +0000 | [diff] [blame] | 290 | switch (fDeviceType) { |
scroggo@google.com | 0556ea0 | 2013-02-08 19:38:21 +0000 | [diff] [blame] | 291 | case kGPU_DeviceType: |
jvanverth@google.com | f6a9033 | 2013-05-02 12:39:37 +0000 | [diff] [blame] | 292 | if (fSampleCount) { |
| 293 | config.appendf("_msaa%d", fSampleCount); |
| 294 | } else { |
| 295 | config.append("_gpu"); |
| 296 | } |
scroggo@google.com | 0556ea0 | 2013-02-08 19:38:21 +0000 | [diff] [blame] | 297 | break; |
commit-bot@chromium.org | 0fd5270 | 2014-03-07 18:41:14 +0000 | [diff] [blame] | 298 | case kNVPR_DeviceType: |
| 299 | config.appendf("_nvprmsaa%d", fSampleCount); |
| 300 | break; |
scroggo@google.com | 0556ea0 | 2013-02-08 19:38:21 +0000 | [diff] [blame] | 301 | #if SK_ANGLE |
| 302 | case kAngle_DeviceType: |
| 303 | config.append("_angle"); |
| 304 | break; |
scroggo@google.com | 0a049b8 | 2012-11-02 22:01:26 +0000 | [diff] [blame] | 305 | #endif |
rmistry@google.com | 6ab9673 | 2014-01-06 18:37:24 +0000 | [diff] [blame] | 306 | #if SK_MESA |
| 307 | case kMesa_DeviceType: |
| 308 | config.append("_mesa"); |
| 309 | break; |
| 310 | #endif |
scroggo@google.com | 0556ea0 | 2013-02-08 19:38:21 +0000 | [diff] [blame] | 311 | default: |
| 312 | // Assume that no extra info means bitmap. |
| 313 | break; |
| 314 | } |
robertphillips@google.com | e8fe4bc | 2013-02-13 13:26:13 +0000 | [diff] [blame] | 315 | #endif |
caryclark@google.com | a362237 | 2012-11-06 21:26:13 +0000 | [diff] [blame] | 316 | config.append(fDrawFiltersConfig.c_str()); |
scroggo@google.com | 0a049b8 | 2012-11-02 22:01:26 +0000 | [diff] [blame] | 317 | return config; |
| 318 | } |
| 319 | |
keyar@chromium.org | 4ea96c5 | 2012-08-20 15:03:29 +0000 | [diff] [blame] | 320 | #if SK_SUPPORT_GPU |
keyar@chromium.org | fe6391a | 2012-08-20 15:03:41 +0000 | [diff] [blame] | 321 | bool isUsingGpuDevice() { |
scroggo@google.com | 0556ea0 | 2013-02-08 19:38:21 +0000 | [diff] [blame] | 322 | switch (fDeviceType) { |
| 323 | case kGPU_DeviceType: |
commit-bot@chromium.org | 0fd5270 | 2014-03-07 18:41:14 +0000 | [diff] [blame] | 324 | case kNVPR_DeviceType: |
scroggo@google.com | 0556ea0 | 2013-02-08 19:38:21 +0000 | [diff] [blame] | 325 | // fall through |
| 326 | #if SK_ANGLE |
| 327 | case kAngle_DeviceType: |
rmistry@google.com | 6ab9673 | 2014-01-06 18:37:24 +0000 | [diff] [blame] | 328 | // fall through |
| 329 | #endif |
| 330 | #if SK_MESA |
| 331 | case kMesa_DeviceType: |
scroggo@google.com | 0556ea0 | 2013-02-08 19:38:21 +0000 | [diff] [blame] | 332 | #endif |
| 333 | return true; |
| 334 | default: |
| 335 | return false; |
| 336 | } |
keyar@chromium.org | fe6391a | 2012-08-20 15:03:41 +0000 | [diff] [blame] | 337 | } |
keyar@chromium.org | 77a5522 | 2012-08-20 15:03:47 +0000 | [diff] [blame] | 338 | |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 339 | SkGLContextHelper* getGLContext() { |
scroggo@google.com | 0556ea0 | 2013-02-08 19:38:21 +0000 | [diff] [blame] | 340 | GrContextFactory::GLContextType glContextType |
| 341 | = GrContextFactory::kNull_GLContextType; |
| 342 | switch(fDeviceType) { |
| 343 | case kGPU_DeviceType: |
| 344 | glContextType = GrContextFactory::kNative_GLContextType; |
| 345 | break; |
commit-bot@chromium.org | 0fd5270 | 2014-03-07 18:41:14 +0000 | [diff] [blame] | 346 | case kNVPR_DeviceType: |
| 347 | glContextType = GrContextFactory::kNVPR_GLContextType; |
| 348 | break; |
scroggo@google.com | 0556ea0 | 2013-02-08 19:38:21 +0000 | [diff] [blame] | 349 | #if SK_ANGLE |
| 350 | case kAngle_DeviceType: |
| 351 | glContextType = GrContextFactory::kANGLE_GLContextType; |
| 352 | break; |
| 353 | #endif |
rmistry@google.com | 6ab9673 | 2014-01-06 18:37:24 +0000 | [diff] [blame] | 354 | #if SK_MESA |
| 355 | case kMesa_DeviceType: |
| 356 | glContextType = GrContextFactory::kMESA_GLContextType; |
| 357 | break; |
| 358 | #endif |
scroggo@google.com | 0556ea0 | 2013-02-08 19:38:21 +0000 | [diff] [blame] | 359 | default: |
| 360 | return NULL; |
keyar@chromium.org | 77a5522 | 2012-08-20 15:03:47 +0000 | [diff] [blame] | 361 | } |
scroggo@google.com | 0556ea0 | 2013-02-08 19:38:21 +0000 | [diff] [blame] | 362 | return fGrContextFactory.getGLContext(glContextType); |
keyar@chromium.org | 77a5522 | 2012-08-20 15:03:47 +0000 | [diff] [blame] | 363 | } |
robertphillips@google.com | 163c84b | 2012-09-13 15:40:37 +0000 | [diff] [blame] | 364 | |
| 365 | GrContext* getGrContext() { |
| 366 | return fGrContext; |
| 367 | } |
keyar@chromium.org | 4ea96c5 | 2012-08-20 15:03:29 +0000 | [diff] [blame] | 368 | #endif |
| 369 | |
commit-bot@chromium.org | 145d1c0 | 2014-03-16 19:46:36 +0000 | [diff] [blame] | 370 | SkCanvas* getCanvas() { |
| 371 | return fCanvas; |
| 372 | } |
| 373 | |
commit-bot@chromium.org | 8ddc26b | 2014-03-31 17:55:12 +0000 | [diff] [blame] | 374 | SkPicture* getPicture() { |
| 375 | return fPicture; |
| 376 | } |
| 377 | |
keyar@chromium.org | 02dfb12 | 2012-08-20 15:03:36 +0000 | [diff] [blame] | 378 | PictureRenderer() |
robertphillips@google.com | 84b18c7 | 2014-04-13 19:09:42 +0000 | [diff] [blame] | 379 | : fJsonSummaryPtr(NULL) |
keyar@chromium.org | 0612564 | 2012-08-20 15:03:33 +0000 | [diff] [blame] | 380 | , fDeviceType(kBitmap_DeviceType) |
junov@chromium.org | 50ff9bd | 2012-11-02 19:16:22 +0000 | [diff] [blame] | 381 | , fBBoxHierarchyType(kNone_BBoxHierarchyType) |
scroggo@google.com | 06d6ac6 | 2013-02-08 21:16:19 +0000 | [diff] [blame] | 382 | , fScaleFactor(SK_Scalar1) |
keyar@chromium.org | 0612564 | 2012-08-20 15:03:33 +0000 | [diff] [blame] | 383 | #if SK_SUPPORT_GPU |
scroggo@google.com | 0556ea0 | 2013-02-08 19:38:21 +0000 | [diff] [blame] | 384 | , fGrContext(NULL) |
jvanverth@google.com | f6a9033 | 2013-05-02 12:39:37 +0000 | [diff] [blame] | 385 | , fSampleCount(0) |
keyar@chromium.org | 0612564 | 2012-08-20 15:03:33 +0000 | [diff] [blame] | 386 | #endif |
caryclark@google.com | e3e940c | 2012-11-07 16:42:17 +0000 | [diff] [blame] | 387 | { |
robertphillips@google.com | 7ae918e | 2013-03-02 17:45:27 +0000 | [diff] [blame] | 388 | fGridInfo.fMargin.setEmpty(); |
| 389 | fGridInfo.fOffset.setZero(); |
| 390 | fGridInfo.fTileInterval.set(1, 1); |
caryclark@google.com | e3e940c | 2012-11-07 16:42:17 +0000 | [diff] [blame] | 391 | sk_bzero(fDrawFilters, sizeof(fDrawFilters)); |
scroggo@google.com | c0d5e54 | 2012-12-13 21:40:48 +0000 | [diff] [blame] | 392 | fViewport.set(0, 0); |
caryclark@google.com | e3e940c | 2012-11-07 16:42:17 +0000 | [diff] [blame] | 393 | } |
keyar@chromium.org | 0612564 | 2012-08-20 15:03:33 +0000 | [diff] [blame] | 394 | |
scroggo@google.com | 0556ea0 | 2013-02-08 19:38:21 +0000 | [diff] [blame] | 395 | #if SK_SUPPORT_GPU |
| 396 | virtual ~PictureRenderer() { |
| 397 | SkSafeUnref(fGrContext); |
| 398 | } |
| 399 | #endif |
| 400 | |
keyar@chromium.org | 9d696c0 | 2012-08-07 17:11:33 +0000 | [diff] [blame] | 401 | protected: |
| 402 | SkAutoTUnref<SkCanvas> fCanvas; |
robertphillips@google.com | 84b18c7 | 2014-04-13 19:09:42 +0000 | [diff] [blame] | 403 | SkAutoTUnref<SkPicture> fPicture; |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 404 | bool fUseChecksumBasedFilenames; |
commit-bot@chromium.org | a3f882c | 2013-12-13 20:52:36 +0000 | [diff] [blame] | 405 | ImageResultsSummary* fJsonSummaryPtr; |
scroggo@google.com | c0d5e54 | 2012-12-13 21:40:48 +0000 | [diff] [blame] | 406 | SkDeviceTypes fDeviceType; |
| 407 | BBoxHierarchyType fBBoxHierarchyType; |
| 408 | DrawFilterFlags fDrawFilters[SkDrawFilter::kTypeCount]; |
| 409 | SkString fDrawFiltersConfig; |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 410 | SkString fOutputDir; |
| 411 | SkString fInputFilename; |
commit-bot@chromium.org | 5fb2ce3 | 2014-04-17 23:35:06 +0000 | [diff] [blame] | 412 | SkTileGridFactory::TileGridInfo fGridInfo; // used when fBBoxHierarchyType is TileGrid |
keyar@chromium.org | 0612564 | 2012-08-20 15:03:33 +0000 | [diff] [blame] | 413 | |
scroggo@google.com | c0d5e54 | 2012-12-13 21:40:48 +0000 | [diff] [blame] | 414 | void buildBBoxHierarchy(); |
| 415 | |
| 416 | /** |
| 417 | * Return the total width that should be drawn. If the viewport width has been set greater than |
| 418 | * 0, this will be the minimum of the current SkPicture's width and the viewport's width. |
| 419 | */ |
| 420 | int getViewWidth(); |
| 421 | |
| 422 | /** |
| 423 | * Return the total height that should be drawn. If the viewport height has been set greater |
| 424 | * than 0, this will be the minimum of the current SkPicture's height and the viewport's height. |
| 425 | */ |
| 426 | int getViewHeight(); |
| 427 | |
scroggo@google.com | 82ec0b0 | 2012-12-17 19:25:54 +0000 | [diff] [blame] | 428 | /** |
| 429 | * Scales the provided canvas to the scale factor set by setScaleFactor. |
| 430 | */ |
| 431 | void scaleToScaleFactor(SkCanvas*); |
| 432 | |
commit-bot@chromium.org | 5fb2ce3 | 2014-04-17 23:35:06 +0000 | [diff] [blame] | 433 | SkBBHFactory* getFactory(); |
scroggo@google.com | c0d5e54 | 2012-12-13 21:40:48 +0000 | [diff] [blame] | 434 | uint32_t recordFlags(); |
| 435 | SkCanvas* setupCanvas(); |
| 436 | virtual SkCanvas* setupCanvas(int width, int height); |
| 437 | |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 438 | /** |
| 439 | * Copy src to dest; if src==NULL, set dest to empty string. |
| 440 | */ |
| 441 | static void CopyString(SkString* dest, const SkString* src); |
| 442 | |
keyar@chromium.org | 9d696c0 | 2012-08-07 17:11:33 +0000 | [diff] [blame] | 443 | private: |
scroggo@google.com | c0d5e54 | 2012-12-13 21:40:48 +0000 | [diff] [blame] | 444 | SkISize fViewport; |
scroggo@google.com | 82ec0b0 | 2012-12-17 19:25:54 +0000 | [diff] [blame] | 445 | SkScalar fScaleFactor; |
scroggo@google.com | 0556ea0 | 2013-02-08 19:38:21 +0000 | [diff] [blame] | 446 | #if SK_SUPPORT_GPU |
| 447 | GrContextFactory fGrContextFactory; |
| 448 | GrContext* fGrContext; |
jvanverth@google.com | f6a9033 | 2013-05-02 12:39:37 +0000 | [diff] [blame] | 449 | int fSampleCount; |
scroggo@google.com | 0556ea0 | 2013-02-08 19:38:21 +0000 | [diff] [blame] | 450 | #endif |
scroggo@google.com | c0d5e54 | 2012-12-13 21:40:48 +0000 | [diff] [blame] | 451 | |
scroggo@google.com | 0a049b8 | 2012-11-02 22:01:26 +0000 | [diff] [blame] | 452 | virtual SkString getConfigNameInternal() = 0; |
| 453 | |
keyar@chromium.org | 9d696c0 | 2012-08-07 17:11:33 +0000 | [diff] [blame] | 454 | typedef SkRefCnt INHERITED; |
keyar@chromium.org | 451bb9f | 2012-07-26 17:27:57 +0000 | [diff] [blame] | 455 | }; |
| 456 | |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 457 | /** |
| 458 | * This class does not do any rendering, but its render function executes recording, which we want |
| 459 | * to time. |
| 460 | */ |
| 461 | class RecordPictureRenderer : public PictureRenderer { |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 462 | virtual bool render(SkBitmap** out = NULL) SK_OVERRIDE; |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 463 | |
| 464 | virtual SkString getPerIterTimeFormat() SK_OVERRIDE { return SkString("%.4f"); } |
| 465 | |
| 466 | virtual SkString getNormalTimeFormat() SK_OVERRIDE { return SkString("%6.4f"); } |
scroggo@google.com | 0a049b8 | 2012-11-02 22:01:26 +0000 | [diff] [blame] | 467 | |
djsollen@google.com | fd9720c | 2012-11-06 16:54:40 +0000 | [diff] [blame] | 468 | protected: |
| 469 | virtual SkCanvas* setupCanvas(int width, int height) SK_OVERRIDE; |
| 470 | |
scroggo@google.com | 0a049b8 | 2012-11-02 22:01:26 +0000 | [diff] [blame] | 471 | private: |
| 472 | virtual SkString getConfigNameInternal() SK_OVERRIDE; |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 473 | }; |
| 474 | |
keyar@chromium.org | 451bb9f | 2012-07-26 17:27:57 +0000 | [diff] [blame] | 475 | class PipePictureRenderer : public PictureRenderer { |
keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 476 | public: |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 477 | virtual bool render(SkBitmap** out = NULL) SK_OVERRIDE; |
keyar@chromium.org | 9d696c0 | 2012-08-07 17:11:33 +0000 | [diff] [blame] | 478 | |
| 479 | private: |
scroggo@google.com | 0a049b8 | 2012-11-02 22:01:26 +0000 | [diff] [blame] | 480 | virtual SkString getConfigNameInternal() SK_OVERRIDE; |
| 481 | |
keyar@chromium.org | 9d696c0 | 2012-08-07 17:11:33 +0000 | [diff] [blame] | 482 | typedef PictureRenderer INHERITED; |
keyar@chromium.org | 451bb9f | 2012-07-26 17:27:57 +0000 | [diff] [blame] | 483 | }; |
| 484 | |
| 485 | class SimplePictureRenderer : public PictureRenderer { |
keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 486 | public: |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 487 | virtual void init(SkPicture* pict, const SkString* outputDir, |
| 488 | const SkString* inputFilename, bool useChecksumBasedFilenames) SK_OVERRIDE; |
junov@chromium.org | 9313ca4 | 2012-11-02 18:11:49 +0000 | [diff] [blame] | 489 | |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 490 | virtual bool render(SkBitmap** out = NULL) SK_OVERRIDE; |
keyar@chromium.org | 9d696c0 | 2012-08-07 17:11:33 +0000 | [diff] [blame] | 491 | |
| 492 | private: |
scroggo@google.com | 0a049b8 | 2012-11-02 22:01:26 +0000 | [diff] [blame] | 493 | virtual SkString getConfigNameInternal() SK_OVERRIDE; |
| 494 | |
keyar@chromium.org | 9d696c0 | 2012-08-07 17:11:33 +0000 | [diff] [blame] | 495 | typedef PictureRenderer INHERITED; |
keyar@chromium.org | 451bb9f | 2012-07-26 17:27:57 +0000 | [diff] [blame] | 496 | }; |
| 497 | |
| 498 | class TiledPictureRenderer : public PictureRenderer { |
| 499 | public: |
| 500 | TiledPictureRenderer(); |
| 501 | |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 502 | virtual void init(SkPicture* pict, const SkString* outputDir, |
| 503 | const SkString* inputFilename, bool useChecksumBasedFilenames) SK_OVERRIDE; |
scroggo@google.com | 81f9d2e | 2012-09-20 14:54:21 +0000 | [diff] [blame] | 504 | |
scroggo@google.com | 81f9d2e | 2012-09-20 14:54:21 +0000 | [diff] [blame] | 505 | /** |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 506 | * Renders to tiles, rather than a single canvas. |
| 507 | * If fOutputDir was provided, a separate file is |
scroggo@google.com | 81f9d2e | 2012-09-20 14:54:21 +0000 | [diff] [blame] | 508 | * created for each tile, named "path0.png", "path1.png", etc. |
| 509 | * Multithreaded mode currently does not support writing to a file. |
| 510 | */ |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 511 | virtual bool render(SkBitmap** out = NULL) SK_OVERRIDE; |
scroggo@google.com | 81f9d2e | 2012-09-20 14:54:21 +0000 | [diff] [blame] | 512 | |
keyar@chromium.org | 9d696c0 | 2012-08-07 17:11:33 +0000 | [diff] [blame] | 513 | virtual void end() SK_OVERRIDE; |
keyar@chromium.org | 451bb9f | 2012-07-26 17:27:57 +0000 | [diff] [blame] | 514 | |
keyar@chromium.org | cc6e5ef | 2012-07-27 20:09:26 +0000 | [diff] [blame] | 515 | void setTileWidth(int width) { |
| 516 | fTileWidth = width; |
| 517 | } |
| 518 | |
| 519 | int getTileWidth() const { |
| 520 | return fTileWidth; |
| 521 | } |
| 522 | |
| 523 | void setTileHeight(int height) { |
| 524 | fTileHeight = height; |
| 525 | } |
| 526 | |
| 527 | int getTileHeight() const { |
| 528 | return fTileHeight; |
| 529 | } |
| 530 | |
| 531 | void setTileWidthPercentage(double percentage) { |
| 532 | fTileWidthPercentage = percentage; |
| 533 | } |
| 534 | |
keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 535 | double getTileWidthPercentage() const { |
keyar@chromium.org | cc6e5ef | 2012-07-27 20:09:26 +0000 | [diff] [blame] | 536 | return fTileWidthPercentage; |
| 537 | } |
| 538 | |
| 539 | void setTileHeightPercentage(double percentage) { |
| 540 | fTileHeightPercentage = percentage; |
| 541 | } |
| 542 | |
keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 543 | double getTileHeightPercentage() const { |
keyar@chromium.org | cc6e5ef | 2012-07-27 20:09:26 +0000 | [diff] [blame] | 544 | return fTileHeightPercentage; |
| 545 | } |
| 546 | |
keyar@chromium.org | f4959ab | 2012-08-23 20:53:25 +0000 | [diff] [blame] | 547 | void setTileMinPowerOf2Width(int width) { |
| 548 | SkASSERT(SkIsPow2(width) && width > 0); |
| 549 | if (!SkIsPow2(width) || width <= 0) { |
| 550 | return; |
| 551 | } |
| 552 | |
| 553 | fTileMinPowerOf2Width = width; |
| 554 | } |
| 555 | |
| 556 | int getTileMinPowerOf2Width() const { |
| 557 | return fTileMinPowerOf2Width; |
| 558 | } |
| 559 | |
scroggo@google.com | cbcef70 | 2012-12-13 22:09:28 +0000 | [diff] [blame] | 560 | virtual TiledPictureRenderer* getTiledRenderer() SK_OVERRIDE { return this; } |
| 561 | |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 562 | virtual bool supportsTimingIndividualTiles() { return true; } |
| 563 | |
scroggo@google.com | cbcef70 | 2012-12-13 22:09:28 +0000 | [diff] [blame] | 564 | /** |
| 565 | * Report the number of tiles in the x and y directions. Must not be called before init. |
| 566 | * @param x Output parameter identifying the number of tiles in the x direction. |
| 567 | * @param y Output parameter identifying the number of tiles in the y direction. |
| 568 | * @return True if the tiles have been set up, and x and y are meaningful. If false, x and y are |
| 569 | * unmodified. |
| 570 | */ |
| 571 | bool tileDimensions(int& x, int&y); |
| 572 | |
| 573 | /** |
| 574 | * Move to the next tile and return its indices. Must be called before calling drawCurrentTile |
| 575 | * for the first time. |
| 576 | * @param i Output parameter identifying the column of the next tile to be drawn on the next |
| 577 | * call to drawNextTile. |
| 578 | * @param j Output parameter identifying the row of the next tile to be drawn on the next call |
| 579 | * to drawNextTile. |
| 580 | * @param True if the tiles have been created and the next tile to be drawn by drawCurrentTile |
| 581 | * is within the range of tiles. If false, i and j are unmodified. |
| 582 | */ |
| 583 | bool nextTile(int& i, int& j); |
| 584 | |
| 585 | /** |
| 586 | * Render one tile. This will draw the same tile each time it is called until nextTile is |
| 587 | * called. The tile rendered will depend on how many calls have been made to nextTile. |
| 588 | * It is an error to call this without first calling nextTile, or if nextTile returns false. |
| 589 | */ |
| 590 | void drawCurrentTile(); |
| 591 | |
scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 592 | protected: |
scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 593 | SkTDArray<SkRect> fTileRects; |
keyar@chromium.org | 451bb9f | 2012-07-26 17:27:57 +0000 | [diff] [blame] | 594 | |
scroggo@google.com | 0a049b8 | 2012-11-02 22:01:26 +0000 | [diff] [blame] | 595 | virtual SkCanvas* setupCanvas(int width, int height) SK_OVERRIDE; |
| 596 | virtual SkString getConfigNameInternal() SK_OVERRIDE; |
| 597 | |
keyar@chromium.org | 451bb9f | 2012-07-26 17:27:57 +0000 | [diff] [blame] | 598 | private: |
scroggo@google.com | cbcef70 | 2012-12-13 22:09:28 +0000 | [diff] [blame] | 599 | int fTileWidth; |
| 600 | int fTileHeight; |
| 601 | double fTileWidthPercentage; |
| 602 | double fTileHeightPercentage; |
| 603 | int fTileMinPowerOf2Width; |
| 604 | |
| 605 | // These variables are only used for timing individual tiles. |
| 606 | // Next tile to draw in fTileRects. |
| 607 | int fCurrentTileOffset; |
| 608 | // Number of tiles in the x direction. |
| 609 | int fTilesX; |
| 610 | // Number of tiles in the y direction. |
| 611 | int fTilesY; |
scroggo@google.com | bcdf2ec | 2012-09-20 14:42:33 +0000 | [diff] [blame] | 612 | |
keyar@chromium.org | 9d696c0 | 2012-08-07 17:11:33 +0000 | [diff] [blame] | 613 | void setupTiles(); |
keyar@chromium.org | f4959ab | 2012-08-23 20:53:25 +0000 | [diff] [blame] | 614 | void setupPowerOf2Tiles(); |
keyar@chromium.org | 9d696c0 | 2012-08-07 17:11:33 +0000 | [diff] [blame] | 615 | |
| 616 | typedef PictureRenderer INHERITED; |
keyar@chromium.org | 451bb9f | 2012-07-26 17:27:57 +0000 | [diff] [blame] | 617 | }; |
| 618 | |
scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 619 | class CloneData; |
| 620 | |
| 621 | class MultiCorePictureRenderer : public TiledPictureRenderer { |
| 622 | public: |
| 623 | explicit MultiCorePictureRenderer(int threadCount); |
| 624 | |
| 625 | ~MultiCorePictureRenderer(); |
| 626 | |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 627 | virtual void init(SkPicture* pict, const SkString* outputDir, |
| 628 | const SkString* inputFilename, bool useChecksumBasedFilenames) SK_OVERRIDE; |
scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 629 | |
| 630 | /** |
| 631 | * Behaves like TiledPictureRenderer::render(), only using multiple threads. |
| 632 | */ |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 633 | virtual bool render(SkBitmap** out = NULL) SK_OVERRIDE; |
scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 634 | |
| 635 | virtual void end() SK_OVERRIDE; |
| 636 | |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 637 | virtual bool supportsTimingIndividualTiles() SK_OVERRIDE { return false; } |
| 638 | |
scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 639 | private: |
scroggo@google.com | 0a049b8 | 2012-11-02 22:01:26 +0000 | [diff] [blame] | 640 | virtual SkString getConfigNameInternal() SK_OVERRIDE; |
| 641 | |
scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 642 | const int fNumThreads; |
| 643 | SkTDArray<SkCanvas*> fCanvasPool; |
| 644 | SkThreadPool fThreadPool; |
| 645 | SkPicture* fPictureClones; |
| 646 | CloneData** fCloneData; |
| 647 | SkCountdown fCountdown; |
| 648 | |
| 649 | typedef TiledPictureRenderer INHERITED; |
| 650 | }; |
| 651 | |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 652 | /** |
| 653 | * This class does not do any rendering, but its render function executes turning an SkPictureRecord |
| 654 | * into an SkPicturePlayback, which we want to time. |
| 655 | */ |
| 656 | class PlaybackCreationRenderer : public PictureRenderer { |
| 657 | public: |
| 658 | virtual void setup() SK_OVERRIDE; |
| 659 | |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 660 | virtual bool render(SkBitmap** out = NULL) SK_OVERRIDE; |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 661 | |
| 662 | virtual SkString getPerIterTimeFormat() SK_OVERRIDE { return SkString("%.4f"); } |
| 663 | |
| 664 | virtual SkString getNormalTimeFormat() SK_OVERRIDE { return SkString("%6.4f"); } |
| 665 | |
| 666 | private: |
robertphillips@google.com | 84b18c7 | 2014-04-13 19:09:42 +0000 | [diff] [blame] | 667 | SkAutoTDelete<SkPictureRecorder> fRecorder; |
scroggo@google.com | 0a049b8 | 2012-11-02 22:01:26 +0000 | [diff] [blame] | 668 | |
| 669 | virtual SkString getConfigNameInternal() SK_OVERRIDE; |
| 670 | |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 671 | typedef PictureRenderer INHERITED; |
| 672 | }; |
| 673 | |
reed@google.com | fe7b1ed | 2012-11-29 21:00:39 +0000 | [diff] [blame] | 674 | extern PictureRenderer* CreateGatherPixelRefsRenderer(); |
reed@google.com | 5a34fd3 | 2012-12-10 16:05:09 +0000 | [diff] [blame] | 675 | extern PictureRenderer* CreatePictureCloneRenderer(); |
reed@google.com | fe7b1ed | 2012-11-29 21:00:39 +0000 | [diff] [blame] | 676 | |
keyar@chromium.org | 451bb9f | 2012-07-26 17:27:57 +0000 | [diff] [blame] | 677 | } |
| 678 | |
| 679 | #endif // PictureRenderer_DEFINED |