blob: cd34b1feba72db9a5c9236161c5a6687537a787c [file] [log] [blame]
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +00001/*
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
robertphillipsccb1b572015-05-27 11:02:55 -070010#include "GrBlurUtils.h"
kkinnunenabcfab42015-02-22 22:53:44 -080011#include "GrContext.h"
robertphillips714712b2016-08-04 06:20:45 -070012#include "GrDrawContextPriv.h"
kkinnunenabcfab42015-02-22 22:53:44 -080013#include "GrGpu.h"
bsalomonc55271f2015-11-09 11:55:57 -080014#include "GrImageIDTextureAdjuster.h"
bsalomon6663acf2016-05-10 09:14:17 -070015#include "GrStyle.h"
egdanielbbcb38d2014-06-19 10:19:29 -070016#include "GrTracing.h"
robertphillips714712b2016-08-04 06:20:45 -070017
robertphillips30d78412014-11-24 09:49:17 -080018#include "SkCanvasPriv.h"
robertphillips714712b2016-08-04 06:20:45 -070019#include "SkDraw.h"
kkinnunenabcfab42015-02-22 22:53:44 -080020#include "SkErrorInternals.h"
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +000021#include "SkGlyphCache.h"
bsalomonf276ac52015-10-09 13:36:42 -070022#include "SkGr.h"
bsalomonf1b7a1d2015-09-28 06:26:28 -070023#include "SkGrPriv.h"
reeda85d4d02015-05-06 12:56:48 -070024#include "SkImage_Base.h"
bsalomon1cf6f9b2015-12-08 10:53:43 -080025#include "SkImageCacherator.h"
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +000026#include "SkImageFilter.h"
senorblanco900c3672016-04-27 11:31:23 -070027#include "SkImageFilterCache.h"
msarettc573a402016-08-02 08:05:56 -070028#include "SkLatticeIter.h"
commit-bot@chromium.org82139702014-03-10 22:53:20 +000029#include "SkMaskFilter.h"
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +000030#include "SkPathEffect.h"
commit-bot@chromium.org145d1c02014-03-16 19:46:36 +000031#include "SkPicture.h"
robertphillipsdb539902014-07-01 08:47:04 -070032#include "SkPictureData.h"
reed1e7f5e72016-04-27 07:49:17 -070033#include "SkRasterClip.h"
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +000034#include "SkRRect.h"
kkinnunenabcfab42015-02-22 22:53:44 -080035#include "SkRecord.h"
robertphillips970587b2016-07-14 14:12:55 -070036#include "SkSpecialImage.h"
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +000037#include "SkStroke.h"
reed@google.com76f10a32014-02-05 15:32:21 +000038#include "SkSurface.h"
kkinnunenabcfab42015-02-22 22:53:44 -080039#include "SkSurface_Gpu.h"
commit-bot@chromium.orga7d89c82014-01-13 14:47:00 +000040#include "SkTLazy.h"
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +000041#include "SkUtils.h"
commit-bot@chromium.org559a8832014-05-30 10:08:22 +000042#include "SkVertState.h"
robertphillips320c9232014-07-29 06:07:19 -070043#include "SkXfermode.h"
joshualitta61c8172015-08-17 10:51:22 -070044#include "batches/GrRectBatchFactory.h"
kkinnunenabcfab42015-02-22 22:53:44 -080045#include "effects/GrBicubicEffect.h"
46#include "effects/GrDashingEffect.h"
47#include "effects/GrSimpleTextureEffect.h"
48#include "effects/GrTextureDomain.h"
joshualitt8e84a1e2016-02-16 11:09:25 -080049#include "text/GrTextUtils.h"
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +000050
reedf037e0b2014-10-30 11:34:15 -070051#if SK_SUPPORT_GPU
52
joshualittce894002016-01-11 13:29:31 -080053#define ASSERT_SINGLE_OWNER \
54 SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(fContext->debugSingleOwner());)
55
senorblanco55b6d8b2014-07-30 11:26:46 -070056enum { kDefaultImageFilterCacheSize = 32 * 1024 * 1024 };
57
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +000058#if 0
59 extern bool (*gShouldDrawProc)();
joshualitt5531d512014-12-17 15:50:11 -080060 #define CHECK_SHOULD_DRAW(draw) \
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +000061 do { \
62 if (gShouldDrawProc && !gShouldDrawProc()) return; \
joshualitt5531d512014-12-17 15:50:11 -080063 this->prepareDraw(draw); \
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +000064 } while (0)
65#else
joshualitt5531d512014-12-17 15:50:11 -080066 #define CHECK_SHOULD_DRAW(draw) this->prepareDraw(draw)
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +000067#endif
68
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +000069///////////////////////////////////////////////////////////////////////////////
70
bsalomon74f681d2015-06-23 14:38:48 -070071/** Checks that the alpha type is legal and gets constructor flags. Returns false if device creation
72 should fail. */
73bool SkGpuDevice::CheckAlphaTypeAndGetFlags(
74 const SkImageInfo* info, SkGpuDevice::InitContents init, unsigned* flags) {
75 *flags = 0;
76 if (info) {
77 switch (info->alphaType()) {
78 case kPremul_SkAlphaType:
79 break;
80 case kOpaque_SkAlphaType:
81 *flags |= SkGpuDevice::kIsOpaque_Flag;
82 break;
83 default: // If it is unpremul or unknown don't try to render
84 return false;
85 }
86 }
87 if (kClear_InitContents == init) {
88 *flags |= kNeedClear_Flag;
89 }
90 return true;
91}
92
robertphillips15c42ca2016-08-04 08:45:02 -070093sk_sp<SkGpuDevice> SkGpuDevice::Make(sk_sp<GrDrawContext> drawContext,
94 int width, int height,
95 InitContents init) {
robertphillipsca6eafc2016-05-17 09:57:46 -070096 if (!drawContext || drawContext->wasAbandoned()) {
97 return nullptr;
98 }
99 unsigned flags;
100 if (!CheckAlphaTypeAndGetFlags(nullptr, init, &flags)) {
101 return nullptr;
102 }
robertphillips15c42ca2016-08-04 08:45:02 -0700103 return sk_sp<SkGpuDevice>(new SkGpuDevice(std::move(drawContext), width, height, flags));
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +0000104}
105
robertphillips24e91282016-04-29 06:46:36 -0700106sk_sp<SkGpuDevice> SkGpuDevice::Make(GrContext* context, SkBudgeted budgeted,
107 const SkImageInfo& info, int sampleCount,
robertphillips7e922762016-07-26 11:38:17 -0700108 GrSurfaceOrigin origin,
robertphillips24e91282016-04-29 06:46:36 -0700109 const SkSurfaceProps* props, InitContents init) {
bsalomon74f681d2015-06-23 14:38:48 -0700110 unsigned flags;
111 if (!CheckAlphaTypeAndGetFlags(&info, init, &flags)) {
halcanary96fcdcc2015-08-27 07:41:13 -0700112 return nullptr;
bsalomon74f681d2015-06-23 14:38:48 -0700113 }
114
robertphillips7e922762016-07-26 11:38:17 -0700115 sk_sp<GrDrawContext> drawContext(MakeDrawContext(context, budgeted, info,
116 sampleCount, origin, props));
robertphillipsca6eafc2016-05-17 09:57:46 -0700117 if (!drawContext) {
halcanary96fcdcc2015-08-27 07:41:13 -0700118 return nullptr;
bsalomon74f681d2015-06-23 14:38:48 -0700119 }
120
robertphillipsca6eafc2016-05-17 09:57:46 -0700121 return sk_sp<SkGpuDevice>(new SkGpuDevice(std::move(drawContext),
122 info.width(), info.height(), flags));
bsalomon74f681d2015-06-23 14:38:48 -0700123}
124
robertphillipsca6eafc2016-05-17 09:57:46 -0700125SkGpuDevice::SkGpuDevice(sk_sp<GrDrawContext> drawContext, int width, int height, unsigned flags)
126 : INHERITED(drawContext->surfaceProps())
127 , fContext(SkRef(drawContext->accessRenderTarget()->getContext()))
robertphillipsca6eafc2016-05-17 09:57:46 -0700128 , fDrawContext(std::move(drawContext)) {
robertphillips1f3923e2016-07-21 07:17:54 -0700129 fSize.set(width, height);
bsalomon74f681d2015-06-23 14:38:48 -0700130 fOpaque = SkToBool(flags & kIsOpaque_Flag);
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +0000131
bsalomone63ffef2016-02-05 07:17:34 -0800132 if (flags & kNeedClear_Flag) {
133 this->clearAll();
134 }
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +0000135}
136
robertphillips7e922762016-07-26 11:38:17 -0700137sk_sp<GrDrawContext> SkGpuDevice::MakeDrawContext(GrContext* context,
138 SkBudgeted budgeted,
139 const SkImageInfo& origInfo,
140 int sampleCount,
141 GrSurfaceOrigin origin,
142 const SkSurfaceProps* surfaceProps) {
commit-bot@chromium.org15a14052014-02-16 00:59:25 +0000143 if (kUnknown_SkColorType == origInfo.colorType() ||
144 origInfo.width() < 0 || origInfo.height() < 0) {
halcanary96fcdcc2015-08-27 07:41:13 -0700145 return nullptr;
commit-bot@chromium.org15a14052014-02-16 00:59:25 +0000146 }
147
bsalomonafe30052015-01-16 07:32:33 -0800148 if (!context) {
halcanary96fcdcc2015-08-27 07:41:13 -0700149 return nullptr;
bsalomonafe30052015-01-16 07:32:33 -0800150 }
151
reede5ea5002014-09-03 11:54:58 -0700152 SkColorType ct = origInfo.colorType();
153 SkAlphaType at = origInfo.alphaType();
brianosmanb109b8c2016-06-16 13:03:24 -0700154 SkColorSpace* cs = origInfo.colorSpace();
brianosman6b086522016-04-14 12:39:00 -0700155 if (kRGB_565_SkColorType == ct || kGray_8_SkColorType == ct) {
reede5ea5002014-09-03 11:54:58 -0700156 at = kOpaque_SkAlphaType; // force this setting
bsalomonafe30052015-01-16 07:32:33 -0800157 }
158 if (kOpaque_SkAlphaType != at) {
159 at = kPremul_SkAlphaType; // force this setting
commit-bot@chromium.org15a14052014-02-16 00:59:25 +0000160 }
brianosman6b086522016-04-14 12:39:00 -0700161
brianosmanb109b8c2016-06-16 13:03:24 -0700162 GrPixelConfig origConfig = SkImageInfo2GrPixelConfig(ct, at, cs, *context->caps());
brianosman6b086522016-04-14 12:39:00 -0700163 if (!context->caps()->isConfigRenderable(origConfig, sampleCount > 0)) {
164 // Fall back from whatever ct was to default of kRGBA or kBGRA which is aliased as kN32
165 ct = kN32_SkColorType;
166 }
167
brianosmanb109b8c2016-06-16 13:03:24 -0700168 GrPixelConfig config = SkImageInfo2GrPixelConfig(ct, at, cs, *context->caps());
commit-bot@chromium.org15a14052014-02-16 00:59:25 +0000169
robertphillips6738c702016-07-27 12:13:51 -0700170 return context->makeDrawContext(SkBackingFit::kExact, // Why exact?
171 origInfo.width(), origInfo.height(),
172 config, sk_ref_sp(cs), sampleCount,
173 origin, surfaceProps, budgeted);
kkinnunenabcfab42015-02-22 22:53:44 -0800174}
commit-bot@chromium.org15a14052014-02-16 00:59:25 +0000175
robertphillips970587b2016-07-14 14:12:55 -0700176sk_sp<SkSpecialImage> SkGpuDevice::filterTexture(const SkDraw& draw,
177 SkSpecialImage* srcImg,
178 int left, int top,
179 SkIPoint* offset,
180 const SkImageFilter* filter) {
181 SkASSERT(srcImg->isTextureBacked());
182 SkASSERT(filter);
183
184 SkMatrix matrix = *draw.fMatrix;
185 matrix.postTranslate(SkIntToScalar(-left), SkIntToScalar(-top));
186 const SkIRect clipBounds = draw.fRC->getBounds().makeOffset(-left, -top);
187 SkAutoTUnref<SkImageFilterCache> cache(this->getImageFilterCache());
188 SkImageFilter::Context ctx(matrix, clipBounds, cache.get());
189
190 return filter->filterImage(srcImg, ctx, offset);
191}
192
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +0000193///////////////////////////////////////////////////////////////////////////////
194
commit-bot@chromium.orga713f9c2014-03-17 21:31:26 +0000195bool SkGpuDevice::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes,
196 int x, int y) {
joshualittce894002016-01-11 13:29:31 -0800197 ASSERT_SINGLE_OWNER
commit-bot@chromium.orga713f9c2014-03-17 21:31:26 +0000198
199 // TODO: teach fRenderTarget to take ImageInfo directly to specify the src pixels
brianosmana6359362016-03-21 06:55:37 -0700200 GrPixelConfig config = SkImageInfo2GrPixelConfig(dstInfo, *fContext->caps());
commit-bot@chromium.orga713f9c2014-03-17 21:31:26 +0000201 if (kUnknown_GrPixelConfig == config) {
202 return false;
203 }
204
205 uint32_t flags = 0;
206 if (kUnpremul_SkAlphaType == dstInfo.alphaType()) {
207 flags = GrContext::kUnpremul_PixelOpsFlag;
208 }
robertphillips714712b2016-08-04 06:20:45 -0700209 return fDrawContext->accessRenderTarget()->readPixels(x, y,
210 dstInfo.width(), dstInfo.height(),
211 config, dstPixels,
212 dstRowBytes, flags);
commit-bot@chromium.orga713f9c2014-03-17 21:31:26 +0000213}
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +0000214
commit-bot@chromium.org4cd9e212014-03-07 03:25:16 +0000215bool SkGpuDevice::onWritePixels(const SkImageInfo& info, const void* pixels, size_t rowBytes,
216 int x, int y) {
joshualittce894002016-01-11 13:29:31 -0800217 ASSERT_SINGLE_OWNER
commit-bot@chromium.org4cd9e212014-03-07 03:25:16 +0000218 // TODO: teach fRenderTarget to take ImageInfo directly to specify the src pixels
brianosmana6359362016-03-21 06:55:37 -0700219 GrPixelConfig config = SkImageInfo2GrPixelConfig(info, *fContext->caps());
commit-bot@chromium.org4cd9e212014-03-07 03:25:16 +0000220 if (kUnknown_GrPixelConfig == config) {
221 return false;
222 }
223 uint32_t flags = 0;
224 if (kUnpremul_SkAlphaType == info.alphaType()) {
225 flags = GrContext::kUnpremul_PixelOpsFlag;
226 }
robertphillips15c42ca2016-08-04 08:45:02 -0700227 return fDrawContext->accessRenderTarget()->writePixels(x, y, info.width(), info.height(),
228 config, pixels, rowBytes, flags);
commit-bot@chromium.org4cd9e212014-03-07 03:25:16 +0000229}
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +0000230
reed41e010c2015-06-09 12:16:53 -0700231bool SkGpuDevice::onAccessPixels(SkPixmap* pmap) {
joshualittce894002016-01-11 13:29:31 -0800232 ASSERT_SINGLE_OWNER
reed41e010c2015-06-09 12:16:53 -0700233 return false;
234}
235
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +0000236// call this every draw call, to ensure that the context reflects our state,
237// and not the state from some other canvas/device
joshualitt5531d512014-12-17 15:50:11 -0800238void SkGpuDevice::prepareDraw(const SkDraw& draw) {
joshualittce894002016-01-11 13:29:31 -0800239 ASSERT_SINGLE_OWNER
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +0000240
reed2c9e2002016-07-25 08:05:22 -0700241 fClip.reset(draw.fClipStack, &this->getOrigin());
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +0000242}
243
robertphillips175dd9b2016-04-28 14:32:04 -0700244GrDrawContext* SkGpuDevice::accessDrawContext() {
245 ASSERT_SINGLE_OWNER
246 return fDrawContext.get();
247}
248
reed8eddfb52014-12-04 07:50:14 -0800249void SkGpuDevice::clearAll() {
joshualittce894002016-01-11 13:29:31 -0800250 ASSERT_SINGLE_OWNER
reed8eddfb52014-12-04 07:50:14 -0800251 GrColor color = 0;
joshualitt5651ee62016-01-11 10:39:11 -0800252 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "clearAll", fContext);
reed8eddfb52014-12-04 07:50:14 -0800253 SkIRect rect = SkIRect::MakeWH(this->width(), this->height());
robertphillips2e1e51f2015-10-15 08:01:48 -0700254 fDrawContext->clear(&rect, color, true);
reed8eddfb52014-12-04 07:50:14 -0800255}
256
robertphillipsca6eafc2016-05-17 09:57:46 -0700257void SkGpuDevice::replaceDrawContext(bool shouldRetainContent) {
joshualittce894002016-01-11 13:29:31 -0800258 ASSERT_SINGLE_OWNER
kkinnunenabcfab42015-02-22 22:53:44 -0800259
robertphillips714712b2016-08-04 06:20:45 -0700260 SkBudgeted budgeted = fDrawContext->drawContextPriv().isBudgeted();
kkinnunenabcfab42015-02-22 22:53:44 -0800261
robertphillips7e922762016-07-26 11:38:17 -0700262 sk_sp<GrDrawContext> newDC(MakeDrawContext(this->context(),
263 budgeted,
264 this->imageInfo(),
265 fDrawContext->numColorSamples(),
266 fDrawContext->origin(),
267 &this->surfaceProps()));
robertphillipsca6eafc2016-05-17 09:57:46 -0700268 if (!newDC) {
kkinnunenabcfab42015-02-22 22:53:44 -0800269 return;
270 }
271
272 if (shouldRetainContent) {
robertphillips714712b2016-08-04 06:20:45 -0700273 if (fDrawContext->wasAbandoned()) {
kkinnunenabcfab42015-02-22 22:53:44 -0800274 return;
275 }
robertphillipsca6eafc2016-05-17 09:57:46 -0700276 newDC->copySurface(fDrawContext->asTexture().get(),
277 SkIRect::MakeWH(this->width(), this->height()),
278 SkIPoint::Make(0, 0));
kkinnunenabcfab42015-02-22 22:53:44 -0800279 }
280
robertphillipsca6eafc2016-05-17 09:57:46 -0700281 fDrawContext = newDC;
kkinnunenabcfab42015-02-22 22:53:44 -0800282}
283
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +0000284///////////////////////////////////////////////////////////////////////////////
285
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +0000286void SkGpuDevice::drawPaint(const SkDraw& draw, const SkPaint& paint) {
joshualittce894002016-01-11 13:29:31 -0800287 ASSERT_SINGLE_OWNER
joshualitt5531d512014-12-17 15:50:11 -0800288 CHECK_SHOULD_DRAW(draw);
joshualitt5651ee62016-01-11 10:39:11 -0800289 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawPaint", fContext);
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +0000290
291 GrPaint grPaint;
brianosman8fe485b2016-07-25 12:31:51 -0700292 if (!SkPaintToGrPaint(this->context(), fDrawContext.get(), paint, *draw.fMatrix, &grPaint)) {
bsalomonbed83a62015-04-15 14:18:34 -0700293 return;
294 }
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +0000295
robertphillips2e1e51f2015-10-15 08:01:48 -0700296 fDrawContext->drawPaint(fClip, grPaint, *draw.fMatrix);
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +0000297}
298
299// must be in SkCanvas::PointMode order
300static const GrPrimitiveType gPointMode2PrimtiveType[] = {
301 kPoints_GrPrimitiveType,
302 kLines_GrPrimitiveType,
303 kLineStrip_GrPrimitiveType
304};
305
ethannicholas330bb952015-07-17 06:44:02 -0700306// suppress antialiasing on axis-aligned integer-coordinate lines
307static bool needs_antialiasing(SkCanvas::PointMode mode, size_t count, const SkPoint pts[]) {
308 if (mode == SkCanvas::PointMode::kPoints_PointMode) {
309 return false;
310 }
311 if (count == 2) {
312 // We do not antialias as long as the primary axis of the line is integer-aligned, even if
313 // the other coordinates are not. This does mean the two end pixels of the line will be
herb11a7f7f2015-11-24 12:41:00 -0800314 // sharp even when they shouldn't be, but turning antialiasing on (as things stand
ethannicholas330bb952015-07-17 06:44:02 -0700315 // currently) means that the line will turn into a two-pixel-wide blur. While obviously a
herb11a7f7f2015-11-24 12:41:00 -0800316 // more complete fix is possible down the road, for the time being we accept the error on
ethannicholas330bb952015-07-17 06:44:02 -0700317 // the two end pixels as being the lesser of two evils.
318 if (pts[0].fX == pts[1].fX) {
319 return ((int) pts[0].fX) != pts[0].fX;
320 }
321 if (pts[0].fY == pts[1].fY) {
322 return ((int) pts[0].fY) != pts[0].fY;
323 }
324 }
325 return true;
326}
327
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +0000328void SkGpuDevice::drawPoints(const SkDraw& draw, SkCanvas::PointMode mode,
329 size_t count, const SkPoint pts[], const SkPaint& paint) {
joshualittce894002016-01-11 13:29:31 -0800330 ASSERT_SINGLE_OWNER
joshualitt086cee12016-01-12 06:45:24 -0800331 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawPoints", fContext);
joshualitt5531d512014-12-17 15:50:11 -0800332 CHECK_SHOULD_DRAW(draw);
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +0000333
334 SkScalar width = paint.getStrokeWidth();
335 if (width < 0) {
336 return;
337 }
338
commit-bot@chromium.org628ed0b2014-05-19 14:32:49 +0000339 if (paint.getPathEffect() && 2 == count && SkCanvas::kLines_PointMode == mode) {
bsalomon6663acf2016-05-10 09:14:17 -0700340 GrStyle style(paint, SkPaint::kStroke_Style);
egdaniele61c4112014-06-12 10:24:21 -0700341 GrPaint grPaint;
brianosman8fe485b2016-07-25 12:31:51 -0700342 if (!SkPaintToGrPaint(this->context(), fDrawContext.get(), paint, *draw.fMatrix,
brianosman1638c0d2016-07-25 05:12:53 -0700343 &grPaint)) {
bsalomonbed83a62015-04-15 14:18:34 -0700344 return;
345 }
egdaniele61c4112014-06-12 10:24:21 -0700346 SkPath path;
jvanverthb3eb6872014-10-24 07:12:51 -0700347 path.setIsVolatile(true);
egdaniele61c4112014-06-12 10:24:21 -0700348 path.moveTo(pts[0]);
349 path.lineTo(pts[1]);
bsalomon6663acf2016-05-10 09:14:17 -0700350 fDrawContext->drawPath(fClip, grPaint, *draw.fMatrix, path, style);
egdaniele61c4112014-06-12 10:24:21 -0700351 return;
commit-bot@chromium.org628ed0b2014-05-19 14:32:49 +0000352 }
353
ethannicholas330bb952015-07-17 06:44:02 -0700354 // we only handle non-antialiased hairlines and paints without path effects or mask filters,
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +0000355 // else we let the SkDraw call our drawPath()
herb11a7f7f2015-11-24 12:41:00 -0800356 if (width > 0 || paint.getPathEffect() || paint.getMaskFilter() ||
ethannicholas330bb952015-07-17 06:44:02 -0700357 (paint.isAntiAlias() && needs_antialiasing(mode, count, pts))) {
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +0000358 draw.drawPoints(mode, count, pts, paint, true);
359 return;
360 }
361
362 GrPaint grPaint;
brianosman8fe485b2016-07-25 12:31:51 -0700363 if (!SkPaintToGrPaint(this->context(), fDrawContext.get(), paint, *draw.fMatrix, &grPaint)) {
bsalomonbed83a62015-04-15 14:18:34 -0700364 return;
365 }
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +0000366
robertphillips2e1e51f2015-10-15 08:01:48 -0700367 fDrawContext->drawVertices(fClip,
robertphillipsea461502015-05-26 11:38:03 -0700368 grPaint,
369 *draw.fMatrix,
370 gPointMode2PrimtiveType[mode],
371 SkToS32(count),
372 (SkPoint*)pts,
halcanary96fcdcc2015-08-27 07:41:13 -0700373 nullptr,
374 nullptr,
375 nullptr,
robertphillipsea461502015-05-26 11:38:03 -0700376 0);
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +0000377}
378
379///////////////////////////////////////////////////////////////////////////////
380
robertphillipsff55b492015-11-24 07:56:59 -0800381void SkGpuDevice::drawRect(const SkDraw& draw, const SkRect& rect, const SkPaint& paint) {
joshualittce894002016-01-11 13:29:31 -0800382 ASSERT_SINGLE_OWNER
joshualitt5651ee62016-01-11 10:39:11 -0800383 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawRect", fContext);
joshualitt5531d512014-12-17 15:50:11 -0800384 CHECK_SHOULD_DRAW(draw);
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +0000385
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +0000386
bsalomona7d85ba2016-07-06 11:54:59 -0700387 // A couple reasons we might need to call drawPath.
388 if (paint.getMaskFilter() || paint.getPathEffect()) {
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +0000389 SkPath path;
jvanverthb3eb6872014-10-24 07:12:51 -0700390 path.setIsVolatile(true);
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +0000391 path.addRect(rect);
robertphillips6c7e3252016-04-27 10:47:51 -0700392 GrBlurUtils::drawPathWithMaskFilter(fContext, fDrawContext.get(),
robertphillipsff55b492015-11-24 07:56:59 -0800393 fClip, path, paint,
394 *draw.fMatrix, nullptr,
reed1e7f5e72016-04-27 07:49:17 -0700395 draw.fRC->getBounds(), true);
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +0000396 return;
397 }
398
399 GrPaint grPaint;
brianosman8fe485b2016-07-25 12:31:51 -0700400 if (!SkPaintToGrPaint(this->context(), fDrawContext.get(), paint, *draw.fMatrix, &grPaint)) {
bsalomonbed83a62015-04-15 14:18:34 -0700401 return;
402 }
Mike Klein744fb732014-06-23 15:13:26 -0400403
bsalomon6663acf2016-05-10 09:14:17 -0700404 GrStyle style(paint);
405 fDrawContext->drawRect(fClip, grPaint, *draw.fMatrix, rect, &style);
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +0000406}
407
408///////////////////////////////////////////////////////////////////////////////
409
robertphillips9aff85a2016-08-05 07:51:29 -0700410void SkGpuDevice::drawRRect(const SkDraw& draw, const SkRRect& rrect,
joshualitt5531d512014-12-17 15:50:11 -0800411 const SkPaint& paint) {
joshualittce894002016-01-11 13:29:31 -0800412 ASSERT_SINGLE_OWNER
joshualitt5651ee62016-01-11 10:39:11 -0800413 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawRRect", fContext);
joshualitt5531d512014-12-17 15:50:11 -0800414 CHECK_SHOULD_DRAW(draw);
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +0000415
commit-bot@chromium.org82139702014-03-10 22:53:20 +0000416 GrPaint grPaint;
brianosman8fe485b2016-07-25 12:31:51 -0700417 if (!SkPaintToGrPaint(this->context(), fDrawContext.get(), paint, *draw.fMatrix, &grPaint)) {
bsalomonbed83a62015-04-15 14:18:34 -0700418 return;
419 }
Mike Klein744fb732014-06-23 15:13:26 -0400420
bsalomon6663acf2016-05-10 09:14:17 -0700421 GrStyle style(paint);
commit-bot@chromium.org82139702014-03-10 22:53:20 +0000422 if (paint.getMaskFilter()) {
423 // try to hit the fast path for drawing filtered round rects
424
425 SkRRect devRRect;
robertphillips9aff85a2016-08-05 07:51:29 -0700426 if (rrect.transform(*draw.fMatrix, &devRRect)) {
commit-bot@chromium.org82139702014-03-10 22:53:20 +0000427 if (devRRect.allCornersCircular()) {
428 SkRect maskRect;
robertphillips30c4cae2015-09-15 10:20:55 -0700429 if (paint.getMaskFilter()->canFilterMaskGPU(devRRect,
reed1e7f5e72016-04-27 07:49:17 -0700430 draw.fRC->getBounds(),
joshualitt5531d512014-12-17 15:50:11 -0800431 *draw.fMatrix,
432 &maskRect)) {
commit-bot@chromium.org82139702014-03-10 22:53:20 +0000433 SkIRect finalIRect;
434 maskRect.roundOut(&finalIRect);
reed1e7f5e72016-04-27 07:49:17 -0700435 if (draw.fRC->quickReject(finalIRect)) {
commit-bot@chromium.org82139702014-03-10 22:53:20 +0000436 // clipped out
437 return;
438 }
robertphillipsff0ca5e2015-07-22 11:54:44 -0700439 if (paint.getMaskFilter()->directFilterRRectMaskGPU(fContext->textureProvider(),
robertphillips6c7e3252016-04-27 10:47:51 -0700440 fDrawContext.get(),
joshualitt25d9c152015-02-18 12:29:52 -0800441 &grPaint,
joshualitt570d2f82015-02-25 13:19:48 -0800442 fClip,
joshualitt5531d512014-12-17 15:50:11 -0800443 *draw.fMatrix,
bsalomon6663acf2016-05-10 09:14:17 -0700444 style.strokeRec(),
egdanield58a0ba2014-06-11 10:30:05 -0700445 devRRect)) {
commit-bot@chromium.org82139702014-03-10 22:53:20 +0000446 return;
447 }
448 }
449
450 }
451 }
commit-bot@chromium.org82139702014-03-10 22:53:20 +0000452 }
453
bsalomon6663acf2016-05-10 09:14:17 -0700454 if (paint.getMaskFilter() || style.pathEffect()) {
robertphillipsff55b492015-11-24 07:56:59 -0800455 // The only mask filter the native rrect drawing code could've handle was taken
456 // care of above.
457 // A path effect will presumably transform this rrect into something else.
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +0000458 SkPath path;
jvanverthb3eb6872014-10-24 07:12:51 -0700459 path.setIsVolatile(true);
robertphillips9aff85a2016-08-05 07:51:29 -0700460 path.addRRect(rrect);
robertphillips6c7e3252016-04-27 10:47:51 -0700461 GrBlurUtils::drawPathWithMaskFilter(fContext, fDrawContext.get(),
robertphillipsff55b492015-11-24 07:56:59 -0800462 fClip, path, paint,
463 *draw.fMatrix, nullptr,
reed1e7f5e72016-04-27 07:49:17 -0700464 draw.fRC->getBounds(), true);
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +0000465 return;
466 }
Mike Klein744fb732014-06-23 15:13:26 -0400467
bsalomon6663acf2016-05-10 09:14:17 -0700468 SkASSERT(!style.pathEffect());
robertphillips514450c2015-11-24 05:36:02 -0800469
robertphillips9aff85a2016-08-05 07:51:29 -0700470 fDrawContext->drawRRect(fClip, grPaint, *draw.fMatrix, rrect, style);
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +0000471}
472
robertphillipsd7706102016-02-25 09:28:08 -0800473
commit-bot@chromium.org0a09d712014-04-09 21:26:11 +0000474void SkGpuDevice::drawDRRect(const SkDraw& draw, const SkRRect& outer,
joshualitt5531d512014-12-17 15:50:11 -0800475 const SkRRect& inner, const SkPaint& paint) {
joshualittce894002016-01-11 13:29:31 -0800476 ASSERT_SINGLE_OWNER
joshualitt5651ee62016-01-11 10:39:11 -0800477 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawDRRect", fContext);
robertphillips0e7029e2015-11-30 05:45:06 -0800478 CHECK_SHOULD_DRAW(draw);
479
robertphillipsd7706102016-02-25 09:28:08 -0800480 if (outer.isEmpty()) {
481 return;
482 }
483
484 if (inner.isEmpty()) {
485 return this->drawRRect(draw, outer, paint);
486 }
487
commit-bot@chromium.org0a09d712014-04-09 21:26:11 +0000488 SkStrokeRec stroke(paint);
commit-bot@chromium.org0a09d712014-04-09 21:26:11 +0000489
robertphillips0e7029e2015-11-30 05:45:06 -0800490 if (stroke.isFillStyle() && !paint.getMaskFilter() && !paint.getPathEffect()) {
robertphillips00095892016-02-29 13:50:40 -0800491 GrPaint grPaint;
brianosman8fe485b2016-07-25 12:31:51 -0700492 if (!SkPaintToGrPaint(this->context(), fDrawContext.get(), paint, *draw.fMatrix,
brianosman1638c0d2016-07-25 05:12:53 -0700493 &grPaint)) {
bsalomonbed83a62015-04-15 14:18:34 -0700494 return;
495 }
robertphillips00095892016-02-29 13:50:40 -0800496
497 fDrawContext->drawDRRect(fClip, grPaint, *draw.fMatrix, outer, inner);
498 return;
commit-bot@chromium.org0a09d712014-04-09 21:26:11 +0000499 }
500
501 SkPath path;
jvanverthb3eb6872014-10-24 07:12:51 -0700502 path.setIsVolatile(true);
commit-bot@chromium.org0a09d712014-04-09 21:26:11 +0000503 path.addRRect(outer);
504 path.addRRect(inner);
505 path.setFillType(SkPath::kEvenOdd_FillType);
506
robertphillips6c7e3252016-04-27 10:47:51 -0700507 GrBlurUtils::drawPathWithMaskFilter(fContext, fDrawContext.get(),
robertphillips0e7029e2015-11-30 05:45:06 -0800508 fClip, path, paint,
509 *draw.fMatrix, nullptr,
reed1e7f5e72016-04-27 07:49:17 -0700510 draw.fRC->getBounds(), true);
commit-bot@chromium.org0a09d712014-04-09 21:26:11 +0000511}
512
513
commit-bot@chromium.org82139702014-03-10 22:53:20 +0000514/////////////////////////////////////////////////////////////////////////////
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +0000515
robertphillips514450c2015-11-24 05:36:02 -0800516void SkGpuDevice::drawOval(const SkDraw& draw, const SkRect& oval, const SkPaint& paint) {
joshualittce894002016-01-11 13:29:31 -0800517 ASSERT_SINGLE_OWNER
joshualitt5651ee62016-01-11 10:39:11 -0800518 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawOval", fContext);
joshualitt5531d512014-12-17 15:50:11 -0800519 CHECK_SHOULD_DRAW(draw);
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +0000520
robertphillips514450c2015-11-24 05:36:02 -0800521 // Presumably the path effect warps this to something other than an oval
522 if (paint.getPathEffect()) {
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +0000523 SkPath path;
jvanverthb3eb6872014-10-24 07:12:51 -0700524 path.setIsVolatile(true);
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +0000525 path.addOval(oval);
halcanary96fcdcc2015-08-27 07:41:13 -0700526 this->drawPath(draw, path, paint, nullptr, true);
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +0000527 return;
herb11a7f7f2015-11-24 12:41:00 -0800528 }
529
robertphillips514450c2015-11-24 05:36:02 -0800530 if (paint.getMaskFilter()) {
531 // The RRect path can handle special case blurring
532 SkRRect rr = SkRRect::MakeOval(oval);
533 return this->drawRRect(draw, rr, paint);
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +0000534 }
535
536 GrPaint grPaint;
brianosman8fe485b2016-07-25 12:31:51 -0700537 if (!SkPaintToGrPaint(this->context(), fDrawContext.get(), paint, *draw.fMatrix, &grPaint)) {
bsalomonbed83a62015-04-15 14:18:34 -0700538 return;
539 }
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +0000540
bsalomon6663acf2016-05-10 09:14:17 -0700541 fDrawContext->drawOval(fClip, grPaint, *draw.fMatrix, oval, GrStyle(paint));
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +0000542}
543
544#include "SkMaskFilter.h"
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +0000545
546///////////////////////////////////////////////////////////////////////////////
robertphillips0851d2d2016-06-02 05:21:34 -0700547void SkGpuDevice::drawStrokedLine(const SkPoint points[2],
548 const SkDraw& draw,
549 const SkPaint& origPaint) {
550 ASSERT_SINGLE_OWNER
551 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawStrokedLine", fContext);
552 CHECK_SHOULD_DRAW(draw);
553
554 // Adding support for round capping would require a GrDrawContext::fillRRectWithLocalMatrix
555 // entry point
556 SkASSERT(SkPaint::kRound_Cap != origPaint.getStrokeCap());
557 SkASSERT(SkPaint::kStroke_Style == origPaint.getStyle());
558 SkASSERT(!origPaint.getPathEffect());
559 SkASSERT(!origPaint.getMaskFilter());
560
561 const SkScalar halfWidth = 0.5f * origPaint.getStrokeWidth();
562 SkASSERT(halfWidth > 0);
563
564 SkVector v = points[1] - points[0];
565
566 SkScalar length = SkPoint::Normalize(&v);
567 if (!length) {
568 v.fX = 1.0f;
569 v.fY = 0.0f;
570 }
571
572 SkPaint newPaint(origPaint);
573 newPaint.setStyle(SkPaint::kFill_Style);
574
575 SkScalar xtraLength = 0.0f;
576 if (SkPaint::kButt_Cap != origPaint.getStrokeCap()) {
577 xtraLength = halfWidth;
578 }
579
580 SkPoint mid = points[0] + points[1];
581 mid.scale(0.5f);
582
583 SkRect rect = SkRect::MakeLTRB(mid.fX-halfWidth, mid.fY - 0.5f*length - xtraLength,
584 mid.fX+halfWidth, mid.fY + 0.5f*length + xtraLength);
585 SkMatrix m;
586 m.setSinCos(v.fX, -v.fY, mid.fX, mid.fY);
587
588 SkMatrix local = m;
589
590 m.postConcat(*draw.fMatrix);
591
592 GrPaint grPaint;
brianosman8fe485b2016-07-25 12:31:51 -0700593 if (!SkPaintToGrPaint(this->context(), fDrawContext.get(), newPaint, m, &grPaint)) {
robertphillips0851d2d2016-06-02 05:21:34 -0700594 return;
595 }
596
597 fDrawContext->fillRectWithLocalMatrix(fClip, grPaint, m, rect, local);
598}
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +0000599
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +0000600void SkGpuDevice::drawPath(const SkDraw& draw, const SkPath& origSrcPath,
601 const SkPaint& paint, const SkMatrix* prePathMatrix,
602 bool pathIsMutable) {
joshualittce894002016-01-11 13:29:31 -0800603 ASSERT_SINGLE_OWNER
robertphillipsff55b492015-11-24 07:56:59 -0800604 if (!origSrcPath.isInverseFillType() && !paint.getPathEffect() && !prePathMatrix) {
robertphillips0851d2d2016-06-02 05:21:34 -0700605 SkPoint points[2];
606 if (SkPaint::kStroke_Style == paint.getStyle() && paint.getStrokeWidth() > 0 &&
607 !paint.getMaskFilter() && SkPaint::kRound_Cap != paint.getStrokeCap() &&
608 draw.fMatrix->preservesRightAngles() && origSrcPath.isLine(points)) {
609 // Path-based stroking looks better for thin rects
610 SkScalar strokeWidth = draw.fMatrix->getMaxScale() * paint.getStrokeWidth();
robertphillipsf2204c92016-06-02 10:57:59 -0700611 if (strokeWidth >= 1.0f) {
robertphillips0851d2d2016-06-02 05:21:34 -0700612 // Round capping support is currently disabled b.c. it would require
613 // a RRect batch that takes a localMatrix.
614 this->drawStrokedLine(points, draw, paint);
615 return;
616 }
617 }
robertphillipsff55b492015-11-24 07:56:59 -0800618 bool isClosed;
619 SkRect rect;
620 if (origSrcPath.isRect(&rect, &isClosed) && isClosed) {
621 this->drawRect(draw, rect, paint);
622 return;
623 }
624 if (origSrcPath.isOval(&rect)) {
625 this->drawOval(draw, rect, paint);
626 return;
627 }
628 SkRRect rrect;
629 if (origSrcPath.isRRect(&rrect)) {
630 this->drawRRect(draw, rrect, paint);
631 return;
632 }
633 }
634
joshualitt5531d512014-12-17 15:50:11 -0800635 CHECK_SHOULD_DRAW(draw);
joshualitt5651ee62016-01-11 10:39:11 -0800636 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawPath", fContext);
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +0000637
robertphillips6c7e3252016-04-27 10:47:51 -0700638 GrBlurUtils::drawPathWithMaskFilter(fContext, fDrawContext.get(),
robertphillipsccb1b572015-05-27 11:02:55 -0700639 fClip, origSrcPath, paint,
640 *draw.fMatrix, prePathMatrix,
reed1e7f5e72016-04-27 07:49:17 -0700641 draw.fRC->getBounds(), pathIsMutable);
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +0000642}
643
644static const int kBmpSmallTileSize = 1 << 10;
645
646static inline int get_tile_count(const SkIRect& srcRect, int tileSize) {
647 int tilesX = (srcRect.fRight / tileSize) - (srcRect.fLeft / tileSize) + 1;
648 int tilesY = (srcRect.fBottom / tileSize) - (srcRect.fTop / tileSize) + 1;
649 return tilesX * tilesY;
650}
651
reed85d91782015-09-10 14:33:38 -0700652static int determine_tile_size(const SkIRect& src, int maxTileSize) {
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +0000653 if (maxTileSize <= kBmpSmallTileSize) {
654 return maxTileSize;
655 }
656
657 size_t maxTileTotalTileSize = get_tile_count(src, maxTileSize);
658 size_t smallTotalTileSize = get_tile_count(src, kBmpSmallTileSize);
659
660 maxTileTotalTileSize *= maxTileSize * maxTileSize;
661 smallTotalTileSize *= kBmpSmallTileSize * kBmpSmallTileSize;
662
663 if (maxTileTotalTileSize > 2 * smallTotalTileSize) {
664 return kBmpSmallTileSize;
665 } else {
666 return maxTileSize;
667 }
668}
669
670// Given a bitmap, an optional src rect, and a context with a clip and matrix determine what
671// pixels from the bitmap are necessary.
robertphillipse5768742016-05-13 11:20:46 -0700672static void determine_clipped_src_rect(int width, int height,
joshualitt570d2f82015-02-25 13:19:48 -0800673 const GrClip& clip,
joshualitt5531d512014-12-17 15:50:11 -0800674 const SkMatrix& viewMatrix,
reed85d91782015-09-10 14:33:38 -0700675 const SkISize& imageSize,
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +0000676 const SkRect* srcRectPtr,
677 SkIRect* clippedSrcIRect) {
robertphillipse5768742016-05-13 11:20:46 -0700678 clip.getConservativeBounds(width, height, clippedSrcIRect, nullptr);
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +0000679 SkMatrix inv;
joshualitt5531d512014-12-17 15:50:11 -0800680 if (!viewMatrix.invert(&inv)) {
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +0000681 clippedSrcIRect->setEmpty();
682 return;
683 }
684 SkRect clippedSrcRect = SkRect::Make(*clippedSrcIRect);
685 inv.mapRect(&clippedSrcRect);
bsalomon49f085d2014-09-05 13:34:00 -0700686 if (srcRectPtr) {
commit-bot@chromium.orga7d89c82014-01-13 14:47:00 +0000687 // we've setup src space 0,0 to map to the top left of the src rect.
688 clippedSrcRect.offset(srcRectPtr->fLeft, srcRectPtr->fTop);
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +0000689 if (!clippedSrcRect.intersect(*srcRectPtr)) {
690 clippedSrcIRect->setEmpty();
691 return;
692 }
693 }
694 clippedSrcRect.roundOut(clippedSrcIRect);
reed85d91782015-09-10 14:33:38 -0700695 SkIRect bmpBounds = SkIRect::MakeSize(imageSize);
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +0000696 if (!clippedSrcIRect->intersect(bmpBounds)) {
697 clippedSrcIRect->setEmpty();
698 }
699}
700
reed85d91782015-09-10 14:33:38 -0700701bool SkGpuDevice::shouldTileImageID(uint32_t imageID, const SkIRect& imageRect,
702 const SkMatrix& viewMatrix,
703 const GrTextureParams& params,
704 const SkRect* srcRectPtr,
705 int maxTileSize,
706 int* tileSize,
707 SkIRect* clippedSubset) const {
joshualittce894002016-01-11 13:29:31 -0800708 ASSERT_SINGLE_OWNER
reed85d91782015-09-10 14:33:38 -0700709 // if it's larger than the max tile size, then we have no choice but tiling.
710 if (imageRect.width() > maxTileSize || imageRect.height() > maxTileSize) {
robertphillipse5768742016-05-13 11:20:46 -0700711 determine_clipped_src_rect(fDrawContext->width(), fDrawContext->height(),
712 fClip, viewMatrix, imageRect.size(),
reed85d91782015-09-10 14:33:38 -0700713 srcRectPtr, clippedSubset);
714 *tileSize = determine_tile_size(*clippedSubset, maxTileSize);
715 return true;
716 }
717
bsalomon1a1d0b82015-10-16 07:49:42 -0700718 // If the image would only produce 4 tiles of the smaller size, don't bother tiling it.
reed85d91782015-09-10 14:33:38 -0700719 const size_t area = imageRect.width() * imageRect.height();
720 if (area < 4 * kBmpSmallTileSize * kBmpSmallTileSize) {
721 return false;
722 }
723
reed85d91782015-09-10 14:33:38 -0700724 // At this point we know we could do the draw by uploading the entire bitmap
725 // as a texture. However, if the texture would be large compared to the
726 // cache size and we don't require most of it for this draw then tile to
727 // reduce the amount of upload and cache spill.
728
729 // assumption here is that sw bitmap size is a good proxy for its size as
730 // a texture
731 size_t bmpSize = area * sizeof(SkPMColor); // assume 32bit pixels
732 size_t cacheSize;
733 fContext->getResourceCacheLimits(nullptr, &cacheSize);
734 if (bmpSize < cacheSize / 2) {
735 return false;
736 }
737
bsalomon1a1d0b82015-10-16 07:49:42 -0700738 // Figure out how much of the src we will need based on the src rect and clipping. Reject if
739 // tiling memory savings would be < 50%.
robertphillipse5768742016-05-13 11:20:46 -0700740 determine_clipped_src_rect(fDrawContext->width(), fDrawContext->height(),
741 fClip, viewMatrix, imageRect.size(), srcRectPtr,
reed85d91782015-09-10 14:33:38 -0700742 clippedSubset);
743 *tileSize = kBmpSmallTileSize; // already know whole bitmap fits in one max sized tile.
744 size_t usedTileBytes = get_tile_count(*clippedSubset, kBmpSmallTileSize) *
745 kBmpSmallTileSize * kBmpSmallTileSize;
746
747 return usedTileBytes < 2 * bmpSize;
748}
749
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +0000750bool SkGpuDevice::shouldTileBitmap(const SkBitmap& bitmap,
joshualitt5531d512014-12-17 15:50:11 -0800751 const SkMatrix& viewMatrix,
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +0000752 const GrTextureParams& params,
753 const SkRect* srcRectPtr,
754 int maxTileSize,
755 int* tileSize,
756 SkIRect* clippedSrcRect) const {
joshualittce894002016-01-11 13:29:31 -0800757 ASSERT_SINGLE_OWNER
reed85d91782015-09-10 14:33:38 -0700758 return this->shouldTileImageID(bitmap.getGenerationID(), bitmap.getSubset(), viewMatrix, params,
759 srcRectPtr, maxTileSize, tileSize, clippedSrcRect);
760}
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +0000761
reed85d91782015-09-10 14:33:38 -0700762bool SkGpuDevice::shouldTileImage(const SkImage* image, const SkRect* srcRectPtr,
763 SkCanvas::SrcRectConstraint constraint, SkFilterQuality quality,
764 const SkMatrix& viewMatrix) const {
joshualittce894002016-01-11 13:29:31 -0800765 ASSERT_SINGLE_OWNER
reed85d91782015-09-10 14:33:38 -0700766 // if image is explictly texture backed then just use the texture
767 if (as_IB(image)->peekTexture()) {
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +0000768 return false;
769 }
770
reed85d91782015-09-10 14:33:38 -0700771 GrTextureParams params;
772 bool doBicubic;
773 GrTextureParams::FilterMode textureFilterMode =
774 GrSkFilterQualityToGrFilterMode(quality, viewMatrix, SkMatrix::I(), &doBicubic);
775
776 int tileFilterPad;
777 if (doBicubic) {
778 tileFilterPad = GrBicubicEffect::kFilterTexelPad;
779 } else if (GrTextureParams::kNone_FilterMode == textureFilterMode) {
780 tileFilterPad = 0;
781 } else {
782 tileFilterPad = 1;
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +0000783 }
reed85d91782015-09-10 14:33:38 -0700784 params.setFilterMode(textureFilterMode);
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +0000785
bsalomon8c07b7a2015-11-02 11:36:52 -0800786 int maxTileSize = fContext->caps()->maxTileSize() - 2 * tileFilterPad;
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +0000787
reed85d91782015-09-10 14:33:38 -0700788 // these are output, which we safely ignore, as we just want to know the predicate
789 int outTileSize;
790 SkIRect outClippedSrcRect;
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +0000791
reed85d91782015-09-10 14:33:38 -0700792 return this->shouldTileImageID(image->unique(), image->bounds(), viewMatrix, params, srcRectPtr,
793 maxTileSize, &outTileSize, &outClippedSrcRect);
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +0000794}
795
commit-bot@chromium.orga7d89c82014-01-13 14:47:00 +0000796void SkGpuDevice::drawBitmap(const SkDraw& origDraw,
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +0000797 const SkBitmap& bitmap,
798 const SkMatrix& m,
799 const SkPaint& paint) {
joshualittce894002016-01-11 13:29:31 -0800800 ASSERT_SINGLE_OWNER
bsalomonb1b01992015-11-18 10:56:08 -0800801 CHECK_SHOULD_DRAW(origDraw);
bsalomonb1b01992015-11-18 10:56:08 -0800802 SkMatrix viewMatrix;
803 viewMatrix.setConcat(*origDraw.fMatrix, m);
reedc7ec7c92016-07-25 08:29:10 -0700804
bsalomonb1b01992015-11-18 10:56:08 -0800805 int maxTileSize = fContext->caps()->maxTileSize();
806
807 // The tile code path doesn't currently support AA, so if the paint asked for aa and we could
808 // draw untiled, then we bypass checking for tiling purely for optimization reasons.
robertphillips071457b2016-05-16 09:50:03 -0700809 bool drawAA = !fDrawContext->isUnifiedMultisampled() &&
bsalomonb1b01992015-11-18 10:56:08 -0800810 paint.isAntiAlias() &&
811 bitmap.width() <= maxTileSize &&
812 bitmap.height() <= maxTileSize;
813
814 bool skipTileCheck = drawAA || paint.getMaskFilter();
815
816 if (!skipTileCheck) {
817 SkRect srcRect = SkRect::MakeIWH(bitmap.width(), bitmap.height());
818 int tileSize;
819 SkIRect clippedSrcRect;
820
821 GrTextureParams params;
822 bool doBicubic;
823 GrTextureParams::FilterMode textureFilterMode =
824 GrSkFilterQualityToGrFilterMode(paint.getFilterQuality(), viewMatrix, SkMatrix::I(),
825 &doBicubic);
826
827 int tileFilterPad;
828
829 if (doBicubic) {
830 tileFilterPad = GrBicubicEffect::kFilterTexelPad;
831 } else if (GrTextureParams::kNone_FilterMode == textureFilterMode) {
832 tileFilterPad = 0;
833 } else {
834 tileFilterPad = 1;
835 }
836 params.setFilterMode(textureFilterMode);
837
838 int maxTileSizeForFilter = fContext->caps()->maxTileSize() - 2 * tileFilterPad;
839 if (this->shouldTileBitmap(bitmap, viewMatrix, params, &srcRect,
840 maxTileSizeForFilter, &tileSize, &clippedSrcRect)) {
841 this->drawTiledBitmap(bitmap, viewMatrix, srcRect, clippedSrcRect, params, paint,
842 SkCanvas::kStrict_SrcRectConstraint, tileSize, doBicubic);
843 return;
844 }
commit-bot@chromium.orga7d89c82014-01-13 14:47:00 +0000845 }
bsalomonb1b01992015-11-18 10:56:08 -0800846 GrBitmapTextureMaker maker(fContext, bitmap);
bsalomonf1ecd212015-12-09 17:06:02 -0800847 this->drawTextureProducer(&maker, nullptr, nullptr, SkCanvas::kStrict_SrcRectConstraint,
848 viewMatrix, fClip, paint);
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +0000849}
850
commit-bot@chromium.orgdec61502013-12-02 22:22:35 +0000851// This method outsets 'iRect' by 'outset' all around and then clamps its extents to
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +0000852// 'clamp'. 'offset' is adjusted to remain positioned over the top-left corner
853// of 'iRect' for all possible outsets/clamps.
commit-bot@chromium.orgdec61502013-12-02 22:22:35 +0000854static inline void clamped_outset_with_offset(SkIRect* iRect,
855 int outset,
856 SkPoint* offset,
857 const SkIRect& clamp) {
858 iRect->outset(outset, outset);
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +0000859
commit-bot@chromium.orgdec61502013-12-02 22:22:35 +0000860 int leftClampDelta = clamp.fLeft - iRect->fLeft;
861 if (leftClampDelta > 0) {
862 offset->fX -= outset - leftClampDelta;
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +0000863 iRect->fLeft = clamp.fLeft;
864 } else {
commit-bot@chromium.orgdec61502013-12-02 22:22:35 +0000865 offset->fX -= outset;
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +0000866 }
commit-bot@chromium.orgdec61502013-12-02 22:22:35 +0000867
868 int topClampDelta = clamp.fTop - iRect->fTop;
869 if (topClampDelta > 0) {
870 offset->fY -= outset - topClampDelta;
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +0000871 iRect->fTop = clamp.fTop;
872 } else {
commit-bot@chromium.orgdec61502013-12-02 22:22:35 +0000873 offset->fY -= outset;
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +0000874 }
875
876 if (iRect->fRight > clamp.fRight) {
877 iRect->fRight = clamp.fRight;
878 }
879 if (iRect->fBottom > clamp.fBottom) {
880 iRect->fBottom = clamp.fBottom;
881 }
882}
883
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +0000884// Break 'bitmap' into several tiles to draw it since it has already
885// been determined to be too large to fit in VRAM
886void SkGpuDevice::drawTiledBitmap(const SkBitmap& bitmap,
joshualitt5531d512014-12-17 15:50:11 -0800887 const SkMatrix& viewMatrix,
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +0000888 const SkRect& srcRect,
889 const SkIRect& clippedSrcIRect,
890 const GrTextureParams& params,
bsalomonc55271f2015-11-09 11:55:57 -0800891 const SkPaint& origPaint,
reeda5517e22015-07-14 10:54:12 -0700892 SkCanvas::SrcRectConstraint constraint,
commit-bot@chromium.orgdec61502013-12-02 22:22:35 +0000893 int tileSize,
894 bool bicubic) {
joshualittce894002016-01-11 13:29:31 -0800895 ASSERT_SINGLE_OWNER
ericrk369e9372016-02-05 15:32:36 -0800896
ericrk983294f2016-04-18 09:14:00 -0700897 // This is the funnel for all paths that draw tiled bitmaps/images. Log histogram entries.
ericrk369e9372016-02-05 15:32:36 -0800898 SK_HISTOGRAM_BOOLEAN("DrawTiled", true);
ericrk983294f2016-04-18 09:14:00 -0700899 LogDrawScaleFactor(viewMatrix, origPaint.getFilterQuality());
ericrk369e9372016-02-05 15:32:36 -0800900
commit-bot@chromium.org9d5e3f12014-05-01 21:23:19 +0000901 // The following pixel lock is technically redundant, but it is desirable
902 // to lock outside of the tile loop to prevent redecoding the whole image
903 // at each tile in cases where 'bitmap' holds an SkDiscardablePixelRef that
904 // is larger than the limit of the discardable memory pool.
905 SkAutoLockPixels alp(bitmap);
bsalomonc55271f2015-11-09 11:55:57 -0800906
907 const SkPaint* paint = &origPaint;
908 SkPaint tempPaint;
robertphillips071457b2016-05-16 09:50:03 -0700909 if (origPaint.isAntiAlias() && !fDrawContext->isUnifiedMultisampled()) {
bsalomonc55271f2015-11-09 11:55:57 -0800910 // Drop antialiasing to avoid seams at tile boundaries.
911 tempPaint = origPaint;
912 tempPaint.setAntiAlias(false);
913 paint = &tempPaint;
914 }
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +0000915 SkRect clippedSrcRect = SkRect::Make(clippedSrcIRect);
916
917 int nx = bitmap.width() / tileSize;
918 int ny = bitmap.height() / tileSize;
919 for (int x = 0; x <= nx; x++) {
920 for (int y = 0; y <= ny; y++) {
921 SkRect tileR;
922 tileR.set(SkIntToScalar(x * tileSize),
923 SkIntToScalar(y * tileSize),
924 SkIntToScalar((x + 1) * tileSize),
925 SkIntToScalar((y + 1) * tileSize));
926
927 if (!SkRect::Intersects(tileR, clippedSrcRect)) {
928 continue;
929 }
930
931 if (!tileR.intersect(srcRect)) {
932 continue;
933 }
934
935 SkBitmap tmpB;
936 SkIRect iTileR;
937 tileR.roundOut(&iTileR);
938 SkPoint offset = SkPoint::Make(SkIntToScalar(iTileR.fLeft),
939 SkIntToScalar(iTileR.fTop));
940
commit-bot@chromium.orga7d89c82014-01-13 14:47:00 +0000941 // Adjust the context matrix to draw at the right x,y in device space
joshualitt5531d512014-12-17 15:50:11 -0800942 SkMatrix viewM = viewMatrix;
commit-bot@chromium.orga7d89c82014-01-13 14:47:00 +0000943 SkMatrix tmpM;
commit-bot@chromium.orga7d89c82014-01-13 14:47:00 +0000944 tmpM.setTranslate(offset.fX - srcRect.fLeft, offset.fY - srcRect.fTop);
joshualitt5531d512014-12-17 15:50:11 -0800945 viewM.preConcat(tmpM);
commit-bot@chromium.orga7d89c82014-01-13 14:47:00 +0000946
robertphillipsec8bb942014-11-21 10:16:25 -0800947 if (GrTextureParams::kNone_FilterMode != params.filterMode() || bicubic) {
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +0000948 SkIRect iClampRect;
949
reeda5517e22015-07-14 10:54:12 -0700950 if (SkCanvas::kFast_SrcRectConstraint == constraint) {
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +0000951 // In bleed mode we want to always expand the tile on all edges
952 // but stay within the bitmap bounds
953 iClampRect = SkIRect::MakeWH(bitmap.width(), bitmap.height());
954 } else {
955 // In texture-domain/clamp mode we only want to expand the
956 // tile on edges interior to "srcRect" (i.e., we want to
957 // not bleed across the original clamped edges)
958 srcRect.roundOut(&iClampRect);
959 }
commit-bot@chromium.orgdec61502013-12-02 22:22:35 +0000960 int outset = bicubic ? GrBicubicEffect::kFilterTexelPad : 1;
961 clamped_outset_with_offset(&iTileR, outset, &offset, iClampRect);
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +0000962 }
963
964 if (bitmap.extractSubset(&tmpB, iTileR)) {
965 // now offset it to make it "local" to our tmp bitmap
966 tileR.offset(-offset.fX, -offset.fY);
commit-bot@chromium.orga17773f2014-05-09 13:53:38 +0000967 GrTextureParams paramsTemp = params;
bsalomonb1b01992015-11-18 10:56:08 -0800968 // de-optimized this determination
969 bool needsTextureDomain = true;
commit-bot@chromium.orga17773f2014-05-09 13:53:38 +0000970 this->internalDrawBitmap(tmpB,
joshualitt5531d512014-12-17 15:50:11 -0800971 viewM,
commit-bot@chromium.orga17773f2014-05-09 13:53:38 +0000972 tileR,
973 paramsTemp,
bsalomonc55271f2015-11-09 11:55:57 -0800974 *paint,
reeda5517e22015-07-14 10:54:12 -0700975 constraint,
commit-bot@chromium.orga17773f2014-05-09 13:53:38 +0000976 bicubic,
977 needsTextureDomain);
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +0000978 }
979 }
980 }
981}
982
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +0000983/*
984 * This is called by drawBitmap(), which has to handle images that may be too
985 * large to be represented by a single texture.
986 *
987 * internalDrawBitmap assumes that the specified bitmap will fit in a texture
988 * and that non-texture portion of the GrPaint has already been setup.
989 */
990void SkGpuDevice::internalDrawBitmap(const SkBitmap& bitmap,
joshualitt5531d512014-12-17 15:50:11 -0800991 const SkMatrix& viewMatrix,
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +0000992 const SkRect& srcRect,
993 const GrTextureParams& params,
994 const SkPaint& paint,
reeda5517e22015-07-14 10:54:12 -0700995 SkCanvas::SrcRectConstraint constraint,
commit-bot@chromium.orga17773f2014-05-09 13:53:38 +0000996 bool bicubic,
997 bool needsTextureDomain) {
bsalomon9c586542015-11-02 12:33:21 -0800998 // We should have already handled bitmaps larger than the max texture size.
999 SkASSERT(bitmap.width() <= fContext->caps()->maxTextureSize() &&
1000 bitmap.height() <= fContext->caps()->maxTextureSize());
reedc7ec7c92016-07-25 08:29:10 -07001001 // We should be respecting the max tile size by the time we get here.
1002 SkASSERT(bitmap.width() <= fContext->caps()->maxTileSize() &&
1003 bitmap.height() <= fContext->caps()->maxTileSize());
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +00001004
brianosman8fe485b2016-07-25 12:31:51 -07001005 sk_sp<GrTexture> texture = GrMakeCachedBitmapTexture(fContext, bitmap, params,
1006 fDrawContext->sourceGammaTreatment());
halcanary96fcdcc2015-08-27 07:41:13 -07001007 if (nullptr == texture) {
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +00001008 return;
1009 }
1010
brianosman500bb3e2016-07-22 10:33:07 -07001011 sk_sp<GrColorSpaceXform> colorSpaceXform =
1012 GrColorSpaceXform::Make(bitmap.colorSpace(), fDrawContext->getColorSpace());
commit-bot@chromium.orga7d89c82014-01-13 14:47:00 +00001013 SkRect dstRect = {0, 0, srcRect.width(), srcRect.height() };
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +00001014 SkRect paintRect;
1015 SkScalar wInv = SkScalarInvert(SkIntToScalar(texture->width()));
1016 SkScalar hInv = SkScalarInvert(SkIntToScalar(texture->height()));
1017 paintRect.setLTRB(SkScalarMul(srcRect.fLeft, wInv),
1018 SkScalarMul(srcRect.fTop, hInv),
1019 SkScalarMul(srcRect.fRight, wInv),
1020 SkScalarMul(srcRect.fBottom, hInv));
1021
egdaniel79da63f2015-10-09 10:55:16 -07001022 SkMatrix texMatrix;
1023 texMatrix.reset();
1024 if (kAlpha_8_SkColorType == bitmap.colorType() && paint.getShader()) {
1025 // In cases where we are doing an A8 bitmap draw with a shader installed, we cannot use
1026 // local coords with the bitmap draw since it may mess up texture look ups for the shader.
1027 // Thus we need to pass in the transform matrix directly to the texture processor used for
1028 // the bitmap draw.
1029 texMatrix.setScale(wInv, hInv);
1030 }
1031
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +00001032 SkRect textureDomain = SkRect::MakeEmpty();
joshualitt5f10b5c2015-07-09 10:24:35 -07001033
1034 // Construct a GrPaint by setting the bitmap texture as the first effect and then configuring
1035 // the rest from the SkPaint.
bungeman06ca8ec2016-06-09 08:01:03 -07001036 sk_sp<GrFragmentProcessor> fp;
joshualitt5f10b5c2015-07-09 10:24:35 -07001037
reeda5517e22015-07-14 10:54:12 -07001038 if (needsTextureDomain && (SkCanvas::kStrict_SrcRectConstraint == constraint)) {
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +00001039 // Use a constrained texture domain to avoid color bleeding
1040 SkScalar left, top, right, bottom;
1041 if (srcRect.width() > SK_Scalar1) {
1042 SkScalar border = SK_ScalarHalf / texture->width();
1043 left = paintRect.left() + border;
1044 right = paintRect.right() - border;
1045 } else {
1046 left = right = SkScalarHalf(paintRect.left() + paintRect.right());
1047 }
1048 if (srcRect.height() > SK_Scalar1) {
1049 SkScalar border = SK_ScalarHalf / texture->height();
1050 top = paintRect.top() + border;
1051 bottom = paintRect.bottom() - border;
1052 } else {
1053 top = bottom = SkScalarHalf(paintRect.top() + paintRect.bottom());
1054 }
1055 textureDomain.setLTRB(left, top, right, bottom);
commit-bot@chromium.org7d7f3142013-12-16 15:18:11 +00001056 if (bicubic) {
reedc7ec7c92016-07-25 08:29:10 -07001057 fp = GrBicubicEffect::Make(texture.get(), std::move(colorSpaceXform), texMatrix,
brianosman54f30c12016-07-18 10:53:52 -07001058 textureDomain);
commit-bot@chromium.org7d7f3142013-12-16 15:18:11 +00001059 } else {
reedc7ec7c92016-07-25 08:29:10 -07001060 fp = GrTextureDomainEffect::Make(texture.get(), std::move(colorSpaceXform), texMatrix,
brianosman54f30c12016-07-18 10:53:52 -07001061 textureDomain, GrTextureDomain::kClamp_Mode,
1062 params.filterMode());
commit-bot@chromium.org7d7f3142013-12-16 15:18:11 +00001063 }
commit-bot@chromium.orgdec61502013-12-02 22:22:35 +00001064 } else if (bicubic) {
commit-bot@chromium.orgbc91fd72013-12-10 12:53:39 +00001065 SkASSERT(GrTextureParams::kNone_FilterMode == params.filterMode());
1066 SkShader::TileMode tileModes[2] = { params.getTileModeX(), params.getTileModeY() };
reedc7ec7c92016-07-25 08:29:10 -07001067 fp = GrBicubicEffect::Make(texture.get(), std::move(colorSpaceXform), texMatrix, tileModes);
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +00001068 } else {
reedc7ec7c92016-07-25 08:29:10 -07001069 fp = GrSimpleTextureEffect::Make(texture.get(), std::move(colorSpaceXform), texMatrix, params);
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +00001070 }
1071
joshualitt33a5fce2015-11-18 13:28:51 -08001072 GrPaint grPaint;
brianosman8fe485b2016-07-25 12:31:51 -07001073 if (!SkPaintToGrPaintWithTexture(this->context(), fDrawContext.get(), paint, viewMatrix,
1074 std::move(fp), kAlpha_8_SkColorType == bitmap.colorType(),
1075 &grPaint)) {
bsalomonbed83a62015-04-15 14:18:34 -07001076 return;
1077 }
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +00001078
egdaniel79da63f2015-10-09 10:55:16 -07001079 if (kAlpha_8_SkColorType == bitmap.colorType() && paint.getShader()) {
1080 // We don't have local coords in this case and have previously set the transform
1081 // matrices directly on the texture processor.
robertphillips2e1e51f2015-10-15 08:01:48 -07001082 fDrawContext->drawRect(fClip, grPaint, viewMatrix, dstRect);
egdaniel79da63f2015-10-09 10:55:16 -07001083 } else {
bsalomona2e69fc2015-11-05 10:41:43 -08001084 fDrawContext->fillRectToRect(fClip, grPaint, viewMatrix, dstRect, paintRect);
egdaniel79da63f2015-10-09 10:55:16 -07001085 }
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +00001086}
1087
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +00001088void SkGpuDevice::drawSprite(const SkDraw& draw, const SkBitmap& bitmap,
1089 int left, int top, const SkPaint& paint) {
joshualittce894002016-01-11 13:29:31 -08001090 ASSERT_SINGLE_OWNER
joshualitt5531d512014-12-17 15:50:11 -08001091 CHECK_SHOULD_DRAW(draw);
robertphillips970587b2016-07-14 14:12:55 -07001092 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawSprite", fContext);
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +00001093
robertphillips970587b2016-07-14 14:12:55 -07001094 if (fContext->abandoned()) {
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +00001095 return;
1096 }
1097
reedc7ec7c92016-07-25 08:29:10 -07001098 sk_sp<GrTexture> texture;
1099 {
robertphillips970587b2016-07-14 14:12:55 -07001100 SkAutoLockPixels alp(bitmap, true);
1101 if (!bitmap.readyToDraw()) {
1102 return;
1103 }
1104
1105 // draw sprite neither filters nor tiles.
1106 texture.reset(GrRefCachedBitmapTexture(fContext, bitmap,
1107 GrTextureParams::ClampNoFilter(),
1108 SkSourceGammaTreatment::kRespect));
1109 if (!texture) {
1110 return;
1111 }
joshualitt5f5a8d72015-02-25 14:09:45 -08001112 }
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +00001113
robertphillips970587b2016-07-14 14:12:55 -07001114 SkIRect srcRect = SkIRect::MakeXYWH(bitmap.pixelRefOrigin().fX,
1115 bitmap.pixelRefOrigin().fY,
1116 bitmap.width(),
1117 bitmap.height());
bsalomonf1b7a1d2015-09-28 06:26:28 -07001118
robertphillips970587b2016-07-14 14:12:55 -07001119 sk_sp<SkSpecialImage> srcImg(SkSpecialImage::MakeFromGpu(srcRect,
1120 bitmap.getGenerationID(),
brianosmanafbf71d2016-07-21 07:15:37 -07001121 std::move(texture),
1122 sk_ref_sp(bitmap.colorSpace()),
robertphillips1b5f9682016-07-15 08:01:12 -07001123 &this->surfaceProps()));
robertphillips970587b2016-07-14 14:12:55 -07001124
1125 this->drawSpecial(draw, srcImg.get(), left, top, paint);
1126}
1127
1128
1129void SkGpuDevice::drawSpecial(const SkDraw& draw,
1130 SkSpecialImage* special1,
1131 int left, int top,
1132 const SkPaint& paint) {
robertphillips1b5f9682016-07-15 08:01:12 -07001133 ASSERT_SINGLE_OWNER
1134 CHECK_SHOULD_DRAW(draw);
1135 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawSpecial", fContext);
robertphillips970587b2016-07-14 14:12:55 -07001136
1137 SkIPoint offset = { 0, 0 };
1138
1139 sk_sp<SkSpecialImage> result;
1140 if (paint.getImageFilter()) {
1141 result = this->filterTexture(draw, special1, left, top,
1142 &offset,
1143 paint.getImageFilter());
1144 if (!result) {
1145 return;
1146 }
1147 } else {
1148 result = sk_ref_sp(special1);
1149 }
1150
1151 SkASSERT(result->isTextureBacked());
1152 sk_sp<GrTexture> texture = result->asTextureRef(fContext);
1153
1154 SkPaint tmpUnfiltered(paint);
1155 tmpUnfiltered.setImageFilter(nullptr);
1156
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +00001157 GrPaint grPaint;
brianosman54f30c12016-07-18 10:53:52 -07001158 sk_sp<GrFragmentProcessor> fp(GrSimpleTextureEffect::Make(texture.get(), nullptr,
1159 SkMatrix::I()));
robertphillips1b5f9682016-07-15 08:01:12 -07001160 if (GrPixelConfigIsAlphaOnly(texture->config())) {
bungeman06ca8ec2016-06-09 08:01:03 -07001161 fp = GrFragmentProcessor::MulOutputByInputUnpremulColor(std::move(fp));
bsalomonf1b7a1d2015-09-28 06:26:28 -07001162 } else {
bungeman06ca8ec2016-06-09 08:01:03 -07001163 fp = GrFragmentProcessor::MulOutputByInputAlpha(std::move(fp));
bsalomonf1b7a1d2015-09-28 06:26:28 -07001164 }
brianosman8fe485b2016-07-25 12:31:51 -07001165 if (!SkPaintToGrPaintReplaceShader(this->context(), fDrawContext.get(), tmpUnfiltered,
1166 std::move(fp), &grPaint)) {
bsalomonbed83a62015-04-15 14:18:34 -07001167 return;
1168 }
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +00001169
robertphillips970587b2016-07-14 14:12:55 -07001170 const SkIRect& subset = result->subset();
1171
bsalomona2e69fc2015-11-05 10:41:43 -08001172 fDrawContext->fillRectToRect(fClip,
1173 grPaint,
1174 SkMatrix::I(),
robertphillips970587b2016-07-14 14:12:55 -07001175 SkRect::Make(SkIRect::MakeXYWH(left + offset.fX, top + offset.fY,
1176 subset.width(), subset.height())),
1177 SkRect::MakeXYWH(SkIntToScalar(subset.fLeft) / texture->width(),
1178 SkIntToScalar(subset.fTop) / texture->height(),
1179 SkIntToScalar(subset.width()) / texture->width(),
1180 SkIntToScalar(subset.height()) / texture->height()));
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +00001181}
1182
bsalomonb1b01992015-11-18 10:56:08 -08001183void SkGpuDevice::drawBitmapRect(const SkDraw& draw, const SkBitmap& bitmap,
1184 const SkRect* src, const SkRect& origDst,
reed562fe472015-07-28 07:35:14 -07001185 const SkPaint& paint, SkCanvas::SrcRectConstraint constraint) {
joshualittce894002016-01-11 13:29:31 -08001186 ASSERT_SINGLE_OWNER
lsalzman973ed242016-01-14 13:06:41 -08001187 CHECK_SHOULD_DRAW(draw);
reedc7ec7c92016-07-25 08:29:10 -07001188
bsalomonb1b01992015-11-18 10:56:08 -08001189 // The src rect is inferred to be the bmp bounds if not provided. Otherwise, the src rect must
1190 // be clipped to the bmp bounds. To determine tiling parameters we need the filter mode which
1191 // in turn requires knowing the src-to-dst mapping. If the src was clipped to the bmp bounds
1192 // then we use the src-to-dst mapping to compute a new clipped dst rect.
1193 const SkRect* dst = &origDst;
1194 const SkRect bmpBounds = SkRect::MakeIWH(bitmap.width(), bitmap.height());
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +00001195 // Compute matrix from the two rectangles
bsalomonb1b01992015-11-18 10:56:08 -08001196 if (!src) {
1197 src = &bmpBounds;
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +00001198 }
commit-bot@chromium.orga7d89c82014-01-13 14:47:00 +00001199
bsalomonb1b01992015-11-18 10:56:08 -08001200 SkMatrix srcToDstMatrix;
1201 if (!srcToDstMatrix.setRectToRect(*src, *dst, SkMatrix::kFill_ScaleToFit)) {
1202 return;
1203 }
1204 SkRect tmpSrc, tmpDst;
1205 if (src != &bmpBounds) {
1206 if (!bmpBounds.contains(*src)) {
1207 tmpSrc = *src;
1208 if (!tmpSrc.intersect(bmpBounds)) {
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +00001209 return; // nothing to draw
1210 }
bsalomonb1b01992015-11-18 10:56:08 -08001211 src = &tmpSrc;
1212 srcToDstMatrix.mapRect(&tmpDst, *src);
1213 dst = &tmpDst;
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +00001214 }
1215 }
1216
bsalomonb1b01992015-11-18 10:56:08 -08001217 int maxTileSize = fContext->caps()->maxTileSize();
commit-bot@chromium.orga7d89c82014-01-13 14:47:00 +00001218
bsalomonb1b01992015-11-18 10:56:08 -08001219 // The tile code path doesn't currently support AA, so if the paint asked for aa and we could
1220 // draw untiled, then we bypass checking for tiling purely for optimization reasons.
robertphillips071457b2016-05-16 09:50:03 -07001221 bool drawAA = !fDrawContext->isUnifiedMultisampled() &&
bsalomonb1b01992015-11-18 10:56:08 -08001222 paint.isAntiAlias() &&
1223 bitmap.width() <= maxTileSize &&
1224 bitmap.height() <= maxTileSize;
1225
1226 bool skipTileCheck = drawAA || paint.getMaskFilter();
1227
1228 if (!skipTileCheck) {
1229 int tileSize;
1230 SkIRect clippedSrcRect;
1231
1232 GrTextureParams params;
1233 bool doBicubic;
1234 GrTextureParams::FilterMode textureFilterMode =
1235 GrSkFilterQualityToGrFilterMode(paint.getFilterQuality(), *draw.fMatrix, srcToDstMatrix,
1236 &doBicubic);
1237
1238 int tileFilterPad;
1239
1240 if (doBicubic) {
1241 tileFilterPad = GrBicubicEffect::kFilterTexelPad;
1242 } else if (GrTextureParams::kNone_FilterMode == textureFilterMode) {
1243 tileFilterPad = 0;
1244 } else {
1245 tileFilterPad = 1;
1246 }
1247 params.setFilterMode(textureFilterMode);
1248
1249 int maxTileSizeForFilter = fContext->caps()->maxTileSize() - 2 * tileFilterPad;
1250 // Fold the dst rect into the view matrix. This is only OK because we don't get here if
1251 // we have a mask filter.
1252 SkMatrix viewMatrix = *draw.fMatrix;
1253 viewMatrix.preTranslate(dst->fLeft, dst->fTop);
1254 viewMatrix.preScale(dst->width()/src->width(), dst->height()/src->height());
1255 if (this->shouldTileBitmap(bitmap, viewMatrix, params, src,
1256 maxTileSizeForFilter, &tileSize, &clippedSrcRect)) {
1257 this->drawTiledBitmap(bitmap, viewMatrix, *src, clippedSrcRect, params, paint,
1258 constraint, tileSize, doBicubic);
1259 return;
1260 }
commit-bot@chromium.orga7d89c82014-01-13 14:47:00 +00001261 }
bsalomonb1b01992015-11-18 10:56:08 -08001262 GrBitmapTextureMaker maker(fContext, bitmap);
bsalomonf1ecd212015-12-09 17:06:02 -08001263 this->drawTextureProducer(&maker, src, dst, constraint, *draw.fMatrix, fClip, paint);
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +00001264}
1265
robertphillips6451a0c2016-07-18 08:31:31 -07001266sk_sp<SkSpecialImage> SkGpuDevice::makeSpecial(const SkBitmap& bitmap) {
robertphillips6451a0c2016-07-18 08:31:31 -07001267 SkAutoLockPixels alp(bitmap, true);
1268 if (!bitmap.readyToDraw()) {
1269 return nullptr;
1270 }
1271
reedc7ec7c92016-07-25 08:29:10 -07001272 sk_sp<GrTexture> texture = GrMakeCachedBitmapTexture(fContext, bitmap,
1273 GrTextureParams::ClampNoFilter(),
1274 SkSourceGammaTreatment::kRespect);
robertphillips6451a0c2016-07-18 08:31:31 -07001275 if (!texture) {
1276 return nullptr;
1277 }
1278
1279 return SkSpecialImage::MakeFromGpu(bitmap.bounds(),
1280 bitmap.getGenerationID(),
reedc7ec7c92016-07-25 08:29:10 -07001281 texture,
brianosmanafbf71d2016-07-21 07:15:37 -07001282 sk_ref_sp(bitmap.colorSpace()),
robertphillips6451a0c2016-07-18 08:31:31 -07001283 &this->surfaceProps());
1284}
1285
reede51c3562016-07-19 14:33:20 -07001286sk_sp<SkSpecialImage> SkGpuDevice::makeSpecial(const SkImage* image) {
robertphillips6451a0c2016-07-18 08:31:31 -07001287 SkPixmap pm;
1288 if (image->isTextureBacked()) {
1289 GrTexture* texture = as_IB(image)->peekTexture();
1290
1291 return SkSpecialImage::MakeFromGpu(SkIRect::MakeWH(image->width(), image->height()),
1292 image->uniqueID(),
brianosmanafbf71d2016-07-21 07:15:37 -07001293 sk_ref_sp(texture),
1294 sk_ref_sp(as_IB(image)->onImageInfo().colorSpace()),
robertphillips6451a0c2016-07-18 08:31:31 -07001295 &this->surfaceProps());
1296 } else if (image->peekPixels(&pm)) {
1297 SkBitmap bm;
1298
1299 bm.installPixels(pm);
1300 return this->makeSpecial(bm);
1301 } else {
1302 return nullptr;
1303 }
1304}
1305
1306sk_sp<SkSpecialImage> SkGpuDevice::snapSpecial() {
robertphillips1b5f9682016-07-15 08:01:12 -07001307 sk_sp<GrTexture> texture(this->accessDrawContext()->asTexture());
1308 if (!texture) {
robertphillips04d62182016-07-15 12:21:33 -07001309 // When the device doesn't have a texture, we create a temporary texture.
1310 // TODO: we should actually only copy the portion of the source needed to apply the image
1311 // filter
1312 texture.reset(fContext->textureProvider()->createTexture(this->accessDrawContext()->desc(),
1313 SkBudgeted::kYes));
1314 if (!texture) {
1315 return nullptr;
1316 }
1317
reede51c3562016-07-19 14:33:20 -07001318 if (!fContext->copySurface(texture.get(), this->accessDrawContext()->accessRenderTarget())){
robertphillips04d62182016-07-15 12:21:33 -07001319 return nullptr;
1320 }
robertphillips1b5f9682016-07-15 08:01:12 -07001321 }
1322
1323 const SkImageInfo ii = this->imageInfo();
1324 const SkIRect srcRect = SkIRect::MakeWH(ii.width(), ii.height());
1325
1326 return SkSpecialImage::MakeFromGpu(srcRect,
1327 kNeedNewImageUniqueID_SpecialImage,
brianosmanafbf71d2016-07-21 07:15:37 -07001328 std::move(texture),
1329 sk_ref_sp(ii.colorSpace()),
robertphillips1b5f9682016-07-15 08:01:12 -07001330 &this->surfaceProps());
1331}
1332
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +00001333void SkGpuDevice::drawDevice(const SkDraw& draw, SkBaseDevice* device,
robertphillips1b5f9682016-07-15 08:01:12 -07001334 int left, int top, const SkPaint& paint) {
reedcf5c8462016-07-20 12:28:40 -07001335 SkASSERT(!paint.getImageFilter());
1336
joshualittce894002016-01-11 13:29:31 -08001337 ASSERT_SINGLE_OWNER
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +00001338 // clear of the source device must occur before CHECK_SHOULD_DRAW
joshualitt5651ee62016-01-11 10:39:11 -08001339 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawDevice", fContext);
kkinnunen2e4414e2015-02-19 07:20:40 -08001340
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +00001341 // drawDevice is defined to be in device coords.
joshualitt5531d512014-12-17 15:50:11 -08001342 CHECK_SHOULD_DRAW(draw);
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +00001343
robertphillips1b5f9682016-07-15 08:01:12 -07001344 SkGpuDevice* dev = static_cast<SkGpuDevice*>(device);
robertphillips6451a0c2016-07-18 08:31:31 -07001345 sk_sp<SkSpecialImage> srcImg(dev->snapSpecial());
robertphillips1b5f9682016-07-15 08:01:12 -07001346 if (!srcImg) {
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +00001347 return;
1348 }
1349
robertphillips1b5f9682016-07-15 08:01:12 -07001350 this->drawSpecial(draw, srcImg.get(), left, top, paint);
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +00001351}
1352
reeda85d4d02015-05-06 12:56:48 -07001353void SkGpuDevice::drawImage(const SkDraw& draw, const SkImage* image, SkScalar x, SkScalar y,
1354 const SkPaint& paint) {
joshualittce894002016-01-11 13:29:31 -08001355 ASSERT_SINGLE_OWNER
bsalomon1cf6f9b2015-12-08 10:53:43 -08001356 SkMatrix viewMatrix = *draw.fMatrix;
1357 viewMatrix.preTranslate(x, y);
bsalomonf1ecd212015-12-09 17:06:02 -08001358 if (as_IB(image)->peekTexture()) {
bsalomonc55271f2015-11-09 11:55:57 -08001359 CHECK_SHOULD_DRAW(draw);
bsalomonc55271f2015-11-09 11:55:57 -08001360 GrImageTextureAdjuster adjuster(as_IB(image));
bsalomonf1ecd212015-12-09 17:06:02 -08001361 this->drawTextureProducer(&adjuster, nullptr, nullptr, SkCanvas::kFast_SrcRectConstraint,
1362 viewMatrix, fClip, paint);
bsalomonc55271f2015-11-09 11:55:57 -08001363 return;
reed85d91782015-09-10 14:33:38 -07001364 } else {
bsalomon1cf6f9b2015-12-08 10:53:43 -08001365 SkBitmap bm;
reed85d91782015-09-10 14:33:38 -07001366 if (this->shouldTileImage(image, nullptr, SkCanvas::kFast_SrcRectConstraint,
1367 paint.getFilterQuality(), *draw.fMatrix)) {
1368 // only support tiling as bitmap at the moment, so force raster-version
1369 if (!as_IB(image)->getROPixels(&bm)) {
1370 return;
1371 }
bsalomon1cf6f9b2015-12-08 10:53:43 -08001372 this->drawBitmap(draw, bm, SkMatrix::MakeTrans(x, y), paint);
1373 } else if (SkImageCacherator* cacher = as_IB(image)->peekCacherator()) {
1374 CHECK_SHOULD_DRAW(draw);
1375 GrImageTextureMaker maker(fContext, cacher, image, SkImage::kAllow_CachingHint);
bsalomonf1ecd212015-12-09 17:06:02 -08001376 this->drawTextureProducer(&maker, nullptr, nullptr, SkCanvas::kFast_SrcRectConstraint,
1377 viewMatrix, fClip, paint);
bsalomon1cf6f9b2015-12-08 10:53:43 -08001378 } else if (as_IB(image)->getROPixels(&bm)) {
1379 this->drawBitmap(draw, bm, SkMatrix::MakeTrans(x, y), paint);
reed85d91782015-09-10 14:33:38 -07001380 }
reeda85d4d02015-05-06 12:56:48 -07001381 }
1382}
1383
1384void SkGpuDevice::drawImageRect(const SkDraw& draw, const SkImage* image, const SkRect* src,
reeda5517e22015-07-14 10:54:12 -07001385 const SkRect& dst, const SkPaint& paint,
1386 SkCanvas::SrcRectConstraint constraint) {
joshualittce894002016-01-11 13:29:31 -08001387 ASSERT_SINGLE_OWNER
bsalomonf1ecd212015-12-09 17:06:02 -08001388 if (as_IB(image)->peekTexture()) {
bsalomonc55271f2015-11-09 11:55:57 -08001389 CHECK_SHOULD_DRAW(draw);
1390 GrImageTextureAdjuster adjuster(as_IB(image));
bsalomonf1ecd212015-12-09 17:06:02 -08001391 this->drawTextureProducer(&adjuster, src, &dst, constraint, *draw.fMatrix, fClip, paint);
bsalomonc55271f2015-11-09 11:55:57 -08001392 return;
1393 }
1394 SkBitmap bm;
bsalomon1cf6f9b2015-12-08 10:53:43 -08001395 SkMatrix totalMatrix = *draw.fMatrix;
1396 totalMatrix.preScale(dst.width() / (src ? src->width() : image->width()),
1397 dst.height() / (src ? src->height() : image->height()));
1398 if (this->shouldTileImage(image, src, constraint, paint.getFilterQuality(), totalMatrix)) {
bsalomonc55271f2015-11-09 11:55:57 -08001399 // only support tiling as bitmap at the moment, so force raster-version
1400 if (!as_IB(image)->getROPixels(&bm)) {
1401 return;
1402 }
bsalomon1cf6f9b2015-12-08 10:53:43 -08001403 this->drawBitmapRect(draw, bm, src, dst, paint, constraint);
1404 } else if (SkImageCacherator* cacher = as_IB(image)->peekCacherator()) {
1405 CHECK_SHOULD_DRAW(draw);
1406 GrImageTextureMaker maker(fContext, cacher, image, SkImage::kAllow_CachingHint);
bsalomonf1ecd212015-12-09 17:06:02 -08001407 this->drawTextureProducer(&maker, src, &dst, constraint, *draw.fMatrix, fClip, paint);
bsalomon1cf6f9b2015-12-08 10:53:43 -08001408 } else if (as_IB(image)->getROPixels(&bm)) {
1409 this->drawBitmapRect(draw, bm, src, dst, paint, constraint);
reeda85d4d02015-05-06 12:56:48 -07001410 }
bsalomon1cf6f9b2015-12-08 10:53:43 -08001411}
1412
bsalomonf1ecd212015-12-09 17:06:02 -08001413void SkGpuDevice::drawProducerNine(const SkDraw& draw, GrTextureProducer* producer,
bsalomon2bbd0c62015-12-09 12:50:56 -08001414 const SkIRect& center, const SkRect& dst, const SkPaint& paint) {
joshualitt5651ee62016-01-11 10:39:11 -08001415 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawProducerNine", fContext);
joshualitt33a5fce2015-11-18 13:28:51 -08001416
joshualitt33a5fce2015-11-18 13:28:51 -08001417 CHECK_SHOULD_DRAW(draw);
1418
joshualittedb36442015-11-19 14:29:30 -08001419 bool useFallback = paint.getMaskFilter() || paint.isAntiAlias() ||
robertphillips071457b2016-05-16 09:50:03 -07001420 fDrawContext->isUnifiedMultisampled();
joshualitt33a5fce2015-11-18 13:28:51 -08001421 bool doBicubic;
1422 GrTextureParams::FilterMode textureFilterMode =
bsalomon2bbd0c62015-12-09 12:50:56 -08001423 GrSkFilterQualityToGrFilterMode(paint.getFilterQuality(), *draw.fMatrix, SkMatrix::I(),
1424 &doBicubic);
joshualitt33a5fce2015-11-18 13:28:51 -08001425 if (useFallback || doBicubic || GrTextureParams::kNone_FilterMode != textureFilterMode) {
msarettc573a402016-08-02 08:05:56 -07001426 SkLatticeIter iter(producer->width(), producer->height(), center, dst);
joshualitt33a5fce2015-11-18 13:28:51 -08001427
1428 SkRect srcR, dstR;
1429 while (iter.next(&srcR, &dstR)) {
erikchen9a1ed5d2016-02-10 16:32:34 -08001430 this->drawTextureProducer(producer, &srcR, &dstR, SkCanvas::kStrict_SrcRectConstraint,
bsalomonf1ecd212015-12-09 17:06:02 -08001431 *draw.fMatrix, fClip, paint);
joshualitt33a5fce2015-11-18 13:28:51 -08001432 }
1433 return;
1434 }
1435
bsalomon2bbd0c62015-12-09 12:50:56 -08001436 static const GrTextureParams::FilterMode kMode = GrTextureParams::kNone_FilterMode;
bungeman06ca8ec2016-06-09 08:01:03 -07001437 sk_sp<GrFragmentProcessor> fp(
bsalomon2bbd0c62015-12-09 12:50:56 -08001438 producer->createFragmentProcessor(SkMatrix::I(),
1439 SkRect::MakeIWH(producer->width(), producer->height()),
1440 GrTextureProducer::kNo_FilterConstraint, true,
brianosman8fe485b2016-07-25 12:31:51 -07001441 &kMode, fDrawContext->getColorSpace(),
1442 fDrawContext->sourceGammaTreatment()));
joshualitt33a5fce2015-11-18 13:28:51 -08001443 GrPaint grPaint;
brianosman8fe485b2016-07-25 12:31:51 -07001444 if (!SkPaintToGrPaintWithTexture(this->context(), fDrawContext.get(), paint, *draw.fMatrix,
1445 std::move(fp), producer->isAlphaOnly(), &grPaint)) {
joshualitt33a5fce2015-11-18 13:28:51 -08001446 return;
1447 }
1448
bsalomon2bbd0c62015-12-09 12:50:56 -08001449 fDrawContext->drawImageNine(fClip, grPaint, *draw.fMatrix, producer->width(),
1450 producer->height(), center, dst);
1451}
1452
1453void SkGpuDevice::drawImageNine(const SkDraw& draw, const SkImage* image,
1454 const SkIRect& center, const SkRect& dst, const SkPaint& paint) {
joshualittce894002016-01-11 13:29:31 -08001455 ASSERT_SINGLE_OWNER
bsalomonf1ecd212015-12-09 17:06:02 -08001456 if (as_IB(image)->peekTexture()) {
bsalomon2bbd0c62015-12-09 12:50:56 -08001457 GrImageTextureAdjuster adjuster(as_IB(image));
bsalomonf1ecd212015-12-09 17:06:02 -08001458 this->drawProducerNine(draw, &adjuster, center, dst, paint);
bsalomon2bbd0c62015-12-09 12:50:56 -08001459 } else {
1460 SkBitmap bm;
1461 if (SkImageCacherator* cacher = as_IB(image)->peekCacherator()) {
1462 GrImageTextureMaker maker(fContext, cacher, image, SkImage::kAllow_CachingHint);
bsalomonf1ecd212015-12-09 17:06:02 -08001463 this->drawProducerNine(draw, &maker, center, dst, paint);
bsalomon2bbd0c62015-12-09 12:50:56 -08001464 } else if (as_IB(image)->getROPixels(&bm)) {
1465 this->drawBitmapNine(draw, bm, center, dst, paint);
1466 }
1467 }
1468}
1469
1470void SkGpuDevice::drawBitmapNine(const SkDraw& draw, const SkBitmap& bitmap, const SkIRect& center,
1471 const SkRect& dst, const SkPaint& paint) {
joshualittce894002016-01-11 13:29:31 -08001472 ASSERT_SINGLE_OWNER
reedc7ec7c92016-07-25 08:29:10 -07001473 GrBitmapTextureMaker maker(fContext, bitmap);
1474 this->drawProducerNine(draw, &maker, center, dst, paint);
joshualitt33a5fce2015-11-18 13:28:51 -08001475}
1476
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +00001477///////////////////////////////////////////////////////////////////////////////
1478
1479// must be in SkCanvas::VertexMode order
1480static const GrPrimitiveType gVertexMode2PrimitiveType[] = {
1481 kTriangles_GrPrimitiveType,
1482 kTriangleStrip_GrPrimitiveType,
1483 kTriangleFan_GrPrimitiveType,
1484};
1485
1486void SkGpuDevice::drawVertices(const SkDraw& draw, SkCanvas::VertexMode vmode,
1487 int vertexCount, const SkPoint vertices[],
1488 const SkPoint texs[], const SkColor colors[],
1489 SkXfermode* xmode,
1490 const uint16_t indices[], int indexCount,
1491 const SkPaint& paint) {
joshualittce894002016-01-11 13:29:31 -08001492 ASSERT_SINGLE_OWNER
joshualitt5531d512014-12-17 15:50:11 -08001493 CHECK_SHOULD_DRAW(draw);
joshualitt5651ee62016-01-11 10:39:11 -08001494 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawVertices", fContext);
mtklein533eb782014-08-27 10:39:42 -07001495
halcanary96fcdcc2015-08-27 07:41:13 -07001496 // If both textures and vertex-colors are nullptr, strokes hairlines with the paint's color.
1497 if ((nullptr == texs || nullptr == paint.getShader()) && nullptr == colors) {
mtklein533eb782014-08-27 10:39:42 -07001498
halcanary96fcdcc2015-08-27 07:41:13 -07001499 texs = nullptr;
mtklein533eb782014-08-27 10:39:42 -07001500
commit-bot@chromium.org559a8832014-05-30 10:08:22 +00001501 SkPaint copy(paint);
1502 copy.setStyle(SkPaint::kStroke_Style);
1503 copy.setStrokeWidth(0);
mtklein533eb782014-08-27 10:39:42 -07001504
bsalomonf1b7a1d2015-09-28 06:26:28 -07001505 GrPaint grPaint;
dandov32a311b2014-07-15 19:46:26 -07001506 // we ignore the shader if texs is null.
brianosman8fe485b2016-07-25 12:31:51 -07001507 if (!SkPaintToGrPaintNoShader(this->context(), fDrawContext.get(), copy, &grPaint)) {
bsalomonbed83a62015-04-15 14:18:34 -07001508 return;
1509 }
commit-bot@chromium.org559a8832014-05-30 10:08:22 +00001510
dandov32a311b2014-07-15 19:46:26 -07001511 int triangleCount = 0;
halcanary96fcdcc2015-08-27 07:41:13 -07001512 int n = (nullptr == indices) ? vertexCount : indexCount;
dandov32a311b2014-07-15 19:46:26 -07001513 switch (vmode) {
1514 case SkCanvas::kTriangles_VertexMode:
bsalomona098dd42014-08-06 11:01:44 -07001515 triangleCount = n / 3;
dandov32a311b2014-07-15 19:46:26 -07001516 break;
1517 case SkCanvas::kTriangleStrip_VertexMode:
1518 case SkCanvas::kTriangleFan_VertexMode:
bsalomona098dd42014-08-06 11:01:44 -07001519 triangleCount = n - 2;
dandov32a311b2014-07-15 19:46:26 -07001520 break;
1521 }
mtklein533eb782014-08-27 10:39:42 -07001522
commit-bot@chromium.org559a8832014-05-30 10:08:22 +00001523 VertState state(vertexCount, indices, indexCount);
1524 VertState::Proc vertProc = state.chooseProc(vmode);
mtklein533eb782014-08-27 10:39:42 -07001525
dandov32a311b2014-07-15 19:46:26 -07001526 //number of indices for lines per triangle with kLines
1527 indexCount = triangleCount * 6;
mtklein533eb782014-08-27 10:39:42 -07001528
bsalomonf1b7a1d2015-09-28 06:26:28 -07001529 SkAutoTDeleteArray<uint16_t> lineIndices(new uint16_t[indexCount]);
commit-bot@chromium.org559a8832014-05-30 10:08:22 +00001530 int i = 0;
1531 while (vertProc(&state)) {
bsalomonf1b7a1d2015-09-28 06:26:28 -07001532 lineIndices[i] = state.f0;
1533 lineIndices[i + 1] = state.f1;
1534 lineIndices[i + 2] = state.f1;
1535 lineIndices[i + 3] = state.f2;
1536 lineIndices[i + 4] = state.f2;
1537 lineIndices[i + 5] = state.f0;
commit-bot@chromium.org559a8832014-05-30 10:08:22 +00001538 i += 6;
1539 }
robertphillips2e1e51f2015-10-15 08:01:48 -07001540 fDrawContext->drawVertices(fClip,
bsalomonf1b7a1d2015-09-28 06:26:28 -07001541 grPaint,
1542 *draw.fMatrix,
1543 kLines_GrPrimitiveType,
1544 vertexCount,
1545 vertices,
1546 texs,
1547 colors,
1548 lineIndices.get(),
1549 indexCount);
1550 return;
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +00001551 }
1552
bsalomonf1b7a1d2015-09-28 06:26:28 -07001553 GrPrimitiveType primType = gVertexMode2PrimitiveType[vmode];
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +00001554
1555 SkAutoSTMalloc<128, GrColor> convertedColors(0);
bsalomon49f085d2014-09-05 13:34:00 -07001556 if (colors) {
bsalomonaa48d362015-10-01 08:34:17 -07001557 // need to convert byte order and from non-PM to PM. TODO: Keep unpremul until after
1558 // interpolation.
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +00001559 convertedColors.reset(vertexCount);
1560 for (int i = 0; i < vertexCount; ++i) {
bsalomonaa48d362015-10-01 08:34:17 -07001561 convertedColors[i] = SkColorToPremulGrColor(colors[i]);
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +00001562 }
1563 colors = convertedColors.get();
1564 }
bsalomonf1b7a1d2015-09-28 06:26:28 -07001565 GrPaint grPaint;
bsalomonaa48d362015-10-01 08:34:17 -07001566 if (texs && paint.getShader()) {
1567 if (colors) {
1568 // When there are texs and colors the shader and colors are combined using xmode. A null
1569 // xmode is defined to mean modulate.
1570 SkXfermode::Mode colorMode;
1571 if (xmode) {
1572 if (!xmode->asMode(&colorMode)) {
1573 return;
1574 }
1575 } else {
1576 colorMode = SkXfermode::kModulate_Mode;
1577 }
brianosman8fe485b2016-07-25 12:31:51 -07001578 if (!SkPaintToGrPaintWithXfermode(this->context(), fDrawContext.get(), paint,
1579 *draw.fMatrix, colorMode, false, &grPaint)) {
bsalomonf1b7a1d2015-09-28 06:26:28 -07001580 return;
1581 }
1582 } else {
bsalomonaa48d362015-10-01 08:34:17 -07001583 // We have a shader, but no colors to blend it against.
brianosman8fe485b2016-07-25 12:31:51 -07001584 if (!SkPaintToGrPaint(this->context(), fDrawContext.get(), paint, *draw.fMatrix,
1585 &grPaint)) {
bsalomonaa48d362015-10-01 08:34:17 -07001586 return;
1587 }
bsalomonf1b7a1d2015-09-28 06:26:28 -07001588 }
bsalomonaa48d362015-10-01 08:34:17 -07001589 } else {
1590 if (colors) {
1591 // We have colors, but either have no shader or no texture coords (which implies that
1592 // we should ignore the shader).
brianosman8fe485b2016-07-25 12:31:51 -07001593 if (!SkPaintToGrPaintWithPrimitiveColor(this->context(), fDrawContext.get(), paint,
1594 &grPaint)) {
bsalomonaa48d362015-10-01 08:34:17 -07001595 return;
1596 }
1597 } else {
1598 // No colors and no shaders. Just draw with the paint color.
brianosman8fe485b2016-07-25 12:31:51 -07001599 if (!SkPaintToGrPaintNoShader(this->context(), fDrawContext.get(), paint, &grPaint)) {
bsalomonaa48d362015-10-01 08:34:17 -07001600 return;
1601 }
bsalomonf1b7a1d2015-09-28 06:26:28 -07001602 }
bsalomonf1b7a1d2015-09-28 06:26:28 -07001603 }
1604
robertphillips2e1e51f2015-10-15 08:01:48 -07001605 fDrawContext->drawVertices(fClip,
robertphillipsea461502015-05-26 11:38:03 -07001606 grPaint,
1607 *draw.fMatrix,
1608 primType,
1609 vertexCount,
1610 vertices,
1611 texs,
1612 colors,
bsalomonf1b7a1d2015-09-28 06:26:28 -07001613 indices,
robertphillipsea461502015-05-26 11:38:03 -07001614 indexCount);
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +00001615}
1616
1617///////////////////////////////////////////////////////////////////////////////
1618
jvanverth31ff7622015-08-07 10:09:28 -07001619void SkGpuDevice::drawAtlas(const SkDraw& draw, const SkImage* atlas, const SkRSXform xform[],
reedca109532015-06-25 16:25:25 -07001620 const SkRect texRect[], const SkColor colors[], int count,
1621 SkXfermode::Mode mode, const SkPaint& paint) {
joshualittce894002016-01-11 13:29:31 -08001622 ASSERT_SINGLE_OWNER
reedca109532015-06-25 16:25:25 -07001623 if (paint.isAntiAlias()) {
jvanverth31ff7622015-08-07 10:09:28 -07001624 this->INHERITED::drawAtlas(draw, atlas, xform, texRect, colors, count, mode, paint);
reedca109532015-06-25 16:25:25 -07001625 return;
1626 }
1627
jvanverth31ff7622015-08-07 10:09:28 -07001628 CHECK_SHOULD_DRAW(draw);
joshualitt5651ee62016-01-11 10:39:11 -08001629 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawText", fContext);
herb11a7f7f2015-11-24 12:41:00 -08001630
reedca109532015-06-25 16:25:25 -07001631 SkPaint p(paint);
reed5671c5b2016-03-09 14:47:34 -08001632 p.setShader(atlas->makeShader(SkShader::kClamp_TileMode, SkShader::kClamp_TileMode));
reedca109532015-06-25 16:25:25 -07001633
jvanverth31ff7622015-08-07 10:09:28 -07001634 GrPaint grPaint;
robertphillips29ccdf82015-07-24 10:20:45 -07001635 if (colors) {
brianosman8fe485b2016-07-25 12:31:51 -07001636 if (!SkPaintToGrPaintWithXfermode(this->context(), fDrawContext.get(), p, *draw.fMatrix,
1637 mode, true, &grPaint)) {
bsalomonf1b7a1d2015-09-28 06:26:28 -07001638 return;
1639 }
1640 } else {
brianosman8fe485b2016-07-25 12:31:51 -07001641 if (!SkPaintToGrPaint(this->context(), fDrawContext.get(), p, *draw.fMatrix, &grPaint)) {
jvanverth31ff7622015-08-07 10:09:28 -07001642 return;
robertphillips29ccdf82015-07-24 10:20:45 -07001643 }
1644 }
bsalomonf1b7a1d2015-09-28 06:26:28 -07001645
1646 SkDEBUGCODE(this->validate();)
robertphillips2e1e51f2015-10-15 08:01:48 -07001647 fDrawContext->drawAtlas(fClip, grPaint, *draw.fMatrix, count, xform, texRect, colors);
reedca109532015-06-25 16:25:25 -07001648}
1649
1650///////////////////////////////////////////////////////////////////////////////
1651
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +00001652void SkGpuDevice::drawText(const SkDraw& draw, const void* text,
joshualitt5531d512014-12-17 15:50:11 -08001653 size_t byteLength, SkScalar x, SkScalar y,
1654 const SkPaint& paint) {
joshualittce894002016-01-11 13:29:31 -08001655 ASSERT_SINGLE_OWNER
joshualitt5531d512014-12-17 15:50:11 -08001656 CHECK_SHOULD_DRAW(draw);
joshualitt5651ee62016-01-11 10:39:11 -08001657 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawText", fContext);
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +00001658
jvanverth8c27a182014-10-14 08:45:50 -07001659 GrPaint grPaint;
brianosman8fe485b2016-07-25 12:31:51 -07001660 if (!SkPaintToGrPaint(this->context(), fDrawContext.get(), paint, *draw.fMatrix, &grPaint)) {
bsalomonbed83a62015-04-15 14:18:34 -07001661 return;
1662 }
commit-bot@chromium.org8128d8c2013-12-19 16:12:25 +00001663
jvanverth8c27a182014-10-14 08:45:50 -07001664 SkDEBUGCODE(this->validate();)
commit-bot@chromium.org8128d8c2013-12-19 16:12:25 +00001665
robertphillips2e1e51f2015-10-15 08:01:48 -07001666 fDrawContext->drawText(fClip, grPaint, paint, *draw.fMatrix,
reed1e7f5e72016-04-27 07:49:17 -07001667 (const char *)text, byteLength, x, y, draw.fRC->getBounds());
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +00001668}
1669
fmalita05c4a432014-09-29 06:29:53 -07001670void SkGpuDevice::drawPosText(const SkDraw& draw, const void* text, size_t byteLength,
1671 const SkScalar pos[], int scalarsPerPos,
1672 const SkPoint& offset, const SkPaint& paint) {
joshualittce894002016-01-11 13:29:31 -08001673 ASSERT_SINGLE_OWNER
joshualitt5651ee62016-01-11 10:39:11 -08001674 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawPosText", fContext);
joshualitt5531d512014-12-17 15:50:11 -08001675 CHECK_SHOULD_DRAW(draw);
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +00001676
jvanverth8c27a182014-10-14 08:45:50 -07001677 GrPaint grPaint;
brianosman8fe485b2016-07-25 12:31:51 -07001678 if (!SkPaintToGrPaint(this->context(), fDrawContext.get(), paint, *draw.fMatrix, &grPaint)) {
bsalomonbed83a62015-04-15 14:18:34 -07001679 return;
1680 }
commit-bot@chromium.org8128d8c2013-12-19 16:12:25 +00001681
jvanverth8c27a182014-10-14 08:45:50 -07001682 SkDEBUGCODE(this->validate();)
commit-bot@chromium.org8128d8c2013-12-19 16:12:25 +00001683
robertphillips2e1e51f2015-10-15 08:01:48 -07001684 fDrawContext->drawPosText(fClip, grPaint, paint, *draw.fMatrix,
joshualitt6e8cd962015-03-20 10:30:14 -07001685 (const char *)text, byteLength, pos, scalarsPerPos, offset,
reed1e7f5e72016-04-27 07:49:17 -07001686 draw.fRC->getBounds());
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +00001687}
1688
joshualitt9c328182015-03-23 08:13:04 -07001689void SkGpuDevice::drawTextBlob(const SkDraw& draw, const SkTextBlob* blob, SkScalar x, SkScalar y,
1690 const SkPaint& paint, SkDrawFilter* drawFilter) {
joshualittce894002016-01-11 13:29:31 -08001691 ASSERT_SINGLE_OWNER
joshualitt5651ee62016-01-11 10:39:11 -08001692 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawTextBlob", fContext);
joshualitt9c328182015-03-23 08:13:04 -07001693 CHECK_SHOULD_DRAW(draw);
1694
1695 SkDEBUGCODE(this->validate();)
1696
robertphillips2e1e51f2015-10-15 08:01:48 -07001697 fDrawContext->drawTextBlob(fClip, paint, *draw.fMatrix,
reed1e7f5e72016-04-27 07:49:17 -07001698 blob, x, y, drawFilter, draw.fRC->getBounds());
joshualitt9c328182015-03-23 08:13:04 -07001699}
1700
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +00001701///////////////////////////////////////////////////////////////////////////////
1702
reedb2db8982014-11-13 12:41:02 -08001703bool SkGpuDevice::onShouldDisableLCD(const SkPaint& paint) const {
joshualitt8e84a1e2016-02-16 11:09:25 -08001704 return GrTextUtils::ShouldDisableLCD(paint);
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +00001705}
1706
1707void SkGpuDevice::flush() {
joshualittce894002016-01-11 13:29:31 -08001708 ASSERT_SINGLE_OWNER
joshualittbc907352016-01-13 06:45:40 -08001709
robertphillips8c523e02016-07-26 07:41:00 -07001710 fDrawContext->prepareForExternalIO();
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +00001711}
1712
1713///////////////////////////////////////////////////////////////////////////////
1714
reed76033be2015-03-14 10:54:31 -07001715SkBaseDevice* SkGpuDevice::onCreateDevice(const CreateInfo& cinfo, const SkPaint*) {
joshualittce894002016-01-11 13:29:31 -08001716 ASSERT_SINGLE_OWNER
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +00001717
robertphillipsca6eafc2016-05-17 09:57:46 -07001718 SkSurfaceProps props(this->surfaceProps().flags(), cinfo.fPixelGeometry);
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +00001719
robertphillipsca6eafc2016-05-17 09:57:46 -07001720 // layers are never drawn in repeat modes, so we can request an approx
hcm4396fa52014-10-27 21:43:30 -07001721 // match and ignore any padding.
robertphillipsca6eafc2016-05-17 09:57:46 -07001722 SkBackingFit fit = kNever_TileUsage == cinfo.fTileUsage ? SkBackingFit::kApprox
1723 : SkBackingFit::kExact;
bsalomonafe30052015-01-16 07:32:33 -08001724
robertphillips6738c702016-07-27 12:13:51 -07001725 sk_sp<GrDrawContext> dc(fContext->makeDrawContext(fit,
1726 cinfo.fInfo.width(), cinfo.fInfo.height(),
1727 fDrawContext->config(),
1728 sk_ref_sp(fDrawContext->getColorSpace()),
1729 fDrawContext->desc().fSampleCnt,
1730 kDefault_GrSurfaceOrigin,
1731 &props));
robertphillipsca6eafc2016-05-17 09:57:46 -07001732 if (!dc) {
joshualitt5f5a8d72015-02-25 14:09:45 -08001733 SkErrorInternals::SetError( kInternalError_SkError,
reed61f501f2015-04-29 08:34:00 -07001734 "---- failed to create gpu device texture [%d %d]\n",
joshualitt5f5a8d72015-02-25 14:09:45 -08001735 cinfo.fInfo.width(), cinfo.fInfo.height());
robertphillipsca6eafc2016-05-17 09:57:46 -07001736 return nullptr;
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +00001737 }
robertphillipsca6eafc2016-05-17 09:57:46 -07001738
1739 // Skia's convention is to only clear a device if it is non-opaque.
1740 InitContents init = cinfo.fInfo.isOpaque() ? kUninit_InitContents : kClear_InitContents;
1741
1742 return SkGpuDevice::Make(std::move(dc),
1743 cinfo.fInfo.width(), cinfo.fInfo.height(),
1744 init).release();
skia.committer@gmail.com11a253b2013-11-12 07:02:05 +00001745}
1746
reede8f30622016-03-23 18:59:25 -07001747sk_sp<SkSurface> SkGpuDevice::makeSurface(const SkImageInfo& info, const SkSurfaceProps& props) {
joshualittce894002016-01-11 13:29:31 -08001748 ASSERT_SINGLE_OWNER
bsalomonafe30052015-01-16 07:32:33 -08001749 // TODO: Change the signature of newSurface to take a budgeted parameter.
bsalomon5ec26ae2016-02-25 08:33:02 -08001750 static const SkBudgeted kBudgeted = SkBudgeted::kNo;
robertphillipse5768742016-05-13 11:20:46 -07001751 return SkSurface::MakeRenderTarget(fContext, kBudgeted, info, fDrawContext->desc().fSampleCnt,
robertphillips7e922762016-07-26 11:38:17 -07001752 fDrawContext->origin(), &props);
reed@google.com76f10a32014-02-05 15:32:21 +00001753}
1754
senorblanco900c3672016-04-27 11:31:23 -07001755SkImageFilterCache* SkGpuDevice::getImageFilterCache() {
joshualittce894002016-01-11 13:29:31 -08001756 ASSERT_SINGLE_OWNER
senorblanco55b6d8b2014-07-30 11:26:46 -07001757 // We always return a transient cache, so it is freed after each
1758 // filter traversal.
senorblanco900c3672016-04-27 11:31:23 -07001759 return SkImageFilterCache::Create(kDefaultImageFilterCacheSize);
senorblanco55b6d8b2014-07-30 11:26:46 -07001760}
reedf037e0b2014-10-30 11:34:15 -07001761
1762#endif