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