| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2011 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 | #include "SkGpuDevice.h" |
| 9 | |
| commit-bot@chromium.org | dec6150 | 2013-12-02 22:22:35 +0000 | [diff] [blame] | 10 | #include "effects/GrBicubicEffect.h" |
| commit-bot@chromium.org | 628ed0b | 2014-05-19 14:32:49 +0000 | [diff] [blame] | 11 | #include "effects/GrDashingEffect.h" |
| commit-bot@chromium.org | 907fbd5 | 2013-12-09 17:03:02 +0000 | [diff] [blame] | 12 | #include "effects/GrTextureDomain.h" |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 13 | #include "effects/GrSimpleTextureEffect.h" |
| 14 | |
| 15 | #include "GrContext.h" |
| 16 | #include "GrBitmapTextContext.h" |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 17 | #include "GrDistanceFieldTextContext.h" |
| robertphillips@google.com | e930a07 | 2014-04-03 00:34:27 +0000 | [diff] [blame] | 18 | #include "GrLayerCache.h" |
| commit-bot@chromium.org | 8ddc26b | 2014-03-31 17:55:12 +0000 | [diff] [blame] | 19 | #include "GrPictureUtils.h" |
| egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 20 | #include "GrStrokeInfo.h" |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 21 | |
| 22 | #include "SkGrTexturePixelRef.h" |
| 23 | |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 24 | #include "SkDeviceImageFilterProxy.h" |
| 25 | #include "SkDrawProcs.h" |
| 26 | #include "SkGlyphCache.h" |
| 27 | #include "SkImageFilter.h" |
| commit-bot@chromium.org | 8213970 | 2014-03-10 22:53:20 +0000 | [diff] [blame] | 28 | #include "SkMaskFilter.h" |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 29 | #include "SkPathEffect.h" |
| commit-bot@chromium.org | 145d1c0 | 2014-03-16 19:46:36 +0000 | [diff] [blame] | 30 | #include "SkPicture.h" |
| robertphillips@google.com | beb1af2 | 2014-05-07 21:31:09 +0000 | [diff] [blame] | 31 | #include "SkPicturePlayback.h" |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 32 | #include "SkRRect.h" |
| 33 | #include "SkStroke.h" |
| reed@google.com | 76f10a3 | 2014-02-05 15:32:21 +0000 | [diff] [blame] | 34 | #include "SkSurface.h" |
| commit-bot@chromium.org | a7d89c8 | 2014-01-13 14:47:00 +0000 | [diff] [blame] | 35 | #include "SkTLazy.h" |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 36 | #include "SkUtils.h" |
| commit-bot@chromium.org | 559a883 | 2014-05-30 10:08:22 +0000 | [diff] [blame] | 37 | #include "SkVertState.h" |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 38 | #include "SkErrorInternals.h" |
| 39 | |
| 40 | #define CACHE_COMPATIBLE_DEVICE_TEXTURES 1 |
| 41 | |
| 42 | #if 0 |
| 43 | extern bool (*gShouldDrawProc)(); |
| 44 | #define CHECK_SHOULD_DRAW(draw, forceI) \ |
| 45 | do { \ |
| 46 | if (gShouldDrawProc && !gShouldDrawProc()) return; \ |
| 47 | this->prepareDraw(draw, forceI); \ |
| 48 | } while (0) |
| 49 | #else |
| 50 | #define CHECK_SHOULD_DRAW(draw, forceI) this->prepareDraw(draw, forceI) |
| 51 | #endif |
| 52 | |
| 53 | // This constant represents the screen alignment criterion in texels for |
| 54 | // requiring texture domain clamping to prevent color bleeding when drawing |
| 55 | // a sub region of a larger source image. |
| commit-bot@chromium.org | 4b413c8 | 2013-11-25 19:44:07 +0000 | [diff] [blame] | 56 | #define COLOR_BLEED_TOLERANCE 0.001f |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 57 | |
| 58 | #define DO_DEFERRED_CLEAR() \ |
| 59 | do { \ |
| 60 | if (fNeedClear) { \ |
| 61 | this->clear(SK_ColorTRANSPARENT); \ |
| 62 | } \ |
| 63 | } while (false) \ |
| 64 | |
| 65 | /////////////////////////////////////////////////////////////////////////////// |
| 66 | |
| 67 | #define CHECK_FOR_ANNOTATION(paint) \ |
| 68 | do { if (paint.getAnnotation()) { return; } } while (0) |
| 69 | |
| 70 | /////////////////////////////////////////////////////////////////////////////// |
| 71 | |
| 72 | |
| 73 | class SkGpuDevice::SkAutoCachedTexture : public ::SkNoncopyable { |
| 74 | public: |
| 75 | SkAutoCachedTexture() |
| 76 | : fDevice(NULL) |
| 77 | , fTexture(NULL) { |
| 78 | } |
| 79 | |
| 80 | SkAutoCachedTexture(SkGpuDevice* device, |
| 81 | const SkBitmap& bitmap, |
| 82 | const GrTextureParams* params, |
| 83 | GrTexture** texture) |
| 84 | : fDevice(NULL) |
| 85 | , fTexture(NULL) { |
| 86 | SkASSERT(NULL != texture); |
| 87 | *texture = this->set(device, bitmap, params); |
| 88 | } |
| 89 | |
| 90 | ~SkAutoCachedTexture() { |
| 91 | if (NULL != fTexture) { |
| 92 | GrUnlockAndUnrefCachedBitmapTexture(fTexture); |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | GrTexture* set(SkGpuDevice* device, |
| 97 | const SkBitmap& bitmap, |
| 98 | const GrTextureParams* params) { |
| 99 | if (NULL != fTexture) { |
| 100 | GrUnlockAndUnrefCachedBitmapTexture(fTexture); |
| 101 | fTexture = NULL; |
| 102 | } |
| 103 | fDevice = device; |
| 104 | GrTexture* result = (GrTexture*)bitmap.getTexture(); |
| 105 | if (NULL == result) { |
| 106 | // Cannot return the native texture so look it up in our cache |
| 107 | fTexture = GrLockAndRefCachedBitmapTexture(device->context(), bitmap, params); |
| 108 | result = fTexture; |
| 109 | } |
| 110 | return result; |
| 111 | } |
| 112 | |
| 113 | private: |
| 114 | SkGpuDevice* fDevice; |
| 115 | GrTexture* fTexture; |
| 116 | }; |
| 117 | |
| 118 | /////////////////////////////////////////////////////////////////////////////// |
| 119 | |
| 120 | struct GrSkDrawProcs : public SkDrawProcs { |
| 121 | public: |
| 122 | GrContext* fContext; |
| 123 | GrTextContext* fTextContext; |
| 124 | GrFontScaler* fFontScaler; // cached in the skia glyphcache |
| 125 | }; |
| 126 | |
| 127 | /////////////////////////////////////////////////////////////////////////////// |
| 128 | |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 129 | /* |
| 130 | * GrRenderTarget does not know its opaqueness, only its config, so we have |
| 131 | * to make conservative guesses when we return an "equivalent" bitmap. |
| 132 | */ |
| 133 | static SkBitmap make_bitmap(GrContext* context, GrRenderTarget* renderTarget) { |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 134 | SkBitmap bitmap; |
| reed | 6c22573 | 2014-06-09 19:52:07 -0700 | [diff] [blame] | 135 | bitmap.setInfo(renderTarget->info()); |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 136 | return bitmap; |
| 137 | } |
| 138 | |
| commit-bot@chromium.org | d8a57af | 2014-03-19 21:19:16 +0000 | [diff] [blame] | 139 | SkGpuDevice* SkGpuDevice::Create(GrSurface* surface, unsigned flags) { |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 140 | SkASSERT(NULL != surface); |
| 141 | if (NULL == surface->asRenderTarget() || NULL == surface->getContext()) { |
| 142 | return NULL; |
| 143 | } |
| 144 | if (surface->asTexture()) { |
| commit-bot@chromium.org | d8a57af | 2014-03-19 21:19:16 +0000 | [diff] [blame] | 145 | return SkNEW_ARGS(SkGpuDevice, (surface->getContext(), surface->asTexture(), flags)); |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 146 | } else { |
| commit-bot@chromium.org | d8a57af | 2014-03-19 21:19:16 +0000 | [diff] [blame] | 147 | return SkNEW_ARGS(SkGpuDevice, (surface->getContext(), surface->asRenderTarget(), flags)); |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 148 | } |
| 149 | } |
| 150 | |
| commit-bot@chromium.org | d8a57af | 2014-03-19 21:19:16 +0000 | [diff] [blame] | 151 | SkGpuDevice::SkGpuDevice(GrContext* context, GrTexture* texture, unsigned flags) |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 152 | : SkBitmapDevice(make_bitmap(context, texture->asRenderTarget())) { |
| commit-bot@chromium.org | d8a57af | 2014-03-19 21:19:16 +0000 | [diff] [blame] | 153 | this->initFromRenderTarget(context, texture->asRenderTarget(), flags); |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 154 | } |
| 155 | |
| commit-bot@chromium.org | d8a57af | 2014-03-19 21:19:16 +0000 | [diff] [blame] | 156 | SkGpuDevice::SkGpuDevice(GrContext* context, GrRenderTarget* renderTarget, unsigned flags) |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 157 | : SkBitmapDevice(make_bitmap(context, renderTarget)) { |
| commit-bot@chromium.org | d8a57af | 2014-03-19 21:19:16 +0000 | [diff] [blame] | 158 | this->initFromRenderTarget(context, renderTarget, flags); |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | void SkGpuDevice::initFromRenderTarget(GrContext* context, |
| 162 | GrRenderTarget* renderTarget, |
| commit-bot@chromium.org | d8a57af | 2014-03-19 21:19:16 +0000 | [diff] [blame] | 163 | unsigned flags) { |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 164 | fDrawProcs = NULL; |
| 165 | |
| 166 | fContext = context; |
| 167 | fContext->ref(); |
| 168 | |
| commit-bot@chromium.org | 6fcd1ef | 2014-05-02 12:39:41 +0000 | [diff] [blame] | 169 | bool useDFFonts = !!(flags & kDFFonts_Flag); |
| 170 | fMainTextContext = SkNEW_ARGS(GrDistanceFieldTextContext, (fContext, fLeakyProperties, |
| 171 | useDFFonts)); |
| commit-bot@chromium.org | 4784182 | 2014-03-27 14:19:17 +0000 | [diff] [blame] | 172 | fFallbackTextContext = SkNEW_ARGS(GrBitmapTextContext, (fContext, fLeakyProperties)); |
| 173 | |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 174 | fRenderTarget = NULL; |
| commit-bot@chromium.org | d8a57af | 2014-03-19 21:19:16 +0000 | [diff] [blame] | 175 | fNeedClear = flags & kNeedClear_Flag; |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 176 | |
| 177 | SkASSERT(NULL != renderTarget); |
| 178 | fRenderTarget = renderTarget; |
| 179 | fRenderTarget->ref(); |
| 180 | |
| 181 | // Hold onto to the texture in the pixel ref (if there is one) because the texture holds a ref |
| 182 | // on the RT but not vice-versa. |
| 183 | // TODO: Remove this trickery once we figure out how to make SkGrPixelRef do this without |
| 184 | // busting chrome (for a currently unknown reason). |
| 185 | GrSurface* surface = fRenderTarget->asTexture(); |
| 186 | if (NULL == surface) { |
| 187 | surface = fRenderTarget; |
| 188 | } |
| reed@google.com | bf79023 | 2013-12-13 19:45:58 +0000 | [diff] [blame] | 189 | |
| reed | 6c22573 | 2014-06-09 19:52:07 -0700 | [diff] [blame] | 190 | SkPixelRef* pr = SkNEW_ARGS(SkGrPixelRef, |
| 191 | (surface->info(), surface, SkToBool(flags & kCached_Flag))); |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 192 | |
| reed@google.com | 672588b | 2014-01-08 15:42:01 +0000 | [diff] [blame] | 193 | this->setPixelRef(pr)->unref(); |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 194 | } |
| 195 | |
| commit-bot@chromium.org | 15a1405 | 2014-02-16 00:59:25 +0000 | [diff] [blame] | 196 | SkGpuDevice* SkGpuDevice::Create(GrContext* context, const SkImageInfo& origInfo, |
| 197 | int sampleCount) { |
| 198 | if (kUnknown_SkColorType == origInfo.colorType() || |
| 199 | origInfo.width() < 0 || origInfo.height() < 0) { |
| 200 | return NULL; |
| 201 | } |
| 202 | |
| 203 | SkImageInfo info = origInfo; |
| 204 | // TODO: perhas we can loosen this check now that colortype is more detailed |
| 205 | // e.g. can we support both RGBA and BGRA here? |
| 206 | if (kRGB_565_SkColorType == info.colorType()) { |
| 207 | info.fAlphaType = kOpaque_SkAlphaType; // force this setting |
| 208 | } else { |
| commit-bot@chromium.org | 28fcae2 | 2014-04-11 17:15:40 +0000 | [diff] [blame] | 209 | info.fColorType = kN32_SkColorType; |
| commit-bot@chromium.org | 15a1405 | 2014-02-16 00:59:25 +0000 | [diff] [blame] | 210 | if (kOpaque_SkAlphaType != info.alphaType()) { |
| 211 | info.fAlphaType = kPremul_SkAlphaType; // force this setting |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | GrTextureDesc desc; |
| 216 | desc.fFlags = kRenderTarget_GrTextureFlagBit; |
| 217 | desc.fWidth = info.width(); |
| 218 | desc.fHeight = info.height(); |
| commit-bot@chromium.org | 3adcc34 | 2014-04-23 19:18:09 +0000 | [diff] [blame] | 219 | desc.fConfig = SkImageInfo2GrPixelConfig(info); |
| commit-bot@chromium.org | 15a1405 | 2014-02-16 00:59:25 +0000 | [diff] [blame] | 220 | desc.fSampleCnt = sampleCount; |
| 221 | |
| 222 | SkAutoTUnref<GrTexture> texture(context->createUncachedTexture(desc, NULL, 0)); |
| 223 | if (!texture.get()) { |
| 224 | return NULL; |
| 225 | } |
| skia.committer@gmail.com | 969588f | 2014-02-16 03:01:56 +0000 | [diff] [blame] | 226 | |
| commit-bot@chromium.org | 15a1405 | 2014-02-16 00:59:25 +0000 | [diff] [blame] | 227 | return SkNEW_ARGS(SkGpuDevice, (context, texture.get())); |
| 228 | } |
| 229 | |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 230 | SkGpuDevice::~SkGpuDevice() { |
| 231 | if (fDrawProcs) { |
| 232 | delete fDrawProcs; |
| 233 | } |
| skia.committer@gmail.com | d2ac07b | 2014-01-25 07:01:49 +0000 | [diff] [blame] | 234 | |
| commit-bot@chromium.org | cbbc481 | 2014-01-30 22:05:47 +0000 | [diff] [blame] | 235 | delete fMainTextContext; |
| 236 | delete fFallbackTextContext; |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 237 | |
| 238 | // The GrContext takes a ref on the target. We don't want to cause the render |
| 239 | // target to be unnecessarily kept alive. |
| 240 | if (fContext->getRenderTarget() == fRenderTarget) { |
| 241 | fContext->setRenderTarget(NULL); |
| 242 | } |
| 243 | |
| 244 | if (fContext->getClip() == &fClipData) { |
| 245 | fContext->setClip(NULL); |
| 246 | } |
| 247 | |
| 248 | SkSafeUnref(fRenderTarget); |
| 249 | fContext->unref(); |
| 250 | } |
| 251 | |
| 252 | /////////////////////////////////////////////////////////////////////////////// |
| 253 | |
| 254 | void SkGpuDevice::makeRenderTargetCurrent() { |
| 255 | DO_DEFERRED_CLEAR(); |
| 256 | fContext->setRenderTarget(fRenderTarget); |
| 257 | } |
| 258 | |
| 259 | /////////////////////////////////////////////////////////////////////////////// |
| 260 | |
| commit-bot@chromium.org | a713f9c | 2014-03-17 21:31:26 +0000 | [diff] [blame] | 261 | bool SkGpuDevice::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes, |
| 262 | int x, int y) { |
| 263 | DO_DEFERRED_CLEAR(); |
| 264 | |
| 265 | // TODO: teach fRenderTarget to take ImageInfo directly to specify the src pixels |
| commit-bot@chromium.org | 3adcc34 | 2014-04-23 19:18:09 +0000 | [diff] [blame] | 266 | GrPixelConfig config = SkImageInfo2GrPixelConfig(dstInfo); |
| commit-bot@chromium.org | a713f9c | 2014-03-17 21:31:26 +0000 | [diff] [blame] | 267 | if (kUnknown_GrPixelConfig == config) { |
| 268 | return false; |
| 269 | } |
| 270 | |
| 271 | uint32_t flags = 0; |
| 272 | if (kUnpremul_SkAlphaType == dstInfo.alphaType()) { |
| 273 | flags = GrContext::kUnpremul_PixelOpsFlag; |
| 274 | } |
| 275 | return fContext->readRenderTargetPixels(fRenderTarget, x, y, dstInfo.width(), dstInfo.height(), |
| 276 | config, dstPixels, dstRowBytes, flags); |
| 277 | } |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 278 | |
| commit-bot@chromium.org | 4cd9e21 | 2014-03-07 03:25:16 +0000 | [diff] [blame] | 279 | bool SkGpuDevice::onWritePixels(const SkImageInfo& info, const void* pixels, size_t rowBytes, |
| 280 | int x, int y) { |
| 281 | // TODO: teach fRenderTarget to take ImageInfo directly to specify the src pixels |
| commit-bot@chromium.org | 3adcc34 | 2014-04-23 19:18:09 +0000 | [diff] [blame] | 282 | GrPixelConfig config = SkImageInfo2GrPixelConfig(info); |
| commit-bot@chromium.org | 4cd9e21 | 2014-03-07 03:25:16 +0000 | [diff] [blame] | 283 | if (kUnknown_GrPixelConfig == config) { |
| 284 | return false; |
| 285 | } |
| 286 | uint32_t flags = 0; |
| 287 | if (kUnpremul_SkAlphaType == info.alphaType()) { |
| 288 | flags = GrContext::kUnpremul_PixelOpsFlag; |
| 289 | } |
| 290 | fRenderTarget->writePixels(x, y, info.width(), info.height(), config, pixels, rowBytes, flags); |
| 291 | |
| 292 | // need to bump our genID for compatibility with clients that "know" we have a bitmap |
| 293 | this->onAccessBitmap().notifyPixelsChanged(); |
| 294 | |
| 295 | return true; |
| 296 | } |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 297 | |
| senorblanco@chromium.org | b7b7eb3 | 2014-03-19 18:24:04 +0000 | [diff] [blame] | 298 | const SkBitmap& SkGpuDevice::onAccessBitmap() { |
| 299 | DO_DEFERRED_CLEAR(); |
| 300 | return INHERITED::onAccessBitmap(); |
| 301 | } |
| 302 | |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 303 | void SkGpuDevice::onAttachToCanvas(SkCanvas* canvas) { |
| 304 | INHERITED::onAttachToCanvas(canvas); |
| 305 | |
| 306 | // Canvas promises that this ptr is valid until onDetachFromCanvas is called |
| 307 | fClipData.fClipStack = canvas->getClipStack(); |
| 308 | } |
| 309 | |
| 310 | void SkGpuDevice::onDetachFromCanvas() { |
| 311 | INHERITED::onDetachFromCanvas(); |
| 312 | fClipData.fClipStack = NULL; |
| 313 | } |
| 314 | |
| 315 | // call this every draw call, to ensure that the context reflects our state, |
| 316 | // and not the state from some other canvas/device |
| 317 | void SkGpuDevice::prepareDraw(const SkDraw& draw, bool forceIdentity) { |
| 318 | SkASSERT(NULL != fClipData.fClipStack); |
| 319 | |
| 320 | fContext->setRenderTarget(fRenderTarget); |
| 321 | |
| 322 | SkASSERT(draw.fClipStack && draw.fClipStack == fClipData.fClipStack); |
| 323 | |
| 324 | if (forceIdentity) { |
| 325 | fContext->setIdentityMatrix(); |
| 326 | } else { |
| 327 | fContext->setMatrix(*draw.fMatrix); |
| 328 | } |
| 329 | fClipData.fOrigin = this->getOrigin(); |
| 330 | |
| 331 | fContext->setClip(&fClipData); |
| 332 | |
| 333 | DO_DEFERRED_CLEAR(); |
| 334 | } |
| 335 | |
| 336 | GrRenderTarget* SkGpuDevice::accessRenderTarget() { |
| 337 | DO_DEFERRED_CLEAR(); |
| 338 | return fRenderTarget; |
| 339 | } |
| 340 | |
| 341 | /////////////////////////////////////////////////////////////////////////////// |
| 342 | |
| 343 | SK_COMPILE_ASSERT(SkShader::kNone_BitmapType == 0, shader_type_mismatch); |
| 344 | SK_COMPILE_ASSERT(SkShader::kDefault_BitmapType == 1, shader_type_mismatch); |
| 345 | SK_COMPILE_ASSERT(SkShader::kRadial_BitmapType == 2, shader_type_mismatch); |
| 346 | SK_COMPILE_ASSERT(SkShader::kSweep_BitmapType == 3, shader_type_mismatch); |
| 347 | SK_COMPILE_ASSERT(SkShader::kTwoPointRadial_BitmapType == 4, |
| 348 | shader_type_mismatch); |
| 349 | SK_COMPILE_ASSERT(SkShader::kTwoPointConical_BitmapType == 5, |
| 350 | shader_type_mismatch); |
| 351 | SK_COMPILE_ASSERT(SkShader::kLinear_BitmapType == 6, shader_type_mismatch); |
| 352 | SK_COMPILE_ASSERT(SkShader::kLast_BitmapType == 6, shader_type_mismatch); |
| 353 | |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 354 | /////////////////////////////////////////////////////////////////////////////// |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 355 | |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 356 | void SkGpuDevice::clear(SkColor color) { |
| 357 | SkIRect rect = SkIRect::MakeWH(this->width(), this->height()); |
| 358 | fContext->clear(&rect, SkColor2GrColor(color), true, fRenderTarget); |
| 359 | fNeedClear = false; |
| 360 | } |
| 361 | |
| 362 | void SkGpuDevice::drawPaint(const SkDraw& draw, const SkPaint& paint) { |
| 363 | CHECK_SHOULD_DRAW(draw, false); |
| 364 | |
| 365 | GrPaint grPaint; |
| commit-bot@chromium.org | 3595f88 | 2014-05-19 19:35:57 +0000 | [diff] [blame] | 366 | SkPaint2GrPaintShader(this->context(), paint, true, &grPaint); |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 367 | |
| 368 | fContext->drawPaint(grPaint); |
| 369 | } |
| 370 | |
| 371 | // must be in SkCanvas::PointMode order |
| 372 | static const GrPrimitiveType gPointMode2PrimtiveType[] = { |
| 373 | kPoints_GrPrimitiveType, |
| 374 | kLines_GrPrimitiveType, |
| 375 | kLineStrip_GrPrimitiveType |
| 376 | }; |
| 377 | |
| 378 | void SkGpuDevice::drawPoints(const SkDraw& draw, SkCanvas::PointMode mode, |
| 379 | size_t count, const SkPoint pts[], const SkPaint& paint) { |
| 380 | CHECK_FOR_ANNOTATION(paint); |
| 381 | CHECK_SHOULD_DRAW(draw, false); |
| 382 | |
| 383 | SkScalar width = paint.getStrokeWidth(); |
| 384 | if (width < 0) { |
| 385 | return; |
| 386 | } |
| 387 | |
| commit-bot@chromium.org | 628ed0b | 2014-05-19 14:32:49 +0000 | [diff] [blame] | 388 | if (paint.getPathEffect() && 2 == count && SkCanvas::kLines_PointMode == mode) { |
| egdaniel | e61c411 | 2014-06-12 10:24:21 -0700 | [diff] [blame] | 389 | GrStrokeInfo strokeInfo(paint, SkPaint::kStroke_Style); |
| 390 | GrPaint grPaint; |
| 391 | SkPaint2GrPaintShader(this->context(), paint, true, &grPaint); |
| 392 | SkPath path; |
| 393 | path.moveTo(pts[0]); |
| 394 | path.lineTo(pts[1]); |
| 395 | fContext->drawPath(grPaint, path, strokeInfo); |
| 396 | return; |
| commit-bot@chromium.org | 628ed0b | 2014-05-19 14:32:49 +0000 | [diff] [blame] | 397 | } |
| 398 | |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 399 | // we only handle hairlines and paints without path effects or mask filters, |
| 400 | // else we let the SkDraw call our drawPath() |
| 401 | if (width > 0 || paint.getPathEffect() || paint.getMaskFilter()) { |
| 402 | draw.drawPoints(mode, count, pts, paint, true); |
| 403 | return; |
| 404 | } |
| 405 | |
| 406 | GrPaint grPaint; |
| commit-bot@chromium.org | 3595f88 | 2014-05-19 19:35:57 +0000 | [diff] [blame] | 407 | SkPaint2GrPaintShader(this->context(), paint, true, &grPaint); |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 408 | |
| 409 | fContext->drawVertices(grPaint, |
| 410 | gPointMode2PrimtiveType[mode], |
| robertphillips@google.com | a466286 | 2013-11-21 14:24:16 +0000 | [diff] [blame] | 411 | SkToS32(count), |
| commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 412 | (SkPoint*)pts, |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 413 | NULL, |
| 414 | NULL, |
| 415 | NULL, |
| 416 | 0); |
| 417 | } |
| 418 | |
| 419 | /////////////////////////////////////////////////////////////////////////////// |
| 420 | |
| 421 | void SkGpuDevice::drawRect(const SkDraw& draw, const SkRect& rect, |
| 422 | const SkPaint& paint) { |
| 423 | CHECK_FOR_ANNOTATION(paint); |
| 424 | CHECK_SHOULD_DRAW(draw, false); |
| 425 | |
| 426 | bool doStroke = paint.getStyle() != SkPaint::kFill_Style; |
| 427 | SkScalar width = paint.getStrokeWidth(); |
| 428 | |
| 429 | /* |
| 430 | We have special code for hairline strokes, miter-strokes, bevel-stroke |
| 431 | and fills. Anything else we just call our path code. |
| 432 | */ |
| 433 | bool usePath = doStroke && width > 0 && |
| 434 | (paint.getStrokeJoin() == SkPaint::kRound_Join || |
| 435 | (paint.getStrokeJoin() == SkPaint::kBevel_Join && rect.isEmpty())); |
| 436 | // another two reasons we might need to call drawPath... |
| egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 437 | |
| 438 | if (paint.getMaskFilter()) { |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 439 | usePath = true; |
| 440 | } |
| egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 441 | |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 442 | if (!usePath && paint.isAntiAlias() && !fContext->getMatrix().rectStaysRect()) { |
| 443 | #if defined(SHADER_AA_FILL_RECT) || !defined(IGNORE_ROT_AA_RECT_OPT) |
| 444 | if (doStroke) { |
| 445 | #endif |
| 446 | usePath = true; |
| 447 | #if defined(SHADER_AA_FILL_RECT) || !defined(IGNORE_ROT_AA_RECT_OPT) |
| 448 | } else { |
| 449 | usePath = !fContext->getMatrix().preservesRightAngles(); |
| 450 | } |
| 451 | #endif |
| 452 | } |
| 453 | // until we can both stroke and fill rectangles |
| 454 | if (paint.getStyle() == SkPaint::kStrokeAndFill_Style) { |
| 455 | usePath = true; |
| 456 | } |
| 457 | |
| egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 458 | GrStrokeInfo strokeInfo(paint); |
| 459 | |
| 460 | const SkPathEffect* pe = paint.getPathEffect(); |
| 461 | if (!usePath && NULL != pe && !strokeInfo.isDashed()) { |
| 462 | usePath = true; |
| 463 | } |
| 464 | |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 465 | if (usePath) { |
| 466 | SkPath path; |
| 467 | path.addRect(rect); |
| 468 | this->drawPath(draw, path, paint, NULL, true); |
| 469 | return; |
| 470 | } |
| 471 | |
| 472 | GrPaint grPaint; |
| commit-bot@chromium.org | 3595f88 | 2014-05-19 19:35:57 +0000 | [diff] [blame] | 473 | SkPaint2GrPaintShader(this->context(), paint, true, &grPaint); |
| egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 474 | |
| 475 | fContext->drawRect(grPaint, rect, &strokeInfo); |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 476 | } |
| 477 | |
| 478 | /////////////////////////////////////////////////////////////////////////////// |
| 479 | |
| 480 | void SkGpuDevice::drawRRect(const SkDraw& draw, const SkRRect& rect, |
| 481 | const SkPaint& paint) { |
| 482 | CHECK_FOR_ANNOTATION(paint); |
| 483 | CHECK_SHOULD_DRAW(draw, false); |
| 484 | |
| commit-bot@chromium.org | 8213970 | 2014-03-10 22:53:20 +0000 | [diff] [blame] | 485 | GrPaint grPaint; |
| commit-bot@chromium.org | 3595f88 | 2014-05-19 19:35:57 +0000 | [diff] [blame] | 486 | SkPaint2GrPaintShader(this->context(), paint, true, &grPaint); |
| egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 487 | |
| 488 | GrStrokeInfo strokeInfo(paint); |
| commit-bot@chromium.org | 8213970 | 2014-03-10 22:53:20 +0000 | [diff] [blame] | 489 | if (paint.getMaskFilter()) { |
| 490 | // try to hit the fast path for drawing filtered round rects |
| 491 | |
| 492 | SkRRect devRRect; |
| 493 | if (rect.transform(fContext->getMatrix(), &devRRect)) { |
| 494 | if (devRRect.allCornersCircular()) { |
| 495 | SkRect maskRect; |
| 496 | if (paint.getMaskFilter()->canFilterMaskGPU(devRRect.rect(), |
| 497 | draw.fClip->getBounds(), |
| 498 | fContext->getMatrix(), |
| 499 | &maskRect)) { |
| 500 | SkIRect finalIRect; |
| 501 | maskRect.roundOut(&finalIRect); |
| 502 | if (draw.fClip->quickReject(finalIRect)) { |
| 503 | // clipped out |
| 504 | return; |
| 505 | } |
| commit-bot@chromium.org | 8213970 | 2014-03-10 22:53:20 +0000 | [diff] [blame] | 506 | if (paint.getMaskFilter()->directFilterRRectMaskGPU(fContext, &grPaint, |
| egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 507 | strokeInfo.getStrokeRec(), |
| 508 | devRRect)) { |
| commit-bot@chromium.org | 8213970 | 2014-03-10 22:53:20 +0000 | [diff] [blame] | 509 | return; |
| 510 | } |
| 511 | } |
| 512 | |
| 513 | } |
| 514 | } |
| 515 | |
| 516 | } |
| 517 | |
| egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 518 | bool usePath = false; |
| 519 | |
| 520 | if (paint.getMaskFilter()) { |
| 521 | usePath = true; |
| 522 | } else { |
| 523 | const SkPathEffect* pe = paint.getPathEffect(); |
| 524 | if (NULL != pe && !strokeInfo.isDashed()) { |
| 525 | usePath = true; |
| 526 | } |
| 527 | } |
| 528 | |
| 529 | |
| 530 | if (usePath) { |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 531 | SkPath path; |
| 532 | path.addRRect(rect); |
| 533 | this->drawPath(draw, path, paint, NULL, true); |
| 534 | return; |
| 535 | } |
| egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 536 | |
| 537 | fContext->drawRRect(grPaint, rect, strokeInfo); |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 538 | } |
| 539 | |
| commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 540 | void SkGpuDevice::drawDRRect(const SkDraw& draw, const SkRRect& outer, |
| 541 | const SkRRect& inner, const SkPaint& paint) { |
| 542 | SkStrokeRec stroke(paint); |
| 543 | if (stroke.isFillStyle()) { |
| 544 | |
| 545 | CHECK_FOR_ANNOTATION(paint); |
| 546 | CHECK_SHOULD_DRAW(draw, false); |
| 547 | |
| 548 | GrPaint grPaint; |
| commit-bot@chromium.org | 3595f88 | 2014-05-19 19:35:57 +0000 | [diff] [blame] | 549 | SkPaint2GrPaintShader(this->context(), paint, true, &grPaint); |
| commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 550 | |
| 551 | if (NULL == paint.getMaskFilter() && NULL == paint.getPathEffect()) { |
| 552 | fContext->drawDRRect(grPaint, outer, inner); |
| 553 | return; |
| 554 | } |
| 555 | } |
| 556 | |
| 557 | SkPath path; |
| 558 | path.addRRect(outer); |
| 559 | path.addRRect(inner); |
| 560 | path.setFillType(SkPath::kEvenOdd_FillType); |
| 561 | |
| 562 | this->drawPath(draw, path, paint, NULL, true); |
| 563 | } |
| 564 | |
| 565 | |
| commit-bot@chromium.org | 8213970 | 2014-03-10 22:53:20 +0000 | [diff] [blame] | 566 | ///////////////////////////////////////////////////////////////////////////// |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 567 | |
| 568 | void SkGpuDevice::drawOval(const SkDraw& draw, const SkRect& oval, |
| 569 | const SkPaint& paint) { |
| 570 | CHECK_FOR_ANNOTATION(paint); |
| 571 | CHECK_SHOULD_DRAW(draw, false); |
| 572 | |
| egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 573 | GrStrokeInfo strokeInfo(paint); |
| 574 | |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 575 | bool usePath = false; |
| 576 | // some basic reasons we might need to call drawPath... |
| egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 577 | if (paint.getMaskFilter()) { |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 578 | usePath = true; |
| egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 579 | } else { |
| 580 | const SkPathEffect* pe = paint.getPathEffect(); |
| 581 | if (NULL != pe && !strokeInfo.isDashed()) { |
| 582 | usePath = true; |
| 583 | } |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 584 | } |
| 585 | |
| 586 | if (usePath) { |
| 587 | SkPath path; |
| 588 | path.addOval(oval); |
| 589 | this->drawPath(draw, path, paint, NULL, true); |
| 590 | return; |
| 591 | } |
| 592 | |
| 593 | GrPaint grPaint; |
| commit-bot@chromium.org | 3595f88 | 2014-05-19 19:35:57 +0000 | [diff] [blame] | 594 | SkPaint2GrPaintShader(this->context(), paint, true, &grPaint); |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 595 | |
| egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 596 | fContext->drawOval(grPaint, oval, strokeInfo); |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 597 | } |
| 598 | |
| 599 | #include "SkMaskFilter.h" |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 600 | |
| 601 | /////////////////////////////////////////////////////////////////////////////// |
| 602 | |
| 603 | // helpers for applying mask filters |
| 604 | namespace { |
| 605 | |
| 606 | // Draw a mask using the supplied paint. Since the coverage/geometry |
| 607 | // is already burnt into the mask this boils down to a rect draw. |
| 608 | // Return true if the mask was successfully drawn. |
| 609 | bool draw_mask(GrContext* context, const SkRect& maskRect, |
| 610 | GrPaint* grp, GrTexture* mask) { |
| 611 | GrContext::AutoMatrix am; |
| 612 | if (!am.setIdentity(context, grp)) { |
| 613 | return false; |
| 614 | } |
| 615 | |
| 616 | SkMatrix matrix; |
| 617 | matrix.setTranslate(-maskRect.fLeft, -maskRect.fTop); |
| 618 | matrix.postIDiv(mask->width(), mask->height()); |
| 619 | |
| 620 | grp->addCoverageEffect(GrSimpleTextureEffect::Create(mask, matrix))->unref(); |
| 621 | context->drawRect(*grp, maskRect); |
| 622 | return true; |
| 623 | } |
| 624 | |
| 625 | bool draw_with_mask_filter(GrContext* context, const SkPath& devPath, |
| reed | 868074b | 2014-06-03 10:53:59 -0700 | [diff] [blame] | 626 | SkMaskFilter* filter, const SkRegion& clip, |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 627 | GrPaint* grp, SkPaint::Style style) { |
| 628 | SkMask srcM, dstM; |
| 629 | |
| 630 | if (!SkDraw::DrawToMask(devPath, &clip.getBounds(), filter, &context->getMatrix(), &srcM, |
| 631 | SkMask::kComputeBoundsAndRenderImage_CreateMode, style)) { |
| 632 | return false; |
| 633 | } |
| 634 | SkAutoMaskFreeImage autoSrc(srcM.fImage); |
| 635 | |
| 636 | if (!filter->filterMask(&dstM, srcM, context->getMatrix(), NULL)) { |
| 637 | return false; |
| 638 | } |
| 639 | // this will free-up dstM when we're done (allocated in filterMask()) |
| 640 | SkAutoMaskFreeImage autoDst(dstM.fImage); |
| 641 | |
| 642 | if (clip.quickReject(dstM.fBounds)) { |
| 643 | return false; |
| 644 | } |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 645 | |
| 646 | // we now have a device-aligned 8bit mask in dstM, ready to be drawn using |
| 647 | // the current clip (and identity matrix) and GrPaint settings |
| 648 | GrTextureDesc desc; |
| 649 | desc.fWidth = dstM.fBounds.width(); |
| 650 | desc.fHeight = dstM.fBounds.height(); |
| 651 | desc.fConfig = kAlpha_8_GrPixelConfig; |
| 652 | |
| 653 | GrAutoScratchTexture ast(context, desc); |
| 654 | GrTexture* texture = ast.texture(); |
| 655 | |
| 656 | if (NULL == texture) { |
| 657 | return false; |
| 658 | } |
| 659 | texture->writePixels(0, 0, desc.fWidth, desc.fHeight, desc.fConfig, |
| 660 | dstM.fImage, dstM.fRowBytes); |
| 661 | |
| 662 | SkRect maskRect = SkRect::Make(dstM.fBounds); |
| 663 | |
| 664 | return draw_mask(context, maskRect, grp, texture); |
| 665 | } |
| 666 | |
| 667 | // Create a mask of 'devPath' and place the result in 'mask'. Return true on |
| 668 | // success; false otherwise. |
| 669 | bool create_mask_GPU(GrContext* context, |
| 670 | const SkRect& maskRect, |
| 671 | const SkPath& devPath, |
| egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 672 | const GrStrokeInfo& strokeInfo, |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 673 | bool doAA, |
| 674 | GrAutoScratchTexture* mask) { |
| 675 | GrTextureDesc desc; |
| 676 | desc.fFlags = kRenderTarget_GrTextureFlagBit; |
| 677 | desc.fWidth = SkScalarCeilToInt(maskRect.width()); |
| 678 | desc.fHeight = SkScalarCeilToInt(maskRect.height()); |
| 679 | // We actually only need A8, but it often isn't supported as a |
| 680 | // render target so default to RGBA_8888 |
| 681 | desc.fConfig = kRGBA_8888_GrPixelConfig; |
| 682 | if (context->isConfigRenderable(kAlpha_8_GrPixelConfig, false)) { |
| 683 | desc.fConfig = kAlpha_8_GrPixelConfig; |
| 684 | } |
| 685 | |
| 686 | mask->set(context, desc); |
| 687 | if (NULL == mask->texture()) { |
| 688 | return false; |
| 689 | } |
| 690 | |
| 691 | GrTexture* maskTexture = mask->texture(); |
| 692 | SkRect clipRect = SkRect::MakeWH(maskRect.width(), maskRect.height()); |
| 693 | |
| 694 | GrContext::AutoRenderTarget art(context, maskTexture->asRenderTarget()); |
| 695 | GrContext::AutoClip ac(context, clipRect); |
| 696 | |
| 697 | context->clear(NULL, 0x0, true); |
| 698 | |
| 699 | GrPaint tempPaint; |
| 700 | if (doAA) { |
| 701 | tempPaint.setAntiAlias(true); |
| 702 | // AA uses the "coverage" stages on GrDrawTarget. Coverage with a dst |
| 703 | // blend coeff of zero requires dual source blending support in order |
| 704 | // to properly blend partially covered pixels. This means the AA |
| 705 | // code path may not be taken. So we use a dst blend coeff of ISA. We |
| 706 | // could special case AA draws to a dst surface with known alpha=0 to |
| 707 | // use a zero dst coeff when dual source blending isn't available. |
| 708 | tempPaint.setBlendFunc(kOne_GrBlendCoeff, kISC_GrBlendCoeff); |
| 709 | } |
| 710 | |
| 711 | GrContext::AutoMatrix am; |
| 712 | |
| 713 | // Draw the mask into maskTexture with the path's top-left at the origin using tempPaint. |
| 714 | SkMatrix translate; |
| 715 | translate.setTranslate(-maskRect.fLeft, -maskRect.fTop); |
| 716 | am.set(context, translate); |
| egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 717 | context->drawPath(tempPaint, devPath, strokeInfo); |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 718 | return true; |
| 719 | } |
| 720 | |
| 721 | SkBitmap wrap_texture(GrTexture* texture) { |
| 722 | SkBitmap result; |
| reed | 6c22573 | 2014-06-09 19:52:07 -0700 | [diff] [blame] | 723 | result.setInfo(texture->info()); |
| 724 | result.setPixelRef(SkNEW_ARGS(SkGrPixelRef, (result.info(), texture)))->unref(); |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 725 | return result; |
| 726 | } |
| 727 | |
| 728 | }; |
| 729 | |
| 730 | void SkGpuDevice::drawPath(const SkDraw& draw, const SkPath& origSrcPath, |
| 731 | const SkPaint& paint, const SkMatrix* prePathMatrix, |
| 732 | bool pathIsMutable) { |
| 733 | CHECK_FOR_ANNOTATION(paint); |
| 734 | CHECK_SHOULD_DRAW(draw, false); |
| 735 | |
| 736 | GrPaint grPaint; |
| commit-bot@chromium.org | 3595f88 | 2014-05-19 19:35:57 +0000 | [diff] [blame] | 737 | SkPaint2GrPaintShader(this->context(), paint, true, &grPaint); |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 738 | |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 739 | // If we have a prematrix, apply it to the path, optimizing for the case |
| 740 | // where the original path can in fact be modified in place (even though |
| 741 | // its parameter type is const). |
| 742 | SkPath* pathPtr = const_cast<SkPath*>(&origSrcPath); |
| commit-bot@chromium.org | f0c41e2 | 2014-01-14 18:42:34 +0000 | [diff] [blame] | 743 | SkTLazy<SkPath> tmpPath; |
| 744 | SkTLazy<SkPath> effectPath; |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 745 | |
| 746 | if (prePathMatrix) { |
| 747 | SkPath* result = pathPtr; |
| 748 | |
| 749 | if (!pathIsMutable) { |
| commit-bot@chromium.org | f0c41e2 | 2014-01-14 18:42:34 +0000 | [diff] [blame] | 750 | result = tmpPath.init(); |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 751 | pathIsMutable = true; |
| 752 | } |
| 753 | // should I push prePathMatrix on our MV stack temporarily, instead |
| 754 | // of applying it here? See SkDraw.cpp |
| 755 | pathPtr->transform(*prePathMatrix, result); |
| 756 | pathPtr = result; |
| 757 | } |
| 758 | // at this point we're done with prePathMatrix |
| 759 | SkDEBUGCODE(prePathMatrix = (const SkMatrix*)0x50FF8001;) |
| 760 | |
| egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 761 | GrStrokeInfo strokeInfo(paint); |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 762 | SkPathEffect* pathEffect = paint.getPathEffect(); |
| 763 | const SkRect* cullRect = NULL; // TODO: what is our bounds? |
| egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 764 | SkStrokeRec* strokePtr = strokeInfo.getStrokeRecPtr(); |
| 765 | if (pathEffect && pathEffect->filterPath(effectPath.init(), *pathPtr, strokePtr, |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 766 | cullRect)) { |
| commit-bot@chromium.org | f0c41e2 | 2014-01-14 18:42:34 +0000 | [diff] [blame] | 767 | pathPtr = effectPath.get(); |
| 768 | pathIsMutable = true; |
| egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 769 | strokeInfo.removeDash(); |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 770 | } |
| 771 | |
| egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 772 | const SkStrokeRec& stroke = strokeInfo.getStrokeRec(); |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 773 | if (paint.getMaskFilter()) { |
| 774 | if (!stroke.isHairlineStyle()) { |
| commit-bot@chromium.org | f0c41e2 | 2014-01-14 18:42:34 +0000 | [diff] [blame] | 775 | SkPath* strokedPath = pathIsMutable ? pathPtr : tmpPath.init(); |
| 776 | if (stroke.applyToPath(strokedPath, *pathPtr)) { |
| 777 | pathPtr = strokedPath; |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 778 | pathIsMutable = true; |
| egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 779 | strokeInfo.setFillStyle(); |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 780 | } |
| 781 | } |
| 782 | |
| 783 | // avoid possibly allocating a new path in transform if we can |
| commit-bot@chromium.org | f0c41e2 | 2014-01-14 18:42:34 +0000 | [diff] [blame] | 784 | SkPath* devPathPtr = pathIsMutable ? pathPtr : tmpPath.init(); |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 785 | |
| 786 | // transform the path into device space |
| 787 | pathPtr->transform(fContext->getMatrix(), devPathPtr); |
| skia.committer@gmail.com | 4c18e9f | 2014-01-31 03:01:59 +0000 | [diff] [blame] | 788 | |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 789 | SkRect maskRect; |
| 790 | if (paint.getMaskFilter()->canFilterMaskGPU(devPathPtr->getBounds(), |
| 791 | draw.fClip->getBounds(), |
| 792 | fContext->getMatrix(), |
| 793 | &maskRect)) { |
| commit-bot@chromium.org | 439ff1b | 2014-01-13 16:39:39 +0000 | [diff] [blame] | 794 | // The context's matrix may change while creating the mask, so save the CTM here to |
| 795 | // pass to filterMaskGPU. |
| 796 | const SkMatrix ctm = fContext->getMatrix(); |
| 797 | |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 798 | SkIRect finalIRect; |
| 799 | maskRect.roundOut(&finalIRect); |
| 800 | if (draw.fClip->quickReject(finalIRect)) { |
| 801 | // clipped out |
| 802 | return; |
| 803 | } |
| skia.committer@gmail.com | 4c18e9f | 2014-01-31 03:01:59 +0000 | [diff] [blame] | 804 | |
| commit-bot@chromium.org | cf34bc0 | 2014-01-30 15:34:43 +0000 | [diff] [blame] | 805 | if (paint.getMaskFilter()->directFilterMaskGPU(fContext, &grPaint, |
| commit-bot@chromium.org | 8213970 | 2014-03-10 22:53:20 +0000 | [diff] [blame] | 806 | stroke, *devPathPtr)) { |
| commit-bot@chromium.org | cf34bc0 | 2014-01-30 15:34:43 +0000 | [diff] [blame] | 807 | // the mask filter was able to draw itself directly, so there's nothing |
| 808 | // left to do. |
| 809 | return; |
| 810 | } |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 811 | |
| 812 | GrAutoScratchTexture mask; |
| 813 | |
| egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 814 | if (create_mask_GPU(fContext, maskRect, *devPathPtr, strokeInfo, |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 815 | grPaint.isAntiAlias(), &mask)) { |
| 816 | GrTexture* filtered; |
| 817 | |
| commit-bot@chromium.org | 41bf930 | 2014-01-08 22:25:53 +0000 | [diff] [blame] | 818 | if (paint.getMaskFilter()->filterMaskGPU(mask.texture(), |
| commit-bot@chromium.org | 439ff1b | 2014-01-13 16:39:39 +0000 | [diff] [blame] | 819 | ctm, maskRect, &filtered, true)) { |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 820 | // filterMaskGPU gives us ownership of a ref to the result |
| 821 | SkAutoTUnref<GrTexture> atu(filtered); |
| 822 | |
| 823 | // If the scratch texture that we used as the filter src also holds the filter |
| 824 | // result then we must detach so that this texture isn't recycled for a later |
| 825 | // draw. |
| 826 | if (filtered == mask.texture()) { |
| 827 | mask.detach(); |
| 828 | filtered->unref(); // detach transfers GrAutoScratchTexture's ref to us. |
| 829 | } |
| 830 | |
| 831 | if (draw_mask(fContext, maskRect, &grPaint, filtered)) { |
| 832 | // This path is completely drawn |
| 833 | return; |
| 834 | } |
| 835 | } |
| 836 | } |
| 837 | } |
| 838 | |
| 839 | // draw the mask on the CPU - this is a fallthrough path in case the |
| 840 | // GPU path fails |
| 841 | SkPaint::Style style = stroke.isHairlineStyle() ? SkPaint::kStroke_Style : |
| 842 | SkPaint::kFill_Style; |
| egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 843 | draw_with_mask_filter(fContext, *devPathPtr, paint.getMaskFilter(), |
| 844 | *draw.fClip, &grPaint, style); |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 845 | return; |
| 846 | } |
| 847 | |
| egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 848 | fContext->drawPath(grPaint, *pathPtr, strokeInfo); |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 849 | } |
| 850 | |
| 851 | static const int kBmpSmallTileSize = 1 << 10; |
| 852 | |
| 853 | static inline int get_tile_count(const SkIRect& srcRect, int tileSize) { |
| 854 | int tilesX = (srcRect.fRight / tileSize) - (srcRect.fLeft / tileSize) + 1; |
| 855 | int tilesY = (srcRect.fBottom / tileSize) - (srcRect.fTop / tileSize) + 1; |
| 856 | return tilesX * tilesY; |
| 857 | } |
| 858 | |
| 859 | static int determine_tile_size(const SkBitmap& bitmap, const SkIRect& src, int maxTileSize) { |
| 860 | if (maxTileSize <= kBmpSmallTileSize) { |
| 861 | return maxTileSize; |
| 862 | } |
| 863 | |
| 864 | size_t maxTileTotalTileSize = get_tile_count(src, maxTileSize); |
| 865 | size_t smallTotalTileSize = get_tile_count(src, kBmpSmallTileSize); |
| 866 | |
| 867 | maxTileTotalTileSize *= maxTileSize * maxTileSize; |
| 868 | smallTotalTileSize *= kBmpSmallTileSize * kBmpSmallTileSize; |
| 869 | |
| 870 | if (maxTileTotalTileSize > 2 * smallTotalTileSize) { |
| 871 | return kBmpSmallTileSize; |
| 872 | } else { |
| 873 | return maxTileSize; |
| 874 | } |
| 875 | } |
| 876 | |
| 877 | // Given a bitmap, an optional src rect, and a context with a clip and matrix determine what |
| 878 | // pixels from the bitmap are necessary. |
| 879 | static void determine_clipped_src_rect(const GrContext* context, |
| 880 | const SkBitmap& bitmap, |
| 881 | const SkRect* srcRectPtr, |
| 882 | SkIRect* clippedSrcIRect) { |
| 883 | const GrClipData* clip = context->getClip(); |
| 884 | clip->getConservativeBounds(context->getRenderTarget(), clippedSrcIRect, NULL); |
| 885 | SkMatrix inv; |
| 886 | if (!context->getMatrix().invert(&inv)) { |
| 887 | clippedSrcIRect->setEmpty(); |
| 888 | return; |
| 889 | } |
| 890 | SkRect clippedSrcRect = SkRect::Make(*clippedSrcIRect); |
| 891 | inv.mapRect(&clippedSrcRect); |
| 892 | if (NULL != srcRectPtr) { |
| commit-bot@chromium.org | a7d89c8 | 2014-01-13 14:47:00 +0000 | [diff] [blame] | 893 | // we've setup src space 0,0 to map to the top left of the src rect. |
| 894 | clippedSrcRect.offset(srcRectPtr->fLeft, srcRectPtr->fTop); |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 895 | if (!clippedSrcRect.intersect(*srcRectPtr)) { |
| 896 | clippedSrcIRect->setEmpty(); |
| 897 | return; |
| 898 | } |
| 899 | } |
| 900 | clippedSrcRect.roundOut(clippedSrcIRect); |
| 901 | SkIRect bmpBounds = SkIRect::MakeWH(bitmap.width(), bitmap.height()); |
| 902 | if (!clippedSrcIRect->intersect(bmpBounds)) { |
| 903 | clippedSrcIRect->setEmpty(); |
| 904 | } |
| 905 | } |
| 906 | |
| 907 | bool SkGpuDevice::shouldTileBitmap(const SkBitmap& bitmap, |
| 908 | const GrTextureParams& params, |
| 909 | const SkRect* srcRectPtr, |
| 910 | int maxTileSize, |
| 911 | int* tileSize, |
| 912 | SkIRect* clippedSrcRect) const { |
| 913 | // if bitmap is explictly texture backed then just use the texture |
| 914 | if (NULL != bitmap.getTexture()) { |
| 915 | return false; |
| 916 | } |
| 917 | |
| 918 | // if it's larger than the max tile size, then we have no choice but tiling. |
| 919 | if (bitmap.width() > maxTileSize || bitmap.height() > maxTileSize) { |
| 920 | determine_clipped_src_rect(fContext, bitmap, srcRectPtr, clippedSrcRect); |
| 921 | *tileSize = determine_tile_size(bitmap, *clippedSrcRect, maxTileSize); |
| 922 | return true; |
| 923 | } |
| 924 | |
| 925 | if (bitmap.width() * bitmap.height() < 4 * kBmpSmallTileSize * kBmpSmallTileSize) { |
| 926 | return false; |
| 927 | } |
| 928 | |
| 929 | // if the entire texture is already in our cache then no reason to tile it |
| 930 | if (GrIsBitmapInCache(fContext, bitmap, ¶ms)) { |
| 931 | return false; |
| 932 | } |
| 933 | |
| 934 | // At this point we know we could do the draw by uploading the entire bitmap |
| 935 | // as a texture. However, if the texture would be large compared to the |
| 936 | // cache size and we don't require most of it for this draw then tile to |
| 937 | // reduce the amount of upload and cache spill. |
| 938 | |
| 939 | // assumption here is that sw bitmap size is a good proxy for its size as |
| 940 | // a texture |
| 941 | size_t bmpSize = bitmap.getSize(); |
| 942 | size_t cacheSize; |
| commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 943 | fContext->getResourceCacheLimits(NULL, &cacheSize); |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 944 | if (bmpSize < cacheSize / 2) { |
| 945 | return false; |
| 946 | } |
| 947 | |
| 948 | // Figure out how much of the src we will need based on the src rect and clipping. |
| 949 | determine_clipped_src_rect(fContext, bitmap, srcRectPtr, clippedSrcRect); |
| 950 | *tileSize = kBmpSmallTileSize; // already know whole bitmap fits in one max sized tile. |
| 951 | size_t usedTileBytes = get_tile_count(*clippedSrcRect, kBmpSmallTileSize) * |
| 952 | kBmpSmallTileSize * kBmpSmallTileSize; |
| 953 | |
| 954 | return usedTileBytes < 2 * bmpSize; |
| 955 | } |
| 956 | |
| commit-bot@chromium.org | a7d89c8 | 2014-01-13 14:47:00 +0000 | [diff] [blame] | 957 | void SkGpuDevice::drawBitmap(const SkDraw& origDraw, |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 958 | const SkBitmap& bitmap, |
| 959 | const SkMatrix& m, |
| 960 | const SkPaint& paint) { |
| commit-bot@chromium.org | a7d89c8 | 2014-01-13 14:47:00 +0000 | [diff] [blame] | 961 | SkMatrix concat; |
| 962 | SkTCopyOnFirstWrite<SkDraw> draw(origDraw); |
| 963 | if (!m.isIdentity()) { |
| 964 | concat.setConcat(*draw->fMatrix, m); |
| 965 | draw.writable()->fMatrix = &concat; |
| 966 | } |
| 967 | this->drawBitmapCommon(*draw, bitmap, NULL, NULL, paint, SkCanvas::kNone_DrawBitmapRectFlag); |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 968 | } |
| 969 | |
| commit-bot@chromium.org | dec6150 | 2013-12-02 22:22:35 +0000 | [diff] [blame] | 970 | // This method outsets 'iRect' by 'outset' all around and then clamps its extents to |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 971 | // 'clamp'. 'offset' is adjusted to remain positioned over the top-left corner |
| 972 | // of 'iRect' for all possible outsets/clamps. |
| commit-bot@chromium.org | dec6150 | 2013-12-02 22:22:35 +0000 | [diff] [blame] | 973 | static inline void clamped_outset_with_offset(SkIRect* iRect, |
| 974 | int outset, |
| 975 | SkPoint* offset, |
| 976 | const SkIRect& clamp) { |
| 977 | iRect->outset(outset, outset); |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 978 | |
| commit-bot@chromium.org | dec6150 | 2013-12-02 22:22:35 +0000 | [diff] [blame] | 979 | int leftClampDelta = clamp.fLeft - iRect->fLeft; |
| 980 | if (leftClampDelta > 0) { |
| 981 | offset->fX -= outset - leftClampDelta; |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 982 | iRect->fLeft = clamp.fLeft; |
| 983 | } else { |
| commit-bot@chromium.org | dec6150 | 2013-12-02 22:22:35 +0000 | [diff] [blame] | 984 | offset->fX -= outset; |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 985 | } |
| commit-bot@chromium.org | dec6150 | 2013-12-02 22:22:35 +0000 | [diff] [blame] | 986 | |
| 987 | int topClampDelta = clamp.fTop - iRect->fTop; |
| 988 | if (topClampDelta > 0) { |
| 989 | offset->fY -= outset - topClampDelta; |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 990 | iRect->fTop = clamp.fTop; |
| 991 | } else { |
| commit-bot@chromium.org | dec6150 | 2013-12-02 22:22:35 +0000 | [diff] [blame] | 992 | offset->fY -= outset; |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 993 | } |
| 994 | |
| 995 | if (iRect->fRight > clamp.fRight) { |
| 996 | iRect->fRight = clamp.fRight; |
| 997 | } |
| 998 | if (iRect->fBottom > clamp.fBottom) { |
| 999 | iRect->fBottom = clamp.fBottom; |
| 1000 | } |
| 1001 | } |
| 1002 | |
| commit-bot@chromium.org | a17773f | 2014-05-09 13:53:38 +0000 | [diff] [blame] | 1003 | static bool has_aligned_samples(const SkRect& srcRect, |
| 1004 | const SkRect& transformedRect) { |
| 1005 | // detect pixel disalignment |
| 1006 | if (SkScalarAbs(SkScalarRoundToScalar(transformedRect.left()) - |
| 1007 | transformedRect.left()) < COLOR_BLEED_TOLERANCE && |
| 1008 | SkScalarAbs(SkScalarRoundToScalar(transformedRect.top()) - |
| 1009 | transformedRect.top()) < COLOR_BLEED_TOLERANCE && |
| 1010 | SkScalarAbs(transformedRect.width() - srcRect.width()) < |
| 1011 | COLOR_BLEED_TOLERANCE && |
| 1012 | SkScalarAbs(transformedRect.height() - srcRect.height()) < |
| 1013 | COLOR_BLEED_TOLERANCE) { |
| 1014 | return true; |
| 1015 | } |
| 1016 | return false; |
| 1017 | } |
| 1018 | |
| 1019 | static bool may_color_bleed(const SkRect& srcRect, |
| 1020 | const SkRect& transformedRect, |
| 1021 | const SkMatrix& m) { |
| 1022 | // Only gets called if has_aligned_samples returned false. |
| 1023 | // So we can assume that sampling is axis aligned but not texel aligned. |
| 1024 | SkASSERT(!has_aligned_samples(srcRect, transformedRect)); |
| 1025 | SkRect innerSrcRect(srcRect), innerTransformedRect, |
| 1026 | outerTransformedRect(transformedRect); |
| 1027 | innerSrcRect.inset(SK_ScalarHalf, SK_ScalarHalf); |
| 1028 | m.mapRect(&innerTransformedRect, innerSrcRect); |
| 1029 | |
| 1030 | // The gap between outerTransformedRect and innerTransformedRect |
| 1031 | // represents the projection of the source border area, which is |
| 1032 | // problematic for color bleeding. We must check whether any |
| 1033 | // destination pixels sample the border area. |
| 1034 | outerTransformedRect.inset(COLOR_BLEED_TOLERANCE, COLOR_BLEED_TOLERANCE); |
| 1035 | innerTransformedRect.outset(COLOR_BLEED_TOLERANCE, COLOR_BLEED_TOLERANCE); |
| 1036 | SkIRect outer, inner; |
| 1037 | outerTransformedRect.round(&outer); |
| 1038 | innerTransformedRect.round(&inner); |
| 1039 | // If the inner and outer rects round to the same result, it means the |
| 1040 | // border does not overlap any pixel centers. Yay! |
| 1041 | return inner != outer; |
| 1042 | } |
| 1043 | |
| 1044 | static bool needs_texture_domain(const SkBitmap& bitmap, |
| 1045 | const SkRect& srcRect, |
| 1046 | GrTextureParams ¶ms, |
| 1047 | const SkMatrix& contextMatrix, |
| 1048 | bool bicubic) { |
| 1049 | bool needsTextureDomain = false; |
| 1050 | |
| 1051 | if (bicubic || params.filterMode() != GrTextureParams::kNone_FilterMode) { |
| 1052 | // Need texture domain if drawing a sub rect |
| 1053 | needsTextureDomain = srcRect.width() < bitmap.width() || |
| 1054 | srcRect.height() < bitmap.height(); |
| 1055 | if (!bicubic && needsTextureDomain && contextMatrix.rectStaysRect()) { |
| 1056 | // sampling is axis-aligned |
| 1057 | SkRect transformedRect; |
| 1058 | contextMatrix.mapRect(&transformedRect, srcRect); |
| 1059 | |
| 1060 | if (has_aligned_samples(srcRect, transformedRect)) { |
| 1061 | params.setFilterMode(GrTextureParams::kNone_FilterMode); |
| 1062 | needsTextureDomain = false; |
| 1063 | } else { |
| 1064 | needsTextureDomain = may_color_bleed(srcRect, transformedRect, contextMatrix); |
| 1065 | } |
| 1066 | } |
| 1067 | } |
| 1068 | return needsTextureDomain; |
| 1069 | } |
| 1070 | |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1071 | void SkGpuDevice::drawBitmapCommon(const SkDraw& draw, |
| 1072 | const SkBitmap& bitmap, |
| 1073 | const SkRect* srcRectPtr, |
| commit-bot@chromium.org | a7d89c8 | 2014-01-13 14:47:00 +0000 | [diff] [blame] | 1074 | const SkSize* dstSizePtr, |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1075 | const SkPaint& paint, |
| 1076 | SkCanvas::DrawBitmapRectFlags flags) { |
| 1077 | CHECK_SHOULD_DRAW(draw, false); |
| 1078 | |
| 1079 | SkRect srcRect; |
| commit-bot@chromium.org | a7d89c8 | 2014-01-13 14:47:00 +0000 | [diff] [blame] | 1080 | SkSize dstSize; |
| commit-bot@chromium.org | dec6150 | 2013-12-02 22:22:35 +0000 | [diff] [blame] | 1081 | // If there is no src rect, or the src rect contains the entire bitmap then we're effectively |
| 1082 | // in the (easier) bleed case, so update flags. |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1083 | if (NULL == srcRectPtr) { |
| commit-bot@chromium.org | a7d89c8 | 2014-01-13 14:47:00 +0000 | [diff] [blame] | 1084 | SkScalar w = SkIntToScalar(bitmap.width()); |
| 1085 | SkScalar h = SkIntToScalar(bitmap.height()); |
| 1086 | dstSize.fWidth = w; |
| 1087 | dstSize.fHeight = h; |
| 1088 | srcRect.set(0, 0, w, h); |
| commit-bot@chromium.org | dec6150 | 2013-12-02 22:22:35 +0000 | [diff] [blame] | 1089 | flags = (SkCanvas::DrawBitmapRectFlags) (flags | SkCanvas::kBleed_DrawBitmapRectFlag); |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1090 | } else { |
| commit-bot@chromium.org | a7d89c8 | 2014-01-13 14:47:00 +0000 | [diff] [blame] | 1091 | SkASSERT(NULL != dstSizePtr); |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1092 | srcRect = *srcRectPtr; |
| commit-bot@chromium.org | a7d89c8 | 2014-01-13 14:47:00 +0000 | [diff] [blame] | 1093 | dstSize = *dstSizePtr; |
| commit-bot@chromium.org | dec6150 | 2013-12-02 22:22:35 +0000 | [diff] [blame] | 1094 | if (srcRect.fLeft <= 0 && srcRect.fTop <= 0 && |
| 1095 | srcRect.fRight >= bitmap.width() && srcRect.fBottom >= bitmap.height()) { |
| 1096 | flags = (SkCanvas::DrawBitmapRectFlags) (flags | SkCanvas::kBleed_DrawBitmapRectFlag); |
| 1097 | } |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1098 | } |
| 1099 | |
| 1100 | if (paint.getMaskFilter()){ |
| 1101 | // Convert the bitmap to a shader so that the rect can be drawn |
| 1102 | // through drawRect, which supports mask filters. |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1103 | SkBitmap tmp; // subset of bitmap, if necessary |
| 1104 | const SkBitmap* bitmapPtr = &bitmap; |
| commit-bot@chromium.org | a7d89c8 | 2014-01-13 14:47:00 +0000 | [diff] [blame] | 1105 | SkMatrix localM; |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1106 | if (NULL != srcRectPtr) { |
| commit-bot@chromium.org | a7d89c8 | 2014-01-13 14:47:00 +0000 | [diff] [blame] | 1107 | localM.setTranslate(-srcRectPtr->fLeft, -srcRectPtr->fTop); |
| 1108 | localM.postScale(dstSize.fWidth / srcRectPtr->width(), |
| 1109 | dstSize.fHeight / srcRectPtr->height()); |
| commit-bot@chromium.org | d6ca4ac | 2013-11-22 20:34:59 +0000 | [diff] [blame] | 1110 | // In bleed mode we position and trim the bitmap based on the src rect which is |
| 1111 | // already accounted for in 'm' and 'srcRect'. In clamp mode we need to chop out |
| 1112 | // the desired portion of the bitmap and then update 'm' and 'srcRect' to |
| 1113 | // compensate. |
| 1114 | if (!(SkCanvas::kBleed_DrawBitmapRectFlag & flags)) { |
| 1115 | SkIRect iSrc; |
| 1116 | srcRect.roundOut(&iSrc); |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1117 | |
| commit-bot@chromium.org | d6ca4ac | 2013-11-22 20:34:59 +0000 | [diff] [blame] | 1118 | SkPoint offset = SkPoint::Make(SkIntToScalar(iSrc.fLeft), |
| 1119 | SkIntToScalar(iSrc.fTop)); |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1120 | |
| commit-bot@chromium.org | d6ca4ac | 2013-11-22 20:34:59 +0000 | [diff] [blame] | 1121 | if (!bitmap.extractSubset(&tmp, iSrc)) { |
| 1122 | return; // extraction failed |
| 1123 | } |
| 1124 | bitmapPtr = &tmp; |
| 1125 | srcRect.offset(-offset.fX, -offset.fY); |
| commit-bot@chromium.org | a7d89c8 | 2014-01-13 14:47:00 +0000 | [diff] [blame] | 1126 | |
| commit-bot@chromium.org | d6ca4ac | 2013-11-22 20:34:59 +0000 | [diff] [blame] | 1127 | // The source rect has changed so update the matrix |
| commit-bot@chromium.org | a7d89c8 | 2014-01-13 14:47:00 +0000 | [diff] [blame] | 1128 | localM.preTranslate(offset.fX, offset.fY); |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1129 | } |
| commit-bot@chromium.org | a7d89c8 | 2014-01-13 14:47:00 +0000 | [diff] [blame] | 1130 | } else { |
| 1131 | localM.reset(); |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1132 | } |
| 1133 | |
| commit-bot@chromium.org | a7d89c8 | 2014-01-13 14:47:00 +0000 | [diff] [blame] | 1134 | SkPaint paintWithShader(paint); |
| 1135 | paintWithShader.setShader(SkShader::CreateBitmapShader(*bitmapPtr, |
| commit-bot@chromium.org | 9c9005a | 2014-04-28 14:55:39 +0000 | [diff] [blame] | 1136 | SkShader::kClamp_TileMode, SkShader::kClamp_TileMode, &localM))->unref(); |
| commit-bot@chromium.org | a7d89c8 | 2014-01-13 14:47:00 +0000 | [diff] [blame] | 1137 | SkRect dstRect = {0, 0, dstSize.fWidth, dstSize.fHeight}; |
| 1138 | this->drawRect(draw, dstRect, paintWithShader); |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1139 | |
| 1140 | return; |
| 1141 | } |
| 1142 | |
| commit-bot@chromium.org | a7d89c8 | 2014-01-13 14:47:00 +0000 | [diff] [blame] | 1143 | // If there is no mask filter than it is OK to handle the src rect -> dst rect scaling using |
| 1144 | // the view matrix rather than a local matrix. |
| 1145 | SkMatrix m; |
| 1146 | m.setScale(dstSize.fWidth / srcRect.width(), |
| 1147 | dstSize.fHeight / srcRect.height()); |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1148 | fContext->concatMatrix(m); |
| 1149 | |
| 1150 | GrTextureParams params; |
| 1151 | SkPaint::FilterLevel paintFilterLevel = paint.getFilterLevel(); |
| 1152 | GrTextureParams::FilterMode textureFilterMode; |
| commit-bot@chromium.org | dec6150 | 2013-12-02 22:22:35 +0000 | [diff] [blame] | 1153 | |
| commit-bot@chromium.org | dec6150 | 2013-12-02 22:22:35 +0000 | [diff] [blame] | 1154 | bool doBicubic = false; |
| 1155 | |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1156 | switch(paintFilterLevel) { |
| 1157 | case SkPaint::kNone_FilterLevel: |
| 1158 | textureFilterMode = GrTextureParams::kNone_FilterMode; |
| 1159 | break; |
| 1160 | case SkPaint::kLow_FilterLevel: |
| 1161 | textureFilterMode = GrTextureParams::kBilerp_FilterMode; |
| 1162 | break; |
| 1163 | case SkPaint::kMedium_FilterLevel: |
| commit-bot@chromium.org | 1878651 | 2014-05-20 14:53:45 +0000 | [diff] [blame] | 1164 | if (fContext->getMatrix().getMinScale() < SK_Scalar1) { |
| commit-bot@chromium.org | 79b7eee | 2013-12-16 21:02:29 +0000 | [diff] [blame] | 1165 | textureFilterMode = GrTextureParams::kMipMap_FilterMode; |
| 1166 | } else { |
| 1167 | // Don't trigger MIP level generation unnecessarily. |
| 1168 | textureFilterMode = GrTextureParams::kBilerp_FilterMode; |
| 1169 | } |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1170 | break; |
| commit-bot@chromium.org | 79b7eee | 2013-12-16 21:02:29 +0000 | [diff] [blame] | 1171 | case SkPaint::kHigh_FilterLevel: |
| commit-bot@chromium.org | cea9abb | 2013-12-09 19:15:37 +0000 | [diff] [blame] | 1172 | // Minification can look bad with the bicubic effect. |
| commit-bot@chromium.org | 9927bd3 | 2014-05-20 17:51:13 +0000 | [diff] [blame] | 1173 | doBicubic = |
| 1174 | GrBicubicEffect::ShouldUseBicubic(fContext->getMatrix(), &textureFilterMode); |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1175 | break; |
| 1176 | default: |
| 1177 | SkErrorInternals::SetError( kInvalidPaint_SkError, |
| 1178 | "Sorry, I don't understand the filtering " |
| 1179 | "mode you asked for. Falling back to " |
| 1180 | "MIPMaps."); |
| 1181 | textureFilterMode = GrTextureParams::kMipMap_FilterMode; |
| 1182 | break; |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1183 | } |
| 1184 | |
| commit-bot@chromium.org | 9927bd3 | 2014-05-20 17:51:13 +0000 | [diff] [blame] | 1185 | int tileFilterPad; |
| 1186 | if (doBicubic) { |
| 1187 | tileFilterPad = GrBicubicEffect::kFilterTexelPad; |
| 1188 | } else if (GrTextureParams::kNone_FilterMode == textureFilterMode) { |
| 1189 | tileFilterPad = 0; |
| 1190 | } else { |
| 1191 | tileFilterPad = 1; |
| 1192 | } |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1193 | params.setFilterMode(textureFilterMode); |
| 1194 | |
| commit-bot@chromium.org | dec6150 | 2013-12-02 22:22:35 +0000 | [diff] [blame] | 1195 | int maxTileSize = fContext->getMaxTextureSize() - 2 * tileFilterPad; |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1196 | int tileSize; |
| 1197 | |
| 1198 | SkIRect clippedSrcRect; |
| 1199 | if (this->shouldTileBitmap(bitmap, params, srcRectPtr, maxTileSize, &tileSize, |
| 1200 | &clippedSrcRect)) { |
| commit-bot@chromium.org | dec6150 | 2013-12-02 22:22:35 +0000 | [diff] [blame] | 1201 | this->drawTiledBitmap(bitmap, srcRect, clippedSrcRect, params, paint, flags, tileSize, |
| 1202 | doBicubic); |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1203 | } else { |
| 1204 | // take the simple case |
| commit-bot@chromium.org | a17773f | 2014-05-09 13:53:38 +0000 | [diff] [blame] | 1205 | bool needsTextureDomain = needs_texture_domain(bitmap, |
| 1206 | srcRect, |
| 1207 | params, |
| 1208 | fContext->getMatrix(), |
| 1209 | doBicubic); |
| 1210 | this->internalDrawBitmap(bitmap, |
| 1211 | srcRect, |
| 1212 | params, |
| 1213 | paint, |
| 1214 | flags, |
| 1215 | doBicubic, |
| 1216 | needsTextureDomain); |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1217 | } |
| 1218 | } |
| 1219 | |
| 1220 | // Break 'bitmap' into several tiles to draw it since it has already |
| 1221 | // been determined to be too large to fit in VRAM |
| 1222 | void SkGpuDevice::drawTiledBitmap(const SkBitmap& bitmap, |
| 1223 | const SkRect& srcRect, |
| 1224 | const SkIRect& clippedSrcIRect, |
| 1225 | const GrTextureParams& params, |
| 1226 | const SkPaint& paint, |
| 1227 | SkCanvas::DrawBitmapRectFlags flags, |
| commit-bot@chromium.org | dec6150 | 2013-12-02 22:22:35 +0000 | [diff] [blame] | 1228 | int tileSize, |
| 1229 | bool bicubic) { |
| commit-bot@chromium.org | 9d5e3f1 | 2014-05-01 21:23:19 +0000 | [diff] [blame] | 1230 | // The following pixel lock is technically redundant, but it is desirable |
| 1231 | // to lock outside of the tile loop to prevent redecoding the whole image |
| 1232 | // at each tile in cases where 'bitmap' holds an SkDiscardablePixelRef that |
| 1233 | // is larger than the limit of the discardable memory pool. |
| 1234 | SkAutoLockPixels alp(bitmap); |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1235 | SkRect clippedSrcRect = SkRect::Make(clippedSrcIRect); |
| 1236 | |
| 1237 | int nx = bitmap.width() / tileSize; |
| 1238 | int ny = bitmap.height() / tileSize; |
| 1239 | for (int x = 0; x <= nx; x++) { |
| 1240 | for (int y = 0; y <= ny; y++) { |
| 1241 | SkRect tileR; |
| 1242 | tileR.set(SkIntToScalar(x * tileSize), |
| 1243 | SkIntToScalar(y * tileSize), |
| 1244 | SkIntToScalar((x + 1) * tileSize), |
| 1245 | SkIntToScalar((y + 1) * tileSize)); |
| 1246 | |
| 1247 | if (!SkRect::Intersects(tileR, clippedSrcRect)) { |
| 1248 | continue; |
| 1249 | } |
| 1250 | |
| 1251 | if (!tileR.intersect(srcRect)) { |
| 1252 | continue; |
| 1253 | } |
| 1254 | |
| 1255 | SkBitmap tmpB; |
| 1256 | SkIRect iTileR; |
| 1257 | tileR.roundOut(&iTileR); |
| 1258 | SkPoint offset = SkPoint::Make(SkIntToScalar(iTileR.fLeft), |
| 1259 | SkIntToScalar(iTileR.fTop)); |
| 1260 | |
| commit-bot@chromium.org | a7d89c8 | 2014-01-13 14:47:00 +0000 | [diff] [blame] | 1261 | // Adjust the context matrix to draw at the right x,y in device space |
| 1262 | SkMatrix tmpM; |
| 1263 | GrContext::AutoMatrix am; |
| 1264 | tmpM.setTranslate(offset.fX - srcRect.fLeft, offset.fY - srcRect.fTop); |
| 1265 | am.setPreConcat(fContext, tmpM); |
| 1266 | |
| commit-bot@chromium.org | dec6150 | 2013-12-02 22:22:35 +0000 | [diff] [blame] | 1267 | if (SkPaint::kNone_FilterLevel != paint.getFilterLevel() || bicubic) { |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1268 | SkIRect iClampRect; |
| 1269 | |
| 1270 | if (SkCanvas::kBleed_DrawBitmapRectFlag & flags) { |
| 1271 | // In bleed mode we want to always expand the tile on all edges |
| 1272 | // but stay within the bitmap bounds |
| 1273 | iClampRect = SkIRect::MakeWH(bitmap.width(), bitmap.height()); |
| 1274 | } else { |
| 1275 | // In texture-domain/clamp mode we only want to expand the |
| 1276 | // tile on edges interior to "srcRect" (i.e., we want to |
| 1277 | // not bleed across the original clamped edges) |
| 1278 | srcRect.roundOut(&iClampRect); |
| 1279 | } |
| commit-bot@chromium.org | dec6150 | 2013-12-02 22:22:35 +0000 | [diff] [blame] | 1280 | int outset = bicubic ? GrBicubicEffect::kFilterTexelPad : 1; |
| 1281 | clamped_outset_with_offset(&iTileR, outset, &offset, iClampRect); |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1282 | } |
| 1283 | |
| 1284 | if (bitmap.extractSubset(&tmpB, iTileR)) { |
| 1285 | // now offset it to make it "local" to our tmp bitmap |
| 1286 | tileR.offset(-offset.fX, -offset.fY); |
| commit-bot@chromium.org | a17773f | 2014-05-09 13:53:38 +0000 | [diff] [blame] | 1287 | GrTextureParams paramsTemp = params; |
| 1288 | bool needsTextureDomain = needs_texture_domain(bitmap, |
| 1289 | srcRect, |
| 1290 | paramsTemp, |
| 1291 | fContext->getMatrix(), |
| 1292 | bicubic); |
| 1293 | this->internalDrawBitmap(tmpB, |
| 1294 | tileR, |
| 1295 | paramsTemp, |
| 1296 | paint, |
| 1297 | flags, |
| 1298 | bicubic, |
| 1299 | needsTextureDomain); |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1300 | } |
| 1301 | } |
| 1302 | } |
| 1303 | } |
| 1304 | |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1305 | |
| 1306 | /* |
| 1307 | * This is called by drawBitmap(), which has to handle images that may be too |
| 1308 | * large to be represented by a single texture. |
| 1309 | * |
| 1310 | * internalDrawBitmap assumes that the specified bitmap will fit in a texture |
| 1311 | * and that non-texture portion of the GrPaint has already been setup. |
| 1312 | */ |
| 1313 | void SkGpuDevice::internalDrawBitmap(const SkBitmap& bitmap, |
| 1314 | const SkRect& srcRect, |
| 1315 | const GrTextureParams& params, |
| 1316 | const SkPaint& paint, |
| commit-bot@chromium.org | dec6150 | 2013-12-02 22:22:35 +0000 | [diff] [blame] | 1317 | SkCanvas::DrawBitmapRectFlags flags, |
| commit-bot@chromium.org | a17773f | 2014-05-09 13:53:38 +0000 | [diff] [blame] | 1318 | bool bicubic, |
| 1319 | bool needsTextureDomain) { |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1320 | SkASSERT(bitmap.width() <= fContext->getMaxTextureSize() && |
| 1321 | bitmap.height() <= fContext->getMaxTextureSize()); |
| 1322 | |
| 1323 | GrTexture* texture; |
| 1324 | SkAutoCachedTexture act(this, bitmap, ¶ms, &texture); |
| 1325 | if (NULL == texture) { |
| 1326 | return; |
| 1327 | } |
| 1328 | |
| commit-bot@chromium.org | a7d89c8 | 2014-01-13 14:47:00 +0000 | [diff] [blame] | 1329 | SkRect dstRect = {0, 0, srcRect.width(), srcRect.height() }; |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1330 | SkRect paintRect; |
| 1331 | SkScalar wInv = SkScalarInvert(SkIntToScalar(texture->width())); |
| 1332 | SkScalar hInv = SkScalarInvert(SkIntToScalar(texture->height())); |
| 1333 | paintRect.setLTRB(SkScalarMul(srcRect.fLeft, wInv), |
| 1334 | SkScalarMul(srcRect.fTop, hInv), |
| 1335 | SkScalarMul(srcRect.fRight, wInv), |
| 1336 | SkScalarMul(srcRect.fBottom, hInv)); |
| 1337 | |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1338 | SkRect textureDomain = SkRect::MakeEmpty(); |
| 1339 | SkAutoTUnref<GrEffectRef> effect; |
| commit-bot@chromium.org | a17773f | 2014-05-09 13:53:38 +0000 | [diff] [blame] | 1340 | if (needsTextureDomain && !(flags & SkCanvas::kBleed_DrawBitmapRectFlag)) { |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1341 | // Use a constrained texture domain to avoid color bleeding |
| 1342 | SkScalar left, top, right, bottom; |
| 1343 | if (srcRect.width() > SK_Scalar1) { |
| 1344 | SkScalar border = SK_ScalarHalf / texture->width(); |
| 1345 | left = paintRect.left() + border; |
| 1346 | right = paintRect.right() - border; |
| 1347 | } else { |
| 1348 | left = right = SkScalarHalf(paintRect.left() + paintRect.right()); |
| 1349 | } |
| 1350 | if (srcRect.height() > SK_Scalar1) { |
| 1351 | SkScalar border = SK_ScalarHalf / texture->height(); |
| 1352 | top = paintRect.top() + border; |
| 1353 | bottom = paintRect.bottom() - border; |
| 1354 | } else { |
| 1355 | top = bottom = SkScalarHalf(paintRect.top() + paintRect.bottom()); |
| 1356 | } |
| 1357 | textureDomain.setLTRB(left, top, right, bottom); |
| commit-bot@chromium.org | 7d7f314 | 2013-12-16 15:18:11 +0000 | [diff] [blame] | 1358 | if (bicubic) { |
| 1359 | effect.reset(GrBicubicEffect::Create(texture, SkMatrix::I(), textureDomain)); |
| 1360 | } else { |
| 1361 | effect.reset(GrTextureDomainEffect::Create(texture, |
| 1362 | SkMatrix::I(), |
| 1363 | textureDomain, |
| 1364 | GrTextureDomain::kClamp_Mode, |
| 1365 | params.filterMode())); |
| 1366 | } |
| commit-bot@chromium.org | dec6150 | 2013-12-02 22:22:35 +0000 | [diff] [blame] | 1367 | } else if (bicubic) { |
| commit-bot@chromium.org | bc91fd7 | 2013-12-10 12:53:39 +0000 | [diff] [blame] | 1368 | SkASSERT(GrTextureParams::kNone_FilterMode == params.filterMode()); |
| 1369 | SkShader::TileMode tileModes[2] = { params.getTileModeX(), params.getTileModeY() }; |
| 1370 | effect.reset(GrBicubicEffect::Create(texture, SkMatrix::I(), tileModes)); |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1371 | } else { |
| 1372 | effect.reset(GrSimpleTextureEffect::Create(texture, SkMatrix::I(), params)); |
| 1373 | } |
| 1374 | |
| 1375 | // Construct a GrPaint by setting the bitmap texture as the first effect and then configuring |
| 1376 | // the rest from the SkPaint. |
| 1377 | GrPaint grPaint; |
| 1378 | grPaint.addColorEffect(effect); |
| reed | 0689d7b | 2014-06-14 05:30:20 -0700 | [diff] [blame^] | 1379 | bool alphaOnly = !(kAlpha_8_SkColorType == bitmap.colorType()); |
| dandov | 9de5b51 | 2014-06-10 14:38:28 -0700 | [diff] [blame] | 1380 | GrColor grColor = (alphaOnly) ? SkColor2GrColorJustAlpha(paint.getColor()) : |
| 1381 | SkColor2GrColor(paint.getColor()); |
| 1382 | SkPaint2GrPaintNoShader(this->context(), paint, grColor, false, &grPaint); |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1383 | |
| 1384 | fContext->drawRectToRect(grPaint, dstRect, paintRect, NULL); |
| 1385 | } |
| 1386 | |
| 1387 | static bool filter_texture(SkBaseDevice* device, GrContext* context, |
| commit-bot@chromium.org | ae761f7 | 2014-02-05 22:32:02 +0000 | [diff] [blame] | 1388 | GrTexture* texture, const SkImageFilter* filter, |
| senorblanco@chromium.org | 4cb543d | 2014-03-14 15:44:01 +0000 | [diff] [blame] | 1389 | int w, int h, const SkImageFilter::Context& ctx, |
| 1390 | SkBitmap* result, SkIPoint* offset) { |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1391 | SkASSERT(filter); |
| 1392 | SkDeviceImageFilterProxy proxy(device); |
| 1393 | |
| 1394 | if (filter->canFilterImageGPU()) { |
| 1395 | // Save the render target and set it to NULL, so we don't accidentally draw to it in the |
| 1396 | // filter. Also set the clip wide open and the matrix to identity. |
| 1397 | GrContext::AutoWideOpenIdentityDraw awo(context, NULL); |
| senorblanco@chromium.org | 4cb543d | 2014-03-14 15:44:01 +0000 | [diff] [blame] | 1398 | return filter->filterImageGPU(&proxy, wrap_texture(texture), ctx, result, offset); |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1399 | } else { |
| 1400 | return false; |
| 1401 | } |
| 1402 | } |
| 1403 | |
| 1404 | void SkGpuDevice::drawSprite(const SkDraw& draw, const SkBitmap& bitmap, |
| 1405 | int left, int top, const SkPaint& paint) { |
| 1406 | // drawSprite is defined to be in device coords. |
| 1407 | CHECK_SHOULD_DRAW(draw, true); |
| 1408 | |
| 1409 | SkAutoLockPixels alp(bitmap, !bitmap.getTexture()); |
| 1410 | if (!bitmap.getTexture() && !bitmap.readyToDraw()) { |
| 1411 | return; |
| 1412 | } |
| 1413 | |
| 1414 | int w = bitmap.width(); |
| 1415 | int h = bitmap.height(); |
| 1416 | |
| 1417 | GrTexture* texture; |
| 1418 | // draw sprite uses the default texture params |
| 1419 | SkAutoCachedTexture act(this, bitmap, NULL, &texture); |
| 1420 | |
| 1421 | SkImageFilter* filter = paint.getImageFilter(); |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1422 | // This bitmap will own the filtered result as a texture. |
| 1423 | SkBitmap filteredBitmap; |
| 1424 | |
| 1425 | if (NULL != filter) { |
| senorblanco@chromium.org | 6776b82 | 2014-01-03 21:48:22 +0000 | [diff] [blame] | 1426 | SkIPoint offset = SkIPoint::Make(0, 0); |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1427 | SkMatrix matrix(*draw.fMatrix); |
| 1428 | matrix.postTranslate(SkIntToScalar(-left), SkIntToScalar(-top)); |
| senorblanco@chromium.org | 4cb543d | 2014-03-14 15:44:01 +0000 | [diff] [blame] | 1429 | SkIRect clipBounds = SkIRect::MakeWH(bitmap.width(), bitmap.height()); |
| commit-bot@chromium.org | f7efa50 | 2014-04-11 18:57:00 +0000 | [diff] [blame] | 1430 | SkImageFilter::Cache* cache = SkImageFilter::Cache::Create(); |
| 1431 | SkAutoUnref aur(cache); |
| 1432 | SkImageFilter::Context ctx(matrix, clipBounds, cache); |
| senorblanco@chromium.org | 4cb543d | 2014-03-14 15:44:01 +0000 | [diff] [blame] | 1433 | if (filter_texture(this, fContext, texture, filter, w, h, ctx, &filteredBitmap, |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1434 | &offset)) { |
| 1435 | texture = (GrTexture*) filteredBitmap.getTexture(); |
| 1436 | w = filteredBitmap.width(); |
| 1437 | h = filteredBitmap.height(); |
| senorblanco@chromium.org | 6776b82 | 2014-01-03 21:48:22 +0000 | [diff] [blame] | 1438 | left += offset.x(); |
| 1439 | top += offset.y(); |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1440 | } else { |
| 1441 | return; |
| 1442 | } |
| 1443 | } |
| 1444 | |
| 1445 | GrPaint grPaint; |
| 1446 | grPaint.addColorTextureEffect(texture, SkMatrix::I()); |
| 1447 | |
| dandov | 9de5b51 | 2014-06-10 14:38:28 -0700 | [diff] [blame] | 1448 | SkPaint2GrPaintNoShader(this->context(), paint, SkColor2GrColorJustAlpha(paint.getColor()), |
| 1449 | false, &grPaint); |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1450 | |
| 1451 | fContext->drawRectToRect(grPaint, |
| senorblanco@chromium.org | 6776b82 | 2014-01-03 21:48:22 +0000 | [diff] [blame] | 1452 | SkRect::MakeXYWH(SkIntToScalar(left), |
| 1453 | SkIntToScalar(top), |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1454 | SkIntToScalar(w), |
| 1455 | SkIntToScalar(h)), |
| 1456 | SkRect::MakeXYWH(0, |
| 1457 | 0, |
| 1458 | SK_Scalar1 * w / texture->width(), |
| 1459 | SK_Scalar1 * h / texture->height())); |
| 1460 | } |
| 1461 | |
| commit-bot@chromium.org | a7d89c8 | 2014-01-13 14:47:00 +0000 | [diff] [blame] | 1462 | void SkGpuDevice::drawBitmapRect(const SkDraw& origDraw, const SkBitmap& bitmap, |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1463 | const SkRect* src, const SkRect& dst, |
| 1464 | const SkPaint& paint, |
| 1465 | SkCanvas::DrawBitmapRectFlags flags) { |
| 1466 | SkMatrix matrix; |
| 1467 | SkRect bitmapBounds, tmpSrc; |
| 1468 | |
| 1469 | bitmapBounds.set(0, 0, |
| 1470 | SkIntToScalar(bitmap.width()), |
| 1471 | SkIntToScalar(bitmap.height())); |
| 1472 | |
| 1473 | // Compute matrix from the two rectangles |
| 1474 | if (NULL != src) { |
| 1475 | tmpSrc = *src; |
| 1476 | } else { |
| 1477 | tmpSrc = bitmapBounds; |
| 1478 | } |
| commit-bot@chromium.org | a7d89c8 | 2014-01-13 14:47:00 +0000 | [diff] [blame] | 1479 | |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1480 | matrix.setRectToRect(tmpSrc, dst, SkMatrix::kFill_ScaleToFit); |
| 1481 | |
| 1482 | // clip the tmpSrc to the bounds of the bitmap. No check needed if src==null. |
| 1483 | if (NULL != src) { |
| 1484 | if (!bitmapBounds.contains(tmpSrc)) { |
| 1485 | if (!tmpSrc.intersect(bitmapBounds)) { |
| 1486 | return; // nothing to draw |
| 1487 | } |
| 1488 | } |
| 1489 | } |
| 1490 | |
| commit-bot@chromium.org | a7d89c8 | 2014-01-13 14:47:00 +0000 | [diff] [blame] | 1491 | SkRect tmpDst; |
| 1492 | matrix.mapRect(&tmpDst, tmpSrc); |
| 1493 | |
| 1494 | SkTCopyOnFirstWrite<SkDraw> draw(origDraw); |
| 1495 | if (0 != tmpDst.fLeft || 0 != tmpDst.fTop) { |
| 1496 | // Translate so that tempDst's top left is at the origin. |
| 1497 | matrix = *origDraw.fMatrix; |
| 1498 | matrix.preTranslate(tmpDst.fLeft, tmpDst.fTop); |
| 1499 | draw.writable()->fMatrix = &matrix; |
| 1500 | } |
| 1501 | SkSize dstSize; |
| 1502 | dstSize.fWidth = tmpDst.width(); |
| 1503 | dstSize.fHeight = tmpDst.height(); |
| 1504 | |
| 1505 | this->drawBitmapCommon(*draw, bitmap, &tmpSrc, &dstSize, paint, flags); |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1506 | } |
| 1507 | |
| 1508 | void SkGpuDevice::drawDevice(const SkDraw& draw, SkBaseDevice* device, |
| 1509 | int x, int y, const SkPaint& paint) { |
| 1510 | // clear of the source device must occur before CHECK_SHOULD_DRAW |
| 1511 | SkGpuDevice* dev = static_cast<SkGpuDevice*>(device); |
| 1512 | if (dev->fNeedClear) { |
| 1513 | // TODO: could check here whether we really need to draw at all |
| 1514 | dev->clear(0x0); |
| 1515 | } |
| 1516 | |
| 1517 | // drawDevice is defined to be in device coords. |
| 1518 | CHECK_SHOULD_DRAW(draw, true); |
| 1519 | |
| 1520 | GrRenderTarget* devRT = dev->accessRenderTarget(); |
| 1521 | GrTexture* devTex; |
| 1522 | if (NULL == (devTex = devRT->asTexture())) { |
| 1523 | return; |
| 1524 | } |
| 1525 | |
| 1526 | const SkBitmap& bm = dev->accessBitmap(false); |
| 1527 | int w = bm.width(); |
| 1528 | int h = bm.height(); |
| 1529 | |
| 1530 | SkImageFilter* filter = paint.getImageFilter(); |
| 1531 | // This bitmap will own the filtered result as a texture. |
| 1532 | SkBitmap filteredBitmap; |
| 1533 | |
| 1534 | if (NULL != filter) { |
| 1535 | SkIPoint offset = SkIPoint::Make(0, 0); |
| 1536 | SkMatrix matrix(*draw.fMatrix); |
| 1537 | matrix.postTranslate(SkIntToScalar(-x), SkIntToScalar(-y)); |
| senorblanco@chromium.org | 4cb543d | 2014-03-14 15:44:01 +0000 | [diff] [blame] | 1538 | SkIRect clipBounds = SkIRect::MakeWH(devTex->width(), devTex->height()); |
| commit-bot@chromium.org | f7efa50 | 2014-04-11 18:57:00 +0000 | [diff] [blame] | 1539 | SkImageFilter::Cache* cache = SkImageFilter::Cache::Create(); |
| 1540 | SkAutoUnref aur(cache); |
| 1541 | SkImageFilter::Context ctx(matrix, clipBounds, cache); |
| senorblanco@chromium.org | 4cb543d | 2014-03-14 15:44:01 +0000 | [diff] [blame] | 1542 | if (filter_texture(this, fContext, devTex, filter, w, h, ctx, &filteredBitmap, |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1543 | &offset)) { |
| 1544 | devTex = filteredBitmap.getTexture(); |
| 1545 | w = filteredBitmap.width(); |
| 1546 | h = filteredBitmap.height(); |
| 1547 | x += offset.fX; |
| 1548 | y += offset.fY; |
| 1549 | } else { |
| 1550 | return; |
| 1551 | } |
| 1552 | } |
| 1553 | |
| 1554 | GrPaint grPaint; |
| 1555 | grPaint.addColorTextureEffect(devTex, SkMatrix::I()); |
| 1556 | |
| dandov | 9de5b51 | 2014-06-10 14:38:28 -0700 | [diff] [blame] | 1557 | SkPaint2GrPaintNoShader(this->context(), paint, SkColor2GrColorJustAlpha(paint.getColor()), |
| 1558 | false, &grPaint); |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1559 | |
| 1560 | SkRect dstRect = SkRect::MakeXYWH(SkIntToScalar(x), |
| 1561 | SkIntToScalar(y), |
| 1562 | SkIntToScalar(w), |
| 1563 | SkIntToScalar(h)); |
| 1564 | |
| 1565 | // The device being drawn may not fill up its texture (e.g. saveLayer uses approximate |
| 1566 | // scratch texture). |
| 1567 | SkRect srcRect = SkRect::MakeWH(SK_Scalar1 * w / devTex->width(), |
| 1568 | SK_Scalar1 * h / devTex->height()); |
| 1569 | |
| 1570 | fContext->drawRectToRect(grPaint, dstRect, srcRect); |
| 1571 | } |
| 1572 | |
| commit-bot@chromium.org | ae761f7 | 2014-02-05 22:32:02 +0000 | [diff] [blame] | 1573 | bool SkGpuDevice::canHandleImageFilter(const SkImageFilter* filter) { |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1574 | return filter->canFilterImageGPU(); |
| 1575 | } |
| 1576 | |
| commit-bot@chromium.org | ae761f7 | 2014-02-05 22:32:02 +0000 | [diff] [blame] | 1577 | bool SkGpuDevice::filterImage(const SkImageFilter* filter, const SkBitmap& src, |
| senorblanco@chromium.org | 4cb543d | 2014-03-14 15:44:01 +0000 | [diff] [blame] | 1578 | const SkImageFilter::Context& ctx, |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1579 | SkBitmap* result, SkIPoint* offset) { |
| 1580 | // want explicitly our impl, so guard against a subclass of us overriding it |
| 1581 | if (!this->SkGpuDevice::canHandleImageFilter(filter)) { |
| 1582 | return false; |
| 1583 | } |
| 1584 | |
| 1585 | SkAutoLockPixels alp(src, !src.getTexture()); |
| 1586 | if (!src.getTexture() && !src.readyToDraw()) { |
| 1587 | return false; |
| 1588 | } |
| 1589 | |
| 1590 | GrTexture* texture; |
| 1591 | // We assume here that the filter will not attempt to tile the src. Otherwise, this cache lookup |
| 1592 | // must be pushed upstack. |
| 1593 | SkAutoCachedTexture act(this, src, NULL, &texture); |
| 1594 | |
| senorblanco@chromium.org | 4cb543d | 2014-03-14 15:44:01 +0000 | [diff] [blame] | 1595 | return filter_texture(this, fContext, texture, filter, src.width(), src.height(), ctx, |
| 1596 | result, offset); |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1597 | } |
| 1598 | |
| 1599 | /////////////////////////////////////////////////////////////////////////////// |
| 1600 | |
| 1601 | // must be in SkCanvas::VertexMode order |
| 1602 | static const GrPrimitiveType gVertexMode2PrimitiveType[] = { |
| 1603 | kTriangles_GrPrimitiveType, |
| 1604 | kTriangleStrip_GrPrimitiveType, |
| 1605 | kTriangleFan_GrPrimitiveType, |
| 1606 | }; |
| 1607 | |
| 1608 | void SkGpuDevice::drawVertices(const SkDraw& draw, SkCanvas::VertexMode vmode, |
| 1609 | int vertexCount, const SkPoint vertices[], |
| 1610 | const SkPoint texs[], const SkColor colors[], |
| 1611 | SkXfermode* xmode, |
| 1612 | const uint16_t indices[], int indexCount, |
| 1613 | const SkPaint& paint) { |
| 1614 | CHECK_SHOULD_DRAW(draw, false); |
| 1615 | |
| commit-bot@chromium.org | 559a883 | 2014-05-30 10:08:22 +0000 | [diff] [blame] | 1616 | // If both textures and vertex-colors are NULL, strokes hairlines with the paint's color. |
| 1617 | if ((NULL == texs || NULL == paint.getShader()) && NULL == colors) { |
| 1618 | texs = NULL; |
| 1619 | SkPaint copy(paint); |
| 1620 | copy.setStyle(SkPaint::kStroke_Style); |
| 1621 | copy.setStrokeWidth(0); |
| 1622 | |
| 1623 | VertState state(vertexCount, indices, indexCount); |
| 1624 | VertState::Proc vertProc = state.chooseProc(vmode); |
| 1625 | |
| 1626 | SkPoint* pts = new SkPoint[vertexCount * 6]; |
| 1627 | int i = 0; |
| 1628 | while (vertProc(&state)) { |
| 1629 | pts[i] = vertices[state.f0]; |
| 1630 | pts[i + 1] = vertices[state.f1]; |
| 1631 | pts[i + 2] = vertices[state.f1]; |
| 1632 | pts[i + 3] = vertices[state.f2]; |
| 1633 | pts[i + 4] = vertices[state.f2]; |
| 1634 | pts[i + 5] = vertices[state.f0]; |
| 1635 | i += 6; |
| 1636 | } |
| 1637 | draw.drawPoints(SkCanvas::kLines_PointMode, i, pts, copy, true); |
| 1638 | return; |
| 1639 | } |
| 1640 | |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1641 | GrPaint grPaint; |
| 1642 | // we ignore the shader if texs is null. |
| 1643 | if (NULL == texs) { |
| dandov | 9de5b51 | 2014-06-10 14:38:28 -0700 | [diff] [blame] | 1644 | SkPaint2GrPaintNoShader(this->context(), paint, SkColor2GrColor(paint.getColor()), |
| 1645 | NULL == colors, &grPaint); |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1646 | } else { |
| commit-bot@chromium.org | 3595f88 | 2014-05-19 19:35:57 +0000 | [diff] [blame] | 1647 | SkPaint2GrPaintShader(this->context(), paint, NULL == colors, &grPaint); |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1648 | } |
| 1649 | |
| mtklein | 2583b62 | 2014-06-04 08:20:41 -0700 | [diff] [blame] | 1650 | #if 0 |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1651 | if (NULL != xmode && NULL != texs && NULL != colors) { |
| 1652 | if (!SkXfermode::IsMode(xmode, SkXfermode::kModulate_Mode)) { |
| 1653 | SkDebugf("Unsupported vertex-color/texture xfer mode.\n"); |
| mtklein | 2583b62 | 2014-06-04 08:20:41 -0700 | [diff] [blame] | 1654 | return; |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1655 | } |
| 1656 | } |
| mtklein | 2583b62 | 2014-06-04 08:20:41 -0700 | [diff] [blame] | 1657 | #endif |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1658 | |
| 1659 | SkAutoSTMalloc<128, GrColor> convertedColors(0); |
| 1660 | if (NULL != colors) { |
| 1661 | // need to convert byte order and from non-PM to PM |
| 1662 | convertedColors.reset(vertexCount); |
| commit-bot@chromium.org | c93e681 | 2014-05-23 08:09:26 +0000 | [diff] [blame] | 1663 | SkColor color; |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1664 | for (int i = 0; i < vertexCount; ++i) { |
| commit-bot@chromium.org | c93e681 | 2014-05-23 08:09:26 +0000 | [diff] [blame] | 1665 | color = colors[i]; |
| 1666 | if (paint.getAlpha() != 255) { |
| 1667 | color = SkColorSetA(color, SkMulDiv255Round(SkColorGetA(color), paint.getAlpha())); |
| 1668 | } |
| 1669 | convertedColors[i] = SkColor2GrColor(color); |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1670 | } |
| 1671 | colors = convertedColors.get(); |
| 1672 | } |
| 1673 | fContext->drawVertices(grPaint, |
| 1674 | gVertexMode2PrimitiveType[vmode], |
| 1675 | vertexCount, |
| commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 1676 | vertices, |
| 1677 | texs, |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1678 | colors, |
| 1679 | indices, |
| 1680 | indexCount); |
| 1681 | } |
| 1682 | |
| 1683 | /////////////////////////////////////////////////////////////////////////////// |
| 1684 | |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1685 | void SkGpuDevice::drawText(const SkDraw& draw, const void* text, |
| 1686 | size_t byteLength, SkScalar x, SkScalar y, |
| 1687 | const SkPaint& paint) { |
| 1688 | CHECK_SHOULD_DRAW(draw, false); |
| 1689 | |
| commit-bot@chromium.org | cbbc481 | 2014-01-30 22:05:47 +0000 | [diff] [blame] | 1690 | if (fMainTextContext->canDraw(paint)) { |
| commit-bot@chromium.org | 8128d8c | 2013-12-19 16:12:25 +0000 | [diff] [blame] | 1691 | GrPaint grPaint; |
| commit-bot@chromium.org | 3595f88 | 2014-05-19 19:35:57 +0000 | [diff] [blame] | 1692 | SkPaint2GrPaintShader(this->context(), paint, true, &grPaint); |
| commit-bot@chromium.org | 8128d8c | 2013-12-19 16:12:25 +0000 | [diff] [blame] | 1693 | |
| 1694 | SkDEBUGCODE(this->validate();) |
| 1695 | |
| commit-bot@chromium.org | cbbc481 | 2014-01-30 22:05:47 +0000 | [diff] [blame] | 1696 | fMainTextContext->drawText(grPaint, paint, (const char *)text, byteLength, x, y); |
| 1697 | } else if (fFallbackTextContext && fFallbackTextContext->canDraw(paint)) { |
| commit-bot@chromium.org | 9f94b91 | 2014-01-30 15:22:54 +0000 | [diff] [blame] | 1698 | GrPaint grPaint; |
| commit-bot@chromium.org | 3595f88 | 2014-05-19 19:35:57 +0000 | [diff] [blame] | 1699 | SkPaint2GrPaintShader(this->context(), paint, true, &grPaint); |
| commit-bot@chromium.org | 9f94b91 | 2014-01-30 15:22:54 +0000 | [diff] [blame] | 1700 | |
| 1701 | SkDEBUGCODE(this->validate();) |
| 1702 | |
| commit-bot@chromium.org | cbbc481 | 2014-01-30 22:05:47 +0000 | [diff] [blame] | 1703 | fFallbackTextContext->drawText(grPaint, paint, (const char *)text, byteLength, x, y); |
| commit-bot@chromium.org | 9f94b91 | 2014-01-30 15:22:54 +0000 | [diff] [blame] | 1704 | } else { |
| 1705 | // this guy will just call our drawPath() |
| 1706 | draw.drawText_asPaths((const char*)text, byteLength, x, y, paint); |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1707 | } |
| 1708 | } |
| 1709 | |
| 1710 | void SkGpuDevice::drawPosText(const SkDraw& draw, const void* text, |
| 1711 | size_t byteLength, const SkScalar pos[], |
| 1712 | SkScalar constY, int scalarsPerPos, |
| 1713 | const SkPaint& paint) { |
| 1714 | CHECK_SHOULD_DRAW(draw, false); |
| 1715 | |
| commit-bot@chromium.org | cbbc481 | 2014-01-30 22:05:47 +0000 | [diff] [blame] | 1716 | if (fMainTextContext->canDraw(paint)) { |
| commit-bot@chromium.org | 8128d8c | 2013-12-19 16:12:25 +0000 | [diff] [blame] | 1717 | GrPaint grPaint; |
| commit-bot@chromium.org | 3595f88 | 2014-05-19 19:35:57 +0000 | [diff] [blame] | 1718 | SkPaint2GrPaintShader(this->context(), paint, true, &grPaint); |
| commit-bot@chromium.org | 8128d8c | 2013-12-19 16:12:25 +0000 | [diff] [blame] | 1719 | |
| 1720 | SkDEBUGCODE(this->validate();) |
| 1721 | |
| skia.committer@gmail.com | 4c18e9f | 2014-01-31 03:01:59 +0000 | [diff] [blame] | 1722 | fMainTextContext->drawPosText(grPaint, paint, (const char *)text, byteLength, pos, |
| commit-bot@chromium.org | cbbc481 | 2014-01-30 22:05:47 +0000 | [diff] [blame] | 1723 | constY, scalarsPerPos); |
| 1724 | } else if (fFallbackTextContext && fFallbackTextContext->canDraw(paint)) { |
| commit-bot@chromium.org | 9f94b91 | 2014-01-30 15:22:54 +0000 | [diff] [blame] | 1725 | GrPaint grPaint; |
| commit-bot@chromium.org | 3595f88 | 2014-05-19 19:35:57 +0000 | [diff] [blame] | 1726 | SkPaint2GrPaintShader(this->context(), paint, true, &grPaint); |
| skia.committer@gmail.com | 4c18e9f | 2014-01-31 03:01:59 +0000 | [diff] [blame] | 1727 | |
| commit-bot@chromium.org | 9f94b91 | 2014-01-30 15:22:54 +0000 | [diff] [blame] | 1728 | SkDEBUGCODE(this->validate();) |
| skia.committer@gmail.com | 4c18e9f | 2014-01-31 03:01:59 +0000 | [diff] [blame] | 1729 | |
| 1730 | fFallbackTextContext->drawPosText(grPaint, paint, (const char *)text, byteLength, pos, |
| commit-bot@chromium.org | cbbc481 | 2014-01-30 22:05:47 +0000 | [diff] [blame] | 1731 | constY, scalarsPerPos); |
| commit-bot@chromium.org | 9f94b91 | 2014-01-30 15:22:54 +0000 | [diff] [blame] | 1732 | } else { |
| 1733 | draw.drawPosText_asPaths((const char*)text, byteLength, pos, constY, |
| 1734 | scalarsPerPos, paint); |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1735 | } |
| 1736 | } |
| 1737 | |
| 1738 | void SkGpuDevice::drawTextOnPath(const SkDraw& draw, const void* text, |
| 1739 | size_t len, const SkPath& path, |
| 1740 | const SkMatrix* m, const SkPaint& paint) { |
| 1741 | CHECK_SHOULD_DRAW(draw, false); |
| 1742 | |
| 1743 | SkASSERT(draw.fDevice == this); |
| 1744 | draw.drawTextOnPath((const char*)text, len, path, m, paint); |
| 1745 | } |
| 1746 | |
| 1747 | /////////////////////////////////////////////////////////////////////////////// |
| 1748 | |
| 1749 | bool SkGpuDevice::filterTextFlags(const SkPaint& paint, TextFlags* flags) { |
| 1750 | if (!paint.isLCDRenderText()) { |
| 1751 | // we're cool with the paint as is |
| 1752 | return false; |
| 1753 | } |
| 1754 | |
| 1755 | if (paint.getShader() || |
| 1756 | paint.getXfermode() || // unless its srcover |
| 1757 | paint.getMaskFilter() || |
| 1758 | paint.getRasterizer() || |
| 1759 | paint.getColorFilter() || |
| 1760 | paint.getPathEffect() || |
| 1761 | paint.isFakeBoldText() || |
| 1762 | paint.getStyle() != SkPaint::kFill_Style) { |
| 1763 | // turn off lcd |
| 1764 | flags->fFlags = paint.getFlags() & ~SkPaint::kLCDRenderText_Flag; |
| 1765 | flags->fHinting = paint.getHinting(); |
| 1766 | return true; |
| 1767 | } |
| 1768 | // we're cool with the paint as is |
| 1769 | return false; |
| 1770 | } |
| 1771 | |
| 1772 | void SkGpuDevice::flush() { |
| 1773 | DO_DEFERRED_CLEAR(); |
| 1774 | fContext->resolveRenderTarget(fRenderTarget); |
| 1775 | } |
| 1776 | |
| 1777 | /////////////////////////////////////////////////////////////////////////////// |
| 1778 | |
| commit-bot@chromium.org | 15a1405 | 2014-02-16 00:59:25 +0000 | [diff] [blame] | 1779 | SkBaseDevice* SkGpuDevice::onCreateDevice(const SkImageInfo& info, Usage usage) { |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1780 | GrTextureDesc desc; |
| 1781 | desc.fConfig = fRenderTarget->config(); |
| 1782 | desc.fFlags = kRenderTarget_GrTextureFlagBit; |
| commit-bot@chromium.org | 15a1405 | 2014-02-16 00:59:25 +0000 | [diff] [blame] | 1783 | desc.fWidth = info.width(); |
| 1784 | desc.fHeight = info.height(); |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1785 | desc.fSampleCnt = fRenderTarget->numSamples(); |
| 1786 | |
| 1787 | SkAutoTUnref<GrTexture> texture; |
| 1788 | // Skia's convention is to only clear a device if it is non-opaque. |
| commit-bot@chromium.org | d8a57af | 2014-03-19 21:19:16 +0000 | [diff] [blame] | 1789 | unsigned flags = info.isOpaque() ? 0 : kNeedClear_Flag; |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1790 | |
| 1791 | #if CACHE_COMPATIBLE_DEVICE_TEXTURES |
| 1792 | // layers are never draw in repeat modes, so we can request an approx |
| 1793 | // match and ignore any padding. |
| commit-bot@chromium.org | d8a57af | 2014-03-19 21:19:16 +0000 | [diff] [blame] | 1794 | flags |= kCached_Flag; |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1795 | const GrContext::ScratchTexMatch match = (kSaveLayer_Usage == usage) ? |
| 1796 | GrContext::kApprox_ScratchTexMatch : |
| 1797 | GrContext::kExact_ScratchTexMatch; |
| 1798 | texture.reset(fContext->lockAndRefScratchTexture(desc, match)); |
| 1799 | #else |
| 1800 | texture.reset(fContext->createUncachedTexture(desc, NULL, 0)); |
| 1801 | #endif |
| 1802 | if (NULL != texture.get()) { |
| commit-bot@chromium.org | d8a57af | 2014-03-19 21:19:16 +0000 | [diff] [blame] | 1803 | return SkGpuDevice::Create(texture, flags); |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1804 | } else { |
| commit-bot@chromium.org | 15a1405 | 2014-02-16 00:59:25 +0000 | [diff] [blame] | 1805 | GrPrintf("---- failed to create compatible device texture [%d %d]\n", |
| 1806 | info.width(), info.height()); |
| skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1807 | return NULL; |
| 1808 | } |
| 1809 | } |
| 1810 | |
| reed@google.com | 76f10a3 | 2014-02-05 15:32:21 +0000 | [diff] [blame] | 1811 | SkSurface* SkGpuDevice::newSurface(const SkImageInfo& info) { |
| 1812 | return SkSurface::NewRenderTarget(fContext, info, fRenderTarget->numSamples()); |
| 1813 | } |
| 1814 | |
| robertphillips | 9b14f26 | 2014-06-04 05:40:44 -0700 | [diff] [blame] | 1815 | void SkGpuDevice::EXPERIMENTAL_optimize(const SkPicture* picture) { |
| commit-bot@chromium.org | 0205aba | 2014-05-06 12:02:22 +0000 | [diff] [blame] | 1816 | SkPicture::AccelData::Key key = GPUAccelData::ComputeAccelDataKey(); |
| commit-bot@chromium.org | 145d1c0 | 2014-03-16 19:46:36 +0000 | [diff] [blame] | 1817 | |
| commit-bot@chromium.org | 8ec8bab | 2014-05-14 13:11:48 +0000 | [diff] [blame] | 1818 | const SkPicture::AccelData* existing = picture->EXPERIMENTAL_getAccelData(key); |
| 1819 | if (NULL != existing) { |
| 1820 | return; |
| 1821 | } |
| 1822 | |
| commit-bot@chromium.org | 8fd9382 | 2014-05-06 13:43:22 +0000 | [diff] [blame] | 1823 | SkAutoTUnref<GPUAccelData> data(SkNEW_ARGS(GPUAccelData, (key))); |
| commit-bot@chromium.org | 145d1c0 | 2014-03-16 19:46:36 +0000 | [diff] [blame] | 1824 | |
| 1825 | picture->EXPERIMENTAL_addAccelData(data); |
| commit-bot@chromium.org | 8ddc26b | 2014-03-31 17:55:12 +0000 | [diff] [blame] | 1826 | |
| 1827 | GatherGPUInfo(picture, data); |
| commit-bot@chromium.org | 145d1c0 | 2014-03-16 19:46:36 +0000 | [diff] [blame] | 1828 | } |
| 1829 | |
| robertphillips@google.com | beb1af2 | 2014-05-07 21:31:09 +0000 | [diff] [blame] | 1830 | static void wrap_texture(GrTexture* texture, int width, int height, SkBitmap* result) { |
| 1831 | SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); |
| commit-bot@chromium.org | a3264e5 | 2014-05-30 13:26:10 +0000 | [diff] [blame] | 1832 | result->setInfo(info); |
| robertphillips@google.com | beb1af2 | 2014-05-07 21:31:09 +0000 | [diff] [blame] | 1833 | result->setPixelRef(SkNEW_ARGS(SkGrPixelRef, (info, texture)))->unref(); |
| 1834 | } |
| 1835 | |
| robertphillips | 9b14f26 | 2014-06-04 05:40:44 -0700 | [diff] [blame] | 1836 | void SkGpuDevice::EXPERIMENTAL_purge(const SkPicture* picture) { |
| commit-bot@chromium.org | c873329 | 2014-04-11 15:54:14 +0000 | [diff] [blame] | 1837 | |
| 1838 | } |
| 1839 | |
| robertphillips | 9b14f26 | 2014-06-04 05:40:44 -0700 | [diff] [blame] | 1840 | bool SkGpuDevice::EXPERIMENTAL_drawPicture(SkCanvas* canvas, const SkPicture* picture) { |
| commit-bot@chromium.org | 8ddc26b | 2014-03-31 17:55:12 +0000 | [diff] [blame] | 1841 | |
| commit-bot@chromium.org | 0205aba | 2014-05-06 12:02:22 +0000 | [diff] [blame] | 1842 | SkPicture::AccelData::Key key = GPUAccelData::ComputeAccelDataKey(); |
| commit-bot@chromium.org | 145d1c0 | 2014-03-16 19:46:36 +0000 | [diff] [blame] | 1843 | |
| commit-bot@chromium.org | 8ddc26b | 2014-03-31 17:55:12 +0000 | [diff] [blame] | 1844 | const SkPicture::AccelData* data = picture->EXPERIMENTAL_getAccelData(key); |
| commit-bot@chromium.org | 145d1c0 | 2014-03-16 19:46:36 +0000 | [diff] [blame] | 1845 | if (NULL == data) { |
| 1846 | return false; |
| 1847 | } |
| 1848 | |
| commit-bot@chromium.org | 145d1c0 | 2014-03-16 19:46:36 +0000 | [diff] [blame] | 1849 | const GPUAccelData *gpuData = static_cast<const GPUAccelData*>(data); |
| commit-bot@chromium.org | 8ddc26b | 2014-03-31 17:55:12 +0000 | [diff] [blame] | 1850 | |
| commit-bot@chromium.org | 8ec8bab | 2014-05-14 13:11:48 +0000 | [diff] [blame] | 1851 | if (0 == gpuData->numSaveLayers()) { |
| 1852 | return false; |
| 1853 | } |
| 1854 | |
| commit-bot@chromium.org | 8ddc26b | 2014-03-31 17:55:12 +0000 | [diff] [blame] | 1855 | SkAutoTArray<bool> pullForward(gpuData->numSaveLayers()); |
| 1856 | for (int i = 0; i < gpuData->numSaveLayers(); ++i) { |
| 1857 | pullForward[i] = false; |
| 1858 | } |
| 1859 | |
| robertphillips@google.com | beb1af2 | 2014-05-07 21:31:09 +0000 | [diff] [blame] | 1860 | SkRect clipBounds; |
| 1861 | if (!canvas->getClipBounds(&clipBounds)) { |
| 1862 | return true; |
| commit-bot@chromium.org | 8ddc26b | 2014-03-31 17:55:12 +0000 | [diff] [blame] | 1863 | } |
| robertphillips@google.com | beb1af2 | 2014-05-07 21:31:09 +0000 | [diff] [blame] | 1864 | SkIRect query; |
| 1865 | clipBounds.roundOut(&query); |
| commit-bot@chromium.org | 8ddc26b | 2014-03-31 17:55:12 +0000 | [diff] [blame] | 1866 | |
| robertphillips@google.com | beb1af2 | 2014-05-07 21:31:09 +0000 | [diff] [blame] | 1867 | const SkPicture::OperationList& ops = picture->EXPERIMENTAL_getActiveOps(query); |
| commit-bot@chromium.org | 8ddc26b | 2014-03-31 17:55:12 +0000 | [diff] [blame] | 1868 | |
| robertphillips@google.com | beb1af2 | 2014-05-07 21:31:09 +0000 | [diff] [blame] | 1869 | // This code pre-renders the entire layer since it will be cached and potentially |
| 1870 | // reused with different clips (e.g., in different tiles). Because of this the |
| 1871 | // clip will not be limiting the size of the pre-rendered layer. kSaveLayerMaxSize |
| 1872 | // is used to limit which clips are pre-rendered. |
| 1873 | static const int kSaveLayerMaxSize = 256; |
| commit-bot@chromium.org | 8ddc26b | 2014-03-31 17:55:12 +0000 | [diff] [blame] | 1874 | |
| robertphillips@google.com | beb1af2 | 2014-05-07 21:31:09 +0000 | [diff] [blame] | 1875 | if (ops.valid()) { |
| 1876 | // In this case the picture has been generated with a BBH so we use |
| skia.committer@gmail.com | b2c82c9 | 2014-05-08 03:05:29 +0000 | [diff] [blame] | 1877 | // the BBH to limit the pre-rendering to just the layers needed to cover |
| 1878 | // the region being drawn |
| robertphillips@google.com | beb1af2 | 2014-05-07 21:31:09 +0000 | [diff] [blame] | 1879 | for (int i = 0; i < ops.numOps(); ++i) { |
| 1880 | uint32_t offset = ops.offset(i); |
| 1881 | |
| 1882 | // For now we're saving all the layers in the GPUAccelData so they |
| skia.committer@gmail.com | b2c82c9 | 2014-05-08 03:05:29 +0000 | [diff] [blame] | 1883 | // can be nested. Additionally, the nested layers appear before |
| robertphillips@google.com | beb1af2 | 2014-05-07 21:31:09 +0000 | [diff] [blame] | 1884 | // their parent in the list. |
| 1885 | for (int j = 0 ; j < gpuData->numSaveLayers(); ++j) { |
| 1886 | const GPUAccelData::SaveLayerInfo& info = gpuData->saveLayerInfo(j); |
| 1887 | |
| 1888 | if (pullForward[j]) { |
| 1889 | continue; // already pulling forward |
| 1890 | } |
| 1891 | |
| 1892 | if (offset < info.fSaveLayerOpID || offset > info.fRestoreOpID) { |
| 1893 | continue; // the op isn't in this range |
| 1894 | } |
| 1895 | |
| 1896 | // TODO: once this code is more stable unsuitable layers can |
| 1897 | // just be omitted during the optimization stage |
| 1898 | if (!info.fValid || |
| 1899 | kSaveLayerMaxSize < info.fSize.fWidth || |
| 1900 | kSaveLayerMaxSize < info.fSize.fHeight || |
| 1901 | info.fIsNested) { |
| 1902 | continue; // this layer is unsuitable |
| 1903 | } |
| 1904 | |
| 1905 | pullForward[j] = true; |
| 1906 | } |
| 1907 | } |
| 1908 | } else { |
| 1909 | // In this case there is no BBH associated with the picture. Pre-render |
| commit-bot@chromium.org | f97d65d | 2014-05-08 23:24:05 +0000 | [diff] [blame] | 1910 | // all the layers that intersect the drawn region |
| commit-bot@chromium.org | 8ddc26b | 2014-03-31 17:55:12 +0000 | [diff] [blame] | 1911 | for (int j = 0; j < gpuData->numSaveLayers(); ++j) { |
| 1912 | const GPUAccelData::SaveLayerInfo& info = gpuData->saveLayerInfo(j); |
| 1913 | |
| commit-bot@chromium.org | f97d65d | 2014-05-08 23:24:05 +0000 | [diff] [blame] | 1914 | SkIRect layerRect = SkIRect::MakeXYWH(info.fOffset.fX, |
| 1915 | info.fOffset.fY, |
| 1916 | info.fSize.fWidth, |
| 1917 | info.fSize.fHeight); |
| 1918 | |
| 1919 | if (!SkIRect::Intersects(query, layerRect)) { |
| 1920 | continue; |
| 1921 | } |
| 1922 | |
| robertphillips@google.com | beb1af2 | 2014-05-07 21:31:09 +0000 | [diff] [blame] | 1923 | // TODO: once this code is more stable unsuitable layers can |
| 1924 | // just be omitted during the optimization stage |
| 1925 | if (!info.fValid || |
| 1926 | kSaveLayerMaxSize < info.fSize.fWidth || |
| 1927 | kSaveLayerMaxSize < info.fSize.fHeight || |
| 1928 | info.fIsNested) { |
| 1929 | continue; |
| 1930 | } |
| 1931 | |
| skia.committer@gmail.com | b2c82c9 | 2014-05-08 03:05:29 +0000 | [diff] [blame] | 1932 | pullForward[j] = true; |
| robertphillips@google.com | beb1af2 | 2014-05-07 21:31:09 +0000 | [diff] [blame] | 1933 | } |
| 1934 | } |
| 1935 | |
| 1936 | SkPicturePlayback::PlaybackReplacements replacements; |
| 1937 | |
| 1938 | for (int i = 0; i < gpuData->numSaveLayers(); ++i) { |
| 1939 | if (pullForward[i]) { |
| 1940 | GrCachedLayer* layer = fContext->getLayerCache()->findLayerOrCreate(picture, i); |
| 1941 | |
| 1942 | const GPUAccelData::SaveLayerInfo& info = gpuData->saveLayerInfo(i); |
| 1943 | |
| 1944 | if (NULL != picture->fPlayback) { |
| skia.committer@gmail.com | b2c82c9 | 2014-05-08 03:05:29 +0000 | [diff] [blame] | 1945 | SkPicturePlayback::PlaybackReplacements::ReplacementInfo* layerInfo = |
| robertphillips@google.com | beb1af2 | 2014-05-07 21:31:09 +0000 | [diff] [blame] | 1946 | replacements.push(); |
| 1947 | layerInfo->fStart = info.fSaveLayerOpID; |
| 1948 | layerInfo->fStop = info.fRestoreOpID; |
| 1949 | layerInfo->fPos = info.fOffset; |
| 1950 | |
| 1951 | GrTextureDesc desc; |
| 1952 | desc.fFlags = kRenderTarget_GrTextureFlagBit; |
| 1953 | desc.fWidth = info.fSize.fWidth; |
| 1954 | desc.fHeight = info.fSize.fHeight; |
| 1955 | desc.fConfig = kSkia8888_GrPixelConfig; |
| 1956 | // TODO: need to deal with sample count |
| 1957 | |
| 1958 | bool bNeedsRendering = true; |
| 1959 | |
| 1960 | // This just uses scratch textures and doesn't cache the texture. |
| 1961 | // This can yield a lot of re-rendering |
| 1962 | if (NULL == layer->getTexture()) { |
| skia.committer@gmail.com | b2c82c9 | 2014-05-08 03:05:29 +0000 | [diff] [blame] | 1963 | layer->setTexture(fContext->lockAndRefScratchTexture(desc, |
| robertphillips@google.com | beb1af2 | 2014-05-07 21:31:09 +0000 | [diff] [blame] | 1964 | GrContext::kApprox_ScratchTexMatch)); |
| 1965 | if (NULL == layer->getTexture()) { |
| 1966 | continue; |
| 1967 | } |
| 1968 | } else { |
| 1969 | bNeedsRendering = false; |
| 1970 | } |
| 1971 | |
| 1972 | layerInfo->fBM = SkNEW(SkBitmap); |
| 1973 | wrap_texture(layer->getTexture(), desc.fWidth, desc.fHeight, layerInfo->fBM); |
| 1974 | |
| 1975 | SkASSERT(info.fPaint); |
| 1976 | layerInfo->fPaint = info.fPaint; |
| 1977 | |
| 1978 | if (bNeedsRendering) { |
| 1979 | SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTargetDirect( |
| 1980 | layer->getTexture()->asRenderTarget())); |
| 1981 | |
| 1982 | SkCanvas* canvas = surface->getCanvas(); |
| 1983 | |
| 1984 | canvas->setMatrix(info.fCTM); |
| 1985 | canvas->clear(SK_ColorTRANSPARENT); |
| 1986 | |
| 1987 | picture->fPlayback->setDrawLimits(info.fSaveLayerOpID, info.fRestoreOpID); |
| 1988 | picture->fPlayback->draw(*canvas, NULL); |
| 1989 | picture->fPlayback->setDrawLimits(0, 0); |
| 1990 | canvas->flush(); |
| 1991 | } |
| commit-bot@chromium.org | 8ddc26b | 2014-03-31 17:55:12 +0000 | [diff] [blame] | 1992 | } |
| 1993 | } |
| 1994 | } |
| 1995 | |
| robertphillips@google.com | beb1af2 | 2014-05-07 21:31:09 +0000 | [diff] [blame] | 1996 | // Playback using new layers |
| 1997 | picture->fPlayback->setReplacements(&replacements); |
| 1998 | picture->fPlayback->draw(*canvas, NULL); |
| 1999 | picture->fPlayback->setReplacements(NULL); |
| 2000 | |
| 2001 | for (int i = 0; i < gpuData->numSaveLayers(); ++i) { |
| 2002 | GrCachedLayer* layer = fContext->getLayerCache()->findLayerOrCreate(picture, i); |
| 2003 | |
| 2004 | if (NULL != layer->getTexture()) { |
| 2005 | fContext->unlockScratchTexture(layer->getTexture()); |
| 2006 | layer->setTexture(NULL); |
| 2007 | } |
| 2008 | } |
| 2009 | |
| 2010 | return true; |
| commit-bot@chromium.org | 145d1c0 | 2014-03-16 19:46:36 +0000 | [diff] [blame] | 2011 | } |