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