keyar@chromium.org | b3fb7c1 | 2012-08-20 21:02:49 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
keyar@chromium.org | 451bb9f | 2012-07-26 17:27:57 +0000 | [diff] [blame] | 8 | #include "PictureRenderer.h" |
scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 9 | #include "picture_utils.h" |
keyar@chromium.org | 451bb9f | 2012-07-26 17:27:57 +0000 | [diff] [blame] | 10 | #include "SamplePipeControllers.h" |
commit-bot@chromium.org | a3f882c | 2013-12-13 20:52:36 +0000 | [diff] [blame] | 11 | #include "SkBitmapHasher.h" |
keyar@chromium.org | 451bb9f | 2012-07-26 17:27:57 +0000 | [diff] [blame] | 12 | #include "SkCanvas.h" |
scroggo@google.com | 1b1bcc3 | 2013-05-21 20:31:23 +0000 | [diff] [blame] | 13 | #include "SkData.h" |
keyar@chromium.org | 451bb9f | 2012-07-26 17:27:57 +0000 | [diff] [blame] | 14 | #include "SkDevice.h" |
robertphillips@google.com | 94d8f1e | 2013-12-18 17:25:33 +0000 | [diff] [blame] | 15 | #include "SkDiscardableMemoryPool.h" |
keyar@chromium.org | 451bb9f | 2012-07-26 17:27:57 +0000 | [diff] [blame] | 16 | #include "SkGPipe.h" |
scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 17 | #if SK_SUPPORT_GPU |
robertphillips@google.com | fe1b536 | 2013-02-07 19:45:46 +0000 | [diff] [blame] | 18 | #include "gl/GrGLDefines.h" |
scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 19 | #include "SkGpuDevice.h" |
| 20 | #endif |
| 21 | #include "SkGraphics.h" |
| 22 | #include "SkImageEncoder.h" |
caryclark@google.com | a362237 | 2012-11-06 21:26:13 +0000 | [diff] [blame] | 23 | #include "SkMaskFilter.h" |
keyar@chromium.org | ea82695 | 2012-08-23 15:24:13 +0000 | [diff] [blame] | 24 | #include "SkMatrix.h" |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 25 | #include "SkOSFile.h" |
keyar@chromium.org | 451bb9f | 2012-07-26 17:27:57 +0000 | [diff] [blame] | 26 | #include "SkPicture.h" |
robertphillips@google.com | 770963f | 2014-04-18 18:04:41 +0000 | [diff] [blame] | 27 | #include "SkPictureRecorder.h" |
scroggo@google.com | 1b1bcc3 | 2013-05-21 20:31:23 +0000 | [diff] [blame] | 28 | #include "SkPictureUtils.h" |
| 29 | #include "SkPixelRef.h" |
keyar@chromium.org | ea82695 | 2012-08-23 15:24:13 +0000 | [diff] [blame] | 30 | #include "SkScalar.h" |
scroggo@google.com | a9e3a36 | 2012-11-07 17:52:48 +0000 | [diff] [blame] | 31 | #include "SkStream.h" |
keyar@chromium.org | 9299ede | 2012-08-21 19:05:08 +0000 | [diff] [blame] | 32 | #include "SkString.h" |
scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 33 | #include "SkTemplates.h" |
keyar@chromium.org | 451bb9f | 2012-07-26 17:27:57 +0000 | [diff] [blame] | 34 | #include "SkTDArray.h" |
scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 35 | #include "SkThreadUtils.h" |
keyar@chromium.org | 451bb9f | 2012-07-26 17:27:57 +0000 | [diff] [blame] | 36 | #include "SkTypes.h" |
keyar@chromium.org | 4ea96c5 | 2012-08-20 15:03:29 +0000 | [diff] [blame] | 37 | |
reed@google.com | e15b2f5 | 2013-12-18 04:59:26 +0000 | [diff] [blame] | 38 | static inline SkScalar scalar_log2(SkScalar x) { |
| 39 | static const SkScalar log2_conversion_factor = SkScalarDiv(1, SkScalarLog(2)); |
skia.committer@gmail.com | 3b85deb | 2013-12-18 07:01:56 +0000 | [diff] [blame] | 40 | |
reed@google.com | e15b2f5 | 2013-12-18 04:59:26 +0000 | [diff] [blame] | 41 | return SkScalarLog(x) * log2_conversion_factor; |
| 42 | } |
| 43 | |
keyar@chromium.org | 451bb9f | 2012-07-26 17:27:57 +0000 | [diff] [blame] | 44 | namespace sk_tools { |
| 45 | |
| 46 | enum { |
| 47 | kDefaultTileWidth = 256, |
| 48 | kDefaultTileHeight = 256 |
| 49 | }; |
| 50 | |
mtklein | 2a65a23 | 2014-08-26 14:07:04 -0700 | [diff] [blame] | 51 | void PictureRenderer::init(const SkPicture* pict, |
| 52 | const SkString* writePath, |
robertphillips | ce4dd3d | 2014-07-07 13:46:35 -0700 | [diff] [blame] | 53 | const SkString* mismatchPath, |
mtklein | 2a65a23 | 2014-08-26 14:07:04 -0700 | [diff] [blame] | 54 | const SkString* inputFilename, |
robertphillips | ce4dd3d | 2014-07-07 13:46:35 -0700 | [diff] [blame] | 55 | bool useChecksumBasedFilenames) { |
commit-bot@chromium.org | 3f04517 | 2014-05-15 15:10:48 +0000 | [diff] [blame] | 56 | this->CopyString(&fWritePath, writePath); |
| 57 | this->CopyString(&fMismatchPath, mismatchPath); |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 58 | this->CopyString(&fInputFilename, inputFilename); |
| 59 | fUseChecksumBasedFilenames = useChecksumBasedFilenames; |
| 60 | |
keyar@chromium.org | 78a35c5 | 2012-08-20 15:03:44 +0000 | [diff] [blame] | 61 | SkASSERT(NULL == fPicture); |
| 62 | SkASSERT(NULL == fCanvas.get()); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 63 | if (fPicture || fCanvas.get()) { |
keyar@chromium.org | 9d696c0 | 2012-08-07 17:11:33 +0000 | [diff] [blame] | 64 | return; |
| 65 | } |
| 66 | |
| 67 | SkASSERT(pict != NULL); |
keyar@chromium.org | 78a35c5 | 2012-08-20 15:03:44 +0000 | [diff] [blame] | 68 | if (NULL == pict) { |
keyar@chromium.org | 9d696c0 | 2012-08-07 17:11:33 +0000 | [diff] [blame] | 69 | return; |
| 70 | } |
| 71 | |
robertphillips@google.com | 84b18c7 | 2014-04-13 19:09:42 +0000 | [diff] [blame] | 72 | fPicture.reset(pict)->ref(); |
keyar@chromium.org | a474ce3 | 2012-08-20 15:03:57 +0000 | [diff] [blame] | 73 | fCanvas.reset(this->setupCanvas()); |
| 74 | } |
| 75 | |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 76 | void PictureRenderer::CopyString(SkString* dest, const SkString* src) { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 77 | if (src) { |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 78 | dest->set(*src); |
| 79 | } else { |
| 80 | dest->reset(); |
| 81 | } |
| 82 | } |
| 83 | |
caryclark@google.com | a362237 | 2012-11-06 21:26:13 +0000 | [diff] [blame] | 84 | class FlagsDrawFilter : public SkDrawFilter { |
| 85 | public: |
| 86 | FlagsDrawFilter(PictureRenderer::DrawFilterFlags* flags) : |
| 87 | fFlags(flags) {} |
| 88 | |
reed@google.com | 971aca7 | 2012-11-26 20:26:54 +0000 | [diff] [blame] | 89 | virtual bool filter(SkPaint* paint, Type t) { |
caryclark@google.com | a362237 | 2012-11-06 21:26:13 +0000 | [diff] [blame] | 90 | paint->setFlags(paint->getFlags() & ~fFlags[t] & SkPaint::kAllFlags); |
robertphillips@google.com | 4914931 | 2013-07-03 15:34:35 +0000 | [diff] [blame] | 91 | if (PictureRenderer::kMaskFilter_DrawFilterFlag & fFlags[t]) { |
caryclark@google.com | a362237 | 2012-11-06 21:26:13 +0000 | [diff] [blame] | 92 | SkMaskFilter* maskFilter = paint->getMaskFilter(); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 93 | if (maskFilter) { |
reed@google.com | 457d8a7 | 2012-12-18 18:20:44 +0000 | [diff] [blame] | 94 | paint->setMaskFilter(NULL); |
caryclark@google.com | a362237 | 2012-11-06 21:26:13 +0000 | [diff] [blame] | 95 | } |
| 96 | } |
| 97 | if (PictureRenderer::kHinting_DrawFilterFlag & fFlags[t]) { |
| 98 | paint->setHinting(SkPaint::kNo_Hinting); |
| 99 | } else if (PictureRenderer::kSlightHinting_DrawFilterFlag & fFlags[t]) { |
| 100 | paint->setHinting(SkPaint::kSlight_Hinting); |
| 101 | } |
reed@google.com | 971aca7 | 2012-11-26 20:26:54 +0000 | [diff] [blame] | 102 | return true; |
caryclark@google.com | a362237 | 2012-11-06 21:26:13 +0000 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | private: |
| 106 | PictureRenderer::DrawFilterFlags* fFlags; |
| 107 | }; |
| 108 | |
scroggo@google.com | 82ec0b0 | 2012-12-17 19:25:54 +0000 | [diff] [blame] | 109 | static void setUpFilter(SkCanvas* canvas, PictureRenderer::DrawFilterFlags* drawFilters) { |
caryclark@google.com | a362237 | 2012-11-06 21:26:13 +0000 | [diff] [blame] | 110 | if (drawFilters && !canvas->getDrawFilter()) { |
| 111 | canvas->setDrawFilter(SkNEW_ARGS(FlagsDrawFilter, (drawFilters)))->unref(); |
caryclark@google.com | e3e940c | 2012-11-07 16:42:17 +0000 | [diff] [blame] | 112 | if (drawFilters[0] & PictureRenderer::kAAClip_DrawFilterFlag) { |
| 113 | canvas->setAllowSoftClip(false); |
| 114 | } |
caryclark@google.com | a362237 | 2012-11-06 21:26:13 +0000 | [diff] [blame] | 115 | } |
caryclark@google.com | a362237 | 2012-11-06 21:26:13 +0000 | [diff] [blame] | 116 | } |
| 117 | |
keyar@chromium.org | a474ce3 | 2012-08-20 15:03:57 +0000 | [diff] [blame] | 118 | SkCanvas* PictureRenderer::setupCanvas() { |
scroggo@google.com | c0d5e54 | 2012-12-13 21:40:48 +0000 | [diff] [blame] | 119 | const int width = this->getViewWidth(); |
| 120 | const int height = this->getViewHeight(); |
| 121 | return this->setupCanvas(width, height); |
keyar@chromium.org | a474ce3 | 2012-08-20 15:03:57 +0000 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | SkCanvas* PictureRenderer::setupCanvas(int width, int height) { |
caryclark@google.com | a362237 | 2012-11-06 21:26:13 +0000 | [diff] [blame] | 125 | SkCanvas* canvas; |
keyar@chromium.org | 4ea96c5 | 2012-08-20 15:03:29 +0000 | [diff] [blame] | 126 | switch(fDeviceType) { |
| 127 | case kBitmap_DeviceType: { |
| 128 | SkBitmap bitmap; |
keyar@chromium.org | a474ce3 | 2012-08-20 15:03:57 +0000 | [diff] [blame] | 129 | sk_tools::setup_bitmap(&bitmap, width, height); |
caryclark@google.com | a362237 | 2012-11-06 21:26:13 +0000 | [diff] [blame] | 130 | canvas = SkNEW_ARGS(SkCanvas, (bitmap)); |
keyar@chromium.org | 4ea96c5 | 2012-08-20 15:03:29 +0000 | [diff] [blame] | 131 | } |
scroggo@google.com | 82ec0b0 | 2012-12-17 19:25:54 +0000 | [diff] [blame] | 132 | break; |
keyar@chromium.org | 4ea96c5 | 2012-08-20 15:03:29 +0000 | [diff] [blame] | 133 | #if SK_SUPPORT_GPU |
scroggo@google.com | 0556ea0 | 2013-02-08 19:38:21 +0000 | [diff] [blame] | 134 | #if SK_ANGLE |
| 135 | case kAngle_DeviceType: |
| 136 | // fall through |
| 137 | #endif |
rmistry@google.com | 6ab9673 | 2014-01-06 18:37:24 +0000 | [diff] [blame] | 138 | #if SK_MESA |
| 139 | case kMesa_DeviceType: |
| 140 | // fall through |
| 141 | #endif |
commit-bot@chromium.org | 0fd5270 | 2014-03-07 18:41:14 +0000 | [diff] [blame] | 142 | case kGPU_DeviceType: |
| 143 | case kNVPR_DeviceType: { |
commit-bot@chromium.org | ae403b9 | 2013-04-10 17:27:30 +0000 | [diff] [blame] | 144 | SkAutoTUnref<GrSurface> target; |
scroggo@google.com | 0556ea0 | 2013-02-08 19:38:21 +0000 | [diff] [blame] | 145 | if (fGrContext) { |
| 146 | // create a render target to back the device |
| 147 | GrTextureDesc desc; |
| 148 | desc.fConfig = kSkia8888_GrPixelConfig; |
| 149 | desc.fFlags = kRenderTarget_GrTextureFlagBit; |
| 150 | desc.fWidth = width; |
| 151 | desc.fHeight = height; |
jvanverth@google.com | f6a9033 | 2013-05-02 12:39:37 +0000 | [diff] [blame] | 152 | desc.fSampleCnt = fSampleCount; |
commit-bot@chromium.org | ae403b9 | 2013-04-10 17:27:30 +0000 | [diff] [blame] | 153 | target.reset(fGrContext->createUncachedTexture(desc, NULL, 0)); |
scroggo@google.com | 0556ea0 | 2013-02-08 19:38:21 +0000 | [diff] [blame] | 154 | } |
commit-bot@chromium.org | ae403b9 | 2013-04-10 17:27:30 +0000 | [diff] [blame] | 155 | if (NULL == target.get()) { |
scroggo@google.com | 0556ea0 | 2013-02-08 19:38:21 +0000 | [diff] [blame] | 156 | SkASSERT(0); |
| 157 | return NULL; |
| 158 | } |
| 159 | |
reed | 3716fd0 | 2014-09-21 09:39:55 -0700 | [diff] [blame^] | 160 | SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(target, |
| 161 | SkSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType))); |
caryclark@google.com | a362237 | 2012-11-06 21:26:13 +0000 | [diff] [blame] | 162 | canvas = SkNEW_ARGS(SkCanvas, (device.get())); |
scroggo@google.com | 0556ea0 | 2013-02-08 19:38:21 +0000 | [diff] [blame] | 163 | break; |
keyar@chromium.org | 4ea96c5 | 2012-08-20 15:03:29 +0000 | [diff] [blame] | 164 | } |
| 165 | #endif |
| 166 | default: |
| 167 | SkASSERT(0); |
scroggo@google.com | 82ec0b0 | 2012-12-17 19:25:54 +0000 | [diff] [blame] | 168 | return NULL; |
keyar@chromium.org | 4ea96c5 | 2012-08-20 15:03:29 +0000 | [diff] [blame] | 169 | } |
scroggo@google.com | 82ec0b0 | 2012-12-17 19:25:54 +0000 | [diff] [blame] | 170 | setUpFilter(canvas, fDrawFilters); |
| 171 | this->scaleToScaleFactor(canvas); |
commit-bot@chromium.org | 17cc3ea | 2014-01-15 14:51:25 +0000 | [diff] [blame] | 172 | |
| 173 | // Pictures often lie about their extent (i.e., claim to be 100x100 but |
| 174 | // only ever draw to 90x100). Clear here so the undrawn portion will have |
| 175 | // a consistent color |
| 176 | canvas->clear(SK_ColorTRANSPARENT); |
scroggo@google.com | 82ec0b0 | 2012-12-17 19:25:54 +0000 | [diff] [blame] | 177 | return canvas; |
| 178 | } |
keyar@chromium.org | a474ce3 | 2012-08-20 15:03:57 +0000 | [diff] [blame] | 179 | |
scroggo@google.com | 82ec0b0 | 2012-12-17 19:25:54 +0000 | [diff] [blame] | 180 | void PictureRenderer::scaleToScaleFactor(SkCanvas* canvas) { |
| 181 | SkASSERT(canvas != NULL); |
| 182 | if (fScaleFactor != SK_Scalar1) { |
| 183 | canvas->scale(fScaleFactor, fScaleFactor); |
| 184 | } |
keyar@chromium.org | 9d696c0 | 2012-08-07 17:11:33 +0000 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | void PictureRenderer::end() { |
scroggo@google.com | 08085f8 | 2013-01-28 20:40:24 +0000 | [diff] [blame] | 188 | this->resetState(true); |
robertphillips@google.com | 84b18c7 | 2014-04-13 19:09:42 +0000 | [diff] [blame] | 189 | fPicture.reset(NULL); |
keyar@chromium.org | 9d696c0 | 2012-08-07 17:11:33 +0000 | [diff] [blame] | 190 | fCanvas.reset(NULL); |
| 191 | } |
| 192 | |
scroggo@google.com | c0d5e54 | 2012-12-13 21:40:48 +0000 | [diff] [blame] | 193 | int PictureRenderer::getViewWidth() { |
| 194 | SkASSERT(fPicture != NULL); |
robertphillips | a8d7f0b | 2014-08-29 08:03:56 -0700 | [diff] [blame] | 195 | int width = SkScalarCeilToInt(fPicture->cullRect().width() * fScaleFactor); |
scroggo@google.com | c0d5e54 | 2012-12-13 21:40:48 +0000 | [diff] [blame] | 196 | if (fViewport.width() > 0) { |
| 197 | width = SkMin32(width, fViewport.width()); |
| 198 | } |
| 199 | return width; |
| 200 | } |
| 201 | |
| 202 | int PictureRenderer::getViewHeight() { |
| 203 | SkASSERT(fPicture != NULL); |
robertphillips | a8d7f0b | 2014-08-29 08:03:56 -0700 | [diff] [blame] | 204 | int height = SkScalarCeilToInt(fPicture->cullRect().height() * fScaleFactor); |
scroggo@google.com | c0d5e54 | 2012-12-13 21:40:48 +0000 | [diff] [blame] | 205 | if (fViewport.height() > 0) { |
| 206 | height = SkMin32(height, fViewport.height()); |
| 207 | } |
| 208 | return height; |
| 209 | } |
| 210 | |
junov@chromium.org | 9313ca4 | 2012-11-02 18:11:49 +0000 | [diff] [blame] | 211 | /** Converts fPicture to a picture that uses a BBoxHierarchy. |
| 212 | * PictureRenderer subclasses that are used to test picture playback |
| 213 | * should call this method during init. |
| 214 | */ |
| 215 | void PictureRenderer::buildBBoxHierarchy() { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 216 | SkASSERT(fPicture); |
| 217 | if (kNone_BBoxHierarchyType != fBBoxHierarchyType && fPicture) { |
commit-bot@chromium.org | 5fb2ce3 | 2014-04-17 23:35:06 +0000 | [diff] [blame] | 218 | SkAutoTDelete<SkBBHFactory> factory(this->getFactory()); |
| 219 | SkPictureRecorder recorder; |
robertphillips | a8d7f0b | 2014-08-29 08:03:56 -0700 | [diff] [blame] | 220 | SkCanvas* canvas = recorder.beginRecording(fPicture->cullRect().width(), |
| 221 | fPicture->cullRect().height(), |
commit-bot@chromium.org | 5fb2ce3 | 2014-04-17 23:35:06 +0000 | [diff] [blame] | 222 | factory.get(), |
robertphillips@google.com | 84b18c7 | 2014-04-13 19:09:42 +0000 | [diff] [blame] | 223 | this->recordFlags()); |
robertphillips | c5ba71d | 2014-09-04 08:42:50 -0700 | [diff] [blame] | 224 | fPicture->playback(canvas); |
robertphillips@google.com | 84b18c7 | 2014-04-13 19:09:42 +0000 | [diff] [blame] | 225 | fPicture.reset(recorder.endRecording()); |
junov@chromium.org | 9313ca4 | 2012-11-02 18:11:49 +0000 | [diff] [blame] | 226 | } |
| 227 | } |
| 228 | |
scroggo@google.com | 08085f8 | 2013-01-28 20:40:24 +0000 | [diff] [blame] | 229 | void PictureRenderer::resetState(bool callFinish) { |
keyar@chromium.org | 28136b3 | 2012-08-20 15:04:15 +0000 | [diff] [blame] | 230 | #if SK_SUPPORT_GPU |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 231 | SkGLContextHelper* glContext = this->getGLContext(); |
scroggo@google.com | 0556ea0 | 2013-02-08 19:38:21 +0000 | [diff] [blame] | 232 | if (NULL == glContext) { |
| 233 | SkASSERT(kBitmap_DeviceType == fDeviceType); |
| 234 | return; |
| 235 | } |
keyar@chromium.org | 28136b3 | 2012-08-20 15:04:15 +0000 | [diff] [blame] | 236 | |
scroggo@google.com | 0556ea0 | 2013-02-08 19:38:21 +0000 | [diff] [blame] | 237 | fGrContext->flush(); |
commit-bot@chromium.org | 51c040e | 2014-03-11 22:58:00 +0000 | [diff] [blame] | 238 | glContext->swapBuffers(); |
scroggo@google.com | 0556ea0 | 2013-02-08 19:38:21 +0000 | [diff] [blame] | 239 | if (callFinish) { |
| 240 | SK_GL(*glContext, Finish()); |
keyar@chromium.org | 77a5522 | 2012-08-20 15:03:47 +0000 | [diff] [blame] | 241 | } |
keyar@chromium.org | a40c20d | 2012-08-20 15:04:12 +0000 | [diff] [blame] | 242 | #endif |
keyar@chromium.org | 77a5522 | 2012-08-20 15:03:47 +0000 | [diff] [blame] | 243 | } |
| 244 | |
robertphillips@google.com | 94d8f1e | 2013-12-18 17:25:33 +0000 | [diff] [blame] | 245 | void PictureRenderer::purgeTextures() { |
| 246 | SkDiscardableMemoryPool* pool = SkGetGlobalDiscardableMemoryPool(); |
| 247 | |
| 248 | pool->dumpPool(); |
| 249 | |
| 250 | #if SK_SUPPORT_GPU |
| 251 | SkGLContextHelper* glContext = this->getGLContext(); |
| 252 | if (NULL == glContext) { |
| 253 | SkASSERT(kBitmap_DeviceType == fDeviceType); |
| 254 | return; |
| 255 | } |
| 256 | |
| 257 | // resetState should've already done this |
| 258 | fGrContext->flush(); |
| 259 | |
| 260 | fGrContext->purgeAllUnlockedResources(); |
| 261 | #endif |
| 262 | } |
| 263 | |
scroggo@google.com | b6e806b | 2012-10-03 17:32:33 +0000 | [diff] [blame] | 264 | /** |
commit-bot@chromium.org | 4610a46 | 2014-04-29 19:39:22 +0000 | [diff] [blame] | 265 | * Write the canvas to an image file and/or JSON summary. |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 266 | * |
scroggo@google.com | b6e806b | 2012-10-03 17:32:33 +0000 | [diff] [blame] | 267 | * @param canvas Must be non-null. Canvas to be written to a file. |
commit-bot@chromium.org | 3f04517 | 2014-05-15 15:10:48 +0000 | [diff] [blame] | 268 | * @param writePath If nonempty, write the binary image to a file within this directory. |
| 269 | * @param mismatchPath If nonempty, write the binary image to a file within this directory, |
| 270 | * but only if the image does not match expectations. |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 271 | * @param inputFilename If we are writing out a binary image, use this to build its filename. |
commit-bot@chromium.org | 4610a46 | 2014-04-29 19:39:22 +0000 | [diff] [blame] | 272 | * @param jsonSummaryPtr If not null, add image results (checksum) to this summary. |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 273 | * @param useChecksumBasedFilenames If true, use checksum-based filenames when writing to disk. |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 274 | * @param tileNumberPtr If not null, which tile number this image contains. |
commit-bot@chromium.org | a3f882c | 2013-12-13 20:52:36 +0000 | [diff] [blame] | 275 | * |
commit-bot@chromium.org | 4610a46 | 2014-04-29 19:39:22 +0000 | [diff] [blame] | 276 | * @return bool True if the operation completed successfully. |
scroggo@google.com | b6e806b | 2012-10-03 17:32:33 +0000 | [diff] [blame] | 277 | */ |
commit-bot@chromium.org | 3f04517 | 2014-05-15 15:10:48 +0000 | [diff] [blame] | 278 | static bool write(SkCanvas* canvas, const SkString& writePath, const SkString& mismatchPath, |
| 279 | const SkString& inputFilename, ImageResultsAndExpectations *jsonSummaryPtr, |
| 280 | bool useChecksumBasedFilenames, const int* tileNumberPtr=NULL) { |
scroggo@google.com | 81f9d2e | 2012-09-20 14:54:21 +0000 | [diff] [blame] | 281 | SkASSERT(canvas != NULL); |
scroggo@google.com | b6e806b | 2012-10-03 17:32:33 +0000 | [diff] [blame] | 282 | if (NULL == canvas) { |
keyar@chromium.org | 9299ede | 2012-08-21 19:05:08 +0000 | [diff] [blame] | 283 | return false; |
| 284 | } |
| 285 | |
| 286 | SkBitmap bitmap; |
scroggo@google.com | 81f9d2e | 2012-09-20 14:54:21 +0000 | [diff] [blame] | 287 | SkISize size = canvas->getDeviceSize(); |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame] | 288 | setup_bitmap(&bitmap, size.width(), size.height()); |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 289 | |
scroggo@google.com | 81f9d2e | 2012-09-20 14:54:21 +0000 | [diff] [blame] | 290 | canvas->readPixels(&bitmap, 0, 0); |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame] | 291 | force_all_opaque(bitmap); |
| 292 | BitmapAndDigest bitmapAndDigest(bitmap); |
keyar@chromium.org | 9299ede | 2012-08-21 19:05:08 +0000 | [diff] [blame] | 293 | |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 294 | SkString escapedInputFilename(inputFilename); |
| 295 | replace_char(&escapedInputFilename, '.', '_'); |
| 296 | |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 297 | // TODO(epoger): what about including the config type within outputFilename? That way, |
| 298 | // we could combine results of different config types without conflicting filenames. |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 299 | SkString outputFilename; |
| 300 | const char *outputSubdirPtr = NULL; |
| 301 | if (useChecksumBasedFilenames) { |
epoger | 85b438d | 2014-08-21 23:21:32 -0700 | [diff] [blame] | 302 | ImageDigest *imageDigestPtr = bitmapAndDigest.getImageDigestPtr(); |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 303 | outputSubdirPtr = escapedInputFilename.c_str(); |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame] | 304 | outputFilename.set(imageDigestPtr->getHashType()); |
| 305 | outputFilename.append("_"); |
| 306 | outputFilename.appendU64(imageDigestPtr->getHashValue()); |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 307 | } else { |
| 308 | outputFilename.set(escapedInputFilename); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 309 | if (tileNumberPtr) { |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 310 | outputFilename.append("-tile"); |
| 311 | outputFilename.appendS32(*tileNumberPtr); |
| 312 | } |
commit-bot@chromium.org | a3f882c | 2013-12-13 20:52:36 +0000 | [diff] [blame] | 313 | } |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 314 | outputFilename.append(".png"); |
commit-bot@chromium.org | a3f882c | 2013-12-13 20:52:36 +0000 | [diff] [blame] | 315 | |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 316 | if (jsonSummaryPtr) { |
epoger | 85b438d | 2014-08-21 23:21:32 -0700 | [diff] [blame] | 317 | ImageDigest *imageDigestPtr = bitmapAndDigest.getImageDigestPtr(); |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 318 | SkString outputRelativePath; |
| 319 | if (outputSubdirPtr) { |
| 320 | outputRelativePath.set(outputSubdirPtr); |
| 321 | outputRelativePath.append("/"); // always use "/", even on Windows |
| 322 | outputRelativePath.append(outputFilename); |
| 323 | } else { |
| 324 | outputRelativePath.set(outputFilename); |
| 325 | } |
| 326 | |
| 327 | jsonSummaryPtr->add(inputFilename.c_str(), outputRelativePath.c_str(), |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame] | 328 | *imageDigestPtr, tileNumberPtr); |
commit-bot@chromium.org | 3f04517 | 2014-05-15 15:10:48 +0000 | [diff] [blame] | 329 | if (!mismatchPath.isEmpty() && |
epoger | 85b438d | 2014-08-21 23:21:32 -0700 | [diff] [blame] | 330 | !jsonSummaryPtr->getExpectation(inputFilename.c_str(), |
| 331 | tileNumberPtr).matches(*imageDigestPtr)) { |
commit-bot@chromium.org | 3f04517 | 2014-05-15 15:10:48 +0000 | [diff] [blame] | 332 | if (!write_bitmap_to_disk(bitmap, mismatchPath, outputSubdirPtr, outputFilename)) { |
| 333 | return false; |
| 334 | } |
| 335 | } |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 336 | } |
| 337 | |
commit-bot@chromium.org | 3f04517 | 2014-05-15 15:10:48 +0000 | [diff] [blame] | 338 | if (writePath.isEmpty()) { |
commit-bot@chromium.org | 4610a46 | 2014-04-29 19:39:22 +0000 | [diff] [blame] | 339 | return true; |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 340 | } else { |
commit-bot@chromium.org | 3f04517 | 2014-05-15 15:10:48 +0000 | [diff] [blame] | 341 | return write_bitmap_to_disk(bitmap, writePath, outputSubdirPtr, outputFilename); |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 342 | } |
keyar@chromium.org | 9299ede | 2012-08-21 19:05:08 +0000 | [diff] [blame] | 343 | } |
| 344 | |
scroggo@google.com | acfb30e | 2012-09-18 14:32:35 +0000 | [diff] [blame] | 345 | /////////////////////////////////////////////////////////////////////////////////////////////// |
| 346 | |
djsollen@google.com | fd9720c | 2012-11-06 16:54:40 +0000 | [diff] [blame] | 347 | SkCanvas* RecordPictureRenderer::setupCanvas(int width, int height) { |
| 348 | // defer the canvas setup until the render step |
| 349 | return NULL; |
| 350 | } |
| 351 | |
reed@google.com | 672588b | 2014-01-08 15:42:01 +0000 | [diff] [blame] | 352 | // the size_t* parameter is deprecated, so we ignore it |
| 353 | static SkData* encode_bitmap_to_data(size_t*, const SkBitmap& bm) { |
scroggo@google.com | 1b1bcc3 | 2013-05-21 20:31:23 +0000 | [diff] [blame] | 354 | return SkImageEncoder::EncodeData(bm, SkImageEncoder::kPNG_Type, 100); |
scroggo@google.com | a9e3a36 | 2012-11-07 17:52:48 +0000 | [diff] [blame] | 355 | } |
| 356 | |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 357 | bool RecordPictureRenderer::render(SkBitmap** out) { |
commit-bot@chromium.org | 5fb2ce3 | 2014-04-17 23:35:06 +0000 | [diff] [blame] | 358 | SkAutoTDelete<SkBBHFactory> factory(this->getFactory()); |
| 359 | SkPictureRecorder recorder; |
robertphillips | a8d7f0b | 2014-08-29 08:03:56 -0700 | [diff] [blame] | 360 | SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(this->getViewWidth()), |
| 361 | SkIntToScalar(this->getViewHeight()), |
commit-bot@chromium.org | 5fb2ce3 | 2014-04-17 23:35:06 +0000 | [diff] [blame] | 362 | factory.get(), |
robertphillips@google.com | 84b18c7 | 2014-04-13 19:09:42 +0000 | [diff] [blame] | 363 | this->recordFlags()); |
| 364 | this->scaleToScaleFactor(canvas); |
robertphillips | c5ba71d | 2014-09-04 08:42:50 -0700 | [diff] [blame] | 365 | fPicture->playback(canvas); |
robertphillips@google.com | 84b18c7 | 2014-04-13 19:09:42 +0000 | [diff] [blame] | 366 | SkAutoTUnref<SkPicture> picture(recorder.endRecording()); |
commit-bot@chromium.org | 3f04517 | 2014-05-15 15:10:48 +0000 | [diff] [blame] | 367 | if (!fWritePath.isEmpty()) { |
scroggo@google.com | a9e3a36 | 2012-11-07 17:52:48 +0000 | [diff] [blame] | 368 | // Record the new picture as a new SKP with PNG encoded bitmaps. |
tfarina | a8e2e15 | 2014-07-28 19:26:58 -0700 | [diff] [blame] | 369 | SkString skpPath = SkOSPath::Join(fWritePath.c_str(), fInputFilename.c_str()); |
scroggo@google.com | a9e3a36 | 2012-11-07 17:52:48 +0000 | [diff] [blame] | 370 | SkFILEWStream stream(skpPath.c_str()); |
robertphillips@google.com | 84b18c7 | 2014-04-13 19:09:42 +0000 | [diff] [blame] | 371 | picture->serialize(&stream, &encode_bitmap_to_data); |
scroggo@google.com | a9e3a36 | 2012-11-07 17:52:48 +0000 | [diff] [blame] | 372 | return true; |
| 373 | } |
scroggo@google.com | 81f9d2e | 2012-09-20 14:54:21 +0000 | [diff] [blame] | 374 | return false; |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 375 | } |
| 376 | |
scroggo@google.com | 0a049b8 | 2012-11-02 22:01:26 +0000 | [diff] [blame] | 377 | SkString RecordPictureRenderer::getConfigNameInternal() { |
| 378 | return SkString("record"); |
| 379 | } |
| 380 | |
scroggo@google.com | acfb30e | 2012-09-18 14:32:35 +0000 | [diff] [blame] | 381 | /////////////////////////////////////////////////////////////////////////////////////////////// |
| 382 | |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 383 | bool PipePictureRenderer::render(SkBitmap** out) { |
keyar@chromium.org | 9d696c0 | 2012-08-07 17:11:33 +0000 | [diff] [blame] | 384 | SkASSERT(fCanvas.get() != NULL); |
| 385 | SkASSERT(fPicture != NULL); |
keyar@chromium.org | 78a35c5 | 2012-08-20 15:03:44 +0000 | [diff] [blame] | 386 | if (NULL == fCanvas.get() || NULL == fPicture) { |
scroggo@google.com | 81f9d2e | 2012-09-20 14:54:21 +0000 | [diff] [blame] | 387 | return false; |
keyar@chromium.org | 9d696c0 | 2012-08-07 17:11:33 +0000 | [diff] [blame] | 388 | } |
| 389 | |
| 390 | PipeController pipeController(fCanvas.get()); |
keyar@chromium.org | 451bb9f | 2012-07-26 17:27:57 +0000 | [diff] [blame] | 391 | SkGPipeWriter writer; |
| 392 | SkCanvas* pipeCanvas = writer.startRecording(&pipeController); |
robertphillips | 9b14f26 | 2014-06-04 05:40:44 -0700 | [diff] [blame] | 393 | pipeCanvas->drawPicture(fPicture); |
keyar@chromium.org | 451bb9f | 2012-07-26 17:27:57 +0000 | [diff] [blame] | 394 | writer.endRecording(); |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 395 | fCanvas->flush(); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 396 | if (out) { |
edisonn@google.com | 84f548c | 2012-12-18 22:24:03 +0000 | [diff] [blame] | 397 | *out = SkNEW(SkBitmap); |
robertphillips | a8d7f0b | 2014-08-29 08:03:56 -0700 | [diff] [blame] | 398 | setup_bitmap(*out, SkScalarCeilToInt(fPicture->cullRect().width()), |
| 399 | SkScalarCeilToInt(fPicture->cullRect().height())); |
edisonn@google.com | 84f548c | 2012-12-18 22:24:03 +0000 | [diff] [blame] | 400 | fCanvas->readPixels(*out, 0, 0); |
skia.committer@gmail.com | a7d8e3e | 2012-12-19 02:01:38 +0000 | [diff] [blame] | 401 | } |
commit-bot@chromium.org | 8991c67 | 2014-05-22 00:36:05 +0000 | [diff] [blame] | 402 | if (fEnableWrites) { |
| 403 | return write(fCanvas, fWritePath, fMismatchPath, fInputFilename, fJsonSummaryPtr, |
| 404 | fUseChecksumBasedFilenames); |
| 405 | } else { |
| 406 | return true; |
| 407 | } |
keyar@chromium.org | 451bb9f | 2012-07-26 17:27:57 +0000 | [diff] [blame] | 408 | } |
| 409 | |
scroggo@google.com | 0a049b8 | 2012-11-02 22:01:26 +0000 | [diff] [blame] | 410 | SkString PipePictureRenderer::getConfigNameInternal() { |
| 411 | return SkString("pipe"); |
| 412 | } |
| 413 | |
scroggo@google.com | acfb30e | 2012-09-18 14:32:35 +0000 | [diff] [blame] | 414 | /////////////////////////////////////////////////////////////////////////////////////////////// |
| 415 | |
robertphillips | ce4dd3d | 2014-07-07 13:46:35 -0700 | [diff] [blame] | 416 | void SimplePictureRenderer::init(const SkPicture* picture, const SkString* writePath, |
commit-bot@chromium.org | 3f04517 | 2014-05-15 15:10:48 +0000 | [diff] [blame] | 417 | const SkString* mismatchPath, const SkString* inputFilename, |
| 418 | bool useChecksumBasedFilenames) { |
| 419 | INHERITED::init(picture, writePath, mismatchPath, inputFilename, useChecksumBasedFilenames); |
junov@chromium.org | 9313ca4 | 2012-11-02 18:11:49 +0000 | [diff] [blame] | 420 | this->buildBBoxHierarchy(); |
| 421 | } |
| 422 | |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 423 | bool SimplePictureRenderer::render(SkBitmap** out) { |
keyar@chromium.org | 9d696c0 | 2012-08-07 17:11:33 +0000 | [diff] [blame] | 424 | SkASSERT(fCanvas.get() != NULL); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 425 | SkASSERT(fPicture); |
keyar@chromium.org | 78a35c5 | 2012-08-20 15:03:44 +0000 | [diff] [blame] | 426 | if (NULL == fCanvas.get() || NULL == fPicture) { |
scroggo@google.com | 81f9d2e | 2012-09-20 14:54:21 +0000 | [diff] [blame] | 427 | return false; |
keyar@chromium.org | 9d696c0 | 2012-08-07 17:11:33 +0000 | [diff] [blame] | 428 | } |
| 429 | |
robertphillips | 9b14f26 | 2014-06-04 05:40:44 -0700 | [diff] [blame] | 430 | fCanvas->drawPicture(fPicture); |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 431 | fCanvas->flush(); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 432 | if (out) { |
edisonn@google.com | 84f548c | 2012-12-18 22:24:03 +0000 | [diff] [blame] | 433 | *out = SkNEW(SkBitmap); |
robertphillips | a8d7f0b | 2014-08-29 08:03:56 -0700 | [diff] [blame] | 434 | setup_bitmap(*out, SkScalarCeilToInt(fPicture->cullRect().width()), |
| 435 | SkScalarCeilToInt(fPicture->cullRect().height())); |
edisonn@google.com | 84f548c | 2012-12-18 22:24:03 +0000 | [diff] [blame] | 436 | fCanvas->readPixels(*out, 0, 0); |
| 437 | } |
commit-bot@chromium.org | 8991c67 | 2014-05-22 00:36:05 +0000 | [diff] [blame] | 438 | if (fEnableWrites) { |
| 439 | return write(fCanvas, fWritePath, fMismatchPath, fInputFilename, fJsonSummaryPtr, |
| 440 | fUseChecksumBasedFilenames); |
| 441 | } else { |
| 442 | return true; |
| 443 | } |
keyar@chromium.org | 451bb9f | 2012-07-26 17:27:57 +0000 | [diff] [blame] | 444 | } |
| 445 | |
scroggo@google.com | 0a049b8 | 2012-11-02 22:01:26 +0000 | [diff] [blame] | 446 | SkString SimplePictureRenderer::getConfigNameInternal() { |
| 447 | return SkString("simple"); |
| 448 | } |
| 449 | |
scroggo@google.com | acfb30e | 2012-09-18 14:32:35 +0000 | [diff] [blame] | 450 | /////////////////////////////////////////////////////////////////////////////////////////////// |
| 451 | |
krajcevski | b1aded8 | 2014-08-18 07:52:17 -0700 | [diff] [blame] | 452 | #if SK_SUPPORT_GPU |
| 453 | TiledPictureRenderer::TiledPictureRenderer(const GrContext::Options& opts) |
mtklein | 2a65a23 | 2014-08-26 14:07:04 -0700 | [diff] [blame] | 454 | : INHERITED(opts) |
krajcevski | b1aded8 | 2014-08-18 07:52:17 -0700 | [diff] [blame] | 455 | , fTileWidth(kDefaultTileWidth) |
| 456 | #else |
keyar@chromium.org | 451bb9f | 2012-07-26 17:27:57 +0000 | [diff] [blame] | 457 | TiledPictureRenderer::TiledPictureRenderer() |
scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 458 | : fTileWidth(kDefaultTileWidth) |
krajcevski | b1aded8 | 2014-08-18 07:52:17 -0700 | [diff] [blame] | 459 | #endif |
rileya@google.com | b947b91 | 2012-08-29 17:35:07 +0000 | [diff] [blame] | 460 | , fTileHeight(kDefaultTileHeight) |
rileya@google.com | a04dc02 | 2012-09-10 19:01:38 +0000 | [diff] [blame] | 461 | , fTileWidthPercentage(0.0) |
rileya@google.com | b947b91 | 2012-08-29 17:35:07 +0000 | [diff] [blame] | 462 | , fTileHeightPercentage(0.0) |
scroggo@google.com | cbcef70 | 2012-12-13 22:09:28 +0000 | [diff] [blame] | 463 | , fTileMinPowerOf2Width(0) |
| 464 | , fCurrentTileOffset(-1) |
| 465 | , fTilesX(0) |
| 466 | , fTilesY(0) { } |
keyar@chromium.org | 451bb9f | 2012-07-26 17:27:57 +0000 | [diff] [blame] | 467 | |
robertphillips | ce4dd3d | 2014-07-07 13:46:35 -0700 | [diff] [blame] | 468 | void TiledPictureRenderer::init(const SkPicture* pict, const SkString* writePath, |
commit-bot@chromium.org | 3f04517 | 2014-05-15 15:10:48 +0000 | [diff] [blame] | 469 | const SkString* mismatchPath, const SkString* inputFilename, |
| 470 | bool useChecksumBasedFilenames) { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 471 | SkASSERT(pict); |
scroggo@google.com | acfb30e | 2012-09-18 14:32:35 +0000 | [diff] [blame] | 472 | SkASSERT(0 == fTileRects.count()); |
| 473 | if (NULL == pict || fTileRects.count() != 0) { |
keyar@chromium.org | 9d696c0 | 2012-08-07 17:11:33 +0000 | [diff] [blame] | 474 | return; |
| 475 | } |
| 476 | |
scroggo@google.com | acfb30e | 2012-09-18 14:32:35 +0000 | [diff] [blame] | 477 | // Do not call INHERITED::init(), which would create a (potentially large) canvas which is not |
| 478 | // used by bench_pictures. |
robertphillips@google.com | 84b18c7 | 2014-04-13 19:09:42 +0000 | [diff] [blame] | 479 | fPicture.reset(pict)->ref(); |
commit-bot@chromium.org | 3f04517 | 2014-05-15 15:10:48 +0000 | [diff] [blame] | 480 | this->CopyString(&fWritePath, writePath); |
| 481 | this->CopyString(&fMismatchPath, mismatchPath); |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 482 | this->CopyString(&fInputFilename, inputFilename); |
| 483 | fUseChecksumBasedFilenames = useChecksumBasedFilenames; |
scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 484 | this->buildBBoxHierarchy(); |
keyar@chromium.org | cc6e5ef | 2012-07-27 20:09:26 +0000 | [diff] [blame] | 485 | |
| 486 | if (fTileWidthPercentage > 0) { |
robertphillips | a8d7f0b | 2014-08-29 08:03:56 -0700 | [diff] [blame] | 487 | fTileWidth = SkScalarCeilToInt(float(fTileWidthPercentage * fPicture->cullRect().width() / 100)); |
keyar@chromium.org | cc6e5ef | 2012-07-27 20:09:26 +0000 | [diff] [blame] | 488 | } |
| 489 | if (fTileHeightPercentage > 0) { |
robertphillips | a8d7f0b | 2014-08-29 08:03:56 -0700 | [diff] [blame] | 490 | fTileHeight = SkScalarCeilToInt(float(fTileHeightPercentage * fPicture->cullRect().height() / 100)); |
keyar@chromium.org | cc6e5ef | 2012-07-27 20:09:26 +0000 | [diff] [blame] | 491 | } |
| 492 | |
keyar@chromium.org | f4959ab | 2012-08-23 20:53:25 +0000 | [diff] [blame] | 493 | if (fTileMinPowerOf2Width > 0) { |
| 494 | this->setupPowerOf2Tiles(); |
| 495 | } else { |
| 496 | this->setupTiles(); |
| 497 | } |
scroggo@google.com | cbcef70 | 2012-12-13 22:09:28 +0000 | [diff] [blame] | 498 | fCanvas.reset(this->setupCanvas(fTileWidth, fTileHeight)); |
| 499 | // Initialize to -1 so that the first call to nextTile will set this up to draw tile 0 on the |
| 500 | // first call to drawCurrentTile. |
| 501 | fCurrentTileOffset = -1; |
keyar@chromium.org | 451bb9f | 2012-07-26 17:27:57 +0000 | [diff] [blame] | 502 | } |
| 503 | |
keyar@chromium.org | 9d696c0 | 2012-08-07 17:11:33 +0000 | [diff] [blame] | 504 | void TiledPictureRenderer::end() { |
scroggo@google.com | bcdf2ec | 2012-09-20 14:42:33 +0000 | [diff] [blame] | 505 | fTileRects.reset(); |
keyar@chromium.org | 9d696c0 | 2012-08-07 17:11:33 +0000 | [diff] [blame] | 506 | this->INHERITED::end(); |
keyar@chromium.org | 451bb9f | 2012-07-26 17:27:57 +0000 | [diff] [blame] | 507 | } |
| 508 | |
keyar@chromium.org | 9d696c0 | 2012-08-07 17:11:33 +0000 | [diff] [blame] | 509 | void TiledPictureRenderer::setupTiles() { |
scroggo@google.com | c0d5e54 | 2012-12-13 21:40:48 +0000 | [diff] [blame] | 510 | // Only use enough tiles to cover the viewport |
| 511 | const int width = this->getViewWidth(); |
| 512 | const int height = this->getViewHeight(); |
| 513 | |
scroggo@google.com | cbcef70 | 2012-12-13 22:09:28 +0000 | [diff] [blame] | 514 | fTilesX = fTilesY = 0; |
scroggo@google.com | c0d5e54 | 2012-12-13 21:40:48 +0000 | [diff] [blame] | 515 | for (int tile_y_start = 0; tile_y_start < height; tile_y_start += fTileHeight) { |
scroggo@google.com | cbcef70 | 2012-12-13 22:09:28 +0000 | [diff] [blame] | 516 | fTilesY++; |
scroggo@google.com | c0d5e54 | 2012-12-13 21:40:48 +0000 | [diff] [blame] | 517 | for (int tile_x_start = 0; tile_x_start < width; tile_x_start += fTileWidth) { |
scroggo@google.com | cbcef70 | 2012-12-13 22:09:28 +0000 | [diff] [blame] | 518 | if (0 == tile_y_start) { |
| 519 | // Only count tiles in the X direction on the first pass. |
| 520 | fTilesX++; |
| 521 | } |
scroggo@google.com | acfb30e | 2012-09-18 14:32:35 +0000 | [diff] [blame] | 522 | *fTileRects.append() = SkRect::MakeXYWH(SkIntToScalar(tile_x_start), |
| 523 | SkIntToScalar(tile_y_start), |
| 524 | SkIntToScalar(fTileWidth), |
| 525 | SkIntToScalar(fTileHeight)); |
keyar@chromium.org | f4959ab | 2012-08-23 20:53:25 +0000 | [diff] [blame] | 526 | } |
| 527 | } |
| 528 | } |
| 529 | |
scroggo@google.com | cbcef70 | 2012-12-13 22:09:28 +0000 | [diff] [blame] | 530 | bool TiledPictureRenderer::tileDimensions(int &x, int &y) { |
| 531 | if (fTileRects.count() == 0 || NULL == fPicture) { |
| 532 | return false; |
| 533 | } |
| 534 | x = fTilesX; |
| 535 | y = fTilesY; |
| 536 | return true; |
| 537 | } |
| 538 | |
keyar@chromium.org | f4959ab | 2012-08-23 20:53:25 +0000 | [diff] [blame] | 539 | // The goal of the powers of two tiles is to minimize the amount of wasted tile |
| 540 | // space in the width-wise direction and then minimize the number of tiles. The |
| 541 | // constraints are that every tile must have a pixel width that is a power of |
| 542 | // two and also be of some minimal width (that is also a power of two). |
| 543 | // |
scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 544 | // This is solved by first taking our picture size and rounding it up to the |
keyar@chromium.org | f4959ab | 2012-08-23 20:53:25 +0000 | [diff] [blame] | 545 | // multiple of the minimal width. The binary representation of this rounded |
| 546 | // value gives us the tiles we need: a bit of value one means we need a tile of |
| 547 | // that size. |
| 548 | void TiledPictureRenderer::setupPowerOf2Tiles() { |
scroggo@google.com | c0d5e54 | 2012-12-13 21:40:48 +0000 | [diff] [blame] | 549 | // Only use enough tiles to cover the viewport |
| 550 | const int width = this->getViewWidth(); |
| 551 | const int height = this->getViewHeight(); |
| 552 | |
| 553 | int rounded_value = width; |
| 554 | if (width % fTileMinPowerOf2Width != 0) { |
| 555 | rounded_value = width - (width % fTileMinPowerOf2Width) + fTileMinPowerOf2Width; |
keyar@chromium.org | f4959ab | 2012-08-23 20:53:25 +0000 | [diff] [blame] | 556 | } |
| 557 | |
reed@google.com | e15b2f5 | 2013-12-18 04:59:26 +0000 | [diff] [blame] | 558 | int num_bits = SkScalarCeilToInt(scalar_log2(SkIntToScalar(width))); |
keyar@chromium.org | f4959ab | 2012-08-23 20:53:25 +0000 | [diff] [blame] | 559 | int largest_possible_tile_size = 1 << num_bits; |
| 560 | |
scroggo@google.com | cbcef70 | 2012-12-13 22:09:28 +0000 | [diff] [blame] | 561 | fTilesX = fTilesY = 0; |
keyar@chromium.org | f4959ab | 2012-08-23 20:53:25 +0000 | [diff] [blame] | 562 | // The tile height is constant for a particular picture. |
scroggo@google.com | c0d5e54 | 2012-12-13 21:40:48 +0000 | [diff] [blame] | 563 | for (int tile_y_start = 0; tile_y_start < height; tile_y_start += fTileHeight) { |
scroggo@google.com | cbcef70 | 2012-12-13 22:09:28 +0000 | [diff] [blame] | 564 | fTilesY++; |
keyar@chromium.org | f4959ab | 2012-08-23 20:53:25 +0000 | [diff] [blame] | 565 | int tile_x_start = 0; |
| 566 | int current_width = largest_possible_tile_size; |
scroggo@google.com | acfb30e | 2012-09-18 14:32:35 +0000 | [diff] [blame] | 567 | // Set fTileWidth to be the width of the widest tile, so that each canvas is large enough |
| 568 | // to draw each tile. |
| 569 | fTileWidth = current_width; |
keyar@chromium.org | f4959ab | 2012-08-23 20:53:25 +0000 | [diff] [blame] | 570 | |
| 571 | while (current_width >= fTileMinPowerOf2Width) { |
| 572 | // It is very important this is a bitwise AND. |
| 573 | if (current_width & rounded_value) { |
scroggo@google.com | cbcef70 | 2012-12-13 22:09:28 +0000 | [diff] [blame] | 574 | if (0 == tile_y_start) { |
| 575 | // Only count tiles in the X direction on the first pass. |
| 576 | fTilesX++; |
| 577 | } |
scroggo@google.com | acfb30e | 2012-09-18 14:32:35 +0000 | [diff] [blame] | 578 | *fTileRects.append() = SkRect::MakeXYWH(SkIntToScalar(tile_x_start), |
| 579 | SkIntToScalar(tile_y_start), |
| 580 | SkIntToScalar(current_width), |
| 581 | SkIntToScalar(fTileHeight)); |
keyar@chromium.org | f4959ab | 2012-08-23 20:53:25 +0000 | [diff] [blame] | 582 | tile_x_start += current_width; |
| 583 | } |
| 584 | |
| 585 | current_width >>= 1; |
keyar@chromium.org | 451bb9f | 2012-07-26 17:27:57 +0000 | [diff] [blame] | 586 | } |
| 587 | } |
| 588 | } |
| 589 | |
scroggo@google.com | bcdf2ec | 2012-09-20 14:42:33 +0000 | [diff] [blame] | 590 | /** |
commit-bot@chromium.org | 145d1c0 | 2014-03-16 19:46:36 +0000 | [diff] [blame] | 591 | * Draw the specified picture to the canvas translated to rectangle provided, so that this mini |
scroggo@google.com | bcdf2ec | 2012-09-20 14:42:33 +0000 | [diff] [blame] | 592 | * canvas represents the rectangle's portion of the overall picture. |
| 593 | * Saves and restores so that the initial clip and matrix return to their state before this function |
| 594 | * is called. |
| 595 | */ |
mtklein | 2a65a23 | 2014-08-26 14:07:04 -0700 | [diff] [blame] | 596 | static void draw_tile_to_canvas(SkCanvas* canvas, |
| 597 | const SkRect& tileRect, |
robertphillips | ce4dd3d | 2014-07-07 13:46:35 -0700 | [diff] [blame] | 598 | const SkPicture* picture) { |
scroggo@google.com | bcdf2ec | 2012-09-20 14:42:33 +0000 | [diff] [blame] | 599 | int saveCount = canvas->save(); |
scroggo@google.com | 82ec0b0 | 2012-12-17 19:25:54 +0000 | [diff] [blame] | 600 | // Translate so that we draw the correct portion of the picture. |
| 601 | // Perform a postTranslate so that the scaleFactor does not interfere with the positioning. |
| 602 | SkMatrix mat(canvas->getTotalMatrix()); |
| 603 | mat.postTranslate(-tileRect.fLeft, -tileRect.fTop); |
| 604 | canvas->setMatrix(mat); |
robertphillips | 9b14f26 | 2014-06-04 05:40:44 -0700 | [diff] [blame] | 605 | canvas->drawPicture(picture); |
scroggo@google.com | bcdf2ec | 2012-09-20 14:42:33 +0000 | [diff] [blame] | 606 | canvas->restoreToCount(saveCount); |
| 607 | canvas->flush(); |
keyar@chromium.org | 451bb9f | 2012-07-26 17:27:57 +0000 | [diff] [blame] | 608 | } |
| 609 | |
scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 610 | /////////////////////////////////////////////////////////////////////////////////////////////// |
scroggo@google.com | bcdf2ec | 2012-09-20 14:42:33 +0000 | [diff] [blame] | 611 | |
commit-bot@chromium.org | a3f882c | 2013-12-13 20:52:36 +0000 | [diff] [blame] | 612 | /** |
| 613 | * Copies the entirety of the src bitmap (typically a tile) into a portion of the dst bitmap. |
| 614 | * If the src bitmap is too large to fit within the dst bitmap after the x and y |
| 615 | * offsets have been applied, any excess will be ignored (so only the top-left portion of the |
| 616 | * src bitmap will be copied). |
| 617 | * |
| 618 | * @param src source bitmap |
| 619 | * @param dst destination bitmap |
| 620 | * @param xOffset x-offset within destination bitmap |
| 621 | * @param yOffset y-offset within destination bitmap |
| 622 | */ |
| 623 | static void bitmapCopyAtOffset(const SkBitmap& src, SkBitmap* dst, |
| 624 | int xOffset, int yOffset) { |
| 625 | for (int y = 0; y <src.height() && y + yOffset < dst->height() ; y++) { |
| 626 | for (int x = 0; x < src.width() && x + xOffset < dst->width() ; x++) { |
| 627 | *dst->getAddr32(xOffset + x, yOffset + y) = *src.getAddr32(x, y); |
edisonn@google.com | 84f548c | 2012-12-18 22:24:03 +0000 | [diff] [blame] | 628 | } |
| 629 | } |
| 630 | } |
| 631 | |
scroggo@google.com | cbcef70 | 2012-12-13 22:09:28 +0000 | [diff] [blame] | 632 | bool TiledPictureRenderer::nextTile(int &i, int &j) { |
| 633 | if (++fCurrentTileOffset < fTileRects.count()) { |
| 634 | i = fCurrentTileOffset % fTilesX; |
| 635 | j = fCurrentTileOffset / fTilesX; |
| 636 | return true; |
| 637 | } |
| 638 | return false; |
| 639 | } |
| 640 | |
| 641 | void TiledPictureRenderer::drawCurrentTile() { |
| 642 | SkASSERT(fCurrentTileOffset >= 0 && fCurrentTileOffset < fTileRects.count()); |
commit-bot@chromium.org | 145d1c0 | 2014-03-16 19:46:36 +0000 | [diff] [blame] | 643 | draw_tile_to_canvas(fCanvas, fTileRects[fCurrentTileOffset], fPicture); |
scroggo@google.com | cbcef70 | 2012-12-13 22:09:28 +0000 | [diff] [blame] | 644 | } |
| 645 | |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 646 | bool TiledPictureRenderer::render(SkBitmap** out) { |
scroggo@google.com | acfb30e | 2012-09-18 14:32:35 +0000 | [diff] [blame] | 647 | SkASSERT(fPicture != NULL); |
| 648 | if (NULL == fPicture) { |
scroggo@google.com | 81f9d2e | 2012-09-20 14:54:21 +0000 | [diff] [blame] | 649 | return false; |
scroggo@google.com | acfb30e | 2012-09-18 14:32:35 +0000 | [diff] [blame] | 650 | } |
| 651 | |
edisonn@google.com | 84f548c | 2012-12-18 22:24:03 +0000 | [diff] [blame] | 652 | SkBitmap bitmap; |
| 653 | if (out){ |
| 654 | *out = SkNEW(SkBitmap); |
robertphillips | a8d7f0b | 2014-08-29 08:03:56 -0700 | [diff] [blame] | 655 | setup_bitmap(*out, SkScalarCeilToInt(fPicture->cullRect().width()), |
| 656 | SkScalarCeilToInt(fPicture->cullRect().height())); |
edisonn@google.com | 84f548c | 2012-12-18 22:24:03 +0000 | [diff] [blame] | 657 | setup_bitmap(&bitmap, fTileWidth, fTileHeight); |
| 658 | } |
scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 659 | bool success = true; |
| 660 | for (int i = 0; i < fTileRects.count(); ++i) { |
commit-bot@chromium.org | 145d1c0 | 2014-03-16 19:46:36 +0000 | [diff] [blame] | 661 | draw_tile_to_canvas(fCanvas, fTileRects[i], fPicture); |
commit-bot@chromium.org | 8991c67 | 2014-05-22 00:36:05 +0000 | [diff] [blame] | 662 | if (fEnableWrites) { |
| 663 | success &= write(fCanvas, fWritePath, fMismatchPath, fInputFilename, fJsonSummaryPtr, |
| 664 | fUseChecksumBasedFilenames, &i); |
| 665 | } |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 666 | if (out) { |
edisonn@google.com | 84f548c | 2012-12-18 22:24:03 +0000 | [diff] [blame] | 667 | if (fCanvas->readPixels(&bitmap, 0, 0)) { |
commit-bot@chromium.org | a3f882c | 2013-12-13 20:52:36 +0000 | [diff] [blame] | 668 | // Add this tile to the entire bitmap. |
| 669 | bitmapCopyAtOffset(bitmap, *out, SkScalarFloorToInt(fTileRects[i].left()), |
| 670 | SkScalarFloorToInt(fTileRects[i].top())); |
edisonn@google.com | 84f548c | 2012-12-18 22:24:03 +0000 | [diff] [blame] | 671 | } else { |
| 672 | success = false; |
| 673 | } |
| 674 | } |
keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 675 | } |
scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 676 | return success; |
keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 677 | } |
| 678 | |
scroggo@google.com | bcdf2ec | 2012-09-20 14:42:33 +0000 | [diff] [blame] | 679 | SkCanvas* TiledPictureRenderer::setupCanvas(int width, int height) { |
| 680 | SkCanvas* canvas = this->INHERITED::setupCanvas(width, height); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 681 | SkASSERT(fPicture); |
scroggo@google.com | 82ec0b0 | 2012-12-17 19:25:54 +0000 | [diff] [blame] | 682 | // Clip the tile to an area that is completely inside both the SkPicture and the viewport. This |
| 683 | // is mostly important for tiles on the right and bottom edges as they may go over this area and |
| 684 | // the picture may have some commands that draw outside of this area and so should not actually |
| 685 | // be written. |
| 686 | // Uses a clipRegion so that it will be unaffected by the scale factor, which may have been set |
| 687 | // by INHERITED::setupCanvas. |
| 688 | SkRegion clipRegion; |
| 689 | clipRegion.setRect(0, 0, this->getViewWidth(), this->getViewHeight()); |
| 690 | canvas->clipRegion(clipRegion); |
scroggo@google.com | bcdf2ec | 2012-09-20 14:42:33 +0000 | [diff] [blame] | 691 | return canvas; |
| 692 | } |
scroggo@google.com | 0a049b8 | 2012-11-02 22:01:26 +0000 | [diff] [blame] | 693 | |
| 694 | SkString TiledPictureRenderer::getConfigNameInternal() { |
| 695 | SkString name; |
| 696 | if (fTileMinPowerOf2Width > 0) { |
| 697 | name.append("pow2tile_"); |
| 698 | name.appendf("%i", fTileMinPowerOf2Width); |
| 699 | } else { |
| 700 | name.append("tile_"); |
| 701 | if (fTileWidthPercentage > 0) { |
| 702 | name.appendf("%.f%%", fTileWidthPercentage); |
| 703 | } else { |
| 704 | name.appendf("%i", fTileWidth); |
| 705 | } |
| 706 | } |
| 707 | name.append("x"); |
| 708 | if (fTileHeightPercentage > 0) { |
| 709 | name.appendf("%.f%%", fTileHeightPercentage); |
| 710 | } else { |
| 711 | name.appendf("%i", fTileHeight); |
| 712 | } |
| 713 | return name; |
| 714 | } |
| 715 | |
scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 716 | /////////////////////////////////////////////////////////////////////////////////////////////// |
| 717 | |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 718 | void PlaybackCreationRenderer::setup() { |
commit-bot@chromium.org | 5fb2ce3 | 2014-04-17 23:35:06 +0000 | [diff] [blame] | 719 | SkAutoTDelete<SkBBHFactory> factory(this->getFactory()); |
| 720 | fRecorder.reset(SkNEW(SkPictureRecorder)); |
robertphillips | a8d7f0b | 2014-08-29 08:03:56 -0700 | [diff] [blame] | 721 | SkCanvas* canvas = fRecorder->beginRecording(SkIntToScalar(this->getViewWidth()), |
| 722 | SkIntToScalar(this->getViewHeight()), |
commit-bot@chromium.org | 5fb2ce3 | 2014-04-17 23:35:06 +0000 | [diff] [blame] | 723 | factory.get(), |
robertphillips@google.com | 84b18c7 | 2014-04-13 19:09:42 +0000 | [diff] [blame] | 724 | this->recordFlags()); |
| 725 | this->scaleToScaleFactor(canvas); |
robertphillips | 9b14f26 | 2014-06-04 05:40:44 -0700 | [diff] [blame] | 726 | canvas->drawPicture(fPicture); |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 727 | } |
| 728 | |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 729 | bool PlaybackCreationRenderer::render(SkBitmap** out) { |
robertphillips@google.com | 84b18c7 | 2014-04-13 19:09:42 +0000 | [diff] [blame] | 730 | fPicture.reset(fRecorder->endRecording()); |
scroggo@google.com | 81f9d2e | 2012-09-20 14:54:21 +0000 | [diff] [blame] | 731 | // Since this class does not actually render, return false. |
| 732 | return false; |
keyar@chromium.org | 451bb9f | 2012-07-26 17:27:57 +0000 | [diff] [blame] | 733 | } |
| 734 | |
scroggo@google.com | 0a049b8 | 2012-11-02 22:01:26 +0000 | [diff] [blame] | 735 | SkString PlaybackCreationRenderer::getConfigNameInternal() { |
| 736 | return SkString("playback_creation"); |
| 737 | } |
| 738 | |
junov@chromium.org | 9313ca4 | 2012-11-02 18:11:49 +0000 | [diff] [blame] | 739 | /////////////////////////////////////////////////////////////////////////////////////////////// |
| 740 | // SkPicture variants for each BBoxHierarchy type |
| 741 | |
commit-bot@chromium.org | 5fb2ce3 | 2014-04-17 23:35:06 +0000 | [diff] [blame] | 742 | SkBBHFactory* PictureRenderer::getFactory() { |
junov@chromium.org | 9313ca4 | 2012-11-02 18:11:49 +0000 | [diff] [blame] | 743 | switch (fBBoxHierarchyType) { |
| 744 | case kNone_BBoxHierarchyType: |
robertphillips@google.com | 84b18c7 | 2014-04-13 19:09:42 +0000 | [diff] [blame] | 745 | return NULL; |
junov@chromium.org | 9313ca4 | 2012-11-02 18:11:49 +0000 | [diff] [blame] | 746 | case kRTree_BBoxHierarchyType: |
commit-bot@chromium.org | 5fb2ce3 | 2014-04-17 23:35:06 +0000 | [diff] [blame] | 747 | return SkNEW(SkRTreeFactory); |
junov@chromium.org | 7b53706 | 2012-11-06 18:58:43 +0000 | [diff] [blame] | 748 | case kTileGrid_BBoxHierarchyType: |
commit-bot@chromium.org | 5fb2ce3 | 2014-04-17 23:35:06 +0000 | [diff] [blame] | 749 | return SkNEW_ARGS(SkTileGridFactory, (fGridInfo)); |
junov@chromium.org | 9313ca4 | 2012-11-02 18:11:49 +0000 | [diff] [blame] | 750 | } |
| 751 | SkASSERT(0); // invalid bbhType |
| 752 | return NULL; |
keyar@chromium.org | 451bb9f | 2012-07-26 17:27:57 +0000 | [diff] [blame] | 753 | } |
junov@chromium.org | 9313ca4 | 2012-11-02 18:11:49 +0000 | [diff] [blame] | 754 | |
reed@google.com | fe7b1ed | 2012-11-29 21:00:39 +0000 | [diff] [blame] | 755 | /////////////////////////////////////////////////////////////////////////////// |
| 756 | |
| 757 | class GatherRenderer : public PictureRenderer { |
| 758 | public: |
krajcevski | b1aded8 | 2014-08-18 07:52:17 -0700 | [diff] [blame] | 759 | #if SK_SUPPORT_GPU |
| 760 | GatherRenderer(const GrContext::Options& opts) : INHERITED(opts) { } |
| 761 | #endif |
| 762 | |
commit-bot@chromium.org | 8ddc26b | 2014-03-31 17:55:12 +0000 | [diff] [blame] | 763 | virtual bool render(SkBitmap** out = NULL) SK_OVERRIDE { |
robertphillips | a8d7f0b | 2014-08-29 08:03:56 -0700 | [diff] [blame] | 764 | SkRect bounds = SkRect::MakeWH(SkIntToScalar(fPicture->cullRect().width()), |
| 765 | SkIntToScalar(fPicture->cullRect().height())); |
reed@google.com | fe7b1ed | 2012-11-29 21:00:39 +0000 | [diff] [blame] | 766 | SkData* data = SkPictureUtils::GatherPixelRefs(fPicture, bounds); |
| 767 | SkSafeUnref(data); |
skia.committer@gmail.com | c7b4be7 | 2012-12-11 02:01:20 +0000 | [diff] [blame] | 768 | |
commit-bot@chromium.org | 3f04517 | 2014-05-15 15:10:48 +0000 | [diff] [blame] | 769 | return (fWritePath.isEmpty()); // we don't have anything to write |
reed@google.com | fe7b1ed | 2012-11-29 21:00:39 +0000 | [diff] [blame] | 770 | } |
skia.committer@gmail.com | c7b4be7 | 2012-12-11 02:01:20 +0000 | [diff] [blame] | 771 | |
reed@google.com | fe7b1ed | 2012-11-29 21:00:39 +0000 | [diff] [blame] | 772 | private: |
| 773 | virtual SkString getConfigNameInternal() SK_OVERRIDE { |
| 774 | return SkString("gather_pixelrefs"); |
| 775 | } |
krajcevski | b1aded8 | 2014-08-18 07:52:17 -0700 | [diff] [blame] | 776 | |
| 777 | typedef PictureRenderer INHERITED; |
reed@google.com | fe7b1ed | 2012-11-29 21:00:39 +0000 | [diff] [blame] | 778 | }; |
| 779 | |
krajcevski | b1aded8 | 2014-08-18 07:52:17 -0700 | [diff] [blame] | 780 | #if SK_SUPPORT_GPU |
| 781 | PictureRenderer* CreateGatherPixelRefsRenderer(const GrContext::Options& opts) { |
| 782 | return SkNEW_ARGS(GatherRenderer, (opts)); |
| 783 | } |
| 784 | #else |
reed@google.com | fe7b1ed | 2012-11-29 21:00:39 +0000 | [diff] [blame] | 785 | PictureRenderer* CreateGatherPixelRefsRenderer() { |
| 786 | return SkNEW(GatherRenderer); |
| 787 | } |
krajcevski | b1aded8 | 2014-08-18 07:52:17 -0700 | [diff] [blame] | 788 | #endif |
skia.committer@gmail.com | c3d7d90 | 2012-11-30 02:01:24 +0000 | [diff] [blame] | 789 | |
junov@chromium.org | 9313ca4 | 2012-11-02 18:11:49 +0000 | [diff] [blame] | 790 | } // namespace sk_tools |