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