skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2011 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #include "SkGpuDevice.h" |
| 9 | |
Brian Osman | 3b66ab6 | 2016-11-28 09:26:31 -0500 | [diff] [blame] | 10 | #include "GrBitmapTextureMaker.h" |
robertphillips | ccb1b57 | 2015-05-27 11:02:55 -0700 | [diff] [blame] | 11 | #include "GrBlurUtils.h" |
kkinnunen | abcfab4 | 2015-02-22 22:53:44 -0800 | [diff] [blame] | 12 | #include "GrContext.h" |
kkinnunen | abcfab4 | 2015-02-22 22:53:44 -0800 | [diff] [blame] | 13 | #include "GrGpu.h" |
Brian Osman | 3b66ab6 | 2016-11-28 09:26:31 -0500 | [diff] [blame] | 14 | #include "GrImageTextureMaker.h" |
| 15 | #include "GrRenderTargetContextPriv.h" |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 16 | #include "GrStyle.h" |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 17 | #include "GrSurfaceContextPriv.h" |
Brian Osman | e8e5458 | 2016-11-28 10:06:27 -0500 | [diff] [blame] | 18 | #include "GrTextureAdjuster.h" |
Robert Phillips | e2f7d18 | 2016-12-15 09:23:05 -0500 | [diff] [blame] | 19 | #include "GrTextureProxy.h" |
egdaniel | bbcb38d | 2014-06-19 10:19:29 -0700 | [diff] [blame] | 20 | #include "GrTracing.h" |
robertphillips | 30d7841 | 2014-11-24 09:49:17 -0800 | [diff] [blame] | 21 | #include "SkCanvasPriv.h" |
robertphillips | 714712b | 2016-08-04 06:20:45 -0700 | [diff] [blame] | 22 | #include "SkDraw.h" |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 23 | #include "SkGlyphCache.h" |
bsalomon | f276ac5 | 2015-10-09 13:36:42 -0700 | [diff] [blame] | 24 | #include "SkGr.h" |
bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 25 | #include "SkGrPriv.h" |
bsalomon | 1cf6f9b | 2015-12-08 10:53:43 -0800 | [diff] [blame] | 26 | #include "SkImageCacherator.h" |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 27 | #include "SkImageFilter.h" |
senorblanco | 900c367 | 2016-04-27 11:31:23 -0700 | [diff] [blame] | 28 | #include "SkImageFilterCache.h" |
Matt Sarett | cb6266b | 2017-01-17 10:48:53 -0500 | [diff] [blame] | 29 | #include "SkImageInfoPriv.h" |
Brian Salomon | 6a63904 | 2016-12-14 11:08:17 -0500 | [diff] [blame] | 30 | #include "SkImage_Base.h" |
msarett | c573a40 | 2016-08-02 08:05:56 -0700 | [diff] [blame] | 31 | #include "SkLatticeIter.h" |
commit-bot@chromium.org | 8213970 | 2014-03-10 22:53:20 +0000 | [diff] [blame] | 32 | #include "SkMaskFilter.h" |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 33 | #include "SkPathEffect.h" |
commit-bot@chromium.org | 145d1c0 | 2014-03-16 19:46:36 +0000 | [diff] [blame] | 34 | #include "SkPicture.h" |
robertphillips | db53990 | 2014-07-01 08:47:04 -0700 | [diff] [blame] | 35 | #include "SkPictureData.h" |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 36 | #include "SkRRect.h" |
Brian Salomon | 6a63904 | 2016-12-14 11:08:17 -0500 | [diff] [blame] | 37 | #include "SkRasterClip.h" |
Matt Sarett | 03dd6d5 | 2017-01-23 12:15:09 -0500 | [diff] [blame] | 38 | #include "SkReadPixelsRec.h" |
kkinnunen | abcfab4 | 2015-02-22 22:53:44 -0800 | [diff] [blame] | 39 | #include "SkRecord.h" |
robertphillips | 970587b | 2016-07-14 14:12:55 -0700 | [diff] [blame] | 40 | #include "SkSpecialImage.h" |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 41 | #include "SkStroke.h" |
reed@google.com | 76f10a3 | 2014-02-05 15:32:21 +0000 | [diff] [blame] | 42 | #include "SkSurface.h" |
kkinnunen | abcfab4 | 2015-02-22 22:53:44 -0800 | [diff] [blame] | 43 | #include "SkSurface_Gpu.h" |
commit-bot@chromium.org | a7d89c8 | 2014-01-13 14:47:00 +0000 | [diff] [blame] | 44 | #include "SkTLazy.h" |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 45 | #include "SkUtils.h" |
commit-bot@chromium.org | 559a883 | 2014-05-30 10:08:22 +0000 | [diff] [blame] | 46 | #include "SkVertState.h" |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 47 | #include "SkVertices.h" |
Matt Sarett | 03dd6d5 | 2017-01-23 12:15:09 -0500 | [diff] [blame] | 48 | #include "SkWritePixelsRec.h" |
kkinnunen | abcfab4 | 2015-02-22 22:53:44 -0800 | [diff] [blame] | 49 | #include "effects/GrBicubicEffect.h" |
kkinnunen | abcfab4 | 2015-02-22 22:53:44 -0800 | [diff] [blame] | 50 | #include "effects/GrSimpleTextureEffect.h" |
| 51 | #include "effects/GrTextureDomain.h" |
joshualitt | 8e84a1e | 2016-02-16 11:09:25 -0800 | [diff] [blame] | 52 | #include "text/GrTextUtils.h" |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 53 | |
reed | f037e0b | 2014-10-30 11:34:15 -0700 | [diff] [blame] | 54 | #if SK_SUPPORT_GPU |
| 55 | |
joshualitt | ce89400 | 2016-01-11 13:29:31 -0800 | [diff] [blame] | 56 | #define ASSERT_SINGLE_OWNER \ |
| 57 | SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(fContext->debugSingleOwner());) |
| 58 | |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 59 | #if 0 |
| 60 | extern bool (*gShouldDrawProc)(); |
joshualitt | 5531d51 | 2014-12-17 15:50:11 -0800 | [diff] [blame] | 61 | #define CHECK_SHOULD_DRAW(draw) \ |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 62 | do { \ |
| 63 | if (gShouldDrawProc && !gShouldDrawProc()) return; \ |
joshualitt | 5531d51 | 2014-12-17 15:50:11 -0800 | [diff] [blame] | 64 | this->prepareDraw(draw); \ |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 65 | } while (0) |
| 66 | #else |
joshualitt | 5531d51 | 2014-12-17 15:50:11 -0800 | [diff] [blame] | 67 | #define CHECK_SHOULD_DRAW(draw) this->prepareDraw(draw) |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 68 | #endif |
| 69 | |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 70 | /////////////////////////////////////////////////////////////////////////////// |
| 71 | |
bsalomon | 74f681d | 2015-06-23 14:38:48 -0700 | [diff] [blame] | 72 | /** Checks that the alpha type is legal and gets constructor flags. Returns false if device creation |
| 73 | should fail. */ |
| 74 | bool SkGpuDevice::CheckAlphaTypeAndGetFlags( |
| 75 | const SkImageInfo* info, SkGpuDevice::InitContents init, unsigned* flags) { |
| 76 | *flags = 0; |
| 77 | if (info) { |
| 78 | switch (info->alphaType()) { |
| 79 | case kPremul_SkAlphaType: |
| 80 | break; |
| 81 | case kOpaque_SkAlphaType: |
| 82 | *flags |= SkGpuDevice::kIsOpaque_Flag; |
| 83 | break; |
| 84 | default: // If it is unpremul or unknown don't try to render |
| 85 | return false; |
| 86 | } |
| 87 | } |
| 88 | if (kClear_InitContents == init) { |
| 89 | *flags |= kNeedClear_Flag; |
| 90 | } |
| 91 | return true; |
| 92 | } |
| 93 | |
Robert Phillips | 9fab7e9 | 2016-11-17 12:45:04 -0500 | [diff] [blame] | 94 | sk_sp<SkGpuDevice> SkGpuDevice::Make(GrContext* context, |
| 95 | sk_sp<GrRenderTargetContext> renderTargetContext, |
robertphillips | 15c42ca | 2016-08-04 08:45:02 -0700 | [diff] [blame] | 96 | int width, int height, |
| 97 | InitContents init) { |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 98 | if (!renderTargetContext || renderTargetContext->wasAbandoned()) { |
robertphillips | ca6eafc | 2016-05-17 09:57:46 -0700 | [diff] [blame] | 99 | return nullptr; |
| 100 | } |
| 101 | unsigned flags; |
| 102 | if (!CheckAlphaTypeAndGetFlags(nullptr, init, &flags)) { |
| 103 | return nullptr; |
| 104 | } |
Robert Phillips | 9fab7e9 | 2016-11-17 12:45:04 -0500 | [diff] [blame] | 105 | return sk_sp<SkGpuDevice>(new SkGpuDevice(context, std::move(renderTargetContext), |
| 106 | width, height, flags)); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 107 | } |
| 108 | |
robertphillips | 24e9128 | 2016-04-29 06:46:36 -0700 | [diff] [blame] | 109 | sk_sp<SkGpuDevice> SkGpuDevice::Make(GrContext* context, SkBudgeted budgeted, |
| 110 | const SkImageInfo& info, int sampleCount, |
robertphillips | 7e92276 | 2016-07-26 11:38:17 -0700 | [diff] [blame] | 111 | GrSurfaceOrigin origin, |
robertphillips | 24e9128 | 2016-04-29 06:46:36 -0700 | [diff] [blame] | 112 | const SkSurfaceProps* props, InitContents init) { |
bsalomon | 74f681d | 2015-06-23 14:38:48 -0700 | [diff] [blame] | 113 | unsigned flags; |
| 114 | if (!CheckAlphaTypeAndGetFlags(&info, init, &flags)) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 115 | return nullptr; |
bsalomon | 74f681d | 2015-06-23 14:38:48 -0700 | [diff] [blame] | 116 | } |
| 117 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 118 | sk_sp<GrRenderTargetContext> renderTargetContext(MakeRenderTargetContext(context, budgeted, |
| 119 | info, sampleCount, |
| 120 | origin, props)); |
| 121 | if (!renderTargetContext) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 122 | return nullptr; |
bsalomon | 74f681d | 2015-06-23 14:38:48 -0700 | [diff] [blame] | 123 | } |
| 124 | |
Robert Phillips | 9fab7e9 | 2016-11-17 12:45:04 -0500 | [diff] [blame] | 125 | return sk_sp<SkGpuDevice>(new SkGpuDevice(context, std::move(renderTargetContext), |
robertphillips | ca6eafc | 2016-05-17 09:57:46 -0700 | [diff] [blame] | 126 | info.width(), info.height(), flags)); |
bsalomon | 74f681d | 2015-06-23 14:38:48 -0700 | [diff] [blame] | 127 | } |
| 128 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 129 | static SkImageInfo make_info(GrRenderTargetContext* context, int w, int h, bool opaque) { |
reed | 589a39e | 2016-08-20 07:59:19 -0700 | [diff] [blame] | 130 | SkColorType colorType; |
| 131 | if (!GrPixelConfigToColorType(context->config(), &colorType)) { |
| 132 | colorType = kUnknown_SkColorType; |
| 133 | } |
| 134 | return SkImageInfo::Make(w, h, colorType, |
| 135 | opaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType, |
Robert Phillips | 75a475c | 2017-01-13 09:18:59 -0500 | [diff] [blame] | 136 | context->refColorSpace()); |
reed | 589a39e | 2016-08-20 07:59:19 -0700 | [diff] [blame] | 137 | } |
| 138 | |
Robert Phillips | 9fab7e9 | 2016-11-17 12:45:04 -0500 | [diff] [blame] | 139 | SkGpuDevice::SkGpuDevice(GrContext* context, sk_sp<GrRenderTargetContext> renderTargetContext, |
| 140 | int width, int height, unsigned flags) |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 141 | : INHERITED(make_info(renderTargetContext.get(), width, height, |
| 142 | SkToBool(flags & kIsOpaque_Flag)), renderTargetContext->surfaceProps()) |
Robert Phillips | 9fab7e9 | 2016-11-17 12:45:04 -0500 | [diff] [blame] | 143 | , fContext(SkRef(context)) |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 144 | , fRenderTargetContext(std::move(renderTargetContext)) |
reed | 589a39e | 2016-08-20 07:59:19 -0700 | [diff] [blame] | 145 | { |
robertphillips | 1f3923e | 2016-07-21 07:17:54 -0700 | [diff] [blame] | 146 | fSize.set(width, height); |
bsalomon | 74f681d | 2015-06-23 14:38:48 -0700 | [diff] [blame] | 147 | fOpaque = SkToBool(flags & kIsOpaque_Flag); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 148 | |
bsalomon | e63ffef | 2016-02-05 07:17:34 -0800 | [diff] [blame] | 149 | if (flags & kNeedClear_Flag) { |
| 150 | this->clearAll(); |
| 151 | } |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 152 | } |
| 153 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 154 | sk_sp<GrRenderTargetContext> SkGpuDevice::MakeRenderTargetContext( |
| 155 | GrContext* context, |
| 156 | SkBudgeted budgeted, |
| 157 | const SkImageInfo& origInfo, |
| 158 | int sampleCount, |
| 159 | GrSurfaceOrigin origin, |
| 160 | const SkSurfaceProps* surfaceProps) { |
commit-bot@chromium.org | 15a1405 | 2014-02-16 00:59:25 +0000 | [diff] [blame] | 161 | if (kUnknown_SkColorType == origInfo.colorType() || |
| 162 | origInfo.width() < 0 || origInfo.height() < 0) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 163 | return nullptr; |
commit-bot@chromium.org | 15a1405 | 2014-02-16 00:59:25 +0000 | [diff] [blame] | 164 | } |
| 165 | |
bsalomon | afe3005 | 2015-01-16 07:32:33 -0800 | [diff] [blame] | 166 | if (!context) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 167 | return nullptr; |
bsalomon | afe3005 | 2015-01-16 07:32:33 -0800 | [diff] [blame] | 168 | } |
| 169 | |
Brian Osman | 0c2997b | 2017-01-11 16:58:42 -0500 | [diff] [blame] | 170 | GrPixelConfig config = SkImageInfo2GrPixelConfig(origInfo, *context->caps()); |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 171 | return context->makeRenderTargetContext(SkBackingFit::kExact, // Why exact? |
robertphillips | 6738c70 | 2016-07-27 12:13:51 -0700 | [diff] [blame] | 172 | origInfo.width(), origInfo.height(), |
Robert Phillips | 70b49fd | 2017-01-13 11:21:36 -0500 | [diff] [blame] | 173 | config, origInfo.refColorSpace(), sampleCount, |
robertphillips | 6738c70 | 2016-07-27 12:13:51 -0700 | [diff] [blame] | 174 | origin, surfaceProps, budgeted); |
kkinnunen | abcfab4 | 2015-02-22 22:53:44 -0800 | [diff] [blame] | 175 | } |
commit-bot@chromium.org | 15a1405 | 2014-02-16 00:59:25 +0000 | [diff] [blame] | 176 | |
robertphillips | 970587b | 2016-07-14 14:12:55 -0700 | [diff] [blame] | 177 | sk_sp<SkSpecialImage> SkGpuDevice::filterTexture(const SkDraw& draw, |
| 178 | SkSpecialImage* srcImg, |
| 179 | int left, int top, |
| 180 | SkIPoint* offset, |
| 181 | const SkImageFilter* filter) { |
| 182 | SkASSERT(srcImg->isTextureBacked()); |
| 183 | SkASSERT(filter); |
| 184 | |
| 185 | SkMatrix matrix = *draw.fMatrix; |
| 186 | matrix.postTranslate(SkIntToScalar(-left), SkIntToScalar(-top)); |
Mike Reed | fa24d34 | 2017-02-22 15:21:35 -0500 | [diff] [blame] | 187 | const SkIRect clipBounds = this->devClipBounds(draw).makeOffset(-left, -top); |
Hal Canary | 144caf5 | 2016-11-07 17:57:18 -0500 | [diff] [blame] | 188 | sk_sp<SkImageFilterCache> cache(this->getImageFilterCache()); |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 189 | SkImageFilter::OutputProperties outputProperties(fRenderTargetContext->getColorSpace()); |
brianosman | 2a75e5d | 2016-09-22 07:15:37 -0700 | [diff] [blame] | 190 | SkImageFilter::Context ctx(matrix, clipBounds, cache.get(), outputProperties); |
robertphillips | 970587b | 2016-07-14 14:12:55 -0700 | [diff] [blame] | 191 | |
| 192 | return filter->filterImage(srcImg, ctx, offset); |
| 193 | } |
| 194 | |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 195 | /////////////////////////////////////////////////////////////////////////////// |
| 196 | |
commit-bot@chromium.org | a713f9c | 2014-03-17 21:31:26 +0000 | [diff] [blame] | 197 | bool SkGpuDevice::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes, |
| 198 | int x, int y) { |
joshualitt | ce89400 | 2016-01-11 13:29:31 -0800 | [diff] [blame] | 199 | ASSERT_SINGLE_OWNER |
commit-bot@chromium.org | a713f9c | 2014-03-17 21:31:26 +0000 | [diff] [blame] | 200 | |
Matt Sarett | cb6266b | 2017-01-17 10:48:53 -0500 | [diff] [blame] | 201 | if (!SkImageInfoValidConversion(dstInfo, this->imageInfo())) { |
| 202 | return false; |
| 203 | } |
| 204 | |
Matt Sarett | 03dd6d5 | 2017-01-23 12:15:09 -0500 | [diff] [blame] | 205 | SkReadPixelsRec rec(dstInfo, dstPixels, dstRowBytes, x, y); |
| 206 | if (!rec.trim(this->width(), this->height())) { |
| 207 | return false; |
| 208 | } |
| 209 | |
| 210 | return fRenderTargetContext->readPixels(rec.fInfo, rec.fPixels, rec.fRowBytes, rec.fX, rec.fY); |
commit-bot@chromium.org | a713f9c | 2014-03-17 21:31:26 +0000 | [diff] [blame] | 211 | } |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 212 | |
robertphillips | 1da3ecd | 2016-08-31 14:54:15 -0700 | [diff] [blame] | 213 | bool SkGpuDevice::onWritePixels(const SkImageInfo& srcInfo, const void* srcPixels, |
| 214 | size_t srcRowBytes, int x, int y) { |
joshualitt | ce89400 | 2016-01-11 13:29:31 -0800 | [diff] [blame] | 215 | ASSERT_SINGLE_OWNER |
robertphillips | 1da3ecd | 2016-08-31 14:54:15 -0700 | [diff] [blame] | 216 | |
Matt Sarett | cb6266b | 2017-01-17 10:48:53 -0500 | [diff] [blame] | 217 | if (!SkImageInfoValidConversion(this->imageInfo(), srcInfo)) { |
| 218 | return false; |
| 219 | } |
| 220 | |
Matt Sarett | 03dd6d5 | 2017-01-23 12:15:09 -0500 | [diff] [blame] | 221 | SkWritePixelsRec rec(srcInfo, srcPixels, srcRowBytes, x, y); |
| 222 | if (!rec.trim(this->width(), this->height())) { |
| 223 | return false; |
| 224 | } |
| 225 | |
| 226 | return fRenderTargetContext->writePixels(rec.fInfo, rec.fPixels, rec.fRowBytes, rec.fX, rec.fY); |
commit-bot@chromium.org | 4cd9e21 | 2014-03-07 03:25:16 +0000 | [diff] [blame] | 227 | } |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 228 | |
reed | 41e010c | 2015-06-09 12:16:53 -0700 | [diff] [blame] | 229 | bool SkGpuDevice::onAccessPixels(SkPixmap* pmap) { |
joshualitt | ce89400 | 2016-01-11 13:29:31 -0800 | [diff] [blame] | 230 | ASSERT_SINGLE_OWNER |
reed | 41e010c | 2015-06-09 12:16:53 -0700 | [diff] [blame] | 231 | return false; |
| 232 | } |
| 233 | |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 234 | // call this every draw call, to ensure that the context reflects our state, |
| 235 | // and not the state from some other canvas/device |
joshualitt | 5531d51 | 2014-12-17 15:50:11 -0800 | [diff] [blame] | 236 | void SkGpuDevice::prepareDraw(const SkDraw& draw) { |
joshualitt | ce89400 | 2016-01-11 13:29:31 -0800 | [diff] [blame] | 237 | ASSERT_SINGLE_OWNER |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 238 | |
Mike Reed | d519d48 | 2017-02-16 11:04:52 -0500 | [diff] [blame] | 239 | #ifdef SK_USE_DEVICE_CLIPPING |
| 240 | SkASSERT(*draw.fMatrix == this->ctm()); |
Mike Reed | c5e641c | 2017-02-17 14:38:11 -0500 | [diff] [blame] | 241 | fClip.reset(&this->cs(), nullptr); |
Mike Reed | d519d48 | 2017-02-16 11:04:52 -0500 | [diff] [blame] | 242 | #else |
reed | 2c9e200 | 2016-07-25 08:05:22 -0700 | [diff] [blame] | 243 | fClip.reset(draw.fClipStack, &this->getOrigin()); |
Mike Reed | d519d48 | 2017-02-16 11:04:52 -0500 | [diff] [blame] | 244 | #endif |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 245 | } |
| 246 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 247 | GrRenderTargetContext* SkGpuDevice::accessRenderTargetContext() { |
robertphillips | 175dd9b | 2016-04-28 14:32:04 -0700 | [diff] [blame] | 248 | ASSERT_SINGLE_OWNER |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 249 | return fRenderTargetContext.get(); |
robertphillips | 175dd9b | 2016-04-28 14:32:04 -0700 | [diff] [blame] | 250 | } |
| 251 | |
reed | 8eddfb5 | 2014-12-04 07:50:14 -0800 | [diff] [blame] | 252 | void SkGpuDevice::clearAll() { |
joshualitt | ce89400 | 2016-01-11 13:29:31 -0800 | [diff] [blame] | 253 | ASSERT_SINGLE_OWNER |
Hal Canary | 144caf5 | 2016-11-07 17:57:18 -0500 | [diff] [blame] | 254 | GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "clearAll", fContext.get()); |
Robert Phillips | 784b7bf | 2016-12-09 13:35:02 -0500 | [diff] [blame] | 255 | |
reed | 8eddfb5 | 2014-12-04 07:50:14 -0800 | [diff] [blame] | 256 | SkIRect rect = SkIRect::MakeWH(this->width(), this->height()); |
Robert Phillips | 784b7bf | 2016-12-09 13:35:02 -0500 | [diff] [blame] | 257 | fRenderTargetContext->clear(&rect, 0x0, true); |
reed | 8eddfb5 | 2014-12-04 07:50:14 -0800 | [diff] [blame] | 258 | } |
| 259 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 260 | void SkGpuDevice::replaceRenderTargetContext(bool shouldRetainContent) { |
joshualitt | ce89400 | 2016-01-11 13:29:31 -0800 | [diff] [blame] | 261 | ASSERT_SINGLE_OWNER |
kkinnunen | abcfab4 | 2015-02-22 22:53:44 -0800 | [diff] [blame] | 262 | |
Brian Osman | 693a540 | 2016-10-27 15:13:22 -0400 | [diff] [blame] | 263 | SkBudgeted budgeted = fRenderTargetContext->priv().isBudgeted(); |
kkinnunen | abcfab4 | 2015-02-22 22:53:44 -0800 | [diff] [blame] | 264 | |
Brian Osman | 693a540 | 2016-10-27 15:13:22 -0400 | [diff] [blame] | 265 | sk_sp<GrRenderTargetContext> newRTC(MakeRenderTargetContext( |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 266 | this->context(), |
| 267 | budgeted, |
| 268 | this->imageInfo(), |
| 269 | fRenderTargetContext->numColorSamples(), |
| 270 | fRenderTargetContext->origin(), |
| 271 | &this->surfaceProps())); |
Brian Osman | 693a540 | 2016-10-27 15:13:22 -0400 | [diff] [blame] | 272 | if (!newRTC) { |
kkinnunen | abcfab4 | 2015-02-22 22:53:44 -0800 | [diff] [blame] | 273 | return; |
| 274 | } |
| 275 | |
| 276 | if (shouldRetainContent) { |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 277 | if (fRenderTargetContext->wasAbandoned()) { |
kkinnunen | abcfab4 | 2015-02-22 22:53:44 -0800 | [diff] [blame] | 278 | return; |
| 279 | } |
Robert Phillips | f200a90 | 2017-01-30 13:27:37 -0500 | [diff] [blame] | 280 | newRTC->copy(fRenderTargetContext->asSurfaceProxy()); |
kkinnunen | abcfab4 | 2015-02-22 22:53:44 -0800 | [diff] [blame] | 281 | } |
| 282 | |
Brian Osman | 693a540 | 2016-10-27 15:13:22 -0400 | [diff] [blame] | 283 | fRenderTargetContext = newRTC; |
kkinnunen | abcfab4 | 2015-02-22 22:53:44 -0800 | [diff] [blame] | 284 | } |
| 285 | |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 286 | /////////////////////////////////////////////////////////////////////////////// |
| 287 | |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 288 | void SkGpuDevice::drawPaint(const SkDraw& draw, const SkPaint& paint) { |
joshualitt | ce89400 | 2016-01-11 13:29:31 -0800 | [diff] [blame] | 289 | ASSERT_SINGLE_OWNER |
joshualitt | 5531d51 | 2014-12-17 15:50:11 -0800 | [diff] [blame] | 290 | CHECK_SHOULD_DRAW(draw); |
Hal Canary | 144caf5 | 2016-11-07 17:57:18 -0500 | [diff] [blame] | 291 | GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawPaint", fContext.get()); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 292 | |
| 293 | GrPaint grPaint; |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 294 | if (!SkPaintToGrPaint(this->context(), fRenderTargetContext.get(), paint, *draw.fMatrix, |
| 295 | &grPaint)) { |
bsalomon | bed83a6 | 2015-04-15 14:18:34 -0700 | [diff] [blame] | 296 | return; |
| 297 | } |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 298 | |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 299 | fRenderTargetContext->drawPaint(fClip, std::move(grPaint), *draw.fMatrix); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | // must be in SkCanvas::PointMode order |
bsalomon | 6ade6dd | 2016-09-12 12:07:17 -0700 | [diff] [blame] | 303 | static const GrPrimitiveType gPointMode2PrimitiveType[] = { |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 304 | kPoints_GrPrimitiveType, |
| 305 | kLines_GrPrimitiveType, |
| 306 | kLineStrip_GrPrimitiveType |
| 307 | }; |
| 308 | |
Brian Salomon | bd72f5a | 2016-12-06 16:52:24 -0500 | [diff] [blame] | 309 | static inline bool is_int(float x) { return x == (float) sk_float_round2int(x); } |
| 310 | |
ethannicholas | 330bb95 | 2015-07-17 06:44:02 -0700 | [diff] [blame] | 311 | // suppress antialiasing on axis-aligned integer-coordinate lines |
Brian Salomon | bd72f5a | 2016-12-06 16:52:24 -0500 | [diff] [blame] | 312 | static bool needs_antialiasing(SkCanvas::PointMode mode, size_t count, const SkPoint pts[], |
| 313 | const SkMatrix& matrix) { |
ethannicholas | 330bb95 | 2015-07-17 06:44:02 -0700 | [diff] [blame] | 314 | if (mode == SkCanvas::PointMode::kPoints_PointMode) { |
| 315 | return false; |
| 316 | } |
| 317 | if (count == 2) { |
Brian Salomon | bd72f5a | 2016-12-06 16:52:24 -0500 | [diff] [blame] | 318 | // We do not antialias horizontal or vertical lines along pixel centers, even when the ends |
| 319 | // of the line do not fully cover the first and last pixel of the line, which is slightly |
| 320 | // wrong. |
| 321 | if (!matrix.isScaleTranslate()) { |
| 322 | return true; |
| 323 | } |
ethannicholas | 330bb95 | 2015-07-17 06:44:02 -0700 | [diff] [blame] | 324 | if (pts[0].fX == pts[1].fX) { |
Brian Salomon | bd72f5a | 2016-12-06 16:52:24 -0500 | [diff] [blame] | 325 | SkScalar x = matrix.getScaleX() * pts[0].fX + matrix.getTranslateX(); |
| 326 | return !is_int(x + 0.5f); |
ethannicholas | 330bb95 | 2015-07-17 06:44:02 -0700 | [diff] [blame] | 327 | } |
| 328 | if (pts[0].fY == pts[1].fY) { |
Brian Salomon | bd72f5a | 2016-12-06 16:52:24 -0500 | [diff] [blame] | 329 | SkScalar y = matrix.getScaleY() * pts[0].fY + matrix.getTranslateY(); |
| 330 | return !is_int(y + 0.5f); |
ethannicholas | 330bb95 | 2015-07-17 06:44:02 -0700 | [diff] [blame] | 331 | } |
| 332 | } |
| 333 | return true; |
| 334 | } |
| 335 | |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 336 | void SkGpuDevice::drawPoints(const SkDraw& draw, SkCanvas::PointMode mode, |
| 337 | size_t count, const SkPoint pts[], const SkPaint& paint) { |
joshualitt | ce89400 | 2016-01-11 13:29:31 -0800 | [diff] [blame] | 338 | ASSERT_SINGLE_OWNER |
Hal Canary | 144caf5 | 2016-11-07 17:57:18 -0500 | [diff] [blame] | 339 | GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawPoints", fContext.get()); |
joshualitt | 5531d51 | 2014-12-17 15:50:11 -0800 | [diff] [blame] | 340 | CHECK_SHOULD_DRAW(draw); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 341 | |
| 342 | SkScalar width = paint.getStrokeWidth(); |
| 343 | if (width < 0) { |
| 344 | return; |
| 345 | } |
| 346 | |
commit-bot@chromium.org | 628ed0b | 2014-05-19 14:32:49 +0000 | [diff] [blame] | 347 | if (paint.getPathEffect() && 2 == count && SkCanvas::kLines_PointMode == mode) { |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 348 | GrStyle style(paint, SkPaint::kStroke_Style); |
egdaniel | e61c411 | 2014-06-12 10:24:21 -0700 | [diff] [blame] | 349 | GrPaint grPaint; |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 350 | if (!SkPaintToGrPaint(this->context(), fRenderTargetContext.get(), paint, *draw.fMatrix, |
brianosman | 1638c0d | 2016-07-25 05:12:53 -0700 | [diff] [blame] | 351 | &grPaint)) { |
bsalomon | bed83a6 | 2015-04-15 14:18:34 -0700 | [diff] [blame] | 352 | return; |
| 353 | } |
egdaniel | e61c411 | 2014-06-12 10:24:21 -0700 | [diff] [blame] | 354 | SkPath path; |
jvanverth | b3eb687 | 2014-10-24 07:12:51 -0700 | [diff] [blame] | 355 | path.setIsVolatile(true); |
egdaniel | e61c411 | 2014-06-12 10:24:21 -0700 | [diff] [blame] | 356 | path.moveTo(pts[0]); |
| 357 | path.lineTo(pts[1]); |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 358 | fRenderTargetContext->drawPath(fClip, std::move(grPaint), GrBoolToAA(paint.isAntiAlias()), |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 359 | *draw.fMatrix, path, style); |
egdaniel | e61c411 | 2014-06-12 10:24:21 -0700 | [diff] [blame] | 360 | return; |
commit-bot@chromium.org | 628ed0b | 2014-05-19 14:32:49 +0000 | [diff] [blame] | 361 | } |
| 362 | |
bsalomon | 6ade6dd | 2016-09-12 12:07:17 -0700 | [diff] [blame] | 363 | SkScalar scales[2]; |
| 364 | bool isHairline = (0 == width) || (1 == width && draw.fMatrix->getMinMaxScales(scales) && |
| 365 | SkScalarNearlyEqual(scales[0], 1.f) && |
| 366 | SkScalarNearlyEqual(scales[1], 1.f)); |
ethannicholas | 330bb95 | 2015-07-17 06:44:02 -0700 | [diff] [blame] | 367 | // we only handle non-antialiased hairlines and paints without path effects or mask filters, |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 368 | // else we let the SkDraw call our drawPath() |
bsalomon | 6ade6dd | 2016-09-12 12:07:17 -0700 | [diff] [blame] | 369 | if (!isHairline || paint.getPathEffect() || paint.getMaskFilter() || |
Brian Salomon | bd72f5a | 2016-12-06 16:52:24 -0500 | [diff] [blame] | 370 | (paint.isAntiAlias() && needs_antialiasing(mode, count, pts, *draw.fMatrix))) { |
Mike Reed | 99330ba | 2017-02-22 11:01:08 -0500 | [diff] [blame] | 371 | draw.drawPoints(mode, count, pts, paint, this); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 372 | return; |
| 373 | } |
| 374 | |
bsalomon | 6ade6dd | 2016-09-12 12:07:17 -0700 | [diff] [blame] | 375 | GrPrimitiveType primitiveType = gPointMode2PrimitiveType[mode]; |
| 376 | |
| 377 | const SkMatrix* viewMatrix = draw.fMatrix; |
| 378 | #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |
| 379 | // This offsetting in device space matches the expectations of the Android framework for non-AA |
| 380 | // points and lines. |
| 381 | SkMatrix tempMatrix; |
| 382 | if (GrIsPrimTypeLines(primitiveType) || kPoints_GrPrimitiveType == primitiveType) { |
| 383 | tempMatrix = *viewMatrix; |
| 384 | static const SkScalar kOffset = 0.063f; // Just greater than 1/16. |
| 385 | tempMatrix.postTranslate(kOffset, kOffset); |
| 386 | viewMatrix = &tempMatrix; |
| 387 | } |
| 388 | #endif |
| 389 | |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 390 | GrPaint grPaint; |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 391 | if (!SkPaintToGrPaint(this->context(), fRenderTargetContext.get(), paint, *viewMatrix, |
| 392 | &grPaint)) { |
bsalomon | bed83a6 | 2015-04-15 14:18:34 -0700 | [diff] [blame] | 393 | return; |
| 394 | } |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 395 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 396 | fRenderTargetContext->drawVertices(fClip, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 397 | std::move(grPaint), |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 398 | *viewMatrix, |
| 399 | primitiveType, |
| 400 | SkToS32(count), |
| 401 | (SkPoint*)pts, |
| 402 | nullptr, |
| 403 | nullptr, |
| 404 | nullptr, |
| 405 | 0); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 406 | } |
| 407 | |
| 408 | /////////////////////////////////////////////////////////////////////////////// |
| 409 | |
robertphillips | ff55b49 | 2015-11-24 07:56:59 -0800 | [diff] [blame] | 410 | void SkGpuDevice::drawRect(const SkDraw& draw, const SkRect& rect, const SkPaint& paint) { |
joshualitt | ce89400 | 2016-01-11 13:29:31 -0800 | [diff] [blame] | 411 | ASSERT_SINGLE_OWNER |
Hal Canary | 144caf5 | 2016-11-07 17:57:18 -0500 | [diff] [blame] | 412 | GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawRect", fContext.get()); |
joshualitt | 5531d51 | 2014-12-17 15:50:11 -0800 | [diff] [blame] | 413 | CHECK_SHOULD_DRAW(draw); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 414 | |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 415 | |
bsalomon | a7d85ba | 2016-07-06 11:54:59 -0700 | [diff] [blame] | 416 | // A couple reasons we might need to call drawPath. |
| 417 | if (paint.getMaskFilter() || paint.getPathEffect()) { |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 418 | SkPath path; |
jvanverth | b3eb687 | 2014-10-24 07:12:51 -0700 | [diff] [blame] | 419 | path.setIsVolatile(true); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 420 | path.addRect(rect); |
Hal Canary | 144caf5 | 2016-11-07 17:57:18 -0500 | [diff] [blame] | 421 | GrBlurUtils::drawPathWithMaskFilter(fContext.get(), fRenderTargetContext.get(), |
robertphillips | ff55b49 | 2015-11-24 07:56:59 -0800 | [diff] [blame] | 422 | fClip, path, paint, |
| 423 | *draw.fMatrix, nullptr, |
Mike Reed | fa24d34 | 2017-02-22 15:21:35 -0500 | [diff] [blame] | 424 | this->devClipBounds(draw), true); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 425 | return; |
| 426 | } |
| 427 | |
| 428 | GrPaint grPaint; |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 429 | if (!SkPaintToGrPaint(this->context(), fRenderTargetContext.get(), paint, *draw.fMatrix, |
| 430 | &grPaint)) { |
bsalomon | bed83a6 | 2015-04-15 14:18:34 -0700 | [diff] [blame] | 431 | return; |
| 432 | } |
Mike Klein | 744fb73 | 2014-06-23 15:13:26 -0400 | [diff] [blame] | 433 | |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 434 | GrStyle style(paint); |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 435 | fRenderTargetContext->drawRect(fClip, std::move(grPaint), GrBoolToAA(paint.isAntiAlias()), |
| 436 | *draw.fMatrix, rect, &style); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 437 | } |
| 438 | |
| 439 | /////////////////////////////////////////////////////////////////////////////// |
| 440 | |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 441 | void SkGpuDevice::drawRRect(const SkDraw& draw, const SkRRect& rrect, const SkPaint& paint) { |
joshualitt | ce89400 | 2016-01-11 13:29:31 -0800 | [diff] [blame] | 442 | ASSERT_SINGLE_OWNER |
Hal Canary | 144caf5 | 2016-11-07 17:57:18 -0500 | [diff] [blame] | 443 | GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawRRect", fContext.get()); |
joshualitt | 5531d51 | 2014-12-17 15:50:11 -0800 | [diff] [blame] | 444 | CHECK_SHOULD_DRAW(draw); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 445 | |
commit-bot@chromium.org | 8213970 | 2014-03-10 22:53:20 +0000 | [diff] [blame] | 446 | GrPaint grPaint; |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 447 | if (!SkPaintToGrPaint(this->context(), fRenderTargetContext.get(), paint, *draw.fMatrix, |
| 448 | &grPaint)) { |
bsalomon | bed83a6 | 2015-04-15 14:18:34 -0700 | [diff] [blame] | 449 | return; |
| 450 | } |
Mike Klein | 744fb73 | 2014-06-23 15:13:26 -0400 | [diff] [blame] | 451 | |
Robert Phillips | a29a956 | 2016-10-20 09:40:55 -0400 | [diff] [blame] | 452 | SkMaskFilter* mf = paint.getMaskFilter(); |
| 453 | if (mf && mf->asFragmentProcessor(nullptr, nullptr, *draw.fMatrix)) { |
| 454 | mf = nullptr; // already handled in SkPaintToGrPaint |
| 455 | } |
| 456 | |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 457 | GrStyle style(paint); |
Robert Phillips | a29a956 | 2016-10-20 09:40:55 -0400 | [diff] [blame] | 458 | if (mf) { |
commit-bot@chromium.org | 8213970 | 2014-03-10 22:53:20 +0000 | [diff] [blame] | 459 | // try to hit the fast path for drawing filtered round rects |
| 460 | |
| 461 | SkRRect devRRect; |
robertphillips | 9aff85a | 2016-08-05 07:51:29 -0700 | [diff] [blame] | 462 | if (rrect.transform(*draw.fMatrix, &devRRect)) { |
commit-bot@chromium.org | 8213970 | 2014-03-10 22:53:20 +0000 | [diff] [blame] | 463 | if (devRRect.allCornersCircular()) { |
| 464 | SkRect maskRect; |
Mike Reed | fa24d34 | 2017-02-22 15:21:35 -0500 | [diff] [blame] | 465 | if (mf->canFilterMaskGPU(devRRect, this->devClipBounds(draw), |
Robert Phillips | a29a956 | 2016-10-20 09:40:55 -0400 | [diff] [blame] | 466 | *draw.fMatrix, &maskRect)) { |
commit-bot@chromium.org | 8213970 | 2014-03-10 22:53:20 +0000 | [diff] [blame] | 467 | SkIRect finalIRect; |
| 468 | maskRect.roundOut(&finalIRect); |
reed | 1e7f5e7 | 2016-04-27 07:49:17 -0700 | [diff] [blame] | 469 | if (draw.fRC->quickReject(finalIRect)) { |
commit-bot@chromium.org | 8213970 | 2014-03-10 22:53:20 +0000 | [diff] [blame] | 470 | // clipped out |
| 471 | return; |
| 472 | } |
Hal Canary | 144caf5 | 2016-11-07 17:57:18 -0500 | [diff] [blame] | 473 | if (mf->directFilterRRectMaskGPU(fContext.get(), fRenderTargetContext.get(), |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 474 | std::move(grPaint), fClip, *draw.fMatrix, |
Hal Canary | 144caf5 | 2016-11-07 17:57:18 -0500 | [diff] [blame] | 475 | style.strokeRec(), rrect, devRRect)) { |
commit-bot@chromium.org | 8213970 | 2014-03-10 22:53:20 +0000 | [diff] [blame] | 476 | return; |
| 477 | } |
| 478 | } |
| 479 | |
| 480 | } |
| 481 | } |
commit-bot@chromium.org | 8213970 | 2014-03-10 22:53:20 +0000 | [diff] [blame] | 482 | } |
| 483 | |
Robert Phillips | a29a956 | 2016-10-20 09:40:55 -0400 | [diff] [blame] | 484 | if (mf || style.pathEffect()) { |
robertphillips | ff55b49 | 2015-11-24 07:56:59 -0800 | [diff] [blame] | 485 | // The only mask filter the native rrect drawing code could've handle was taken |
| 486 | // care of above. |
| 487 | // A path effect will presumably transform this rrect into something else. |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 488 | SkPath path; |
jvanverth | b3eb687 | 2014-10-24 07:12:51 -0700 | [diff] [blame] | 489 | path.setIsVolatile(true); |
robertphillips | 9aff85a | 2016-08-05 07:51:29 -0700 | [diff] [blame] | 490 | path.addRRect(rrect); |
Hal Canary | 144caf5 | 2016-11-07 17:57:18 -0500 | [diff] [blame] | 491 | GrBlurUtils::drawPathWithMaskFilter(fContext.get(), fRenderTargetContext.get(), |
robertphillips | ff55b49 | 2015-11-24 07:56:59 -0800 | [diff] [blame] | 492 | fClip, path, paint, |
| 493 | *draw.fMatrix, nullptr, |
Mike Reed | fa24d34 | 2017-02-22 15:21:35 -0500 | [diff] [blame] | 494 | this->devClipBounds(draw), true); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 495 | return; |
| 496 | } |
Mike Klein | 744fb73 | 2014-06-23 15:13:26 -0400 | [diff] [blame] | 497 | |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 498 | SkASSERT(!style.pathEffect()); |
robertphillips | 514450c | 2015-11-24 05:36:02 -0800 | [diff] [blame] | 499 | |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 500 | fRenderTargetContext->drawRRect(fClip, std::move(grPaint), GrBoolToAA(paint.isAntiAlias()), |
| 501 | *draw.fMatrix, rrect, style); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 502 | } |
| 503 | |
robertphillips | d770610 | 2016-02-25 09:28:08 -0800 | [diff] [blame] | 504 | |
commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 505 | void SkGpuDevice::drawDRRect(const SkDraw& draw, const SkRRect& outer, |
joshualitt | 5531d51 | 2014-12-17 15:50:11 -0800 | [diff] [blame] | 506 | const SkRRect& inner, const SkPaint& paint) { |
joshualitt | ce89400 | 2016-01-11 13:29:31 -0800 | [diff] [blame] | 507 | ASSERT_SINGLE_OWNER |
Hal Canary | 144caf5 | 2016-11-07 17:57:18 -0500 | [diff] [blame] | 508 | GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawDRRect", fContext.get()); |
robertphillips | 0e7029e | 2015-11-30 05:45:06 -0800 | [diff] [blame] | 509 | CHECK_SHOULD_DRAW(draw); |
| 510 | |
robertphillips | d770610 | 2016-02-25 09:28:08 -0800 | [diff] [blame] | 511 | if (outer.isEmpty()) { |
| 512 | return; |
| 513 | } |
| 514 | |
| 515 | if (inner.isEmpty()) { |
| 516 | return this->drawRRect(draw, outer, paint); |
| 517 | } |
| 518 | |
commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 519 | SkStrokeRec stroke(paint); |
commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 520 | |
robertphillips | 0e7029e | 2015-11-30 05:45:06 -0800 | [diff] [blame] | 521 | if (stroke.isFillStyle() && !paint.getMaskFilter() && !paint.getPathEffect()) { |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 522 | GrPaint grPaint; |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 523 | if (!SkPaintToGrPaint(this->context(), fRenderTargetContext.get(), paint, *draw.fMatrix, |
brianosman | 1638c0d | 2016-07-25 05:12:53 -0700 | [diff] [blame] | 524 | &grPaint)) { |
bsalomon | bed83a6 | 2015-04-15 14:18:34 -0700 | [diff] [blame] | 525 | return; |
| 526 | } |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 527 | |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 528 | fRenderTargetContext->drawDRRect(fClip, std::move(grPaint), GrBoolToAA(paint.isAntiAlias()), |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 529 | *draw.fMatrix, outer, inner); |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 530 | return; |
commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 531 | } |
| 532 | |
| 533 | SkPath path; |
jvanverth | b3eb687 | 2014-10-24 07:12:51 -0700 | [diff] [blame] | 534 | path.setIsVolatile(true); |
commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 535 | path.addRRect(outer); |
| 536 | path.addRRect(inner); |
| 537 | path.setFillType(SkPath::kEvenOdd_FillType); |
| 538 | |
Hal Canary | 144caf5 | 2016-11-07 17:57:18 -0500 | [diff] [blame] | 539 | GrBlurUtils::drawPathWithMaskFilter(fContext.get(), fRenderTargetContext.get(), |
robertphillips | 0e7029e | 2015-11-30 05:45:06 -0800 | [diff] [blame] | 540 | fClip, path, paint, |
| 541 | *draw.fMatrix, nullptr, |
Mike Reed | fa24d34 | 2017-02-22 15:21:35 -0500 | [diff] [blame] | 542 | this->devClipBounds(draw), true); |
commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 543 | } |
| 544 | |
| 545 | |
commit-bot@chromium.org | 8213970 | 2014-03-10 22:53:20 +0000 | [diff] [blame] | 546 | ///////////////////////////////////////////////////////////////////////////// |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 547 | |
msarett | cc319b9 | 2016-08-25 18:07:18 -0700 | [diff] [blame] | 548 | void SkGpuDevice::drawRegion(const SkDraw& draw, const SkRegion& region, const SkPaint& paint) { |
| 549 | if (paint.getMaskFilter()) { |
| 550 | SkPath path; |
| 551 | region.getBoundaryPath(&path); |
| 552 | return this->drawPath(draw, path, paint, nullptr, false); |
| 553 | } |
| 554 | |
| 555 | GrPaint grPaint; |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 556 | if (!SkPaintToGrPaint(this->context(), fRenderTargetContext.get(), paint, *draw.fMatrix, |
| 557 | &grPaint)) { |
msarett | cc319b9 | 2016-08-25 18:07:18 -0700 | [diff] [blame] | 558 | return; |
| 559 | } |
| 560 | |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 561 | fRenderTargetContext->drawRegion(fClip, std::move(grPaint), GrBoolToAA(paint.isAntiAlias()), |
| 562 | *draw.fMatrix, region, GrStyle(paint)); |
msarett | cc319b9 | 2016-08-25 18:07:18 -0700 | [diff] [blame] | 563 | } |
| 564 | |
robertphillips | 514450c | 2015-11-24 05:36:02 -0800 | [diff] [blame] | 565 | void SkGpuDevice::drawOval(const SkDraw& draw, const SkRect& oval, const SkPaint& paint) { |
joshualitt | ce89400 | 2016-01-11 13:29:31 -0800 | [diff] [blame] | 566 | ASSERT_SINGLE_OWNER |
Hal Canary | 144caf5 | 2016-11-07 17:57:18 -0500 | [diff] [blame] | 567 | GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawOval", fContext.get()); |
joshualitt | 5531d51 | 2014-12-17 15:50:11 -0800 | [diff] [blame] | 568 | CHECK_SHOULD_DRAW(draw); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 569 | |
robertphillips | 514450c | 2015-11-24 05:36:02 -0800 | [diff] [blame] | 570 | // Presumably the path effect warps this to something other than an oval |
| 571 | if (paint.getPathEffect()) { |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 572 | SkPath path; |
jvanverth | b3eb687 | 2014-10-24 07:12:51 -0700 | [diff] [blame] | 573 | path.setIsVolatile(true); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 574 | path.addOval(oval); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 575 | this->drawPath(draw, path, paint, nullptr, true); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 576 | return; |
herb | 11a7f7f | 2015-11-24 12:41:00 -0800 | [diff] [blame] | 577 | } |
| 578 | |
robertphillips | 514450c | 2015-11-24 05:36:02 -0800 | [diff] [blame] | 579 | if (paint.getMaskFilter()) { |
| 580 | // The RRect path can handle special case blurring |
| 581 | SkRRect rr = SkRRect::MakeOval(oval); |
| 582 | return this->drawRRect(draw, rr, paint); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 583 | } |
| 584 | |
| 585 | GrPaint grPaint; |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 586 | if (!SkPaintToGrPaint(this->context(), fRenderTargetContext.get(), paint, *draw.fMatrix, |
| 587 | &grPaint)) { |
bsalomon | bed83a6 | 2015-04-15 14:18:34 -0700 | [diff] [blame] | 588 | return; |
| 589 | } |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 590 | |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 591 | fRenderTargetContext->drawOval(fClip, std::move(grPaint), GrBoolToAA(paint.isAntiAlias()), |
| 592 | *draw.fMatrix, oval, GrStyle(paint)); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 593 | } |
| 594 | |
bsalomon | 4f3a0ca | 2016-08-22 13:14:26 -0700 | [diff] [blame] | 595 | void SkGpuDevice::drawArc(const SkDraw& draw, const SkRect& oval, SkScalar startAngle, |
| 596 | SkScalar sweepAngle, bool useCenter, const SkPaint& paint) { |
| 597 | ASSERT_SINGLE_OWNER |
Hal Canary | 144caf5 | 2016-11-07 17:57:18 -0500 | [diff] [blame] | 598 | GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawArc", fContext.get()); |
bsalomon | 4f3a0ca | 2016-08-22 13:14:26 -0700 | [diff] [blame] | 599 | CHECK_SHOULD_DRAW(draw); |
| 600 | |
| 601 | if (paint.getMaskFilter()) { |
| 602 | this->INHERITED::drawArc(draw, oval, startAngle, sweepAngle, useCenter, paint); |
| 603 | return; |
| 604 | } |
| 605 | GrPaint grPaint; |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 606 | if (!SkPaintToGrPaint(this->context(), fRenderTargetContext.get(), paint, *draw.fMatrix, |
| 607 | &grPaint)) { |
bsalomon | 4f3a0ca | 2016-08-22 13:14:26 -0700 | [diff] [blame] | 608 | return; |
| 609 | } |
| 610 | |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 611 | fRenderTargetContext->drawArc(fClip, std::move(grPaint), GrBoolToAA(paint.isAntiAlias()), |
| 612 | *draw.fMatrix, oval, startAngle, sweepAngle, useCenter, |
| 613 | GrStyle(paint)); |
bsalomon | 4f3a0ca | 2016-08-22 13:14:26 -0700 | [diff] [blame] | 614 | } |
| 615 | |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 616 | #include "SkMaskFilter.h" |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 617 | |
| 618 | /////////////////////////////////////////////////////////////////////////////// |
robertphillips | 0851d2d | 2016-06-02 05:21:34 -0700 | [diff] [blame] | 619 | void SkGpuDevice::drawStrokedLine(const SkPoint points[2], |
| 620 | const SkDraw& draw, |
| 621 | const SkPaint& origPaint) { |
| 622 | ASSERT_SINGLE_OWNER |
Hal Canary | 144caf5 | 2016-11-07 17:57:18 -0500 | [diff] [blame] | 623 | GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawStrokedLine", fContext.get()); |
robertphillips | 0851d2d | 2016-06-02 05:21:34 -0700 | [diff] [blame] | 624 | CHECK_SHOULD_DRAW(draw); |
| 625 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 626 | // Adding support for round capping would require a |
| 627 | // GrRenderTargetContext::fillRRectWithLocalMatrix entry point |
robertphillips | 0851d2d | 2016-06-02 05:21:34 -0700 | [diff] [blame] | 628 | SkASSERT(SkPaint::kRound_Cap != origPaint.getStrokeCap()); |
| 629 | SkASSERT(SkPaint::kStroke_Style == origPaint.getStyle()); |
| 630 | SkASSERT(!origPaint.getPathEffect()); |
| 631 | SkASSERT(!origPaint.getMaskFilter()); |
| 632 | |
| 633 | const SkScalar halfWidth = 0.5f * origPaint.getStrokeWidth(); |
| 634 | SkASSERT(halfWidth > 0); |
| 635 | |
| 636 | SkVector v = points[1] - points[0]; |
| 637 | |
| 638 | SkScalar length = SkPoint::Normalize(&v); |
| 639 | if (!length) { |
| 640 | v.fX = 1.0f; |
| 641 | v.fY = 0.0f; |
| 642 | } |
| 643 | |
| 644 | SkPaint newPaint(origPaint); |
| 645 | newPaint.setStyle(SkPaint::kFill_Style); |
| 646 | |
| 647 | SkScalar xtraLength = 0.0f; |
| 648 | if (SkPaint::kButt_Cap != origPaint.getStrokeCap()) { |
| 649 | xtraLength = halfWidth; |
| 650 | } |
| 651 | |
| 652 | SkPoint mid = points[0] + points[1]; |
| 653 | mid.scale(0.5f); |
| 654 | |
| 655 | SkRect rect = SkRect::MakeLTRB(mid.fX-halfWidth, mid.fY - 0.5f*length - xtraLength, |
| 656 | mid.fX+halfWidth, mid.fY + 0.5f*length + xtraLength); |
| 657 | SkMatrix m; |
| 658 | m.setSinCos(v.fX, -v.fY, mid.fX, mid.fY); |
| 659 | |
| 660 | SkMatrix local = m; |
| 661 | |
| 662 | m.postConcat(*draw.fMatrix); |
| 663 | |
| 664 | GrPaint grPaint; |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 665 | if (!SkPaintToGrPaint(this->context(), fRenderTargetContext.get(), newPaint, m, &grPaint)) { |
robertphillips | 0851d2d | 2016-06-02 05:21:34 -0700 | [diff] [blame] | 666 | return; |
| 667 | } |
| 668 | |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 669 | fRenderTargetContext->fillRectWithLocalMatrix( |
| 670 | fClip, std::move(grPaint), GrBoolToAA(newPaint.isAntiAlias()), m, rect, local); |
robertphillips | 0851d2d | 2016-06-02 05:21:34 -0700 | [diff] [blame] | 671 | } |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 672 | |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 673 | void SkGpuDevice::drawPath(const SkDraw& draw, const SkPath& origSrcPath, |
| 674 | const SkPaint& paint, const SkMatrix* prePathMatrix, |
| 675 | bool pathIsMutable) { |
joshualitt | ce89400 | 2016-01-11 13:29:31 -0800 | [diff] [blame] | 676 | ASSERT_SINGLE_OWNER |
robertphillips | ff55b49 | 2015-11-24 07:56:59 -0800 | [diff] [blame] | 677 | if (!origSrcPath.isInverseFillType() && !paint.getPathEffect() && !prePathMatrix) { |
robertphillips | 0851d2d | 2016-06-02 05:21:34 -0700 | [diff] [blame] | 678 | SkPoint points[2]; |
| 679 | if (SkPaint::kStroke_Style == paint.getStyle() && paint.getStrokeWidth() > 0 && |
| 680 | !paint.getMaskFilter() && SkPaint::kRound_Cap != paint.getStrokeCap() && |
| 681 | draw.fMatrix->preservesRightAngles() && origSrcPath.isLine(points)) { |
| 682 | // Path-based stroking looks better for thin rects |
| 683 | SkScalar strokeWidth = draw.fMatrix->getMaxScale() * paint.getStrokeWidth(); |
robertphillips | f2204c9 | 2016-06-02 10:57:59 -0700 | [diff] [blame] | 684 | if (strokeWidth >= 1.0f) { |
Brian Salomon | 09d994e | 2016-12-21 11:14:46 -0500 | [diff] [blame] | 685 | // Round capping support is currently disabled b.c. it would require a RRect |
| 686 | // GrDrawOp that takes a localMatrix. |
robertphillips | 0851d2d | 2016-06-02 05:21:34 -0700 | [diff] [blame] | 687 | this->drawStrokedLine(points, draw, paint); |
| 688 | return; |
| 689 | } |
| 690 | } |
robertphillips | ff55b49 | 2015-11-24 07:56:59 -0800 | [diff] [blame] | 691 | bool isClosed; |
| 692 | SkRect rect; |
| 693 | if (origSrcPath.isRect(&rect, &isClosed) && isClosed) { |
| 694 | this->drawRect(draw, rect, paint); |
| 695 | return; |
| 696 | } |
| 697 | if (origSrcPath.isOval(&rect)) { |
| 698 | this->drawOval(draw, rect, paint); |
| 699 | return; |
| 700 | } |
| 701 | SkRRect rrect; |
| 702 | if (origSrcPath.isRRect(&rrect)) { |
| 703 | this->drawRRect(draw, rrect, paint); |
| 704 | return; |
| 705 | } |
| 706 | } |
| 707 | |
joshualitt | 5531d51 | 2014-12-17 15:50:11 -0800 | [diff] [blame] | 708 | CHECK_SHOULD_DRAW(draw); |
Hal Canary | 144caf5 | 2016-11-07 17:57:18 -0500 | [diff] [blame] | 709 | GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawPath", fContext.get()); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 710 | |
Hal Canary | 144caf5 | 2016-11-07 17:57:18 -0500 | [diff] [blame] | 711 | GrBlurUtils::drawPathWithMaskFilter(fContext.get(), fRenderTargetContext.get(), |
robertphillips | ccb1b57 | 2015-05-27 11:02:55 -0700 | [diff] [blame] | 712 | fClip, origSrcPath, paint, |
| 713 | *draw.fMatrix, prePathMatrix, |
Mike Reed | fa24d34 | 2017-02-22 15:21:35 -0500 | [diff] [blame] | 714 | this->devClipBounds(draw), pathIsMutable); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 715 | } |
| 716 | |
| 717 | static const int kBmpSmallTileSize = 1 << 10; |
| 718 | |
| 719 | static inline int get_tile_count(const SkIRect& srcRect, int tileSize) { |
| 720 | int tilesX = (srcRect.fRight / tileSize) - (srcRect.fLeft / tileSize) + 1; |
| 721 | int tilesY = (srcRect.fBottom / tileSize) - (srcRect.fTop / tileSize) + 1; |
| 722 | return tilesX * tilesY; |
| 723 | } |
| 724 | |
reed | 85d9178 | 2015-09-10 14:33:38 -0700 | [diff] [blame] | 725 | static int determine_tile_size(const SkIRect& src, int maxTileSize) { |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 726 | if (maxTileSize <= kBmpSmallTileSize) { |
| 727 | return maxTileSize; |
| 728 | } |
| 729 | |
| 730 | size_t maxTileTotalTileSize = get_tile_count(src, maxTileSize); |
| 731 | size_t smallTotalTileSize = get_tile_count(src, kBmpSmallTileSize); |
| 732 | |
| 733 | maxTileTotalTileSize *= maxTileSize * maxTileSize; |
| 734 | smallTotalTileSize *= kBmpSmallTileSize * kBmpSmallTileSize; |
| 735 | |
| 736 | if (maxTileTotalTileSize > 2 * smallTotalTileSize) { |
| 737 | return kBmpSmallTileSize; |
| 738 | } else { |
| 739 | return maxTileSize; |
| 740 | } |
| 741 | } |
| 742 | |
| 743 | // Given a bitmap, an optional src rect, and a context with a clip and matrix determine what |
| 744 | // pixels from the bitmap are necessary. |
robertphillips | e576874 | 2016-05-13 11:20:46 -0700 | [diff] [blame] | 745 | static void determine_clipped_src_rect(int width, int height, |
joshualitt | 570d2f8 | 2015-02-25 13:19:48 -0800 | [diff] [blame] | 746 | const GrClip& clip, |
joshualitt | 5531d51 | 2014-12-17 15:50:11 -0800 | [diff] [blame] | 747 | const SkMatrix& viewMatrix, |
bsalomon | e553b64 | 2016-08-17 09:02:09 -0700 | [diff] [blame] | 748 | const SkMatrix& srcToDstRect, |
reed | 85d9178 | 2015-09-10 14:33:38 -0700 | [diff] [blame] | 749 | const SkISize& imageSize, |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 750 | const SkRect* srcRectPtr, |
| 751 | SkIRect* clippedSrcIRect) { |
robertphillips | e576874 | 2016-05-13 11:20:46 -0700 | [diff] [blame] | 752 | clip.getConservativeBounds(width, height, clippedSrcIRect, nullptr); |
bsalomon | e553b64 | 2016-08-17 09:02:09 -0700 | [diff] [blame] | 753 | SkMatrix inv = SkMatrix::Concat(viewMatrix, srcToDstRect); |
| 754 | if (!inv.invert(&inv)) { |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 755 | clippedSrcIRect->setEmpty(); |
| 756 | return; |
| 757 | } |
| 758 | SkRect clippedSrcRect = SkRect::Make(*clippedSrcIRect); |
| 759 | inv.mapRect(&clippedSrcRect); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 760 | if (srcRectPtr) { |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 761 | if (!clippedSrcRect.intersect(*srcRectPtr)) { |
| 762 | clippedSrcIRect->setEmpty(); |
| 763 | return; |
| 764 | } |
| 765 | } |
| 766 | clippedSrcRect.roundOut(clippedSrcIRect); |
reed | 85d9178 | 2015-09-10 14:33:38 -0700 | [diff] [blame] | 767 | SkIRect bmpBounds = SkIRect::MakeSize(imageSize); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 768 | if (!clippedSrcIRect->intersect(bmpBounds)) { |
| 769 | clippedSrcIRect->setEmpty(); |
| 770 | } |
| 771 | } |
| 772 | |
reed | 85d9178 | 2015-09-10 14:33:38 -0700 | [diff] [blame] | 773 | bool SkGpuDevice::shouldTileImageID(uint32_t imageID, const SkIRect& imageRect, |
| 774 | const SkMatrix& viewMatrix, |
bsalomon | e553b64 | 2016-08-17 09:02:09 -0700 | [diff] [blame] | 775 | const SkMatrix& srcToDstRect, |
Brian Salomon | 514baff | 2016-11-17 15:17:07 -0500 | [diff] [blame] | 776 | const GrSamplerParams& params, |
reed | 85d9178 | 2015-09-10 14:33:38 -0700 | [diff] [blame] | 777 | const SkRect* srcRectPtr, |
| 778 | int maxTileSize, |
| 779 | int* tileSize, |
| 780 | SkIRect* clippedSubset) const { |
joshualitt | ce89400 | 2016-01-11 13:29:31 -0800 | [diff] [blame] | 781 | ASSERT_SINGLE_OWNER |
reed | 85d9178 | 2015-09-10 14:33:38 -0700 | [diff] [blame] | 782 | // if it's larger than the max tile size, then we have no choice but tiling. |
| 783 | if (imageRect.width() > maxTileSize || imageRect.height() > maxTileSize) { |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 784 | determine_clipped_src_rect(fRenderTargetContext->width(), fRenderTargetContext->height(), |
| 785 | fClip, viewMatrix, srcToDstRect, imageRect.size(), srcRectPtr, |
| 786 | clippedSubset); |
reed | 85d9178 | 2015-09-10 14:33:38 -0700 | [diff] [blame] | 787 | *tileSize = determine_tile_size(*clippedSubset, maxTileSize); |
| 788 | return true; |
| 789 | } |
| 790 | |
bsalomon | 1a1d0b8 | 2015-10-16 07:49:42 -0700 | [diff] [blame] | 791 | // If the image would only produce 4 tiles of the smaller size, don't bother tiling it. |
reed | 85d9178 | 2015-09-10 14:33:38 -0700 | [diff] [blame] | 792 | const size_t area = imageRect.width() * imageRect.height(); |
| 793 | if (area < 4 * kBmpSmallTileSize * kBmpSmallTileSize) { |
| 794 | return false; |
| 795 | } |
| 796 | |
reed | 85d9178 | 2015-09-10 14:33:38 -0700 | [diff] [blame] | 797 | // At this point we know we could do the draw by uploading the entire bitmap |
| 798 | // as a texture. However, if the texture would be large compared to the |
| 799 | // cache size and we don't require most of it for this draw then tile to |
| 800 | // reduce the amount of upload and cache spill. |
| 801 | |
| 802 | // assumption here is that sw bitmap size is a good proxy for its size as |
| 803 | // a texture |
| 804 | size_t bmpSize = area * sizeof(SkPMColor); // assume 32bit pixels |
| 805 | size_t cacheSize; |
| 806 | fContext->getResourceCacheLimits(nullptr, &cacheSize); |
| 807 | if (bmpSize < cacheSize / 2) { |
| 808 | return false; |
| 809 | } |
| 810 | |
bsalomon | 1a1d0b8 | 2015-10-16 07:49:42 -0700 | [diff] [blame] | 811 | // Figure out how much of the src we will need based on the src rect and clipping. Reject if |
| 812 | // tiling memory savings would be < 50%. |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 813 | determine_clipped_src_rect(fRenderTargetContext->width(), fRenderTargetContext->height(), fClip, |
| 814 | viewMatrix, srcToDstRect, imageRect.size(), srcRectPtr, |
| 815 | clippedSubset); |
reed | 85d9178 | 2015-09-10 14:33:38 -0700 | [diff] [blame] | 816 | *tileSize = kBmpSmallTileSize; // already know whole bitmap fits in one max sized tile. |
| 817 | size_t usedTileBytes = get_tile_count(*clippedSubset, kBmpSmallTileSize) * |
Brian Osman | d05cdc3 | 2017-02-06 13:24:47 -0500 | [diff] [blame] | 818 | kBmpSmallTileSize * kBmpSmallTileSize * |
| 819 | sizeof(SkPMColor); // assume 32bit pixels; |
reed | 85d9178 | 2015-09-10 14:33:38 -0700 | [diff] [blame] | 820 | |
Brian Osman | d05cdc3 | 2017-02-06 13:24:47 -0500 | [diff] [blame] | 821 | return usedTileBytes * 2 < bmpSize; |
reed | 85d9178 | 2015-09-10 14:33:38 -0700 | [diff] [blame] | 822 | } |
| 823 | |
reed | 85d9178 | 2015-09-10 14:33:38 -0700 | [diff] [blame] | 824 | bool SkGpuDevice::shouldTileImage(const SkImage* image, const SkRect* srcRectPtr, |
| 825 | SkCanvas::SrcRectConstraint constraint, SkFilterQuality quality, |
bsalomon | e553b64 | 2016-08-17 09:02:09 -0700 | [diff] [blame] | 826 | const SkMatrix& viewMatrix, |
| 827 | const SkMatrix& srcToDstRect) const { |
joshualitt | ce89400 | 2016-01-11 13:29:31 -0800 | [diff] [blame] | 828 | ASSERT_SINGLE_OWNER |
reed | 85d9178 | 2015-09-10 14:33:38 -0700 | [diff] [blame] | 829 | // if image is explictly texture backed then just use the texture |
Robert Phillips | 6de9904 | 2017-01-31 11:31:39 -0500 | [diff] [blame] | 830 | if (image->isTextureBacked()) { |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 831 | return false; |
| 832 | } |
| 833 | |
Brian Salomon | 514baff | 2016-11-17 15:17:07 -0500 | [diff] [blame] | 834 | GrSamplerParams params; |
reed | 85d9178 | 2015-09-10 14:33:38 -0700 | [diff] [blame] | 835 | bool doBicubic; |
Brian Salomon | 514baff | 2016-11-17 15:17:07 -0500 | [diff] [blame] | 836 | GrSamplerParams::FilterMode textureFilterMode = |
bsalomon | e553b64 | 2016-08-17 09:02:09 -0700 | [diff] [blame] | 837 | GrSkFilterQualityToGrFilterMode(quality, viewMatrix, srcToDstRect, &doBicubic); |
reed | 85d9178 | 2015-09-10 14:33:38 -0700 | [diff] [blame] | 838 | |
| 839 | int tileFilterPad; |
| 840 | if (doBicubic) { |
| 841 | tileFilterPad = GrBicubicEffect::kFilterTexelPad; |
Brian Salomon | 514baff | 2016-11-17 15:17:07 -0500 | [diff] [blame] | 842 | } else if (GrSamplerParams::kNone_FilterMode == textureFilterMode) { |
reed | 85d9178 | 2015-09-10 14:33:38 -0700 | [diff] [blame] | 843 | tileFilterPad = 0; |
| 844 | } else { |
| 845 | tileFilterPad = 1; |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 846 | } |
reed | 85d9178 | 2015-09-10 14:33:38 -0700 | [diff] [blame] | 847 | params.setFilterMode(textureFilterMode); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 848 | |
bsalomon | 8c07b7a | 2015-11-02 11:36:52 -0800 | [diff] [blame] | 849 | int maxTileSize = fContext->caps()->maxTileSize() - 2 * tileFilterPad; |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 850 | |
reed | 85d9178 | 2015-09-10 14:33:38 -0700 | [diff] [blame] | 851 | // these are output, which we safely ignore, as we just want to know the predicate |
| 852 | int outTileSize; |
| 853 | SkIRect outClippedSrcRect; |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 854 | |
bsalomon | e553b64 | 2016-08-17 09:02:09 -0700 | [diff] [blame] | 855 | return this->shouldTileImageID(image->unique(), image->bounds(), viewMatrix, srcToDstRect, |
| 856 | params, srcRectPtr, maxTileSize, &outTileSize, |
| 857 | &outClippedSrcRect); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 858 | } |
| 859 | |
commit-bot@chromium.org | a7d89c8 | 2014-01-13 14:47:00 +0000 | [diff] [blame] | 860 | void SkGpuDevice::drawBitmap(const SkDraw& origDraw, |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 861 | const SkBitmap& bitmap, |
| 862 | const SkMatrix& m, |
| 863 | const SkPaint& paint) { |
joshualitt | ce89400 | 2016-01-11 13:29:31 -0800 | [diff] [blame] | 864 | ASSERT_SINGLE_OWNER |
bsalomon | b1b0199 | 2015-11-18 10:56:08 -0800 | [diff] [blame] | 865 | CHECK_SHOULD_DRAW(origDraw); |
bsalomon | b1b0199 | 2015-11-18 10:56:08 -0800 | [diff] [blame] | 866 | SkMatrix viewMatrix; |
| 867 | viewMatrix.setConcat(*origDraw.fMatrix, m); |
reed | c7ec7c9 | 2016-07-25 08:29:10 -0700 | [diff] [blame] | 868 | |
bsalomon | b1b0199 | 2015-11-18 10:56:08 -0800 | [diff] [blame] | 869 | int maxTileSize = fContext->caps()->maxTileSize(); |
| 870 | |
| 871 | // The tile code path doesn't currently support AA, so if the paint asked for aa and we could |
| 872 | // draw untiled, then we bypass checking for tiling purely for optimization reasons. |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 873 | bool drawAA = !fRenderTargetContext->isUnifiedMultisampled() && |
bsalomon | b1b0199 | 2015-11-18 10:56:08 -0800 | [diff] [blame] | 874 | paint.isAntiAlias() && |
| 875 | bitmap.width() <= maxTileSize && |
| 876 | bitmap.height() <= maxTileSize; |
| 877 | |
| 878 | bool skipTileCheck = drawAA || paint.getMaskFilter(); |
| 879 | |
| 880 | if (!skipTileCheck) { |
| 881 | SkRect srcRect = SkRect::MakeIWH(bitmap.width(), bitmap.height()); |
| 882 | int tileSize; |
| 883 | SkIRect clippedSrcRect; |
| 884 | |
Brian Salomon | 514baff | 2016-11-17 15:17:07 -0500 | [diff] [blame] | 885 | GrSamplerParams params; |
bsalomon | b1b0199 | 2015-11-18 10:56:08 -0800 | [diff] [blame] | 886 | bool doBicubic; |
Brian Salomon | 514baff | 2016-11-17 15:17:07 -0500 | [diff] [blame] | 887 | GrSamplerParams::FilterMode textureFilterMode = |
bsalomon | b1b0199 | 2015-11-18 10:56:08 -0800 | [diff] [blame] | 888 | GrSkFilterQualityToGrFilterMode(paint.getFilterQuality(), viewMatrix, SkMatrix::I(), |
| 889 | &doBicubic); |
| 890 | |
| 891 | int tileFilterPad; |
| 892 | |
| 893 | if (doBicubic) { |
| 894 | tileFilterPad = GrBicubicEffect::kFilterTexelPad; |
Brian Salomon | 514baff | 2016-11-17 15:17:07 -0500 | [diff] [blame] | 895 | } else if (GrSamplerParams::kNone_FilterMode == textureFilterMode) { |
bsalomon | b1b0199 | 2015-11-18 10:56:08 -0800 | [diff] [blame] | 896 | tileFilterPad = 0; |
| 897 | } else { |
| 898 | tileFilterPad = 1; |
| 899 | } |
| 900 | params.setFilterMode(textureFilterMode); |
| 901 | |
| 902 | int maxTileSizeForFilter = fContext->caps()->maxTileSize() - 2 * tileFilterPad; |
bsalomon | e553b64 | 2016-08-17 09:02:09 -0700 | [diff] [blame] | 903 | if (this->shouldTileImageID(bitmap.getGenerationID(), bitmap.getSubset(), viewMatrix, |
| 904 | SkMatrix::I(), params, &srcRect, maxTileSizeForFilter, |
| 905 | &tileSize, &clippedSrcRect)) { |
| 906 | this->drawTiledBitmap(bitmap, viewMatrix, SkMatrix::I(), srcRect, clippedSrcRect, |
| 907 | params, paint, SkCanvas::kStrict_SrcRectConstraint, tileSize, |
| 908 | doBicubic); |
bsalomon | b1b0199 | 2015-11-18 10:56:08 -0800 | [diff] [blame] | 909 | return; |
| 910 | } |
commit-bot@chromium.org | a7d89c8 | 2014-01-13 14:47:00 +0000 | [diff] [blame] | 911 | } |
Hal Canary | 144caf5 | 2016-11-07 17:57:18 -0500 | [diff] [blame] | 912 | GrBitmapTextureMaker maker(fContext.get(), bitmap); |
bsalomon | f1ecd21 | 2015-12-09 17:06:02 -0800 | [diff] [blame] | 913 | this->drawTextureProducer(&maker, nullptr, nullptr, SkCanvas::kStrict_SrcRectConstraint, |
| 914 | viewMatrix, fClip, paint); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 915 | } |
| 916 | |
commit-bot@chromium.org | dec6150 | 2013-12-02 22:22:35 +0000 | [diff] [blame] | 917 | // This method outsets 'iRect' by 'outset' all around and then clamps its extents to |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 918 | // 'clamp'. 'offset' is adjusted to remain positioned over the top-left corner |
| 919 | // of 'iRect' for all possible outsets/clamps. |
commit-bot@chromium.org | dec6150 | 2013-12-02 22:22:35 +0000 | [diff] [blame] | 920 | static inline void clamped_outset_with_offset(SkIRect* iRect, |
| 921 | int outset, |
| 922 | SkPoint* offset, |
| 923 | const SkIRect& clamp) { |
| 924 | iRect->outset(outset, outset); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 925 | |
commit-bot@chromium.org | dec6150 | 2013-12-02 22:22:35 +0000 | [diff] [blame] | 926 | int leftClampDelta = clamp.fLeft - iRect->fLeft; |
| 927 | if (leftClampDelta > 0) { |
| 928 | offset->fX -= outset - leftClampDelta; |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 929 | iRect->fLeft = clamp.fLeft; |
| 930 | } else { |
commit-bot@chromium.org | dec6150 | 2013-12-02 22:22:35 +0000 | [diff] [blame] | 931 | offset->fX -= outset; |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 932 | } |
commit-bot@chromium.org | dec6150 | 2013-12-02 22:22:35 +0000 | [diff] [blame] | 933 | |
| 934 | int topClampDelta = clamp.fTop - iRect->fTop; |
| 935 | if (topClampDelta > 0) { |
| 936 | offset->fY -= outset - topClampDelta; |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 937 | iRect->fTop = clamp.fTop; |
| 938 | } else { |
commit-bot@chromium.org | dec6150 | 2013-12-02 22:22:35 +0000 | [diff] [blame] | 939 | offset->fY -= outset; |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 940 | } |
| 941 | |
| 942 | if (iRect->fRight > clamp.fRight) { |
| 943 | iRect->fRight = clamp.fRight; |
| 944 | } |
| 945 | if (iRect->fBottom > clamp.fBottom) { |
| 946 | iRect->fBottom = clamp.fBottom; |
| 947 | } |
| 948 | } |
| 949 | |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 950 | // Break 'bitmap' into several tiles to draw it since it has already |
| 951 | // been determined to be too large to fit in VRAM |
| 952 | void SkGpuDevice::drawTiledBitmap(const SkBitmap& bitmap, |
joshualitt | 5531d51 | 2014-12-17 15:50:11 -0800 | [diff] [blame] | 953 | const SkMatrix& viewMatrix, |
bsalomon | e553b64 | 2016-08-17 09:02:09 -0700 | [diff] [blame] | 954 | const SkMatrix& dstMatrix, |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 955 | const SkRect& srcRect, |
| 956 | const SkIRect& clippedSrcIRect, |
Brian Salomon | 514baff | 2016-11-17 15:17:07 -0500 | [diff] [blame] | 957 | const GrSamplerParams& params, |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 958 | const SkPaint& origPaint, |
reed | a5517e2 | 2015-07-14 10:54:12 -0700 | [diff] [blame] | 959 | SkCanvas::SrcRectConstraint constraint, |
commit-bot@chromium.org | dec6150 | 2013-12-02 22:22:35 +0000 | [diff] [blame] | 960 | int tileSize, |
| 961 | bool bicubic) { |
joshualitt | ce89400 | 2016-01-11 13:29:31 -0800 | [diff] [blame] | 962 | ASSERT_SINGLE_OWNER |
ericrk | 369e937 | 2016-02-05 15:32:36 -0800 | [diff] [blame] | 963 | |
ericrk | 983294f | 2016-04-18 09:14:00 -0700 | [diff] [blame] | 964 | // This is the funnel for all paths that draw tiled bitmaps/images. Log histogram entries. |
ericrk | 369e937 | 2016-02-05 15:32:36 -0800 | [diff] [blame] | 965 | SK_HISTOGRAM_BOOLEAN("DrawTiled", true); |
ericrk | 983294f | 2016-04-18 09:14:00 -0700 | [diff] [blame] | 966 | LogDrawScaleFactor(viewMatrix, origPaint.getFilterQuality()); |
ericrk | 369e937 | 2016-02-05 15:32:36 -0800 | [diff] [blame] | 967 | |
commit-bot@chromium.org | 9d5e3f1 | 2014-05-01 21:23:19 +0000 | [diff] [blame] | 968 | // The following pixel lock is technically redundant, but it is desirable |
| 969 | // to lock outside of the tile loop to prevent redecoding the whole image |
| 970 | // at each tile in cases where 'bitmap' holds an SkDiscardablePixelRef that |
| 971 | // is larger than the limit of the discardable memory pool. |
| 972 | SkAutoLockPixels alp(bitmap); |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 973 | |
| 974 | const SkPaint* paint = &origPaint; |
| 975 | SkPaint tempPaint; |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 976 | if (origPaint.isAntiAlias() && !fRenderTargetContext->isUnifiedMultisampled()) { |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 977 | // Drop antialiasing to avoid seams at tile boundaries. |
| 978 | tempPaint = origPaint; |
| 979 | tempPaint.setAntiAlias(false); |
| 980 | paint = &tempPaint; |
| 981 | } |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 982 | SkRect clippedSrcRect = SkRect::Make(clippedSrcIRect); |
| 983 | |
| 984 | int nx = bitmap.width() / tileSize; |
| 985 | int ny = bitmap.height() / tileSize; |
| 986 | for (int x = 0; x <= nx; x++) { |
| 987 | for (int y = 0; y <= ny; y++) { |
| 988 | SkRect tileR; |
| 989 | tileR.set(SkIntToScalar(x * tileSize), |
| 990 | SkIntToScalar(y * tileSize), |
| 991 | SkIntToScalar((x + 1) * tileSize), |
| 992 | SkIntToScalar((y + 1) * tileSize)); |
| 993 | |
| 994 | if (!SkRect::Intersects(tileR, clippedSrcRect)) { |
| 995 | continue; |
| 996 | } |
| 997 | |
| 998 | if (!tileR.intersect(srcRect)) { |
| 999 | continue; |
| 1000 | } |
| 1001 | |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1002 | SkIRect iTileR; |
| 1003 | tileR.roundOut(&iTileR); |
bsalomon | e553b64 | 2016-08-17 09:02:09 -0700 | [diff] [blame] | 1004 | SkVector offset = SkPoint::Make(SkIntToScalar(iTileR.fLeft), |
| 1005 | SkIntToScalar(iTileR.fTop)); |
Brian Osman | a950a86 | 2017-02-06 16:48:57 -0500 | [diff] [blame] | 1006 | SkRect rectToDraw = tileR; |
bsalomon | e553b64 | 2016-08-17 09:02:09 -0700 | [diff] [blame] | 1007 | dstMatrix.mapRect(&rectToDraw); |
Brian Salomon | 514baff | 2016-11-17 15:17:07 -0500 | [diff] [blame] | 1008 | if (GrSamplerParams::kNone_FilterMode != params.filterMode() || bicubic) { |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1009 | SkIRect iClampRect; |
| 1010 | |
reed | a5517e2 | 2015-07-14 10:54:12 -0700 | [diff] [blame] | 1011 | if (SkCanvas::kFast_SrcRectConstraint == constraint) { |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1012 | // In bleed mode we want to always expand the tile on all edges |
| 1013 | // but stay within the bitmap bounds |
| 1014 | iClampRect = SkIRect::MakeWH(bitmap.width(), bitmap.height()); |
| 1015 | } else { |
| 1016 | // In texture-domain/clamp mode we only want to expand the |
| 1017 | // tile on edges interior to "srcRect" (i.e., we want to |
| 1018 | // not bleed across the original clamped edges) |
| 1019 | srcRect.roundOut(&iClampRect); |
| 1020 | } |
commit-bot@chromium.org | dec6150 | 2013-12-02 22:22:35 +0000 | [diff] [blame] | 1021 | int outset = bicubic ? GrBicubicEffect::kFilterTexelPad : 1; |
| 1022 | clamped_outset_with_offset(&iTileR, outset, &offset, iClampRect); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1023 | } |
| 1024 | |
bsalomon | e553b64 | 2016-08-17 09:02:09 -0700 | [diff] [blame] | 1025 | SkBitmap tmpB; |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1026 | if (bitmap.extractSubset(&tmpB, iTileR)) { |
| 1027 | // now offset it to make it "local" to our tmp bitmap |
| 1028 | tileR.offset(-offset.fX, -offset.fY); |
bsalomon | b1b0199 | 2015-11-18 10:56:08 -0800 | [diff] [blame] | 1029 | // de-optimized this determination |
| 1030 | bool needsTextureDomain = true; |
bsalomon | e553b64 | 2016-08-17 09:02:09 -0700 | [diff] [blame] | 1031 | this->drawBitmapTile(tmpB, |
| 1032 | viewMatrix, |
| 1033 | rectToDraw, |
| 1034 | tileR, |
Robert Phillips | e14d305 | 2017-02-15 13:18:21 -0500 | [diff] [blame] | 1035 | params, |
bsalomon | e553b64 | 2016-08-17 09:02:09 -0700 | [diff] [blame] | 1036 | *paint, |
| 1037 | constraint, |
| 1038 | bicubic, |
| 1039 | needsTextureDomain); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1040 | } |
| 1041 | } |
| 1042 | } |
| 1043 | } |
| 1044 | |
bsalomon | e553b64 | 2016-08-17 09:02:09 -0700 | [diff] [blame] | 1045 | void SkGpuDevice::drawBitmapTile(const SkBitmap& bitmap, |
| 1046 | const SkMatrix& viewMatrix, |
| 1047 | const SkRect& dstRect, |
| 1048 | const SkRect& srcRect, |
Brian Salomon | 514baff | 2016-11-17 15:17:07 -0500 | [diff] [blame] | 1049 | const GrSamplerParams& params, |
bsalomon | e553b64 | 2016-08-17 09:02:09 -0700 | [diff] [blame] | 1050 | const SkPaint& paint, |
| 1051 | SkCanvas::SrcRectConstraint constraint, |
| 1052 | bool bicubic, |
| 1053 | bool needsTextureDomain) { |
bsalomon | 9c58654 | 2015-11-02 12:33:21 -0800 | [diff] [blame] | 1054 | // We should have already handled bitmaps larger than the max texture size. |
| 1055 | SkASSERT(bitmap.width() <= fContext->caps()->maxTextureSize() && |
| 1056 | bitmap.height() <= fContext->caps()->maxTextureSize()); |
reed | c7ec7c9 | 2016-07-25 08:29:10 -0700 | [diff] [blame] | 1057 | // We should be respecting the max tile size by the time we get here. |
| 1058 | SkASSERT(bitmap.width() <= fContext->caps()->maxTileSize() && |
| 1059 | bitmap.height() <= fContext->caps()->maxTileSize()); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1060 | |
Robert Phillips | e14d305 | 2017-02-15 13:18:21 -0500 | [diff] [blame] | 1061 | SkASSERT(SkShader::kClamp_TileMode == params.getTileModeX() && |
| 1062 | SkShader::kClamp_TileMode == params.getTileModeY()); |
| 1063 | |
Robert Phillips | 67c18d6 | 2017-01-20 12:44:06 -0500 | [diff] [blame] | 1064 | sk_sp<GrTexture> texture = GrMakeCachedBitmapTexture(fContext.get(), bitmap, |
Robert Phillips | e14d305 | 2017-02-15 13:18:21 -0500 | [diff] [blame] | 1065 | params, nullptr); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1066 | if (nullptr == texture) { |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1067 | return; |
| 1068 | } |
brianosman | 500bb3e | 2016-07-22 10:33:07 -0700 | [diff] [blame] | 1069 | sk_sp<GrColorSpaceXform> colorSpaceXform = |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1070 | GrColorSpaceXform::Make(bitmap.colorSpace(), fRenderTargetContext->getColorSpace()); |
bsalomon | e553b64 | 2016-08-17 09:02:09 -0700 | [diff] [blame] | 1071 | |
bsalomon | e553b64 | 2016-08-17 09:02:09 -0700 | [diff] [blame] | 1072 | // Compute a matrix that maps the rect we will draw to the src rect. |
Robert Phillips | e14d305 | 2017-02-15 13:18:21 -0500 | [diff] [blame] | 1073 | const SkMatrix texMatrix = SkMatrix::MakeRectToRect(dstRect, srcRect, |
| 1074 | SkMatrix::kFill_ScaleToFit); |
joshualitt | 5f10b5c | 2015-07-09 10:24:35 -0700 | [diff] [blame] | 1075 | |
| 1076 | // Construct a GrPaint by setting the bitmap texture as the first effect and then configuring |
| 1077 | // the rest from the SkPaint. |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 1078 | sk_sp<GrFragmentProcessor> fp; |
joshualitt | 5f10b5c | 2015-07-09 10:24:35 -0700 | [diff] [blame] | 1079 | |
reed | a5517e2 | 2015-07-14 10:54:12 -0700 | [diff] [blame] | 1080 | if (needsTextureDomain && (SkCanvas::kStrict_SrcRectConstraint == constraint)) { |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1081 | // Use a constrained texture domain to avoid color bleeding |
bsalomon | e553b64 | 2016-08-17 09:02:09 -0700 | [diff] [blame] | 1082 | SkRect domain; |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1083 | if (srcRect.width() > SK_Scalar1) { |
Robert Phillips | e98234f | 2017-01-09 14:23:59 -0500 | [diff] [blame] | 1084 | domain.fLeft = srcRect.fLeft + 0.5f; |
| 1085 | domain.fRight = srcRect.fRight - 0.5f; |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1086 | } else { |
Robert Phillips | e98234f | 2017-01-09 14:23:59 -0500 | [diff] [blame] | 1087 | domain.fLeft = domain.fRight = srcRect.centerX(); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1088 | } |
| 1089 | if (srcRect.height() > SK_Scalar1) { |
Robert Phillips | e98234f | 2017-01-09 14:23:59 -0500 | [diff] [blame] | 1090 | domain.fTop = srcRect.fTop + 0.5f; |
| 1091 | domain.fBottom = srcRect.fBottom - 0.5f; |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1092 | } else { |
Robert Phillips | e98234f | 2017-01-09 14:23:59 -0500 | [diff] [blame] | 1093 | domain.fTop = domain.fBottom = srcRect.centerY(); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1094 | } |
commit-bot@chromium.org | 7d7f314 | 2013-12-16 15:18:11 +0000 | [diff] [blame] | 1095 | if (bicubic) { |
reed | c7ec7c9 | 2016-07-25 08:29:10 -0700 | [diff] [blame] | 1096 | fp = GrBicubicEffect::Make(texture.get(), std::move(colorSpaceXform), texMatrix, |
bsalomon | e553b64 | 2016-08-17 09:02:09 -0700 | [diff] [blame] | 1097 | domain); |
commit-bot@chromium.org | 7d7f314 | 2013-12-16 15:18:11 +0000 | [diff] [blame] | 1098 | } else { |
reed | c7ec7c9 | 2016-07-25 08:29:10 -0700 | [diff] [blame] | 1099 | fp = GrTextureDomainEffect::Make(texture.get(), std::move(colorSpaceXform), texMatrix, |
bsalomon | e553b64 | 2016-08-17 09:02:09 -0700 | [diff] [blame] | 1100 | domain, GrTextureDomain::kClamp_Mode, |
brianosman | 54f30c1 | 2016-07-18 10:53:52 -0700 | [diff] [blame] | 1101 | params.filterMode()); |
commit-bot@chromium.org | 7d7f314 | 2013-12-16 15:18:11 +0000 | [diff] [blame] | 1102 | } |
commit-bot@chromium.org | dec6150 | 2013-12-02 22:22:35 +0000 | [diff] [blame] | 1103 | } else if (bicubic) { |
Brian Salomon | 514baff | 2016-11-17 15:17:07 -0500 | [diff] [blame] | 1104 | SkASSERT(GrSamplerParams::kNone_FilterMode == params.filterMode()); |
commit-bot@chromium.org | bc91fd7 | 2013-12-10 12:53:39 +0000 | [diff] [blame] | 1105 | SkShader::TileMode tileModes[2] = { params.getTileModeX(), params.getTileModeY() }; |
reed | c7ec7c9 | 2016-07-25 08:29:10 -0700 | [diff] [blame] | 1106 | fp = GrBicubicEffect::Make(texture.get(), std::move(colorSpaceXform), texMatrix, tileModes); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1107 | } else { |
reed | c7ec7c9 | 2016-07-25 08:29:10 -0700 | [diff] [blame] | 1108 | fp = GrSimpleTextureEffect::Make(texture.get(), std::move(colorSpaceXform), texMatrix, params); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1109 | } |
| 1110 | |
joshualitt | 33a5fce | 2015-11-18 13:28:51 -0800 | [diff] [blame] | 1111 | GrPaint grPaint; |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1112 | if (!SkPaintToGrPaintWithTexture(this->context(), fRenderTargetContext.get(), paint, viewMatrix, |
brianosman | 8fe485b | 2016-07-25 12:31:51 -0700 | [diff] [blame] | 1113 | std::move(fp), kAlpha_8_SkColorType == bitmap.colorType(), |
| 1114 | &grPaint)) { |
bsalomon | bed83a6 | 2015-04-15 14:18:34 -0700 | [diff] [blame] | 1115 | return; |
| 1116 | } |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1117 | |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1118 | // Coverage-based AA would cause seams between tiles. |
| 1119 | GrAA aa = GrBoolToAA(paint.isAntiAlias() && |
| 1120 | fRenderTargetContext->isStencilBufferMultisampled()); |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1121 | fRenderTargetContext->drawRect(fClip, std::move(grPaint), aa, viewMatrix, dstRect); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1122 | } |
| 1123 | |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1124 | void SkGpuDevice::drawSprite(const SkDraw& draw, const SkBitmap& bitmap, |
| 1125 | int left, int top, const SkPaint& paint) { |
joshualitt | ce89400 | 2016-01-11 13:29:31 -0800 | [diff] [blame] | 1126 | ASSERT_SINGLE_OWNER |
joshualitt | 5531d51 | 2014-12-17 15:50:11 -0800 | [diff] [blame] | 1127 | CHECK_SHOULD_DRAW(draw); |
Hal Canary | 144caf5 | 2016-11-07 17:57:18 -0500 | [diff] [blame] | 1128 | GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawSprite", fContext.get()); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1129 | |
robertphillips | 970587b | 2016-07-14 14:12:55 -0700 | [diff] [blame] | 1130 | if (fContext->abandoned()) { |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1131 | return; |
| 1132 | } |
| 1133 | |
Robert Phillips | e14d305 | 2017-02-15 13:18:21 -0500 | [diff] [blame] | 1134 | sk_sp<SkSpecialImage> srcImg = this->makeSpecial(bitmap); |
| 1135 | if (!srcImg) { |
| 1136 | return; |
joshualitt | 5f5a8d7 | 2015-02-25 14:09:45 -0800 | [diff] [blame] | 1137 | } |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1138 | |
robertphillips | 970587b | 2016-07-14 14:12:55 -0700 | [diff] [blame] | 1139 | this->drawSpecial(draw, srcImg.get(), left, top, paint); |
| 1140 | } |
| 1141 | |
| 1142 | |
Mike Klein | e54c75f | 2016-10-13 14:18:09 -0400 | [diff] [blame] | 1143 | void SkGpuDevice::drawSpecial(const SkDraw& draw, |
robertphillips | 970587b | 2016-07-14 14:12:55 -0700 | [diff] [blame] | 1144 | SkSpecialImage* special1, |
| 1145 | int left, int top, |
| 1146 | const SkPaint& paint) { |
robertphillips | 1b5f968 | 2016-07-15 08:01:12 -0700 | [diff] [blame] | 1147 | ASSERT_SINGLE_OWNER |
| 1148 | CHECK_SHOULD_DRAW(draw); |
Hal Canary | 144caf5 | 2016-11-07 17:57:18 -0500 | [diff] [blame] | 1149 | GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawSpecial", fContext.get()); |
robertphillips | 970587b | 2016-07-14 14:12:55 -0700 | [diff] [blame] | 1150 | |
| 1151 | SkIPoint offset = { 0, 0 }; |
| 1152 | |
| 1153 | sk_sp<SkSpecialImage> result; |
| 1154 | if (paint.getImageFilter()) { |
| 1155 | result = this->filterTexture(draw, special1, left, top, |
| 1156 | &offset, |
| 1157 | paint.getImageFilter()); |
| 1158 | if (!result) { |
| 1159 | return; |
| 1160 | } |
| 1161 | } else { |
| 1162 | result = sk_ref_sp(special1); |
| 1163 | } |
| 1164 | |
| 1165 | SkASSERT(result->isTextureBacked()); |
Robert Phillips | 2c6d2bf | 2017-02-21 10:19:29 -0500 | [diff] [blame] | 1166 | sk_sp<GrTextureProxy> proxy = result->asTextureProxyRef(this->context()); |
Robert Phillips | 8e1c4e6 | 2017-02-19 12:27:01 -0500 | [diff] [blame] | 1167 | if (!proxy) { |
Robert Phillips | 833dcf4 | 2016-11-18 08:44:13 -0500 | [diff] [blame] | 1168 | return; |
| 1169 | } |
robertphillips | 970587b | 2016-07-14 14:12:55 -0700 | [diff] [blame] | 1170 | |
Robert Phillips | 8e1c4e6 | 2017-02-19 12:27:01 -0500 | [diff] [blame] | 1171 | const GrPixelConfig config = proxy->config(); |
| 1172 | |
robertphillips | 970587b | 2016-07-14 14:12:55 -0700 | [diff] [blame] | 1173 | SkPaint tmpUnfiltered(paint); |
| 1174 | tmpUnfiltered.setImageFilter(nullptr); |
| 1175 | |
brianosman | 77320db | 2016-09-07 08:09:10 -0700 | [diff] [blame] | 1176 | sk_sp<GrColorSpaceXform> colorSpaceXform = |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1177 | GrColorSpaceXform::Make(result->getColorSpace(), fRenderTargetContext->getColorSpace()); |
Robert Phillips | 2c6d2bf | 2017-02-21 10:19:29 -0500 | [diff] [blame] | 1178 | |
| 1179 | sk_sp<GrFragmentProcessor> fp(GrSimpleTextureEffect::Make(this->context(), |
Robert Phillips | 8e1c4e6 | 2017-02-19 12:27:01 -0500 | [diff] [blame] | 1180 | std::move(proxy), |
brianosman | 77320db | 2016-09-07 08:09:10 -0700 | [diff] [blame] | 1181 | std::move(colorSpaceXform), |
brianosman | 54f30c1 | 2016-07-18 10:53:52 -0700 | [diff] [blame] | 1182 | SkMatrix::I())); |
Robert Phillips | 8e1c4e6 | 2017-02-19 12:27:01 -0500 | [diff] [blame] | 1183 | if (GrPixelConfigIsAlphaOnly(config)) { |
Brian Salomon | 22af73f | 2017-01-26 11:25:12 -0500 | [diff] [blame] | 1184 | fp = GrFragmentProcessor::MakeInputPremulAndMulByOutput(std::move(fp)); |
bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 1185 | } else { |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 1186 | fp = GrFragmentProcessor::MulOutputByInputAlpha(std::move(fp)); |
bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 1187 | } |
Robert Phillips | 8e1c4e6 | 2017-02-19 12:27:01 -0500 | [diff] [blame] | 1188 | |
| 1189 | GrPaint grPaint; |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1190 | if (!SkPaintToGrPaintReplaceShader(this->context(), fRenderTargetContext.get(), tmpUnfiltered, |
brianosman | 8fe485b | 2016-07-25 12:31:51 -0700 | [diff] [blame] | 1191 | std::move(fp), &grPaint)) { |
bsalomon | bed83a6 | 2015-04-15 14:18:34 -0700 | [diff] [blame] | 1192 | return; |
| 1193 | } |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1194 | |
robertphillips | 970587b | 2016-07-14 14:12:55 -0700 | [diff] [blame] | 1195 | const SkIRect& subset = result->subset(); |
| 1196 | |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1197 | fRenderTargetContext->fillRectToRect( |
| 1198 | fClip, |
| 1199 | std::move(grPaint), |
| 1200 | GrBoolToAA(paint.isAntiAlias()), |
| 1201 | SkMatrix::I(), |
| 1202 | SkRect::Make(SkIRect::MakeXYWH( |
| 1203 | left + offset.fX, top + offset.fY, subset.width(), subset.height())), |
Robert Phillips | 67c18d6 | 2017-01-20 12:44:06 -0500 | [diff] [blame] | 1204 | SkRect::Make(subset)); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1205 | } |
| 1206 | |
bsalomon | b1b0199 | 2015-11-18 10:56:08 -0800 | [diff] [blame] | 1207 | void SkGpuDevice::drawBitmapRect(const SkDraw& draw, const SkBitmap& bitmap, |
| 1208 | const SkRect* src, const SkRect& origDst, |
reed | 562fe47 | 2015-07-28 07:35:14 -0700 | [diff] [blame] | 1209 | const SkPaint& paint, SkCanvas::SrcRectConstraint constraint) { |
joshualitt | ce89400 | 2016-01-11 13:29:31 -0800 | [diff] [blame] | 1210 | ASSERT_SINGLE_OWNER |
lsalzman | 973ed24 | 2016-01-14 13:06:41 -0800 | [diff] [blame] | 1211 | CHECK_SHOULD_DRAW(draw); |
reed | c7ec7c9 | 2016-07-25 08:29:10 -0700 | [diff] [blame] | 1212 | |
bsalomon | b1b0199 | 2015-11-18 10:56:08 -0800 | [diff] [blame] | 1213 | // The src rect is inferred to be the bmp bounds if not provided. Otherwise, the src rect must |
| 1214 | // be clipped to the bmp bounds. To determine tiling parameters we need the filter mode which |
| 1215 | // in turn requires knowing the src-to-dst mapping. If the src was clipped to the bmp bounds |
| 1216 | // then we use the src-to-dst mapping to compute a new clipped dst rect. |
| 1217 | const SkRect* dst = &origDst; |
| 1218 | const SkRect bmpBounds = SkRect::MakeIWH(bitmap.width(), bitmap.height()); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1219 | // Compute matrix from the two rectangles |
bsalomon | b1b0199 | 2015-11-18 10:56:08 -0800 | [diff] [blame] | 1220 | if (!src) { |
| 1221 | src = &bmpBounds; |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1222 | } |
commit-bot@chromium.org | a7d89c8 | 2014-01-13 14:47:00 +0000 | [diff] [blame] | 1223 | |
bsalomon | b1b0199 | 2015-11-18 10:56:08 -0800 | [diff] [blame] | 1224 | SkMatrix srcToDstMatrix; |
| 1225 | if (!srcToDstMatrix.setRectToRect(*src, *dst, SkMatrix::kFill_ScaleToFit)) { |
| 1226 | return; |
| 1227 | } |
| 1228 | SkRect tmpSrc, tmpDst; |
| 1229 | if (src != &bmpBounds) { |
| 1230 | if (!bmpBounds.contains(*src)) { |
| 1231 | tmpSrc = *src; |
| 1232 | if (!tmpSrc.intersect(bmpBounds)) { |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1233 | return; // nothing to draw |
| 1234 | } |
bsalomon | b1b0199 | 2015-11-18 10:56:08 -0800 | [diff] [blame] | 1235 | src = &tmpSrc; |
| 1236 | srcToDstMatrix.mapRect(&tmpDst, *src); |
| 1237 | dst = &tmpDst; |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1238 | } |
| 1239 | } |
| 1240 | |
bsalomon | b1b0199 | 2015-11-18 10:56:08 -0800 | [diff] [blame] | 1241 | int maxTileSize = fContext->caps()->maxTileSize(); |
commit-bot@chromium.org | a7d89c8 | 2014-01-13 14:47:00 +0000 | [diff] [blame] | 1242 | |
bsalomon | b1b0199 | 2015-11-18 10:56:08 -0800 | [diff] [blame] | 1243 | // The tile code path doesn't currently support AA, so if the paint asked for aa and we could |
| 1244 | // draw untiled, then we bypass checking for tiling purely for optimization reasons. |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1245 | bool drawAA = !fRenderTargetContext->isUnifiedMultisampled() && |
bsalomon | b1b0199 | 2015-11-18 10:56:08 -0800 | [diff] [blame] | 1246 | paint.isAntiAlias() && |
| 1247 | bitmap.width() <= maxTileSize && |
| 1248 | bitmap.height() <= maxTileSize; |
| 1249 | |
| 1250 | bool skipTileCheck = drawAA || paint.getMaskFilter(); |
| 1251 | |
| 1252 | if (!skipTileCheck) { |
| 1253 | int tileSize; |
| 1254 | SkIRect clippedSrcRect; |
| 1255 | |
Brian Salomon | 514baff | 2016-11-17 15:17:07 -0500 | [diff] [blame] | 1256 | GrSamplerParams params; |
bsalomon | b1b0199 | 2015-11-18 10:56:08 -0800 | [diff] [blame] | 1257 | bool doBicubic; |
Brian Salomon | 514baff | 2016-11-17 15:17:07 -0500 | [diff] [blame] | 1258 | GrSamplerParams::FilterMode textureFilterMode = |
bsalomon | b1b0199 | 2015-11-18 10:56:08 -0800 | [diff] [blame] | 1259 | GrSkFilterQualityToGrFilterMode(paint.getFilterQuality(), *draw.fMatrix, srcToDstMatrix, |
| 1260 | &doBicubic); |
| 1261 | |
| 1262 | int tileFilterPad; |
| 1263 | |
| 1264 | if (doBicubic) { |
| 1265 | tileFilterPad = GrBicubicEffect::kFilterTexelPad; |
Brian Salomon | 514baff | 2016-11-17 15:17:07 -0500 | [diff] [blame] | 1266 | } else if (GrSamplerParams::kNone_FilterMode == textureFilterMode) { |
bsalomon | b1b0199 | 2015-11-18 10:56:08 -0800 | [diff] [blame] | 1267 | tileFilterPad = 0; |
| 1268 | } else { |
| 1269 | tileFilterPad = 1; |
| 1270 | } |
| 1271 | params.setFilterMode(textureFilterMode); |
| 1272 | |
| 1273 | int maxTileSizeForFilter = fContext->caps()->maxTileSize() - 2 * tileFilterPad; |
bsalomon | e553b64 | 2016-08-17 09:02:09 -0700 | [diff] [blame] | 1274 | if (this->shouldTileImageID(bitmap.getGenerationID(), bitmap.getSubset(), *draw.fMatrix, |
| 1275 | srcToDstMatrix, params, src, maxTileSizeForFilter, &tileSize, |
| 1276 | &clippedSrcRect)) { |
| 1277 | this->drawTiledBitmap(bitmap, *draw.fMatrix, srcToDstMatrix, *src, clippedSrcRect, |
| 1278 | params, paint, constraint, tileSize, doBicubic); |
bsalomon | b1b0199 | 2015-11-18 10:56:08 -0800 | [diff] [blame] | 1279 | return; |
| 1280 | } |
commit-bot@chromium.org | a7d89c8 | 2014-01-13 14:47:00 +0000 | [diff] [blame] | 1281 | } |
Hal Canary | 144caf5 | 2016-11-07 17:57:18 -0500 | [diff] [blame] | 1282 | GrBitmapTextureMaker maker(fContext.get(), bitmap); |
bsalomon | f1ecd21 | 2015-12-09 17:06:02 -0800 | [diff] [blame] | 1283 | this->drawTextureProducer(&maker, src, dst, constraint, *draw.fMatrix, fClip, paint); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1284 | } |
| 1285 | |
robertphillips | 6451a0c | 2016-07-18 08:31:31 -0700 | [diff] [blame] | 1286 | sk_sp<SkSpecialImage> SkGpuDevice::makeSpecial(const SkBitmap& bitmap) { |
Robert Phillips | e14d305 | 2017-02-15 13:18:21 -0500 | [diff] [blame] | 1287 | // TODO: this makes a tight copy of 'bitmap' but it doesn't have to be (given SkSpecialImage's |
| 1288 | // semantics). Since this is cached we would have to bake the fit into the cache key though. |
| 1289 | sk_sp<GrTextureProxy> proxy = GrMakeCachedBitmapProxy(fContext.get(), bitmap); |
| 1290 | if (!proxy) { |
robertphillips | 6451a0c | 2016-07-18 08:31:31 -0700 | [diff] [blame] | 1291 | return nullptr; |
| 1292 | } |
| 1293 | |
Robert Phillips | e14d305 | 2017-02-15 13:18:21 -0500 | [diff] [blame] | 1294 | const SkIRect rect = SkIRect::MakeWH(proxy->width(), proxy->height()); |
robertphillips | 6451a0c | 2016-07-18 08:31:31 -0700 | [diff] [blame] | 1295 | |
Robert Phillips | e14d305 | 2017-02-15 13:18:21 -0500 | [diff] [blame] | 1296 | // GrMakeCachedBitmapProxy creates a tight copy of 'bitmap' so we don't have to subset |
| 1297 | // the special image |
| 1298 | return SkSpecialImage::MakeDeferredFromGpu(fContext.get(), |
| 1299 | rect, |
| 1300 | bitmap.getGenerationID(), |
| 1301 | std::move(proxy), |
| 1302 | bitmap.refColorSpace(), |
| 1303 | &this->surfaceProps()); |
robertphillips | 6451a0c | 2016-07-18 08:31:31 -0700 | [diff] [blame] | 1304 | } |
| 1305 | |
reed | e51c356 | 2016-07-19 14:33:20 -0700 | [diff] [blame] | 1306 | sk_sp<SkSpecialImage> SkGpuDevice::makeSpecial(const SkImage* image) { |
robertphillips | 6451a0c | 2016-07-18 08:31:31 -0700 | [diff] [blame] | 1307 | SkPixmap pm; |
| 1308 | if (image->isTextureBacked()) { |
Robert Phillips | 6de9904 | 2017-01-31 11:31:39 -0500 | [diff] [blame] | 1309 | sk_sp<GrTextureProxy> proxy = as_IB(image)->asTextureProxyRef(); |
robertphillips | 6451a0c | 2016-07-18 08:31:31 -0700 | [diff] [blame] | 1310 | |
Robert Phillips | 6de9904 | 2017-01-31 11:31:39 -0500 | [diff] [blame] | 1311 | return SkSpecialImage::MakeDeferredFromGpu(fContext.get(), |
| 1312 | SkIRect::MakeWH(image->width(), image->height()), |
| 1313 | image->uniqueID(), |
| 1314 | std::move(proxy), |
| 1315 | as_IB(image)->onImageInfo().refColorSpace(), |
| 1316 | &this->surfaceProps()); |
robertphillips | 6451a0c | 2016-07-18 08:31:31 -0700 | [diff] [blame] | 1317 | } else if (image->peekPixels(&pm)) { |
| 1318 | SkBitmap bm; |
| 1319 | |
| 1320 | bm.installPixels(pm); |
| 1321 | return this->makeSpecial(bm); |
| 1322 | } else { |
| 1323 | return nullptr; |
| 1324 | } |
| 1325 | } |
| 1326 | |
| 1327 | sk_sp<SkSpecialImage> SkGpuDevice::snapSpecial() { |
Robert Phillips | 63c6746 | 2017-02-15 14:19:01 -0500 | [diff] [blame] | 1328 | sk_sp<GrTextureProxy> proxy(this->accessRenderTargetContext()->asTextureProxyRef()); |
| 1329 | if (!proxy) { |
robertphillips | 04d6218 | 2016-07-15 12:21:33 -0700 | [diff] [blame] | 1330 | // When the device doesn't have a texture, we create a temporary texture. |
| 1331 | // TODO: we should actually only copy the portion of the source needed to apply the image |
| 1332 | // filter |
Robert Phillips | 63c6746 | 2017-02-15 14:19:01 -0500 | [diff] [blame] | 1333 | proxy = GrSurfaceProxy::Copy(fContext.get(), |
| 1334 | this->accessRenderTargetContext()->asSurfaceProxy(), |
| 1335 | SkBudgeted::kYes); |
| 1336 | if (!proxy) { |
robertphillips | 04d6218 | 2016-07-15 12:21:33 -0700 | [diff] [blame] | 1337 | return nullptr; |
| 1338 | } |
robertphillips | 1b5f968 | 2016-07-15 08:01:12 -0700 | [diff] [blame] | 1339 | } |
| 1340 | |
| 1341 | const SkImageInfo ii = this->imageInfo(); |
| 1342 | const SkIRect srcRect = SkIRect::MakeWH(ii.width(), ii.height()); |
| 1343 | |
Robert Phillips | e2f7d18 | 2016-12-15 09:23:05 -0500 | [diff] [blame] | 1344 | return SkSpecialImage::MakeDeferredFromGpu(fContext.get(), |
| 1345 | srcRect, |
| 1346 | kNeedNewImageUniqueID_SpecialImage, |
Robert Phillips | 63c6746 | 2017-02-15 14:19:01 -0500 | [diff] [blame] | 1347 | std::move(proxy), |
Robert Phillips | 70b49fd | 2017-01-13 11:21:36 -0500 | [diff] [blame] | 1348 | ii.refColorSpace(), |
Robert Phillips | e2f7d18 | 2016-12-15 09:23:05 -0500 | [diff] [blame] | 1349 | &this->surfaceProps()); |
robertphillips | 1b5f968 | 2016-07-15 08:01:12 -0700 | [diff] [blame] | 1350 | } |
| 1351 | |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1352 | void SkGpuDevice::drawDevice(const SkDraw& draw, SkBaseDevice* device, |
robertphillips | 1b5f968 | 2016-07-15 08:01:12 -0700 | [diff] [blame] | 1353 | int left, int top, const SkPaint& paint) { |
reed | cf5c846 | 2016-07-20 12:28:40 -0700 | [diff] [blame] | 1354 | SkASSERT(!paint.getImageFilter()); |
| 1355 | |
joshualitt | ce89400 | 2016-01-11 13:29:31 -0800 | [diff] [blame] | 1356 | ASSERT_SINGLE_OWNER |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1357 | // clear of the source device must occur before CHECK_SHOULD_DRAW |
Hal Canary | 144caf5 | 2016-11-07 17:57:18 -0500 | [diff] [blame] | 1358 | GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawDevice", fContext.get()); |
kkinnunen | 2e4414e | 2015-02-19 07:20:40 -0800 | [diff] [blame] | 1359 | |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1360 | // drawDevice is defined to be in device coords. |
joshualitt | 5531d51 | 2014-12-17 15:50:11 -0800 | [diff] [blame] | 1361 | CHECK_SHOULD_DRAW(draw); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1362 | |
robertphillips | 1b5f968 | 2016-07-15 08:01:12 -0700 | [diff] [blame] | 1363 | SkGpuDevice* dev = static_cast<SkGpuDevice*>(device); |
robertphillips | 6451a0c | 2016-07-18 08:31:31 -0700 | [diff] [blame] | 1364 | sk_sp<SkSpecialImage> srcImg(dev->snapSpecial()); |
robertphillips | 1b5f968 | 2016-07-15 08:01:12 -0700 | [diff] [blame] | 1365 | if (!srcImg) { |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1366 | return; |
| 1367 | } |
| 1368 | |
robertphillips | 1b5f968 | 2016-07-15 08:01:12 -0700 | [diff] [blame] | 1369 | this->drawSpecial(draw, srcImg.get(), left, top, paint); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1370 | } |
| 1371 | |
reed | a85d4d0 | 2015-05-06 12:56:48 -0700 | [diff] [blame] | 1372 | void SkGpuDevice::drawImage(const SkDraw& draw, const SkImage* image, SkScalar x, SkScalar y, |
| 1373 | const SkPaint& paint) { |
joshualitt | ce89400 | 2016-01-11 13:29:31 -0800 | [diff] [blame] | 1374 | ASSERT_SINGLE_OWNER |
bsalomon | 1cf6f9b | 2015-12-08 10:53:43 -0800 | [diff] [blame] | 1375 | SkMatrix viewMatrix = *draw.fMatrix; |
| 1376 | viewMatrix.preTranslate(x, y); |
reed | 2d5b714 | 2016-08-17 11:12:33 -0700 | [diff] [blame] | 1377 | uint32_t pinnedUniqueID; |
| 1378 | if (sk_sp<GrTexture> tex = as_IB(image)->refPinnedTexture(&pinnedUniqueID)) { |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 1379 | CHECK_SHOULD_DRAW(draw); |
brianosman | 5814b8a | 2016-08-18 06:43:03 -0700 | [diff] [blame] | 1380 | GrTextureAdjuster adjuster(tex.get(), image->alphaType(), image->bounds(), pinnedUniqueID, |
reed | 2d5b714 | 2016-08-17 11:12:33 -0700 | [diff] [blame] | 1381 | as_IB(image)->onImageInfo().colorSpace()); |
bsalomon | f1ecd21 | 2015-12-09 17:06:02 -0800 | [diff] [blame] | 1382 | this->drawTextureProducer(&adjuster, nullptr, nullptr, SkCanvas::kFast_SrcRectConstraint, |
| 1383 | viewMatrix, fClip, paint); |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 1384 | return; |
reed | 85d9178 | 2015-09-10 14:33:38 -0700 | [diff] [blame] | 1385 | } else { |
bsalomon | 1cf6f9b | 2015-12-08 10:53:43 -0800 | [diff] [blame] | 1386 | SkBitmap bm; |
reed | 85d9178 | 2015-09-10 14:33:38 -0700 | [diff] [blame] | 1387 | if (this->shouldTileImage(image, nullptr, SkCanvas::kFast_SrcRectConstraint, |
bsalomon | e553b64 | 2016-08-17 09:02:09 -0700 | [diff] [blame] | 1388 | paint.getFilterQuality(), *draw.fMatrix, SkMatrix::I())) { |
reed | 85d9178 | 2015-09-10 14:33:38 -0700 | [diff] [blame] | 1389 | // only support tiling as bitmap at the moment, so force raster-version |
Brian Osman | 61624f0 | 2016-12-09 14:51:59 -0500 | [diff] [blame] | 1390 | if (!as_IB(image)->getROPixels(&bm, fRenderTargetContext->getColorSpace())) { |
reed | 85d9178 | 2015-09-10 14:33:38 -0700 | [diff] [blame] | 1391 | return; |
| 1392 | } |
bsalomon | 1cf6f9b | 2015-12-08 10:53:43 -0800 | [diff] [blame] | 1393 | this->drawBitmap(draw, bm, SkMatrix::MakeTrans(x, y), paint); |
| 1394 | } else if (SkImageCacherator* cacher = as_IB(image)->peekCacherator()) { |
| 1395 | CHECK_SHOULD_DRAW(draw); |
Hal Canary | 144caf5 | 2016-11-07 17:57:18 -0500 | [diff] [blame] | 1396 | GrImageTextureMaker maker(fContext.get(), cacher, image, SkImage::kAllow_CachingHint); |
bsalomon | f1ecd21 | 2015-12-09 17:06:02 -0800 | [diff] [blame] | 1397 | this->drawTextureProducer(&maker, nullptr, nullptr, SkCanvas::kFast_SrcRectConstraint, |
| 1398 | viewMatrix, fClip, paint); |
Brian Osman | 61624f0 | 2016-12-09 14:51:59 -0500 | [diff] [blame] | 1399 | } else if (as_IB(image)->getROPixels(&bm, fRenderTargetContext->getColorSpace())) { |
bsalomon | 1cf6f9b | 2015-12-08 10:53:43 -0800 | [diff] [blame] | 1400 | this->drawBitmap(draw, bm, SkMatrix::MakeTrans(x, y), paint); |
reed | 85d9178 | 2015-09-10 14:33:38 -0700 | [diff] [blame] | 1401 | } |
reed | a85d4d0 | 2015-05-06 12:56:48 -0700 | [diff] [blame] | 1402 | } |
| 1403 | } |
| 1404 | |
| 1405 | void SkGpuDevice::drawImageRect(const SkDraw& draw, const SkImage* image, const SkRect* src, |
reed | a5517e2 | 2015-07-14 10:54:12 -0700 | [diff] [blame] | 1406 | const SkRect& dst, const SkPaint& paint, |
| 1407 | SkCanvas::SrcRectConstraint constraint) { |
joshualitt | ce89400 | 2016-01-11 13:29:31 -0800 | [diff] [blame] | 1408 | ASSERT_SINGLE_OWNER |
reed | 2d5b714 | 2016-08-17 11:12:33 -0700 | [diff] [blame] | 1409 | uint32_t pinnedUniqueID; |
| 1410 | if (sk_sp<GrTexture> tex = as_IB(image)->refPinnedTexture(&pinnedUniqueID)) { |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 1411 | CHECK_SHOULD_DRAW(draw); |
brianosman | 5814b8a | 2016-08-18 06:43:03 -0700 | [diff] [blame] | 1412 | GrTextureAdjuster adjuster(tex.get(), image->alphaType(), image->bounds(), pinnedUniqueID, |
reed | 2d5b714 | 2016-08-17 11:12:33 -0700 | [diff] [blame] | 1413 | as_IB(image)->onImageInfo().colorSpace()); |
bsalomon | f1ecd21 | 2015-12-09 17:06:02 -0800 | [diff] [blame] | 1414 | this->drawTextureProducer(&adjuster, src, &dst, constraint, *draw.fMatrix, fClip, paint); |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 1415 | return; |
| 1416 | } |
| 1417 | SkBitmap bm; |
bsalomon | e553b64 | 2016-08-17 09:02:09 -0700 | [diff] [blame] | 1418 | SkMatrix srcToDstRect; |
| 1419 | srcToDstRect.setRectToRect((src ? *src : SkRect::MakeIWH(image->width(), image->height())), |
| 1420 | dst, SkMatrix::kFill_ScaleToFit); |
| 1421 | if (this->shouldTileImage(image, src, constraint, paint.getFilterQuality(), *draw.fMatrix, |
| 1422 | srcToDstRect)) { |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 1423 | // only support tiling as bitmap at the moment, so force raster-version |
Brian Osman | 61624f0 | 2016-12-09 14:51:59 -0500 | [diff] [blame] | 1424 | if (!as_IB(image)->getROPixels(&bm, fRenderTargetContext->getColorSpace())) { |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 1425 | return; |
| 1426 | } |
bsalomon | 1cf6f9b | 2015-12-08 10:53:43 -0800 | [diff] [blame] | 1427 | this->drawBitmapRect(draw, bm, src, dst, paint, constraint); |
| 1428 | } else if (SkImageCacherator* cacher = as_IB(image)->peekCacherator()) { |
| 1429 | CHECK_SHOULD_DRAW(draw); |
Hal Canary | 144caf5 | 2016-11-07 17:57:18 -0500 | [diff] [blame] | 1430 | GrImageTextureMaker maker(fContext.get(), cacher, image, SkImage::kAllow_CachingHint); |
bsalomon | f1ecd21 | 2015-12-09 17:06:02 -0800 | [diff] [blame] | 1431 | this->drawTextureProducer(&maker, src, &dst, constraint, *draw.fMatrix, fClip, paint); |
Brian Osman | 61624f0 | 2016-12-09 14:51:59 -0500 | [diff] [blame] | 1432 | } else if (as_IB(image)->getROPixels(&bm, fRenderTargetContext->getColorSpace())) { |
bsalomon | 1cf6f9b | 2015-12-08 10:53:43 -0800 | [diff] [blame] | 1433 | this->drawBitmapRect(draw, bm, src, dst, paint, constraint); |
reed | a85d4d0 | 2015-05-06 12:56:48 -0700 | [diff] [blame] | 1434 | } |
bsalomon | 1cf6f9b | 2015-12-08 10:53:43 -0800 | [diff] [blame] | 1435 | } |
| 1436 | |
bsalomon | f1ecd21 | 2015-12-09 17:06:02 -0800 | [diff] [blame] | 1437 | void SkGpuDevice::drawProducerNine(const SkDraw& draw, GrTextureProducer* producer, |
bsalomon | 2bbd0c6 | 2015-12-09 12:50:56 -0800 | [diff] [blame] | 1438 | const SkIRect& center, const SkRect& dst, const SkPaint& paint) { |
Hal Canary | 144caf5 | 2016-11-07 17:57:18 -0500 | [diff] [blame] | 1439 | GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawProducerNine", fContext.get()); |
joshualitt | 33a5fce | 2015-11-18 13:28:51 -0800 | [diff] [blame] | 1440 | |
joshualitt | 33a5fce | 2015-11-18 13:28:51 -0800 | [diff] [blame] | 1441 | CHECK_SHOULD_DRAW(draw); |
| 1442 | |
joshualitt | edb3644 | 2015-11-19 14:29:30 -0800 | [diff] [blame] | 1443 | bool useFallback = paint.getMaskFilter() || paint.isAntiAlias() || |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1444 | fRenderTargetContext->isUnifiedMultisampled(); |
joshualitt | 33a5fce | 2015-11-18 13:28:51 -0800 | [diff] [blame] | 1445 | bool doBicubic; |
Brian Salomon | 514baff | 2016-11-17 15:17:07 -0500 | [diff] [blame] | 1446 | GrSamplerParams::FilterMode textureFilterMode = |
bsalomon | 2bbd0c6 | 2015-12-09 12:50:56 -0800 | [diff] [blame] | 1447 | GrSkFilterQualityToGrFilterMode(paint.getFilterQuality(), *draw.fMatrix, SkMatrix::I(), |
| 1448 | &doBicubic); |
Brian Salomon | 514baff | 2016-11-17 15:17:07 -0500 | [diff] [blame] | 1449 | if (useFallback || doBicubic || GrSamplerParams::kNone_FilterMode != textureFilterMode) { |
msarett | c573a40 | 2016-08-02 08:05:56 -0700 | [diff] [blame] | 1450 | SkLatticeIter iter(producer->width(), producer->height(), center, dst); |
joshualitt | 33a5fce | 2015-11-18 13:28:51 -0800 | [diff] [blame] | 1451 | |
| 1452 | SkRect srcR, dstR; |
| 1453 | while (iter.next(&srcR, &dstR)) { |
erikchen | 9a1ed5d | 2016-02-10 16:32:34 -0800 | [diff] [blame] | 1454 | this->drawTextureProducer(producer, &srcR, &dstR, SkCanvas::kStrict_SrcRectConstraint, |
bsalomon | f1ecd21 | 2015-12-09 17:06:02 -0800 | [diff] [blame] | 1455 | *draw.fMatrix, fClip, paint); |
joshualitt | 33a5fce | 2015-11-18 13:28:51 -0800 | [diff] [blame] | 1456 | } |
| 1457 | return; |
| 1458 | } |
| 1459 | |
Brian Salomon | 514baff | 2016-11-17 15:17:07 -0500 | [diff] [blame] | 1460 | static const GrSamplerParams::FilterMode kMode = GrSamplerParams::kNone_FilterMode; |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 1461 | sk_sp<GrFragmentProcessor> fp( |
bsalomon | 2bbd0c6 | 2015-12-09 12:50:56 -0800 | [diff] [blame] | 1462 | producer->createFragmentProcessor(SkMatrix::I(), |
| 1463 | SkRect::MakeIWH(producer->width(), producer->height()), |
| 1464 | GrTextureProducer::kNo_FilterConstraint, true, |
Brian Osman | 61624f0 | 2016-12-09 14:51:59 -0500 | [diff] [blame] | 1465 | &kMode, fRenderTargetContext->getColorSpace())); |
joshualitt | 33a5fce | 2015-11-18 13:28:51 -0800 | [diff] [blame] | 1466 | GrPaint grPaint; |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1467 | if (!SkPaintToGrPaintWithTexture(this->context(), fRenderTargetContext.get(), paint, |
| 1468 | *draw.fMatrix, std::move(fp), producer->isAlphaOnly(), |
| 1469 | &grPaint)) { |
joshualitt | 33a5fce | 2015-11-18 13:28:51 -0800 | [diff] [blame] | 1470 | return; |
| 1471 | } |
| 1472 | |
msarett | 10e3d9b | 2016-08-18 15:46:03 -0700 | [diff] [blame] | 1473 | std::unique_ptr<SkLatticeIter> iter( |
| 1474 | new SkLatticeIter(producer->width(), producer->height(), center, dst)); |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1475 | fRenderTargetContext->drawImageLattice(fClip, std::move(grPaint), *draw.fMatrix, |
| 1476 | producer->width(), producer->height(), std::move(iter), |
| 1477 | dst); |
bsalomon | 2bbd0c6 | 2015-12-09 12:50:56 -0800 | [diff] [blame] | 1478 | } |
| 1479 | |
| 1480 | void SkGpuDevice::drawImageNine(const SkDraw& draw, const SkImage* image, |
| 1481 | const SkIRect& center, const SkRect& dst, const SkPaint& paint) { |
joshualitt | ce89400 | 2016-01-11 13:29:31 -0800 | [diff] [blame] | 1482 | ASSERT_SINGLE_OWNER |
reed | 2d5b714 | 2016-08-17 11:12:33 -0700 | [diff] [blame] | 1483 | uint32_t pinnedUniqueID; |
| 1484 | if (sk_sp<GrTexture> tex = as_IB(image)->refPinnedTexture(&pinnedUniqueID)) { |
| 1485 | CHECK_SHOULD_DRAW(draw); |
brianosman | 5814b8a | 2016-08-18 06:43:03 -0700 | [diff] [blame] | 1486 | GrTextureAdjuster adjuster(tex.get(), image->alphaType(), image->bounds(), pinnedUniqueID, |
reed | 2d5b714 | 2016-08-17 11:12:33 -0700 | [diff] [blame] | 1487 | as_IB(image)->onImageInfo().colorSpace()); |
bsalomon | f1ecd21 | 2015-12-09 17:06:02 -0800 | [diff] [blame] | 1488 | this->drawProducerNine(draw, &adjuster, center, dst, paint); |
bsalomon | 2bbd0c6 | 2015-12-09 12:50:56 -0800 | [diff] [blame] | 1489 | } else { |
| 1490 | SkBitmap bm; |
| 1491 | if (SkImageCacherator* cacher = as_IB(image)->peekCacherator()) { |
Hal Canary | 144caf5 | 2016-11-07 17:57:18 -0500 | [diff] [blame] | 1492 | GrImageTextureMaker maker(fContext.get(), cacher, image, SkImage::kAllow_CachingHint); |
bsalomon | f1ecd21 | 2015-12-09 17:06:02 -0800 | [diff] [blame] | 1493 | this->drawProducerNine(draw, &maker, center, dst, paint); |
Brian Osman | 61624f0 | 2016-12-09 14:51:59 -0500 | [diff] [blame] | 1494 | } else if (as_IB(image)->getROPixels(&bm, fRenderTargetContext->getColorSpace())) { |
bsalomon | 2bbd0c6 | 2015-12-09 12:50:56 -0800 | [diff] [blame] | 1495 | this->drawBitmapNine(draw, bm, center, dst, paint); |
| 1496 | } |
| 1497 | } |
| 1498 | } |
| 1499 | |
| 1500 | void SkGpuDevice::drawBitmapNine(const SkDraw& draw, const SkBitmap& bitmap, const SkIRect& center, |
| 1501 | const SkRect& dst, const SkPaint& paint) { |
joshualitt | ce89400 | 2016-01-11 13:29:31 -0800 | [diff] [blame] | 1502 | ASSERT_SINGLE_OWNER |
Hal Canary | 144caf5 | 2016-11-07 17:57:18 -0500 | [diff] [blame] | 1503 | GrBitmapTextureMaker maker(fContext.get(), bitmap); |
reed | c7ec7c9 | 2016-07-25 08:29:10 -0700 | [diff] [blame] | 1504 | this->drawProducerNine(draw, &maker, center, dst, paint); |
joshualitt | 33a5fce | 2015-11-18 13:28:51 -0800 | [diff] [blame] | 1505 | } |
| 1506 | |
msarett | 10e3d9b | 2016-08-18 15:46:03 -0700 | [diff] [blame] | 1507 | void SkGpuDevice::drawProducerLattice(const SkDraw& draw, GrTextureProducer* producer, |
| 1508 | const SkCanvas::Lattice& lattice, const SkRect& dst, |
| 1509 | const SkPaint& paint) { |
Hal Canary | 144caf5 | 2016-11-07 17:57:18 -0500 | [diff] [blame] | 1510 | GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawProducerLattice", fContext.get()); |
msarett | 10e3d9b | 2016-08-18 15:46:03 -0700 | [diff] [blame] | 1511 | |
| 1512 | CHECK_SHOULD_DRAW(draw); |
| 1513 | |
Brian Salomon | 514baff | 2016-11-17 15:17:07 -0500 | [diff] [blame] | 1514 | static const GrSamplerParams::FilterMode kMode = GrSamplerParams::kNone_FilterMode; |
msarett | 10e3d9b | 2016-08-18 15:46:03 -0700 | [diff] [blame] | 1515 | sk_sp<GrFragmentProcessor> fp( |
| 1516 | producer->createFragmentProcessor(SkMatrix::I(), |
| 1517 | SkRect::MakeIWH(producer->width(), producer->height()), |
| 1518 | GrTextureProducer::kNo_FilterConstraint, true, |
Brian Osman | 61624f0 | 2016-12-09 14:51:59 -0500 | [diff] [blame] | 1519 | &kMode, fRenderTargetContext->getColorSpace())); |
msarett | 10e3d9b | 2016-08-18 15:46:03 -0700 | [diff] [blame] | 1520 | GrPaint grPaint; |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1521 | if (!SkPaintToGrPaintWithTexture(this->context(), fRenderTargetContext.get(), paint, |
| 1522 | *draw.fMatrix, std::move(fp), producer->isAlphaOnly(), |
| 1523 | &grPaint)) { |
msarett | 10e3d9b | 2016-08-18 15:46:03 -0700 | [diff] [blame] | 1524 | return; |
| 1525 | } |
| 1526 | |
| 1527 | std::unique_ptr<SkLatticeIter> iter( |
msarett | 71df2d7 | 2016-09-30 12:41:42 -0700 | [diff] [blame] | 1528 | new SkLatticeIter(lattice, dst)); |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1529 | fRenderTargetContext->drawImageLattice(fClip, std::move(grPaint), *draw.fMatrix, |
| 1530 | producer->width(), producer->height(), std::move(iter), |
| 1531 | dst); |
msarett | 10e3d9b | 2016-08-18 15:46:03 -0700 | [diff] [blame] | 1532 | } |
| 1533 | |
| 1534 | void SkGpuDevice::drawImageLattice(const SkDraw& draw, const SkImage* image, |
| 1535 | const SkCanvas::Lattice& lattice, const SkRect& dst, |
| 1536 | const SkPaint& paint) { |
| 1537 | ASSERT_SINGLE_OWNER |
| 1538 | uint32_t pinnedUniqueID; |
| 1539 | if (sk_sp<GrTexture> tex = as_IB(image)->refPinnedTexture(&pinnedUniqueID)) { |
| 1540 | CHECK_SHOULD_DRAW(draw); |
| 1541 | GrTextureAdjuster adjuster(tex.get(), image->alphaType(), image->bounds(), pinnedUniqueID, |
| 1542 | as_IB(image)->onImageInfo().colorSpace()); |
| 1543 | this->drawProducerLattice(draw, &adjuster, lattice, dst, paint); |
| 1544 | } else { |
| 1545 | SkBitmap bm; |
| 1546 | if (SkImageCacherator* cacher = as_IB(image)->peekCacherator()) { |
Hal Canary | 144caf5 | 2016-11-07 17:57:18 -0500 | [diff] [blame] | 1547 | GrImageTextureMaker maker(fContext.get(), cacher, image, SkImage::kAllow_CachingHint); |
msarett | 10e3d9b | 2016-08-18 15:46:03 -0700 | [diff] [blame] | 1548 | this->drawProducerLattice(draw, &maker, lattice, dst, paint); |
Brian Osman | 61624f0 | 2016-12-09 14:51:59 -0500 | [diff] [blame] | 1549 | } else if (as_IB(image)->getROPixels(&bm, fRenderTargetContext->getColorSpace())) { |
msarett | 10e3d9b | 2016-08-18 15:46:03 -0700 | [diff] [blame] | 1550 | this->drawBitmapLattice(draw, bm, lattice, dst, paint); |
| 1551 | } |
| 1552 | } |
| 1553 | } |
| 1554 | |
| 1555 | void SkGpuDevice::drawBitmapLattice(const SkDraw& draw, const SkBitmap& bitmap, |
| 1556 | const SkCanvas::Lattice& lattice, const SkRect& dst, |
| 1557 | const SkPaint& paint) { |
| 1558 | ASSERT_SINGLE_OWNER |
Hal Canary | 144caf5 | 2016-11-07 17:57:18 -0500 | [diff] [blame] | 1559 | GrBitmapTextureMaker maker(fContext.get(), bitmap); |
msarett | 10e3d9b | 2016-08-18 15:46:03 -0700 | [diff] [blame] | 1560 | this->drawProducerLattice(draw, &maker, lattice, dst, paint); |
| 1561 | } |
| 1562 | |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 1563 | bool init_vertices_paint(const SkPaint& skPaint, const SkMatrix& matrix, SkBlendMode bmode, |
| 1564 | bool hasTexs, bool hasColors, GrRenderTargetContext* rtc, |
| 1565 | GrPaint* grPaint) { |
| 1566 | GrContext* context = rtc->surfPriv().getContext(); |
| 1567 | if (hasTexs && skPaint.getShader()) { |
| 1568 | if (hasColors) { |
| 1569 | // When there are texs and colors the shader and colors are combined using bmode. |
| 1570 | return SkPaintToGrPaintWithXfermode(context, rtc, skPaint, matrix, bmode, false, |
| 1571 | grPaint); |
| 1572 | } else { |
| 1573 | // We have a shader, but no colors to blend it against. |
| 1574 | return SkPaintToGrPaint(context, rtc, skPaint, matrix, grPaint); |
| 1575 | } |
| 1576 | } else { |
| 1577 | if (hasColors) { |
| 1578 | // We have colors, but either have no shader or no texture coords (which implies that |
| 1579 | // we should ignore the shader). |
| 1580 | return SkPaintToGrPaintWithPrimitiveColor(context, rtc, skPaint, grPaint); |
| 1581 | } else { |
| 1582 | // No colors and no shaders. Just draw with the paint color. |
| 1583 | return (!SkPaintToGrPaintNoShader(context, rtc, skPaint, grPaint)); |
| 1584 | } |
| 1585 | } |
| 1586 | } |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1587 | |
| 1588 | void SkGpuDevice::drawVertices(const SkDraw& draw, SkCanvas::VertexMode vmode, |
| 1589 | int vertexCount, const SkPoint vertices[], |
| 1590 | const SkPoint texs[], const SkColor colors[], |
Mike Reed | faba371 | 2016-11-03 14:45:31 -0400 | [diff] [blame] | 1591 | SkBlendMode bmode, |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1592 | const uint16_t indices[], int indexCount, |
| 1593 | const SkPaint& paint) { |
joshualitt | ce89400 | 2016-01-11 13:29:31 -0800 | [diff] [blame] | 1594 | ASSERT_SINGLE_OWNER |
joshualitt | 5531d51 | 2014-12-17 15:50:11 -0800 | [diff] [blame] | 1595 | CHECK_SHOULD_DRAW(draw); |
Hal Canary | 144caf5 | 2016-11-07 17:57:18 -0500 | [diff] [blame] | 1596 | GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawVertices", fContext.get()); |
mtklein | 533eb78 | 2014-08-27 10:39:42 -0700 | [diff] [blame] | 1597 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1598 | // If both textures and vertex-colors are nullptr, strokes hairlines with the paint's color. |
| 1599 | if ((nullptr == texs || nullptr == paint.getShader()) && nullptr == colors) { |
mtklein | 533eb78 | 2014-08-27 10:39:42 -0700 | [diff] [blame] | 1600 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1601 | texs = nullptr; |
mtklein | 533eb78 | 2014-08-27 10:39:42 -0700 | [diff] [blame] | 1602 | |
commit-bot@chromium.org | 559a883 | 2014-05-30 10:08:22 +0000 | [diff] [blame] | 1603 | SkPaint copy(paint); |
| 1604 | copy.setStyle(SkPaint::kStroke_Style); |
| 1605 | copy.setStrokeWidth(0); |
mtklein | 533eb78 | 2014-08-27 10:39:42 -0700 | [diff] [blame] | 1606 | |
bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 1607 | GrPaint grPaint; |
dandov | 32a311b | 2014-07-15 19:46:26 -0700 | [diff] [blame] | 1608 | // we ignore the shader if texs is null. |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1609 | if (!SkPaintToGrPaintNoShader(this->context(), fRenderTargetContext.get(), copy, |
| 1610 | &grPaint)) { |
bsalomon | bed83a6 | 2015-04-15 14:18:34 -0700 | [diff] [blame] | 1611 | return; |
| 1612 | } |
commit-bot@chromium.org | 559a883 | 2014-05-30 10:08:22 +0000 | [diff] [blame] | 1613 | |
dandov | 32a311b | 2014-07-15 19:46:26 -0700 | [diff] [blame] | 1614 | int triangleCount = 0; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1615 | int n = (nullptr == indices) ? vertexCount : indexCount; |
dandov | 32a311b | 2014-07-15 19:46:26 -0700 | [diff] [blame] | 1616 | switch (vmode) { |
| 1617 | case SkCanvas::kTriangles_VertexMode: |
bsalomon | a098dd4 | 2014-08-06 11:01:44 -0700 | [diff] [blame] | 1618 | triangleCount = n / 3; |
dandov | 32a311b | 2014-07-15 19:46:26 -0700 | [diff] [blame] | 1619 | break; |
| 1620 | case SkCanvas::kTriangleStrip_VertexMode: |
| 1621 | case SkCanvas::kTriangleFan_VertexMode: |
bsalomon | a098dd4 | 2014-08-06 11:01:44 -0700 | [diff] [blame] | 1622 | triangleCount = n - 2; |
dandov | 32a311b | 2014-07-15 19:46:26 -0700 | [diff] [blame] | 1623 | break; |
| 1624 | } |
mtklein | 533eb78 | 2014-08-27 10:39:42 -0700 | [diff] [blame] | 1625 | |
commit-bot@chromium.org | 559a883 | 2014-05-30 10:08:22 +0000 | [diff] [blame] | 1626 | VertState state(vertexCount, indices, indexCount); |
| 1627 | VertState::Proc vertProc = state.chooseProc(vmode); |
mtklein | 533eb78 | 2014-08-27 10:39:42 -0700 | [diff] [blame] | 1628 | |
dandov | 32a311b | 2014-07-15 19:46:26 -0700 | [diff] [blame] | 1629 | //number of indices for lines per triangle with kLines |
| 1630 | indexCount = triangleCount * 6; |
mtklein | 533eb78 | 2014-08-27 10:39:42 -0700 | [diff] [blame] | 1631 | |
Ben Wagner | 7ecc596 | 2016-11-02 17:07:33 -0400 | [diff] [blame] | 1632 | std::unique_ptr<uint16_t[]> lineIndices(new uint16_t[indexCount]); |
commit-bot@chromium.org | 559a883 | 2014-05-30 10:08:22 +0000 | [diff] [blame] | 1633 | int i = 0; |
| 1634 | while (vertProc(&state)) { |
bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 1635 | lineIndices[i] = state.f0; |
| 1636 | lineIndices[i + 1] = state.f1; |
| 1637 | lineIndices[i + 2] = state.f1; |
| 1638 | lineIndices[i + 3] = state.f2; |
| 1639 | lineIndices[i + 4] = state.f2; |
| 1640 | lineIndices[i + 5] = state.f0; |
commit-bot@chromium.org | 559a883 | 2014-05-30 10:08:22 +0000 | [diff] [blame] | 1641 | i += 6; |
| 1642 | } |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1643 | fRenderTargetContext->drawVertices(fClip, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1644 | std::move(grPaint), |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1645 | *draw.fMatrix, |
| 1646 | kLines_GrPrimitiveType, |
| 1647 | vertexCount, |
| 1648 | vertices, |
| 1649 | texs, |
| 1650 | colors, |
| 1651 | lineIndices.get(), |
| 1652 | indexCount); |
bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 1653 | return; |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1654 | } |
| 1655 | |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 1656 | GrPrimitiveType primType = SkVertexModeToGrPrimitiveType(vmode); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1657 | |
bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 1658 | GrPaint grPaint; |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 1659 | if (!init_vertices_paint(paint, *draw.fMatrix, bmode, SkToBool(texs), SkToBool(colors), |
| 1660 | fRenderTargetContext.get(), &grPaint)) { |
| 1661 | return; |
bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 1662 | } |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1663 | fRenderTargetContext->drawVertices(fClip, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1664 | std::move(grPaint), |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1665 | *draw.fMatrix, |
| 1666 | primType, |
| 1667 | vertexCount, |
| 1668 | vertices, |
| 1669 | texs, |
| 1670 | colors, |
| 1671 | indices, |
Brian Salomon | 3de0aee | 2017-01-29 09:34:17 -0500 | [diff] [blame] | 1672 | indexCount, |
| 1673 | GrRenderTargetContext::ColorArrayType::kSkColor); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1674 | } |
| 1675 | |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 1676 | void SkGpuDevice::drawVerticesObject(const SkDraw& draw, sk_sp<SkVertices> vertices, |
| 1677 | SkBlendMode mode, const SkPaint& paint, uint32_t flags) { |
| 1678 | ASSERT_SINGLE_OWNER |
| 1679 | CHECK_SHOULD_DRAW(draw); |
| 1680 | GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawVerticesObject", fContext.get()); |
| 1681 | |
| 1682 | SkASSERT(vertices); |
| 1683 | GrPaint grPaint; |
| 1684 | bool hasColors = vertices->hasColors() && !(SkCanvas::kIgnoreColors_VerticesFlag & flags); |
| 1685 | bool hasTexs = vertices->hasTexCoords() & !(SkCanvas::kIgnoreTexCoords_VerticesFlag & flags); |
| 1686 | if (!hasTexs && !hasColors) { |
| 1687 | // The dreaded wireframe mode. Fallback to drawVertices and go so slooooooow. |
| 1688 | this->drawVertices(draw, vertices->mode(), vertices->vertexCount(), vertices->positions(), |
| 1689 | nullptr, nullptr, mode, vertices->indices(), vertices->indexCount(), |
| 1690 | paint); |
| 1691 | } |
| 1692 | if (!init_vertices_paint(paint, *draw.fMatrix, mode, hasTexs, hasColors, |
| 1693 | fRenderTargetContext.get(), &grPaint)) { |
| 1694 | return; |
| 1695 | } |
| 1696 | fRenderTargetContext->drawVertices(fClip, std::move(grPaint), *draw.fMatrix, |
| 1697 | std::move(vertices), flags); |
| 1698 | } |
| 1699 | |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1700 | /////////////////////////////////////////////////////////////////////////////// |
| 1701 | |
jvanverth | 31ff762 | 2015-08-07 10:09:28 -0700 | [diff] [blame] | 1702 | void SkGpuDevice::drawAtlas(const SkDraw& draw, const SkImage* atlas, const SkRSXform xform[], |
reed | ca10953 | 2015-06-25 16:25:25 -0700 | [diff] [blame] | 1703 | const SkRect texRect[], const SkColor colors[], int count, |
Mike Reed | faba371 | 2016-11-03 14:45:31 -0400 | [diff] [blame] | 1704 | SkBlendMode mode, const SkPaint& paint) { |
joshualitt | ce89400 | 2016-01-11 13:29:31 -0800 | [diff] [blame] | 1705 | ASSERT_SINGLE_OWNER |
reed | ca10953 | 2015-06-25 16:25:25 -0700 | [diff] [blame] | 1706 | if (paint.isAntiAlias()) { |
jvanverth | 31ff762 | 2015-08-07 10:09:28 -0700 | [diff] [blame] | 1707 | this->INHERITED::drawAtlas(draw, atlas, xform, texRect, colors, count, mode, paint); |
reed | ca10953 | 2015-06-25 16:25:25 -0700 | [diff] [blame] | 1708 | return; |
| 1709 | } |
| 1710 | |
jvanverth | 31ff762 | 2015-08-07 10:09:28 -0700 | [diff] [blame] | 1711 | CHECK_SHOULD_DRAW(draw); |
Hal Canary | 144caf5 | 2016-11-07 17:57:18 -0500 | [diff] [blame] | 1712 | GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawText", fContext.get()); |
herb | 11a7f7f | 2015-11-24 12:41:00 -0800 | [diff] [blame] | 1713 | |
reed | ca10953 | 2015-06-25 16:25:25 -0700 | [diff] [blame] | 1714 | SkPaint p(paint); |
reed | 5671c5b | 2016-03-09 14:47:34 -0800 | [diff] [blame] | 1715 | p.setShader(atlas->makeShader(SkShader::kClamp_TileMode, SkShader::kClamp_TileMode)); |
reed | ca10953 | 2015-06-25 16:25:25 -0700 | [diff] [blame] | 1716 | |
jvanverth | 31ff762 | 2015-08-07 10:09:28 -0700 | [diff] [blame] | 1717 | GrPaint grPaint; |
robertphillips | 29ccdf8 | 2015-07-24 10:20:45 -0700 | [diff] [blame] | 1718 | if (colors) { |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1719 | if (!SkPaintToGrPaintWithXfermode(this->context(), fRenderTargetContext.get(), p, |
Mike Reed | 7d954ad | 2016-10-28 15:42:34 -0400 | [diff] [blame] | 1720 | *draw.fMatrix, (SkBlendMode)mode, true, &grPaint)) { |
bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 1721 | return; |
| 1722 | } |
| 1723 | } else { |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1724 | if (!SkPaintToGrPaint(this->context(), fRenderTargetContext.get(), p, *draw.fMatrix, |
| 1725 | &grPaint)) { |
jvanverth | 31ff762 | 2015-08-07 10:09:28 -0700 | [diff] [blame] | 1726 | return; |
robertphillips | 29ccdf8 | 2015-07-24 10:20:45 -0700 | [diff] [blame] | 1727 | } |
| 1728 | } |
bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 1729 | |
| 1730 | SkDEBUGCODE(this->validate();) |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1731 | fRenderTargetContext->drawAtlas(fClip, std::move(grPaint), *draw.fMatrix, count, xform, texRect, |
| 1732 | colors); |
reed | ca10953 | 2015-06-25 16:25:25 -0700 | [diff] [blame] | 1733 | } |
| 1734 | |
| 1735 | /////////////////////////////////////////////////////////////////////////////// |
| 1736 | |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1737 | void SkGpuDevice::drawText(const SkDraw& draw, const void* text, |
joshualitt | 5531d51 | 2014-12-17 15:50:11 -0800 | [diff] [blame] | 1738 | size_t byteLength, SkScalar x, SkScalar y, |
| 1739 | const SkPaint& paint) { |
joshualitt | ce89400 | 2016-01-11 13:29:31 -0800 | [diff] [blame] | 1740 | ASSERT_SINGLE_OWNER |
joshualitt | 5531d51 | 2014-12-17 15:50:11 -0800 | [diff] [blame] | 1741 | CHECK_SHOULD_DRAW(draw); |
Hal Canary | 144caf5 | 2016-11-07 17:57:18 -0500 | [diff] [blame] | 1742 | GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawText", fContext.get()); |
jvanverth | 8c27a18 | 2014-10-14 08:45:50 -0700 | [diff] [blame] | 1743 | SkDEBUGCODE(this->validate();) |
commit-bot@chromium.org | 8128d8c | 2013-12-19 16:12:25 +0000 | [diff] [blame] | 1744 | |
Brian Salomon | 6f1d36c | 2017-01-13 12:02:17 -0500 | [diff] [blame] | 1745 | fRenderTargetContext->drawText(fClip, paint, *draw.fMatrix, |
Mike Reed | fa24d34 | 2017-02-22 15:21:35 -0500 | [diff] [blame] | 1746 | (const char*)text, byteLength, x, y, this->devClipBounds(draw)); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1747 | } |
| 1748 | |
fmalita | 05c4a43 | 2014-09-29 06:29:53 -0700 | [diff] [blame] | 1749 | void SkGpuDevice::drawPosText(const SkDraw& draw, const void* text, size_t byteLength, |
| 1750 | const SkScalar pos[], int scalarsPerPos, |
| 1751 | const SkPoint& offset, const SkPaint& paint) { |
joshualitt | ce89400 | 2016-01-11 13:29:31 -0800 | [diff] [blame] | 1752 | ASSERT_SINGLE_OWNER |
Hal Canary | 144caf5 | 2016-11-07 17:57:18 -0500 | [diff] [blame] | 1753 | GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawPosText", fContext.get()); |
joshualitt | 5531d51 | 2014-12-17 15:50:11 -0800 | [diff] [blame] | 1754 | CHECK_SHOULD_DRAW(draw); |
jvanverth | 8c27a18 | 2014-10-14 08:45:50 -0700 | [diff] [blame] | 1755 | SkDEBUGCODE(this->validate();) |
commit-bot@chromium.org | 8128d8c | 2013-12-19 16:12:25 +0000 | [diff] [blame] | 1756 | |
Brian Salomon | 6f1d36c | 2017-01-13 12:02:17 -0500 | [diff] [blame] | 1757 | fRenderTargetContext->drawPosText(fClip, paint, *draw.fMatrix, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1758 | (const char*)text, byteLength, pos, scalarsPerPos, offset, |
Mike Reed | fa24d34 | 2017-02-22 15:21:35 -0500 | [diff] [blame] | 1759 | this->devClipBounds(draw)); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1760 | } |
| 1761 | |
joshualitt | 9c32818 | 2015-03-23 08:13:04 -0700 | [diff] [blame] | 1762 | void SkGpuDevice::drawTextBlob(const SkDraw& draw, const SkTextBlob* blob, SkScalar x, SkScalar y, |
| 1763 | const SkPaint& paint, SkDrawFilter* drawFilter) { |
joshualitt | ce89400 | 2016-01-11 13:29:31 -0800 | [diff] [blame] | 1764 | ASSERT_SINGLE_OWNER |
Hal Canary | 144caf5 | 2016-11-07 17:57:18 -0500 | [diff] [blame] | 1765 | GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawTextBlob", fContext.get()); |
joshualitt | 9c32818 | 2015-03-23 08:13:04 -0700 | [diff] [blame] | 1766 | CHECK_SHOULD_DRAW(draw); |
| 1767 | |
| 1768 | SkDEBUGCODE(this->validate();) |
| 1769 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1770 | fRenderTargetContext->drawTextBlob(fClip, paint, *draw.fMatrix, |
Mike Reed | fa24d34 | 2017-02-22 15:21:35 -0500 | [diff] [blame] | 1771 | blob, x, y, drawFilter, this->devClipBounds(draw)); |
joshualitt | 9c32818 | 2015-03-23 08:13:04 -0700 | [diff] [blame] | 1772 | } |
| 1773 | |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1774 | /////////////////////////////////////////////////////////////////////////////// |
| 1775 | |
reed | b2db898 | 2014-11-13 12:41:02 -0800 | [diff] [blame] | 1776 | bool SkGpuDevice::onShouldDisableLCD(const SkPaint& paint) const { |
joshualitt | 8e84a1e | 2016-02-16 11:09:25 -0800 | [diff] [blame] | 1777 | return GrTextUtils::ShouldDisableLCD(paint); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1778 | } |
| 1779 | |
| 1780 | void SkGpuDevice::flush() { |
joshualitt | ce89400 | 2016-01-11 13:29:31 -0800 | [diff] [blame] | 1781 | ASSERT_SINGLE_OWNER |
joshualitt | bc90735 | 2016-01-13 06:45:40 -0800 | [diff] [blame] | 1782 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1783 | fRenderTargetContext->prepareForExternalIO(); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1784 | } |
| 1785 | |
| 1786 | /////////////////////////////////////////////////////////////////////////////// |
| 1787 | |
reed | 76033be | 2015-03-14 10:54:31 -0700 | [diff] [blame] | 1788 | SkBaseDevice* SkGpuDevice::onCreateDevice(const CreateInfo& cinfo, const SkPaint*) { |
joshualitt | ce89400 | 2016-01-11 13:29:31 -0800 | [diff] [blame] | 1789 | ASSERT_SINGLE_OWNER |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1790 | |
robertphillips | ca6eafc | 2016-05-17 09:57:46 -0700 | [diff] [blame] | 1791 | SkSurfaceProps props(this->surfaceProps().flags(), cinfo.fPixelGeometry); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1792 | |
robertphillips | ca6eafc | 2016-05-17 09:57:46 -0700 | [diff] [blame] | 1793 | // layers are never drawn in repeat modes, so we can request an approx |
hcm | 4396fa5 | 2014-10-27 21:43:30 -0700 | [diff] [blame] | 1794 | // match and ignore any padding. |
robertphillips | ca6eafc | 2016-05-17 09:57:46 -0700 | [diff] [blame] | 1795 | SkBackingFit fit = kNever_TileUsage == cinfo.fTileUsage ? SkBackingFit::kApprox |
| 1796 | : SkBackingFit::kExact; |
bsalomon | afe3005 | 2015-01-16 07:32:33 -0800 | [diff] [blame] | 1797 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1798 | sk_sp<GrRenderTargetContext> rtc(fContext->makeRenderTargetContext( |
| 1799 | fit, |
| 1800 | cinfo.fInfo.width(), cinfo.fInfo.height(), |
| 1801 | fRenderTargetContext->config(), |
Robert Phillips | 75a475c | 2017-01-13 09:18:59 -0500 | [diff] [blame] | 1802 | fRenderTargetContext->refColorSpace(), |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1803 | fRenderTargetContext->desc().fSampleCnt, |
| 1804 | kDefault_GrSurfaceOrigin, |
| 1805 | &props)); |
| 1806 | if (!rtc) { |
Mike Klein | e54c75f | 2016-10-13 14:18:09 -0400 | [diff] [blame] | 1807 | return nullptr; |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1808 | } |
robertphillips | ca6eafc | 2016-05-17 09:57:46 -0700 | [diff] [blame] | 1809 | |
| 1810 | // Skia's convention is to only clear a device if it is non-opaque. |
| 1811 | InitContents init = cinfo.fInfo.isOpaque() ? kUninit_InitContents : kClear_InitContents; |
| 1812 | |
Robert Phillips | 9fab7e9 | 2016-11-17 12:45:04 -0500 | [diff] [blame] | 1813 | return SkGpuDevice::Make(fContext.get(), std::move(rtc), |
| 1814 | cinfo.fInfo.width(), cinfo.fInfo.height(), init).release(); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1815 | } |
| 1816 | |
reed | e8f3062 | 2016-03-23 18:59:25 -0700 | [diff] [blame] | 1817 | sk_sp<SkSurface> SkGpuDevice::makeSurface(const SkImageInfo& info, const SkSurfaceProps& props) { |
joshualitt | ce89400 | 2016-01-11 13:29:31 -0800 | [diff] [blame] | 1818 | ASSERT_SINGLE_OWNER |
bsalomon | afe3005 | 2015-01-16 07:32:33 -0800 | [diff] [blame] | 1819 | // TODO: Change the signature of newSurface to take a budgeted parameter. |
bsalomon | 5ec26ae | 2016-02-25 08:33:02 -0800 | [diff] [blame] | 1820 | static const SkBudgeted kBudgeted = SkBudgeted::kNo; |
Hal Canary | 144caf5 | 2016-11-07 17:57:18 -0500 | [diff] [blame] | 1821 | return SkSurface::MakeRenderTarget(fContext.get(), kBudgeted, info, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1822 | fRenderTargetContext->desc().fSampleCnt, |
| 1823 | fRenderTargetContext->origin(), &props); |
reed@google.com | 76f10a3 | 2014-02-05 15:32:21 +0000 | [diff] [blame] | 1824 | } |
| 1825 | |
senorblanco | 900c367 | 2016-04-27 11:31:23 -0700 | [diff] [blame] | 1826 | SkImageFilterCache* SkGpuDevice::getImageFilterCache() { |
joshualitt | ce89400 | 2016-01-11 13:29:31 -0800 | [diff] [blame] | 1827 | ASSERT_SINGLE_OWNER |
senorblanco | 55b6d8b | 2014-07-30 11:26:46 -0700 | [diff] [blame] | 1828 | // We always return a transient cache, so it is freed after each |
| 1829 | // filter traversal. |
brianosman | 04a44d0 | 2016-09-21 09:46:57 -0700 | [diff] [blame] | 1830 | return SkImageFilterCache::Create(SkImageFilterCache::kDefaultTransientSize); |
senorblanco | 55b6d8b | 2014-07-30 11:26:46 -0700 | [diff] [blame] | 1831 | } |
reed | f037e0b | 2014-10-30 11:34:15 -0700 | [diff] [blame] | 1832 | |
| 1833 | #endif |