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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "src/gpu/SkGpuDevice.h" |
Hal Canary | c640d0d | 2018-06-13 09:59:02 -0400 | [diff] [blame] | 9 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 10 | #include "include/core/SkImageFilter.h" |
| 11 | #include "include/core/SkPathEffect.h" |
| 12 | #include "include/core/SkPicture.h" |
| 13 | #include "include/core/SkSurface.h" |
| 14 | #include "include/core/SkVertices.h" |
| 15 | #include "include/gpu/GrContext.h" |
| 16 | #include "include/private/SkImageInfoPriv.h" |
| 17 | #include "include/private/SkShadowFlags.h" |
| 18 | #include "include/private/SkTo.h" |
| 19 | #include "src/core/SkCanvasPriv.h" |
| 20 | #include "src/core/SkClipStack.h" |
| 21 | #include "src/core/SkDraw.h" |
| 22 | #include "src/core/SkImageFilterCache.h" |
| 23 | #include "src/core/SkLatticeIter.h" |
| 24 | #include "src/core/SkMakeUnique.h" |
| 25 | #include "src/core/SkPictureData.h" |
| 26 | #include "src/core/SkRRectPriv.h" |
| 27 | #include "src/core/SkRasterClip.h" |
| 28 | #include "src/core/SkRecord.h" |
| 29 | #include "src/core/SkSpecialImage.h" |
| 30 | #include "src/core/SkStroke.h" |
| 31 | #include "src/core/SkTLazy.h" |
| 32 | #include "src/core/SkVertState.h" |
| 33 | #include "src/core/SkWritePixelsRec.h" |
| 34 | #include "src/gpu/GrBitmapTextureMaker.h" |
| 35 | #include "src/gpu/GrBlurUtils.h" |
| 36 | #include "src/gpu/GrContextPriv.h" |
| 37 | #include "src/gpu/GrGpu.h" |
| 38 | #include "src/gpu/GrImageTextureMaker.h" |
| 39 | #include "src/gpu/GrRenderTargetContextPriv.h" |
| 40 | #include "src/gpu/GrShape.h" |
| 41 | #include "src/gpu/GrStyle.h" |
| 42 | #include "src/gpu/GrSurfaceProxyPriv.h" |
| 43 | #include "src/gpu/GrTextureAdjuster.h" |
| 44 | #include "src/gpu/GrTracing.h" |
| 45 | #include "src/gpu/SkGr.h" |
| 46 | #include "src/gpu/effects/GrBicubicEffect.h" |
| 47 | #include "src/gpu/effects/GrTextureDomain.h" |
| 48 | #include "src/gpu/text/GrTextTarget.h" |
| 49 | #include "src/image/SkImage_Base.h" |
| 50 | #include "src/image/SkReadPixelsRec.h" |
| 51 | #include "src/image/SkSurface_Gpu.h" |
| 52 | #include "src/utils/SkUTF.h" |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 53 | |
joshualitt | ce89400 | 2016-01-11 13:29:31 -0800 | [diff] [blame] | 54 | #define ASSERT_SINGLE_OWNER \ |
Robert Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 55 | SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(fContext->priv().singleOwner());) |
joshualitt | ce89400 | 2016-01-11 13:29:31 -0800 | [diff] [blame] | 56 | |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 57 | |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 58 | /////////////////////////////////////////////////////////////////////////////// |
| 59 | |
bsalomon | 74f681d | 2015-06-23 14:38:48 -0700 | [diff] [blame] | 60 | /** Checks that the alpha type is legal and gets constructor flags. Returns false if device creation |
| 61 | should fail. */ |
| 62 | bool SkGpuDevice::CheckAlphaTypeAndGetFlags( |
| 63 | const SkImageInfo* info, SkGpuDevice::InitContents init, unsigned* flags) { |
| 64 | *flags = 0; |
| 65 | if (info) { |
| 66 | switch (info->alphaType()) { |
| 67 | case kPremul_SkAlphaType: |
| 68 | break; |
| 69 | case kOpaque_SkAlphaType: |
| 70 | *flags |= SkGpuDevice::kIsOpaque_Flag; |
| 71 | break; |
| 72 | default: // If it is unpremul or unknown don't try to render |
| 73 | return false; |
| 74 | } |
| 75 | } |
| 76 | if (kClear_InitContents == init) { |
| 77 | *flags |= kNeedClear_Flag; |
| 78 | } |
| 79 | return true; |
| 80 | } |
| 81 | |
Robert Phillips | 9fab7e9 | 2016-11-17 12:45:04 -0500 | [diff] [blame] | 82 | sk_sp<SkGpuDevice> SkGpuDevice::Make(GrContext* context, |
| 83 | sk_sp<GrRenderTargetContext> renderTargetContext, |
robertphillips | 15c42ca | 2016-08-04 08:45:02 -0700 | [diff] [blame] | 84 | int width, int height, |
| 85 | InitContents init) { |
Robert Phillips | 920d488 | 2019-03-04 15:16:44 -0500 | [diff] [blame] | 86 | if (!renderTargetContext || context->priv().abandoned()) { |
robertphillips | ca6eafc | 2016-05-17 09:57:46 -0700 | [diff] [blame] | 87 | return nullptr; |
| 88 | } |
| 89 | unsigned flags; |
| 90 | if (!CheckAlphaTypeAndGetFlags(nullptr, init, &flags)) { |
| 91 | return nullptr; |
| 92 | } |
Robert Phillips | 9fab7e9 | 2016-11-17 12:45:04 -0500 | [diff] [blame] | 93 | return sk_sp<SkGpuDevice>(new SkGpuDevice(context, std::move(renderTargetContext), |
| 94 | width, height, flags)); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 95 | } |
| 96 | |
robertphillips | 24e9128 | 2016-04-29 06:46:36 -0700 | [diff] [blame] | 97 | sk_sp<SkGpuDevice> SkGpuDevice::Make(GrContext* context, SkBudgeted budgeted, |
| 98 | const SkImageInfo& info, int sampleCount, |
Greg Daniel | e252f08 | 2017-10-23 16:05:23 -0400 | [diff] [blame] | 99 | GrSurfaceOrigin origin, const SkSurfaceProps* props, |
| 100 | GrMipMapped mipMapped, InitContents init) { |
bsalomon | 74f681d | 2015-06-23 14:38:48 -0700 | [diff] [blame] | 101 | unsigned flags; |
| 102 | if (!CheckAlphaTypeAndGetFlags(&info, init, &flags)) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 103 | return nullptr; |
bsalomon | 74f681d | 2015-06-23 14:38:48 -0700 | [diff] [blame] | 104 | } |
| 105 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 106 | sk_sp<GrRenderTargetContext> renderTargetContext(MakeRenderTargetContext(context, budgeted, |
| 107 | info, sampleCount, |
Greg Daniel | e252f08 | 2017-10-23 16:05:23 -0400 | [diff] [blame] | 108 | origin, props, |
| 109 | mipMapped)); |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 110 | if (!renderTargetContext) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 111 | return nullptr; |
bsalomon | 74f681d | 2015-06-23 14:38:48 -0700 | [diff] [blame] | 112 | } |
| 113 | |
Robert Phillips | 9fab7e9 | 2016-11-17 12:45:04 -0500 | [diff] [blame] | 114 | return sk_sp<SkGpuDevice>(new SkGpuDevice(context, std::move(renderTargetContext), |
robertphillips | ca6eafc | 2016-05-17 09:57:46 -0700 | [diff] [blame] | 115 | info.width(), info.height(), flags)); |
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 | static SkImageInfo make_info(GrRenderTargetContext* context, int w, int h, bool opaque) { |
reed | 589a39e | 2016-08-20 07:59:19 -0700 | [diff] [blame] | 119 | SkColorType colorType; |
Brian Salomon | f3569f0 | 2017-10-24 12:52:33 -0400 | [diff] [blame] | 120 | if (!GrPixelConfigToColorType(context->colorSpaceInfo().config(), &colorType)) { |
reed | 589a39e | 2016-08-20 07:59:19 -0700 | [diff] [blame] | 121 | colorType = kUnknown_SkColorType; |
| 122 | } |
Brian Salomon | f3569f0 | 2017-10-24 12:52:33 -0400 | [diff] [blame] | 123 | return SkImageInfo::Make(w, h, colorType, opaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType, |
| 124 | context->colorSpaceInfo().refColorSpace()); |
reed | 589a39e | 2016-08-20 07:59:19 -0700 | [diff] [blame] | 125 | } |
| 126 | |
Robert Phillips | 9fab7e9 | 2016-11-17 12:45:04 -0500 | [diff] [blame] | 127 | SkGpuDevice::SkGpuDevice(GrContext* context, sk_sp<GrRenderTargetContext> renderTargetContext, |
| 128 | int width, int height, unsigned flags) |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 129 | : INHERITED(make_info(renderTargetContext.get(), width, height, |
| 130 | SkToBool(flags & kIsOpaque_Flag)), renderTargetContext->surfaceProps()) |
Robert Phillips | 9fab7e9 | 2016-11-17 12:45:04 -0500 | [diff] [blame] | 131 | , fContext(SkRef(context)) |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 132 | , fRenderTargetContext(std::move(renderTargetContext)) |
reed | 589a39e | 2016-08-20 07:59:19 -0700 | [diff] [blame] | 133 | { |
robertphillips | 1f3923e | 2016-07-21 07:17:54 -0700 | [diff] [blame] | 134 | fSize.set(width, height); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 135 | |
bsalomon | e63ffef | 2016-02-05 07:17:34 -0800 | [diff] [blame] | 136 | if (flags & kNeedClear_Flag) { |
| 137 | this->clearAll(); |
| 138 | } |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 139 | } |
| 140 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 141 | sk_sp<GrRenderTargetContext> SkGpuDevice::MakeRenderTargetContext( |
| 142 | GrContext* context, |
| 143 | SkBudgeted budgeted, |
| 144 | const SkImageInfo& origInfo, |
| 145 | int sampleCount, |
| 146 | GrSurfaceOrigin origin, |
Greg Daniel | e252f08 | 2017-10-23 16:05:23 -0400 | [diff] [blame] | 147 | const SkSurfaceProps* surfaceProps, |
| 148 | GrMipMapped mipMapped) { |
commit-bot@chromium.org | 15a1405 | 2014-02-16 00:59:25 +0000 | [diff] [blame] | 149 | if (kUnknown_SkColorType == origInfo.colorType() || |
| 150 | origInfo.width() < 0 || origInfo.height() < 0) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 151 | return nullptr; |
commit-bot@chromium.org | 15a1405 | 2014-02-16 00:59:25 +0000 | [diff] [blame] | 152 | } |
| 153 | |
bsalomon | afe3005 | 2015-01-16 07:32:33 -0800 | [diff] [blame] | 154 | if (!context) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 155 | return nullptr; |
bsalomon | afe3005 | 2015-01-16 07:32:33 -0800 | [diff] [blame] | 156 | } |
| 157 | |
Brian Osman | 2b23c4b | 2018-06-01 12:25:08 -0400 | [diff] [blame] | 158 | GrPixelConfig config = SkImageInfo2GrPixelConfig(origInfo); |
Greg Daniel | 0a7aa14 | 2018-02-21 13:02:32 -0500 | [diff] [blame] | 159 | if (kUnknown_GrPixelConfig == config) { |
| 160 | return nullptr; |
| 161 | } |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 162 | GrBackendFormat format = |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 163 | context->priv().caps()->getBackendFormatFromColorType(origInfo.colorType()); |
Robert Phillips | 0ae6faa | 2017-03-21 16:22:00 -0400 | [diff] [blame] | 164 | // This method is used to create SkGpuDevice's for SkSurface_Gpus. In this case |
| 165 | // they need to be exact. |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 166 | return context->priv().makeDeferredRenderTargetContext( |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 167 | format, SkBackingFit::kExact, |
robertphillips | 6738c70 | 2016-07-27 12:13:51 -0700 | [diff] [blame] | 168 | origInfo.width(), origInfo.height(), |
Robert Phillips | 70b49fd | 2017-01-13 11:21:36 -0500 | [diff] [blame] | 169 | config, origInfo.refColorSpace(), sampleCount, |
Greg Daniel | 45d6303 | 2017-10-30 13:41:26 -0400 | [diff] [blame] | 170 | mipMapped, origin, surfaceProps, budgeted); |
kkinnunen | abcfab4 | 2015-02-22 22:53:44 -0800 | [diff] [blame] | 171 | } |
commit-bot@chromium.org | 15a1405 | 2014-02-16 00:59:25 +0000 | [diff] [blame] | 172 | |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 173 | sk_sp<SkSpecialImage> SkGpuDevice::filterTexture(SkSpecialImage* srcImg, |
robertphillips | 970587b | 2016-07-14 14:12:55 -0700 | [diff] [blame] | 174 | int left, int top, |
| 175 | SkIPoint* offset, |
| 176 | const SkImageFilter* filter) { |
| 177 | SkASSERT(srcImg->isTextureBacked()); |
| 178 | SkASSERT(filter); |
| 179 | |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 180 | SkMatrix matrix = this->ctm(); |
robertphillips | 970587b | 2016-07-14 14:12:55 -0700 | [diff] [blame] | 181 | matrix.postTranslate(SkIntToScalar(-left), SkIntToScalar(-top)); |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 182 | const SkIRect clipBounds = this->devClipBounds().makeOffset(-left, -top); |
Hal Canary | 144caf5 | 2016-11-07 17:57:18 -0500 | [diff] [blame] | 183 | sk_sp<SkImageFilterCache> cache(this->getImageFilterCache()); |
Brian Osman | a50205f | 2018-07-06 13:57:01 -0400 | [diff] [blame] | 184 | SkColorType colorType; |
| 185 | if (!GrPixelConfigToColorType(fRenderTargetContext->colorSpaceInfo().config(), &colorType)) { |
| 186 | colorType = kN32_SkColorType; |
| 187 | } |
Brian Salomon | f3569f0 | 2017-10-24 12:52:33 -0400 | [diff] [blame] | 188 | SkImageFilter::OutputProperties outputProperties( |
Brian Osman | a50205f | 2018-07-06 13:57:01 -0400 | [diff] [blame] | 189 | colorType, fRenderTargetContext->colorSpaceInfo().colorSpace()); |
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 | |
Mike Reed | 353196f | 2017-07-21 11:01:18 -0400 | [diff] [blame] | 197 | bool SkGpuDevice::onReadPixels(const SkPixmap& pm, int x, int y) { |
joshualitt | ce89400 | 2016-01-11 13:29:31 -0800 | [diff] [blame] | 198 | ASSERT_SINGLE_OWNER |
commit-bot@chromium.org | a713f9c | 2014-03-17 21:31:26 +0000 | [diff] [blame] | 199 | |
Mike Reed | 353196f | 2017-07-21 11:01:18 -0400 | [diff] [blame] | 200 | if (!SkImageInfoValidConversion(pm.info(), this->imageInfo())) { |
Matt Sarett | cb6266b | 2017-01-17 10:48:53 -0500 | [diff] [blame] | 201 | return false; |
| 202 | } |
| 203 | |
Mike Reed | 353196f | 2017-07-21 11:01:18 -0400 | [diff] [blame] | 204 | SkReadPixelsRec rec(pm, x, y); |
Matt Sarett | 03dd6d5 | 2017-01-23 12:15:09 -0500 | [diff] [blame] | 205 | if (!rec.trim(this->width(), this->height())) { |
| 206 | return false; |
| 207 | } |
| 208 | |
| 209 | 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] | 210 | } |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 211 | |
Mike Reed | 353196f | 2017-07-21 11:01:18 -0400 | [diff] [blame] | 212 | bool SkGpuDevice::onWritePixels(const SkPixmap& pm, int x, int y) { |
joshualitt | ce89400 | 2016-01-11 13:29:31 -0800 | [diff] [blame] | 213 | ASSERT_SINGLE_OWNER |
robertphillips | 1da3ecd | 2016-08-31 14:54:15 -0700 | [diff] [blame] | 214 | |
Mike Reed | 353196f | 2017-07-21 11:01:18 -0400 | [diff] [blame] | 215 | if (!SkImageInfoValidConversion(this->imageInfo(), pm.info())) { |
Matt Sarett | cb6266b | 2017-01-17 10:48:53 -0500 | [diff] [blame] | 216 | return false; |
| 217 | } |
| 218 | |
Mike Reed | 353196f | 2017-07-21 11:01:18 -0400 | [diff] [blame] | 219 | SkWritePixelsRec rec(pm, x, y); |
Matt Sarett | 03dd6d5 | 2017-01-23 12:15:09 -0500 | [diff] [blame] | 220 | if (!rec.trim(this->width(), this->height())) { |
| 221 | return false; |
| 222 | } |
| 223 | |
| 224 | 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] | 225 | } |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 226 | |
reed | 41e010c | 2015-06-09 12:16:53 -0700 | [diff] [blame] | 227 | bool SkGpuDevice::onAccessPixels(SkPixmap* pmap) { |
joshualitt | ce89400 | 2016-01-11 13:29:31 -0800 | [diff] [blame] | 228 | ASSERT_SINGLE_OWNER |
reed | 41e010c | 2015-06-09 12:16:53 -0700 | [diff] [blame] | 229 | return false; |
| 230 | } |
| 231 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 232 | GrRenderTargetContext* SkGpuDevice::accessRenderTargetContext() { |
robertphillips | 175dd9b | 2016-04-28 14:32:04 -0700 | [diff] [blame] | 233 | ASSERT_SINGLE_OWNER |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 234 | return fRenderTargetContext.get(); |
robertphillips | 175dd9b | 2016-04-28 14:32:04 -0700 | [diff] [blame] | 235 | } |
| 236 | |
reed | 8eddfb5 | 2014-12-04 07:50:14 -0800 | [diff] [blame] | 237 | void SkGpuDevice::clearAll() { |
joshualitt | ce89400 | 2016-01-11 13:29:31 -0800 | [diff] [blame] | 238 | ASSERT_SINGLE_OWNER |
Hal Canary | 144caf5 | 2016-11-07 17:57:18 -0500 | [diff] [blame] | 239 | GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "clearAll", fContext.get()); |
Robert Phillips | 784b7bf | 2016-12-09 13:35:02 -0500 | [diff] [blame] | 240 | |
reed | 8eddfb5 | 2014-12-04 07:50:14 -0800 | [diff] [blame] | 241 | SkIRect rect = SkIRect::MakeWH(this->width(), this->height()); |
Brian Osman | 9a9baae | 2018-11-05 15:06:26 -0500 | [diff] [blame] | 242 | fRenderTargetContext->clear(&rect, SK_PMColor4fTRANSPARENT, |
| 243 | GrRenderTargetContext::CanClearFullscreen::kYes); |
reed | 8eddfb5 | 2014-12-04 07:50:14 -0800 | [diff] [blame] | 244 | } |
| 245 | |
Brian Salomon | aad8315 | 2019-05-24 10:16:35 -0400 | [diff] [blame^] | 246 | void SkGpuDevice::replaceRenderTargetContext(sk_sp<GrRenderTargetContext> rtc, |
| 247 | bool shouldRetainContent) { |
| 248 | SkASSERT(rtc->width() == this->width()); |
| 249 | SkASSERT(rtc->height() == this->height()); |
| 250 | SkASSERT(rtc->numColorSamples() == fRenderTargetContext->numColorSamples()); |
| 251 | SkASSERT(rtc->numStencilSamples() == fRenderTargetContext->numStencilSamples()); |
| 252 | SkASSERT(rtc->asSurfaceProxy()->priv().isExact()); |
| 253 | if (shouldRetainContent) { |
| 254 | if (this->context()->abandoned()) { |
| 255 | return; |
| 256 | } |
| 257 | rtc->copy(fRenderTargetContext->asSurfaceProxy()); |
| 258 | } |
| 259 | |
| 260 | fRenderTargetContext = std::move(rtc); |
| 261 | } |
| 262 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 263 | void SkGpuDevice::replaceRenderTargetContext(bool shouldRetainContent) { |
joshualitt | ce89400 | 2016-01-11 13:29:31 -0800 | [diff] [blame] | 264 | ASSERT_SINGLE_OWNER |
kkinnunen | abcfab4 | 2015-02-22 22:53:44 -0800 | [diff] [blame] | 265 | |
Brian Osman | 693a540 | 2016-10-27 15:13:22 -0400 | [diff] [blame] | 266 | SkBudgeted budgeted = fRenderTargetContext->priv().isBudgeted(); |
kkinnunen | abcfab4 | 2015-02-22 22:53:44 -0800 | [diff] [blame] | 267 | |
Robert Phillips | 0ae6faa | 2017-03-21 16:22:00 -0400 | [diff] [blame] | 268 | // This entry point is used by SkSurface_Gpu::onCopyOnWrite so it must create a |
| 269 | // kExact-backed render target context. |
Brian Osman | 693a540 | 2016-10-27 15:13:22 -0400 | [diff] [blame] | 270 | sk_sp<GrRenderTargetContext> newRTC(MakeRenderTargetContext( |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 271 | this->context(), |
| 272 | budgeted, |
| 273 | this->imageInfo(), |
Robert Phillips | 0ae6faa | 2017-03-21 16:22:00 -0400 | [diff] [blame] | 274 | fRenderTargetContext->numColorSamples(), |
| 275 | fRenderTargetContext->origin(), |
Greg Daniel | e252f08 | 2017-10-23 16:05:23 -0400 | [diff] [blame] | 276 | &this->surfaceProps(), |
| 277 | fRenderTargetContext->mipMapped())); |
Brian Osman | 693a540 | 2016-10-27 15:13:22 -0400 | [diff] [blame] | 278 | if (!newRTC) { |
kkinnunen | abcfab4 | 2015-02-22 22:53:44 -0800 | [diff] [blame] | 279 | return; |
| 280 | } |
Brian Salomon | aad8315 | 2019-05-24 10:16:35 -0400 | [diff] [blame^] | 281 | this->replaceRenderTargetContext(std::move(newRTC), shouldRetainContent); |
kkinnunen | abcfab4 | 2015-02-22 22:53:44 -0800 | [diff] [blame] | 282 | } |
| 283 | |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 284 | /////////////////////////////////////////////////////////////////////////////// |
| 285 | |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 286 | void SkGpuDevice::drawPaint(const SkPaint& paint) { |
joshualitt | ce89400 | 2016-01-11 13:29:31 -0800 | [diff] [blame] | 287 | ASSERT_SINGLE_OWNER |
Hal Canary | 144caf5 | 2016-11-07 17:57:18 -0500 | [diff] [blame] | 288 | GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawPaint", fContext.get()); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 289 | |
| 290 | GrPaint grPaint; |
Brian Salomon | f3569f0 | 2017-10-24 12:52:33 -0400 | [diff] [blame] | 291 | if (!SkPaintToGrPaint(this->context(), fRenderTargetContext->colorSpaceInfo(), paint, |
| 292 | this->ctm(), &grPaint)) { |
bsalomon | bed83a6 | 2015-04-15 14:18:34 -0700 | [diff] [blame] | 293 | return; |
| 294 | } |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 295 | |
Brian Salomon | 0166cfd | 2017-03-13 17:58:25 -0400 | [diff] [blame] | 296 | fRenderTargetContext->drawPaint(this->clip(), std::move(grPaint), this->ctm()); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 297 | } |
| 298 | |
Brian Salomon | 1459ebd | 2017-12-19 16:12:44 -0500 | [diff] [blame] | 299 | static inline GrPrimitiveType point_mode_to_primitive_type(SkCanvas::PointMode mode) { |
| 300 | switch (mode) { |
| 301 | case SkCanvas::kPoints_PointMode: |
| 302 | return GrPrimitiveType::kPoints; |
| 303 | case SkCanvas::kLines_PointMode: |
| 304 | return GrPrimitiveType::kLines; |
| 305 | case SkCanvas::kPolygon_PointMode: |
| 306 | return GrPrimitiveType::kLineStrip; |
| 307 | } |
| 308 | SK_ABORT("Unexpected mode"); |
| 309 | return GrPrimitiveType::kPoints; |
| 310 | } |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 311 | |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 312 | void SkGpuDevice::drawPoints(SkCanvas::PointMode mode, |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 313 | size_t count, const SkPoint pts[], const SkPaint& paint) { |
joshualitt | ce89400 | 2016-01-11 13:29:31 -0800 | [diff] [blame] | 314 | ASSERT_SINGLE_OWNER |
Hal Canary | 144caf5 | 2016-11-07 17:57:18 -0500 | [diff] [blame] | 315 | GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawPoints", fContext.get()); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 316 | SkScalar width = paint.getStrokeWidth(); |
| 317 | if (width < 0) { |
| 318 | return; |
| 319 | } |
| 320 | |
commit-bot@chromium.org | 628ed0b | 2014-05-19 14:32:49 +0000 | [diff] [blame] | 321 | if (paint.getPathEffect() && 2 == count && SkCanvas::kLines_PointMode == mode) { |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 322 | GrStyle style(paint, SkPaint::kStroke_Style); |
egdaniel | e61c411 | 2014-06-12 10:24:21 -0700 | [diff] [blame] | 323 | GrPaint grPaint; |
Brian Salomon | f3569f0 | 2017-10-24 12:52:33 -0400 | [diff] [blame] | 324 | if (!SkPaintToGrPaint(this->context(), fRenderTargetContext->colorSpaceInfo(), paint, |
| 325 | this->ctm(), &grPaint)) { |
bsalomon | bed83a6 | 2015-04-15 14:18:34 -0700 | [diff] [blame] | 326 | return; |
| 327 | } |
egdaniel | e61c411 | 2014-06-12 10:24:21 -0700 | [diff] [blame] | 328 | SkPath path; |
jvanverth | b3eb687 | 2014-10-24 07:12:51 -0700 | [diff] [blame] | 329 | path.setIsVolatile(true); |
egdaniel | e61c411 | 2014-06-12 10:24:21 -0700 | [diff] [blame] | 330 | path.moveTo(pts[0]); |
| 331 | path.lineTo(pts[1]); |
Chris Dalton | 3b51df1 | 2017-11-27 14:33:06 -0700 | [diff] [blame] | 332 | fRenderTargetContext->drawPath(this->clip(), std::move(grPaint), GrAA(paint.isAntiAlias()), |
| 333 | this->ctm(), path, style); |
egdaniel | e61c411 | 2014-06-12 10:24:21 -0700 | [diff] [blame] | 334 | return; |
commit-bot@chromium.org | 628ed0b | 2014-05-19 14:32:49 +0000 | [diff] [blame] | 335 | } |
| 336 | |
bsalomon | 6ade6dd | 2016-09-12 12:07:17 -0700 | [diff] [blame] | 337 | SkScalar scales[2]; |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 338 | bool isHairline = (0 == width) || (1 == width && this->ctm().getMinMaxScales(scales) && |
bsalomon | 6ade6dd | 2016-09-12 12:07:17 -0700 | [diff] [blame] | 339 | SkScalarNearlyEqual(scales[0], 1.f) && |
| 340 | SkScalarNearlyEqual(scales[1], 1.f)); |
ethannicholas | 330bb95 | 2015-07-17 06:44:02 -0700 | [diff] [blame] | 341 | // 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] | 342 | // else we let the SkDraw call our drawPath() |
Ethan Nicholas | 2d78bcd | 2017-06-08 10:11:53 -0400 | [diff] [blame] | 343 | if (!isHairline || paint.getPathEffect() || paint.getMaskFilter() || paint.isAntiAlias()) { |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 344 | SkRasterClip rc(this->devClipBounds()); |
| 345 | SkDraw draw; |
| 346 | draw.fDst = SkPixmap(SkImageInfo::MakeUnknown(this->width(), this->height()), nullptr, 0); |
| 347 | draw.fMatrix = &this->ctm(); |
| 348 | draw.fRC = &rc; |
Mike Reed | 99330ba | 2017-02-22 11:01:08 -0500 | [diff] [blame] | 349 | draw.drawPoints(mode, count, pts, paint, this); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 350 | return; |
| 351 | } |
| 352 | |
Brian Salomon | 1459ebd | 2017-12-19 16:12:44 -0500 | [diff] [blame] | 353 | GrPrimitiveType primitiveType = point_mode_to_primitive_type(mode); |
bsalomon | 6ade6dd | 2016-09-12 12:07:17 -0700 | [diff] [blame] | 354 | |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 355 | const SkMatrix* viewMatrix = &this->ctm(); |
bsalomon | 6ade6dd | 2016-09-12 12:07:17 -0700 | [diff] [blame] | 356 | #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |
| 357 | // This offsetting in device space matches the expectations of the Android framework for non-AA |
| 358 | // points and lines. |
| 359 | SkMatrix tempMatrix; |
Chris Dalton | 3809bab | 2017-06-13 10:55:06 -0600 | [diff] [blame] | 360 | if (GrIsPrimTypeLines(primitiveType) || GrPrimitiveType::kPoints == primitiveType) { |
bsalomon | 6ade6dd | 2016-09-12 12:07:17 -0700 | [diff] [blame] | 361 | tempMatrix = *viewMatrix; |
| 362 | static const SkScalar kOffset = 0.063f; // Just greater than 1/16. |
| 363 | tempMatrix.postTranslate(kOffset, kOffset); |
| 364 | viewMatrix = &tempMatrix; |
| 365 | } |
| 366 | #endif |
| 367 | |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 368 | GrPaint grPaint; |
Brian Salomon | f3569f0 | 2017-10-24 12:52:33 -0400 | [diff] [blame] | 369 | if (!SkPaintToGrPaint(this->context(), fRenderTargetContext->colorSpaceInfo(), paint, |
| 370 | *viewMatrix, &grPaint)) { |
bsalomon | bed83a6 | 2015-04-15 14:18:34 -0700 | [diff] [blame] | 371 | return; |
| 372 | } |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 373 | |
Brian Osman | ae0c50c | 2017-05-25 16:56:34 -0400 | [diff] [blame] | 374 | static constexpr SkVertices::VertexMode kIgnoredMode = SkVertices::kTriangles_VertexMode; |
| 375 | sk_sp<SkVertices> vertices = SkVertices::MakeCopy(kIgnoredMode, SkToS32(count), pts, nullptr, |
| 376 | nullptr); |
| 377 | |
| 378 | fRenderTargetContext->drawVertices(this->clip(), std::move(grPaint), *viewMatrix, |
Ruiqi Mao | 4ec72f7 | 2018-07-10 17:21:07 -0400 | [diff] [blame] | 379 | std::move(vertices), nullptr, 0, &primitiveType); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 380 | } |
| 381 | |
| 382 | /////////////////////////////////////////////////////////////////////////////// |
| 383 | |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 384 | void SkGpuDevice::drawRect(const SkRect& rect, const SkPaint& paint) { |
joshualitt | ce89400 | 2016-01-11 13:29:31 -0800 | [diff] [blame] | 385 | ASSERT_SINGLE_OWNER |
Hal Canary | 144caf5 | 2016-11-07 17:57:18 -0500 | [diff] [blame] | 386 | GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawRect", fContext.get()); |
Robert Phillips | 27927a5 | 2018-08-20 13:18:12 -0400 | [diff] [blame] | 387 | |
| 388 | GrStyle style(paint); |
| 389 | |
bsalomon | a7d85ba | 2016-07-06 11:54:59 -0700 | [diff] [blame] | 390 | // A couple reasons we might need to call drawPath. |
| 391 | if (paint.getMaskFilter() || paint.getPathEffect()) { |
Robert Phillips | 27927a5 | 2018-08-20 13:18:12 -0400 | [diff] [blame] | 392 | GrShape shape(rect, style); |
| 393 | |
| 394 | GrBlurUtils::drawShapeWithMaskFilter(fContext.get(), fRenderTargetContext.get(), |
| 395 | this->clip(), paint, this->ctm(), shape); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 396 | return; |
| 397 | } |
| 398 | |
| 399 | GrPaint grPaint; |
Brian Salomon | f3569f0 | 2017-10-24 12:52:33 -0400 | [diff] [blame] | 400 | if (!SkPaintToGrPaint(this->context(), fRenderTargetContext->colorSpaceInfo(), paint, |
| 401 | this->ctm(), &grPaint)) { |
bsalomon | bed83a6 | 2015-04-15 14:18:34 -0700 | [diff] [blame] | 402 | return; |
| 403 | } |
Mike Klein | 744fb73 | 2014-06-23 15:13:26 -0400 | [diff] [blame] | 404 | |
Chris Dalton | 3b51df1 | 2017-11-27 14:33:06 -0700 | [diff] [blame] | 405 | fRenderTargetContext->drawRect(this->clip(), std::move(grPaint), GrAA(paint.isAntiAlias()), |
| 406 | this->ctm(), rect, &style); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 407 | } |
| 408 | |
Michael Ludwig | 390f0cc | 2019-03-19 09:16:38 -0400 | [diff] [blame] | 409 | void SkGpuDevice::drawEdgeAAQuad(const SkRect& rect, const SkPoint clip[4], |
| 410 | SkCanvas::QuadAAFlags aaFlags, SkColor color, SkBlendMode mode) { |
Michael Ludwig | 7545190 | 2019-01-23 11:14:29 -0500 | [diff] [blame] | 411 | ASSERT_SINGLE_OWNER |
Michael Ludwig | 390f0cc | 2019-03-19 09:16:38 -0400 | [diff] [blame] | 412 | GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawEdgeAAQuad", fContext.get()); |
Michael Ludwig | 7545190 | 2019-01-23 11:14:29 -0500 | [diff] [blame] | 413 | |
| 414 | SkPMColor4f dstColor = SkColor4fPrepForDst(SkColor4f::FromColor(color), |
Brian Osman | 8fa7ab4 | 2019-03-18 10:22:42 -0400 | [diff] [blame] | 415 | fRenderTargetContext->colorSpaceInfo()) |
Michael Ludwig | 7545190 | 2019-01-23 11:14:29 -0500 | [diff] [blame] | 416 | .premul(); |
| 417 | |
| 418 | GrPaint grPaint; |
| 419 | grPaint.setColor4f(dstColor); |
| 420 | if (mode != SkBlendMode::kSrcOver) { |
| 421 | grPaint.setXPFactory(SkBlendMode_AsXPFactory(mode)); |
| 422 | } |
| 423 | |
Michael Ludwig | 136f45a | 2019-02-19 11:44:41 -0500 | [diff] [blame] | 424 | // This is exclusively meant for tiling operations, so keep AA enabled to handle MSAA seaming |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 425 | GrQuadAAFlags grAA = SkToGrQuadAAFlags(aaFlags); |
Michael Ludwig | 390f0cc | 2019-03-19 09:16:38 -0400 | [diff] [blame] | 426 | if (clip) { |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 427 | // Use fillQuadWithEdgeAA |
| 428 | fRenderTargetContext->fillQuadWithEdgeAA(this->clip(), std::move(grPaint), GrAA::kYes, grAA, |
| 429 | this->ctm(), clip, nullptr); |
| 430 | } else { |
| 431 | // Use fillRectWithEdgeAA to preserve mathematical properties of dst being rectangular |
| 432 | fRenderTargetContext->fillRectWithEdgeAA(this->clip(), std::move(grPaint), GrAA::kYes, grAA, |
| 433 | this->ctm(), rect); |
| 434 | } |
Michael Ludwig | 7545190 | 2019-01-23 11:14:29 -0500 | [diff] [blame] | 435 | } |
| 436 | |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 437 | /////////////////////////////////////////////////////////////////////////////// |
| 438 | |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 439 | void SkGpuDevice::drawRRect(const SkRRect& rrect, const SkPaint& paint) { |
joshualitt | ce89400 | 2016-01-11 13:29:31 -0800 | [diff] [blame] | 440 | ASSERT_SINGLE_OWNER |
Hal Canary | 144caf5 | 2016-11-07 17:57:18 -0500 | [diff] [blame] | 441 | GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawRRect", fContext.get()); |
Robert Phillips | 27927a5 | 2018-08-20 13:18:12 -0400 | [diff] [blame] | 442 | |
Mike Reed | 80747ef | 2018-01-23 15:29:32 -0500 | [diff] [blame] | 443 | SkMaskFilterBase* mf = as_MFB(paint.getMaskFilter()); |
Mike Reed | bfadcf0 | 2018-01-20 22:24:21 +0000 | [diff] [blame] | 444 | if (mf) { |
| 445 | if (mf->hasFragmentProcessor()) { |
| 446 | mf = nullptr; // already handled in SkPaintToGrPaint |
| 447 | } |
Robert Phillips | a29a956 | 2016-10-20 09:40:55 -0400 | [diff] [blame] | 448 | } |
| 449 | |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 450 | GrStyle style(paint); |
commit-bot@chromium.org | 8213970 | 2014-03-10 22:53:20 +0000 | [diff] [blame] | 451 | |
Robert Phillips | a29a956 | 2016-10-20 09:40:55 -0400 | [diff] [blame] | 452 | if (mf || style.pathEffect()) { |
robertphillips | ff55b49 | 2015-11-24 07:56:59 -0800 | [diff] [blame] | 453 | // A path effect will presumably transform this rrect into something else. |
Robert Phillips | 27927a5 | 2018-08-20 13:18:12 -0400 | [diff] [blame] | 454 | GrShape shape(rrect, style); |
| 455 | |
Robert Phillips | 27927a5 | 2018-08-20 13:18:12 -0400 | [diff] [blame] | 456 | GrBlurUtils::drawShapeWithMaskFilter(fContext.get(), fRenderTargetContext.get(), |
| 457 | this->clip(), paint, this->ctm(), shape); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 458 | return; |
| 459 | } |
Mike Klein | 744fb73 | 2014-06-23 15:13:26 -0400 | [diff] [blame] | 460 | |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 461 | SkASSERT(!style.pathEffect()); |
robertphillips | 514450c | 2015-11-24 05:36:02 -0800 | [diff] [blame] | 462 | |
Robert Phillips | a522d66 | 2018-08-23 13:50:16 -0400 | [diff] [blame] | 463 | GrPaint grPaint; |
| 464 | if (!SkPaintToGrPaint(this->context(), fRenderTargetContext->colorSpaceInfo(), paint, |
| 465 | this->ctm(), &grPaint)) { |
| 466 | return; |
| 467 | } |
| 468 | |
Chris Dalton | 3b51df1 | 2017-11-27 14:33:06 -0700 | [diff] [blame] | 469 | fRenderTargetContext->drawRRect(this->clip(), std::move(grPaint), GrAA(paint.isAntiAlias()), |
| 470 | this->ctm(), rrect, style); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 471 | } |
| 472 | |
robertphillips | d770610 | 2016-02-25 09:28:08 -0800 | [diff] [blame] | 473 | |
Robert Phillips | 20390c3 | 2018-08-17 11:01:03 -0400 | [diff] [blame] | 474 | void SkGpuDevice::drawDRRect(const SkRRect& outer, const SkRRect& inner, const SkPaint& paint) { |
joshualitt | ce89400 | 2016-01-11 13:29:31 -0800 | [diff] [blame] | 475 | ASSERT_SINGLE_OWNER |
Hal Canary | 144caf5 | 2016-11-07 17:57:18 -0500 | [diff] [blame] | 476 | GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawDRRect", fContext.get()); |
robertphillips | d770610 | 2016-02-25 09:28:08 -0800 | [diff] [blame] | 477 | if (outer.isEmpty()) { |
| 478 | return; |
| 479 | } |
| 480 | |
| 481 | if (inner.isEmpty()) { |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 482 | return this->drawRRect(outer, paint); |
robertphillips | d770610 | 2016-02-25 09:28:08 -0800 | [diff] [blame] | 483 | } |
| 484 | |
commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 485 | SkStrokeRec stroke(paint); |
commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 486 | |
robertphillips | 0e7029e | 2015-11-30 05:45:06 -0800 | [diff] [blame] | 487 | if (stroke.isFillStyle() && !paint.getMaskFilter() && !paint.getPathEffect()) { |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 488 | GrPaint grPaint; |
Brian Salomon | f3569f0 | 2017-10-24 12:52:33 -0400 | [diff] [blame] | 489 | if (!SkPaintToGrPaint(this->context(), fRenderTargetContext->colorSpaceInfo(), paint, |
| 490 | this->ctm(), &grPaint)) { |
bsalomon | bed83a6 | 2015-04-15 14:18:34 -0700 | [diff] [blame] | 491 | return; |
| 492 | } |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 493 | |
Brian Salomon | 0166cfd | 2017-03-13 17:58:25 -0400 | [diff] [blame] | 494 | fRenderTargetContext->drawDRRect(this->clip(), std::move(grPaint), |
Chris Dalton | 3b51df1 | 2017-11-27 14:33:06 -0700 | [diff] [blame] | 495 | GrAA(paint.isAntiAlias()), this->ctm(), outer, inner); |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 496 | return; |
commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 497 | } |
| 498 | |
| 499 | SkPath path; |
jvanverth | b3eb687 | 2014-10-24 07:12:51 -0700 | [diff] [blame] | 500 | path.setIsVolatile(true); |
commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 501 | path.addRRect(outer); |
| 502 | path.addRRect(inner); |
| 503 | path.setFillType(SkPath::kEvenOdd_FillType); |
| 504 | |
Robert Phillips | 27927a5 | 2018-08-20 13:18:12 -0400 | [diff] [blame] | 505 | // TODO: We are losing the possible mutability of the path here but this should probably be |
| 506 | // fixed by upgrading GrShape to handle DRRects. |
| 507 | GrShape shape(path, paint); |
| 508 | |
| 509 | GrBlurUtils::drawShapeWithMaskFilter(fContext.get(), fRenderTargetContext.get(), this->clip(), |
| 510 | paint, this->ctm(), shape); |
commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 511 | } |
| 512 | |
| 513 | |
commit-bot@chromium.org | 8213970 | 2014-03-10 22:53:20 +0000 | [diff] [blame] | 514 | ///////////////////////////////////////////////////////////////////////////// |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 515 | |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 516 | void SkGpuDevice::drawRegion(const SkRegion& region, const SkPaint& paint) { |
msarett | cc319b9 | 2016-08-25 18:07:18 -0700 | [diff] [blame] | 517 | if (paint.getMaskFilter()) { |
| 518 | SkPath path; |
| 519 | region.getBoundaryPath(&path); |
Robert Phillips | 137ca52 | 2018-08-15 10:14:33 -0400 | [diff] [blame] | 520 | path.setIsVolatile(true); |
| 521 | return this->drawPath(path, paint, true); |
msarett | cc319b9 | 2016-08-25 18:07:18 -0700 | [diff] [blame] | 522 | } |
| 523 | |
| 524 | GrPaint grPaint; |
Brian Salomon | f3569f0 | 2017-10-24 12:52:33 -0400 | [diff] [blame] | 525 | if (!SkPaintToGrPaint(this->context(), fRenderTargetContext->colorSpaceInfo(), paint, |
| 526 | this->ctm(), &grPaint)) { |
msarett | cc319b9 | 2016-08-25 18:07:18 -0700 | [diff] [blame] | 527 | return; |
| 528 | } |
| 529 | |
Chris Dalton | 3b51df1 | 2017-11-27 14:33:06 -0700 | [diff] [blame] | 530 | fRenderTargetContext->drawRegion(this->clip(), std::move(grPaint), GrAA(paint.isAntiAlias()), |
| 531 | this->ctm(), region, GrStyle(paint)); |
msarett | cc319b9 | 2016-08-25 18:07:18 -0700 | [diff] [blame] | 532 | } |
| 533 | |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 534 | void SkGpuDevice::drawOval(const SkRect& oval, const SkPaint& paint) { |
joshualitt | ce89400 | 2016-01-11 13:29:31 -0800 | [diff] [blame] | 535 | ASSERT_SINGLE_OWNER |
Hal Canary | 144caf5 | 2016-11-07 17:57:18 -0500 | [diff] [blame] | 536 | GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawOval", fContext.get()); |
herb | 11a7f7f | 2015-11-24 12:41:00 -0800 | [diff] [blame] | 537 | |
robertphillips | 514450c | 2015-11-24 05:36:02 -0800 | [diff] [blame] | 538 | if (paint.getMaskFilter()) { |
| 539 | // The RRect path can handle special case blurring |
| 540 | SkRRect rr = SkRRect::MakeOval(oval); |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 541 | return this->drawRRect(rr, paint); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 542 | } |
| 543 | |
| 544 | GrPaint grPaint; |
Brian Salomon | f3569f0 | 2017-10-24 12:52:33 -0400 | [diff] [blame] | 545 | if (!SkPaintToGrPaint(this->context(), fRenderTargetContext->colorSpaceInfo(), paint, |
| 546 | this->ctm(), &grPaint)) { |
bsalomon | bed83a6 | 2015-04-15 14:18:34 -0700 | [diff] [blame] | 547 | return; |
| 548 | } |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 549 | |
Chris Dalton | 3b51df1 | 2017-11-27 14:33:06 -0700 | [diff] [blame] | 550 | fRenderTargetContext->drawOval(this->clip(), std::move(grPaint), GrAA(paint.isAntiAlias()), |
| 551 | this->ctm(), oval, GrStyle(paint)); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 552 | } |
| 553 | |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 554 | void SkGpuDevice::drawArc(const SkRect& oval, SkScalar startAngle, |
bsalomon | 4f3a0ca | 2016-08-22 13:14:26 -0700 | [diff] [blame] | 555 | SkScalar sweepAngle, bool useCenter, const SkPaint& paint) { |
| 556 | ASSERT_SINGLE_OWNER |
Hal Canary | 144caf5 | 2016-11-07 17:57:18 -0500 | [diff] [blame] | 557 | GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawArc", fContext.get()); |
bsalomon | 4f3a0ca | 2016-08-22 13:14:26 -0700 | [diff] [blame] | 558 | if (paint.getMaskFilter()) { |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 559 | this->INHERITED::drawArc(oval, startAngle, sweepAngle, useCenter, paint); |
bsalomon | 4f3a0ca | 2016-08-22 13:14:26 -0700 | [diff] [blame] | 560 | return; |
| 561 | } |
| 562 | GrPaint grPaint; |
Brian Salomon | f3569f0 | 2017-10-24 12:52:33 -0400 | [diff] [blame] | 563 | if (!SkPaintToGrPaint(this->context(), fRenderTargetContext->colorSpaceInfo(), paint, |
| 564 | this->ctm(), &grPaint)) { |
bsalomon | 4f3a0ca | 2016-08-22 13:14:26 -0700 | [diff] [blame] | 565 | return; |
| 566 | } |
| 567 | |
Chris Dalton | 3b51df1 | 2017-11-27 14:33:06 -0700 | [diff] [blame] | 568 | fRenderTargetContext->drawArc(this->clip(), std::move(grPaint), GrAA(paint.isAntiAlias()), |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 569 | this->ctm(), oval, startAngle, sweepAngle, useCenter, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 570 | GrStyle(paint)); |
bsalomon | 4f3a0ca | 2016-08-22 13:14:26 -0700 | [diff] [blame] | 571 | } |
| 572 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 573 | #include "include/core/SkMaskFilter.h" |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 574 | |
| 575 | /////////////////////////////////////////////////////////////////////////////// |
robertphillips | 0851d2d | 2016-06-02 05:21:34 -0700 | [diff] [blame] | 576 | void SkGpuDevice::drawStrokedLine(const SkPoint points[2], |
robertphillips | 0851d2d | 2016-06-02 05:21:34 -0700 | [diff] [blame] | 577 | const SkPaint& origPaint) { |
| 578 | ASSERT_SINGLE_OWNER |
Hal Canary | 144caf5 | 2016-11-07 17:57:18 -0500 | [diff] [blame] | 579 | GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawStrokedLine", fContext.get()); |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 580 | // Adding support for round capping would require a |
| 581 | // GrRenderTargetContext::fillRRectWithLocalMatrix entry point |
robertphillips | 0851d2d | 2016-06-02 05:21:34 -0700 | [diff] [blame] | 582 | SkASSERT(SkPaint::kRound_Cap != origPaint.getStrokeCap()); |
| 583 | SkASSERT(SkPaint::kStroke_Style == origPaint.getStyle()); |
| 584 | SkASSERT(!origPaint.getPathEffect()); |
| 585 | SkASSERT(!origPaint.getMaskFilter()); |
| 586 | |
| 587 | const SkScalar halfWidth = 0.5f * origPaint.getStrokeWidth(); |
| 588 | SkASSERT(halfWidth > 0); |
| 589 | |
| 590 | SkVector v = points[1] - points[0]; |
| 591 | |
| 592 | SkScalar length = SkPoint::Normalize(&v); |
| 593 | if (!length) { |
| 594 | v.fX = 1.0f; |
| 595 | v.fY = 0.0f; |
| 596 | } |
| 597 | |
| 598 | SkPaint newPaint(origPaint); |
| 599 | newPaint.setStyle(SkPaint::kFill_Style); |
| 600 | |
| 601 | SkScalar xtraLength = 0.0f; |
| 602 | if (SkPaint::kButt_Cap != origPaint.getStrokeCap()) { |
| 603 | xtraLength = halfWidth; |
| 604 | } |
| 605 | |
| 606 | SkPoint mid = points[0] + points[1]; |
| 607 | mid.scale(0.5f); |
| 608 | |
| 609 | SkRect rect = SkRect::MakeLTRB(mid.fX-halfWidth, mid.fY - 0.5f*length - xtraLength, |
| 610 | mid.fX+halfWidth, mid.fY + 0.5f*length + xtraLength); |
| 611 | SkMatrix m; |
| 612 | m.setSinCos(v.fX, -v.fY, mid.fX, mid.fY); |
| 613 | |
| 614 | SkMatrix local = m; |
| 615 | |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 616 | m.postConcat(this->ctm()); |
robertphillips | 0851d2d | 2016-06-02 05:21:34 -0700 | [diff] [blame] | 617 | |
| 618 | GrPaint grPaint; |
Brian Salomon | f3569f0 | 2017-10-24 12:52:33 -0400 | [diff] [blame] | 619 | if (!SkPaintToGrPaint(this->context(), fRenderTargetContext->colorSpaceInfo(), newPaint, m, |
| 620 | &grPaint)) { |
robertphillips | 0851d2d | 2016-06-02 05:21:34 -0700 | [diff] [blame] | 621 | return; |
| 622 | } |
| 623 | |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 624 | fRenderTargetContext->fillRectWithLocalMatrix( |
Chris Dalton | 3b51df1 | 2017-11-27 14:33:06 -0700 | [diff] [blame] | 625 | this->clip(), std::move(grPaint), GrAA(newPaint.isAntiAlias()), m, rect, local); |
robertphillips | 0851d2d | 2016-06-02 05:21:34 -0700 | [diff] [blame] | 626 | } |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 627 | |
Robert Phillips | 20390c3 | 2018-08-17 11:01:03 -0400 | [diff] [blame] | 628 | void SkGpuDevice::drawPath(const SkPath& origSrcPath, const SkPaint& paint, bool pathIsMutable) { |
joshualitt | ce89400 | 2016-01-11 13:29:31 -0800 | [diff] [blame] | 629 | ASSERT_SINGLE_OWNER |
Robert Phillips | 137ca52 | 2018-08-15 10:14:33 -0400 | [diff] [blame] | 630 | if (!origSrcPath.isInverseFillType() && !paint.getPathEffect()) { |
robertphillips | 0851d2d | 2016-06-02 05:21:34 -0700 | [diff] [blame] | 631 | SkPoint points[2]; |
| 632 | if (SkPaint::kStroke_Style == paint.getStyle() && paint.getStrokeWidth() > 0 && |
| 633 | !paint.getMaskFilter() && SkPaint::kRound_Cap != paint.getStrokeCap() && |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 634 | this->ctm().preservesRightAngles() && origSrcPath.isLine(points)) { |
robertphillips | 0851d2d | 2016-06-02 05:21:34 -0700 | [diff] [blame] | 635 | // Path-based stroking looks better for thin rects |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 636 | SkScalar strokeWidth = this->ctm().getMaxScale() * paint.getStrokeWidth(); |
robertphillips | f2204c9 | 2016-06-02 10:57:59 -0700 | [diff] [blame] | 637 | if (strokeWidth >= 1.0f) { |
Brian Salomon | 09d994e | 2016-12-21 11:14:46 -0500 | [diff] [blame] | 638 | // Round capping support is currently disabled b.c. it would require a RRect |
| 639 | // GrDrawOp that takes a localMatrix. |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 640 | this->drawStrokedLine(points, paint); |
robertphillips | 0851d2d | 2016-06-02 05:21:34 -0700 | [diff] [blame] | 641 | return; |
| 642 | } |
| 643 | } |
robertphillips | ff55b49 | 2015-11-24 07:56:59 -0800 | [diff] [blame] | 644 | } |
| 645 | |
Hal Canary | 144caf5 | 2016-11-07 17:57:18 -0500 | [diff] [blame] | 646 | GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawPath", fContext.get()); |
Robert Phillips | 137ca52 | 2018-08-15 10:14:33 -0400 | [diff] [blame] | 647 | if (!paint.getMaskFilter()) { |
Brian Salomon | a3cf365 | 2018-01-03 15:11:00 -0500 | [diff] [blame] | 648 | GrPaint grPaint; |
| 649 | if (!SkPaintToGrPaint(this->context(), fRenderTargetContext->colorSpaceInfo(), paint, |
| 650 | this->ctm(), &grPaint)) { |
| 651 | return; |
| 652 | } |
| 653 | fRenderTargetContext->drawPath(this->clip(), std::move(grPaint), GrAA(paint.isAntiAlias()), |
| 654 | this->ctm(), origSrcPath, GrStyle(paint)); |
| 655 | return; |
| 656 | } |
Robert Phillips | 27927a5 | 2018-08-20 13:18:12 -0400 | [diff] [blame] | 657 | |
| 658 | // TODO: losing possible mutability of 'origSrcPath' here |
| 659 | GrShape shape(origSrcPath, paint); |
| 660 | |
| 661 | GrBlurUtils::drawShapeWithMaskFilter(fContext.get(), fRenderTargetContext.get(), this->clip(), |
| 662 | paint, this->ctm(), shape); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 663 | } |
| 664 | |
| 665 | static const int kBmpSmallTileSize = 1 << 10; |
| 666 | |
| 667 | static inline int get_tile_count(const SkIRect& srcRect, int tileSize) { |
| 668 | int tilesX = (srcRect.fRight / tileSize) - (srcRect.fLeft / tileSize) + 1; |
| 669 | int tilesY = (srcRect.fBottom / tileSize) - (srcRect.fTop / tileSize) + 1; |
| 670 | return tilesX * tilesY; |
| 671 | } |
| 672 | |
reed | 85d9178 | 2015-09-10 14:33:38 -0700 | [diff] [blame] | 673 | static int determine_tile_size(const SkIRect& src, int maxTileSize) { |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 674 | if (maxTileSize <= kBmpSmallTileSize) { |
| 675 | return maxTileSize; |
| 676 | } |
| 677 | |
| 678 | size_t maxTileTotalTileSize = get_tile_count(src, maxTileSize); |
| 679 | size_t smallTotalTileSize = get_tile_count(src, kBmpSmallTileSize); |
| 680 | |
| 681 | maxTileTotalTileSize *= maxTileSize * maxTileSize; |
| 682 | smallTotalTileSize *= kBmpSmallTileSize * kBmpSmallTileSize; |
| 683 | |
| 684 | if (maxTileTotalTileSize > 2 * smallTotalTileSize) { |
| 685 | return kBmpSmallTileSize; |
| 686 | } else { |
| 687 | return maxTileSize; |
| 688 | } |
| 689 | } |
| 690 | |
| 691 | // Given a bitmap, an optional src rect, and a context with a clip and matrix determine what |
| 692 | // pixels from the bitmap are necessary. |
robertphillips | e576874 | 2016-05-13 11:20:46 -0700 | [diff] [blame] | 693 | static void determine_clipped_src_rect(int width, int height, |
joshualitt | 570d2f8 | 2015-02-25 13:19:48 -0800 | [diff] [blame] | 694 | const GrClip& clip, |
joshualitt | 5531d51 | 2014-12-17 15:50:11 -0800 | [diff] [blame] | 695 | const SkMatrix& viewMatrix, |
bsalomon | e553b64 | 2016-08-17 09:02:09 -0700 | [diff] [blame] | 696 | const SkMatrix& srcToDstRect, |
reed | 85d9178 | 2015-09-10 14:33:38 -0700 | [diff] [blame] | 697 | const SkISize& imageSize, |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 698 | const SkRect* srcRectPtr, |
| 699 | SkIRect* clippedSrcIRect) { |
robertphillips | e576874 | 2016-05-13 11:20:46 -0700 | [diff] [blame] | 700 | clip.getConservativeBounds(width, height, clippedSrcIRect, nullptr); |
bsalomon | e553b64 | 2016-08-17 09:02:09 -0700 | [diff] [blame] | 701 | SkMatrix inv = SkMatrix::Concat(viewMatrix, srcToDstRect); |
| 702 | if (!inv.invert(&inv)) { |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 703 | clippedSrcIRect->setEmpty(); |
| 704 | return; |
| 705 | } |
| 706 | SkRect clippedSrcRect = SkRect::Make(*clippedSrcIRect); |
| 707 | inv.mapRect(&clippedSrcRect); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 708 | if (srcRectPtr) { |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 709 | if (!clippedSrcRect.intersect(*srcRectPtr)) { |
| 710 | clippedSrcIRect->setEmpty(); |
| 711 | return; |
| 712 | } |
| 713 | } |
| 714 | clippedSrcRect.roundOut(clippedSrcIRect); |
reed | 85d9178 | 2015-09-10 14:33:38 -0700 | [diff] [blame] | 715 | SkIRect bmpBounds = SkIRect::MakeSize(imageSize); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 716 | if (!clippedSrcIRect->intersect(bmpBounds)) { |
| 717 | clippedSrcIRect->setEmpty(); |
| 718 | } |
| 719 | } |
| 720 | |
Robert Phillips | 920d488 | 2019-03-04 15:16:44 -0500 | [diff] [blame] | 721 | const GrCaps* SkGpuDevice::caps() const { |
| 722 | return fContext->priv().caps(); |
| 723 | } |
| 724 | |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 725 | bool SkGpuDevice::shouldTileImageID(uint32_t imageID, |
| 726 | const SkIRect& imageRect, |
reed | 85d9178 | 2015-09-10 14:33:38 -0700 | [diff] [blame] | 727 | const SkMatrix& viewMatrix, |
bsalomon | e553b64 | 2016-08-17 09:02:09 -0700 | [diff] [blame] | 728 | const SkMatrix& srcToDstRect, |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 729 | const GrSamplerState& params, |
reed | 85d9178 | 2015-09-10 14:33:38 -0700 | [diff] [blame] | 730 | const SkRect* srcRectPtr, |
| 731 | int maxTileSize, |
| 732 | int* tileSize, |
| 733 | SkIRect* clippedSubset) const { |
joshualitt | ce89400 | 2016-01-11 13:29:31 -0800 | [diff] [blame] | 734 | ASSERT_SINGLE_OWNER |
reed | 85d9178 | 2015-09-10 14:33:38 -0700 | [diff] [blame] | 735 | // if it's larger than the max tile size, then we have no choice but tiling. |
| 736 | if (imageRect.width() > maxTileSize || imageRect.height() > maxTileSize) { |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 737 | determine_clipped_src_rect(fRenderTargetContext->width(), fRenderTargetContext->height(), |
Brian Salomon | 0166cfd | 2017-03-13 17:58:25 -0400 | [diff] [blame] | 738 | this->clip(), viewMatrix, srcToDstRect, imageRect.size(), |
| 739 | srcRectPtr, clippedSubset); |
reed | 85d9178 | 2015-09-10 14:33:38 -0700 | [diff] [blame] | 740 | *tileSize = determine_tile_size(*clippedSubset, maxTileSize); |
| 741 | return true; |
| 742 | } |
| 743 | |
bsalomon | 1a1d0b8 | 2015-10-16 07:49:42 -0700 | [diff] [blame] | 744 | // 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] | 745 | const size_t area = imageRect.width() * imageRect.height(); |
| 746 | if (area < 4 * kBmpSmallTileSize * kBmpSmallTileSize) { |
| 747 | return false; |
| 748 | } |
| 749 | |
reed | 85d9178 | 2015-09-10 14:33:38 -0700 | [diff] [blame] | 750 | // At this point we know we could do the draw by uploading the entire bitmap |
| 751 | // as a texture. However, if the texture would be large compared to the |
| 752 | // cache size and we don't require most of it for this draw then tile to |
| 753 | // reduce the amount of upload and cache spill. |
| 754 | |
| 755 | // assumption here is that sw bitmap size is a good proxy for its size as |
| 756 | // a texture |
| 757 | size_t bmpSize = area * sizeof(SkPMColor); // assume 32bit pixels |
| 758 | size_t cacheSize; |
| 759 | fContext->getResourceCacheLimits(nullptr, &cacheSize); |
| 760 | if (bmpSize < cacheSize / 2) { |
| 761 | return false; |
| 762 | } |
| 763 | |
bsalomon | 1a1d0b8 | 2015-10-16 07:49:42 -0700 | [diff] [blame] | 764 | // Figure out how much of the src we will need based on the src rect and clipping. Reject if |
| 765 | // tiling memory savings would be < 50%. |
Brian Salomon | 0166cfd | 2017-03-13 17:58:25 -0400 | [diff] [blame] | 766 | determine_clipped_src_rect(fRenderTargetContext->width(), fRenderTargetContext->height(), |
| 767 | this->clip(), viewMatrix, srcToDstRect, imageRect.size(), srcRectPtr, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 768 | clippedSubset); |
reed | 85d9178 | 2015-09-10 14:33:38 -0700 | [diff] [blame] | 769 | *tileSize = kBmpSmallTileSize; // already know whole bitmap fits in one max sized tile. |
| 770 | size_t usedTileBytes = get_tile_count(*clippedSubset, kBmpSmallTileSize) * |
Brian Osman | d05cdc3 | 2017-02-06 13:24:47 -0500 | [diff] [blame] | 771 | kBmpSmallTileSize * kBmpSmallTileSize * |
| 772 | sizeof(SkPMColor); // assume 32bit pixels; |
reed | 85d9178 | 2015-09-10 14:33:38 -0700 | [diff] [blame] | 773 | |
Brian Osman | d05cdc3 | 2017-02-06 13:24:47 -0500 | [diff] [blame] | 774 | return usedTileBytes * 2 < bmpSize; |
reed | 85d9178 | 2015-09-10 14:33:38 -0700 | [diff] [blame] | 775 | } |
| 776 | |
reed | 85d9178 | 2015-09-10 14:33:38 -0700 | [diff] [blame] | 777 | bool SkGpuDevice::shouldTileImage(const SkImage* image, const SkRect* srcRectPtr, |
| 778 | SkCanvas::SrcRectConstraint constraint, SkFilterQuality quality, |
bsalomon | e553b64 | 2016-08-17 09:02:09 -0700 | [diff] [blame] | 779 | const SkMatrix& viewMatrix, |
| 780 | const SkMatrix& srcToDstRect) const { |
joshualitt | ce89400 | 2016-01-11 13:29:31 -0800 | [diff] [blame] | 781 | ASSERT_SINGLE_OWNER |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 782 | // If image is explicitly texture backed then we shouldn't get here. |
| 783 | SkASSERT(!image->isTextureBacked()); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 784 | |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 785 | GrSamplerState samplerState; |
reed | 85d9178 | 2015-09-10 14:33:38 -0700 | [diff] [blame] | 786 | bool doBicubic; |
Brian Osman | db78cba | 2018-02-15 10:09:48 -0500 | [diff] [blame] | 787 | GrSamplerState::Filter textureFilterMode = GrSkFilterQualityToGrFilterMode( |
Robert Phillips | c1541ae | 2019-02-04 12:05:37 -0500 | [diff] [blame] | 788 | quality, viewMatrix, srcToDstRect, |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 789 | fContext->priv().options().fSharpenMipmappedTextures, &doBicubic); |
reed | 85d9178 | 2015-09-10 14:33:38 -0700 | [diff] [blame] | 790 | |
| 791 | int tileFilterPad; |
| 792 | if (doBicubic) { |
| 793 | tileFilterPad = GrBicubicEffect::kFilterTexelPad; |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 794 | } else if (GrSamplerState::Filter::kNearest == textureFilterMode) { |
reed | 85d9178 | 2015-09-10 14:33:38 -0700 | [diff] [blame] | 795 | tileFilterPad = 0; |
| 796 | } else { |
| 797 | tileFilterPad = 1; |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 798 | } |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 799 | samplerState.setFilterMode(textureFilterMode); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 800 | |
Brian Salomon | c7fe0f7 | 2018-05-11 10:14:21 -0400 | [diff] [blame] | 801 | int maxTileSize = this->caps()->maxTileSize() - 2 * tileFilterPad; |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 802 | |
reed | 85d9178 | 2015-09-10 14:33:38 -0700 | [diff] [blame] | 803 | // these are output, which we safely ignore, as we just want to know the predicate |
| 804 | int outTileSize; |
| 805 | SkIRect outClippedSrcRect; |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 806 | |
bsalomon | e553b64 | 2016-08-17 09:02:09 -0700 | [diff] [blame] | 807 | return this->shouldTileImageID(image->unique(), image->bounds(), viewMatrix, srcToDstRect, |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 808 | samplerState, srcRectPtr, maxTileSize, &outTileSize, |
bsalomon | e553b64 | 2016-08-17 09:02:09 -0700 | [diff] [blame] | 809 | &outClippedSrcRect); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 810 | } |
| 811 | |
commit-bot@chromium.org | dec6150 | 2013-12-02 22:22:35 +0000 | [diff] [blame] | 812 | // 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] | 813 | // 'clamp'. 'offset' is adjusted to remain positioned over the top-left corner |
| 814 | // of 'iRect' for all possible outsets/clamps. |
commit-bot@chromium.org | dec6150 | 2013-12-02 22:22:35 +0000 | [diff] [blame] | 815 | static inline void clamped_outset_with_offset(SkIRect* iRect, |
| 816 | int outset, |
| 817 | SkPoint* offset, |
| 818 | const SkIRect& clamp) { |
| 819 | iRect->outset(outset, outset); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 820 | |
commit-bot@chromium.org | dec6150 | 2013-12-02 22:22:35 +0000 | [diff] [blame] | 821 | int leftClampDelta = clamp.fLeft - iRect->fLeft; |
| 822 | if (leftClampDelta > 0) { |
| 823 | offset->fX -= outset - leftClampDelta; |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 824 | iRect->fLeft = clamp.fLeft; |
| 825 | } else { |
commit-bot@chromium.org | dec6150 | 2013-12-02 22:22:35 +0000 | [diff] [blame] | 826 | offset->fX -= outset; |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 827 | } |
commit-bot@chromium.org | dec6150 | 2013-12-02 22:22:35 +0000 | [diff] [blame] | 828 | |
| 829 | int topClampDelta = clamp.fTop - iRect->fTop; |
| 830 | if (topClampDelta > 0) { |
| 831 | offset->fY -= outset - topClampDelta; |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 832 | iRect->fTop = clamp.fTop; |
| 833 | } else { |
commit-bot@chromium.org | dec6150 | 2013-12-02 22:22:35 +0000 | [diff] [blame] | 834 | offset->fY -= outset; |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 835 | } |
| 836 | |
| 837 | if (iRect->fRight > clamp.fRight) { |
| 838 | iRect->fRight = clamp.fRight; |
| 839 | } |
| 840 | if (iRect->fBottom > clamp.fBottom) { |
| 841 | iRect->fBottom = clamp.fBottom; |
| 842 | } |
| 843 | } |
| 844 | |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 845 | // Break 'bitmap' into several tiles to draw it since it has already |
| 846 | // been determined to be too large to fit in VRAM |
| 847 | void SkGpuDevice::drawTiledBitmap(const SkBitmap& bitmap, |
joshualitt | 5531d51 | 2014-12-17 15:50:11 -0800 | [diff] [blame] | 848 | const SkMatrix& viewMatrix, |
bsalomon | e553b64 | 2016-08-17 09:02:09 -0700 | [diff] [blame] | 849 | const SkMatrix& dstMatrix, |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 850 | const SkRect& srcRect, |
| 851 | const SkIRect& clippedSrcIRect, |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 852 | const GrSamplerState& params, |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 853 | const SkPaint& origPaint, |
reed | a5517e2 | 2015-07-14 10:54:12 -0700 | [diff] [blame] | 854 | SkCanvas::SrcRectConstraint constraint, |
commit-bot@chromium.org | dec6150 | 2013-12-02 22:22:35 +0000 | [diff] [blame] | 855 | int tileSize, |
| 856 | bool bicubic) { |
joshualitt | ce89400 | 2016-01-11 13:29:31 -0800 | [diff] [blame] | 857 | ASSERT_SINGLE_OWNER |
ericrk | 369e937 | 2016-02-05 15:32:36 -0800 | [diff] [blame] | 858 | |
ericrk | 983294f | 2016-04-18 09:14:00 -0700 | [diff] [blame] | 859 | // 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] | 860 | SK_HISTOGRAM_BOOLEAN("DrawTiled", true); |
Michael Ludwig | 3e2cc06 | 2019-02-19 12:11:40 -0500 | [diff] [blame] | 861 | LogDrawScaleFactor(viewMatrix, SkMatrix::I(), origPaint.getFilterQuality()); |
ericrk | 369e937 | 2016-02-05 15:32:36 -0800 | [diff] [blame] | 862 | |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 863 | const SkPaint* paint = &origPaint; |
| 864 | SkPaint tempPaint; |
Brian Salomon | 7c8460e | 2017-05-12 11:36:10 -0400 | [diff] [blame] | 865 | if (origPaint.isAntiAlias() && GrFSAAType::kUnifiedMSAA != fRenderTargetContext->fsaaType()) { |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 866 | // Drop antialiasing to avoid seams at tile boundaries. |
| 867 | tempPaint = origPaint; |
| 868 | tempPaint.setAntiAlias(false); |
| 869 | paint = &tempPaint; |
| 870 | } |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 871 | SkRect clippedSrcRect = SkRect::Make(clippedSrcIRect); |
| 872 | |
| 873 | int nx = bitmap.width() / tileSize; |
| 874 | int ny = bitmap.height() / tileSize; |
| 875 | for (int x = 0; x <= nx; x++) { |
| 876 | for (int y = 0; y <= ny; y++) { |
| 877 | SkRect tileR; |
| 878 | tileR.set(SkIntToScalar(x * tileSize), |
| 879 | SkIntToScalar(y * tileSize), |
| 880 | SkIntToScalar((x + 1) * tileSize), |
| 881 | SkIntToScalar((y + 1) * tileSize)); |
| 882 | |
| 883 | if (!SkRect::Intersects(tileR, clippedSrcRect)) { |
| 884 | continue; |
| 885 | } |
| 886 | |
| 887 | if (!tileR.intersect(srcRect)) { |
| 888 | continue; |
| 889 | } |
| 890 | |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 891 | SkIRect iTileR; |
| 892 | tileR.roundOut(&iTileR); |
bsalomon | e553b64 | 2016-08-17 09:02:09 -0700 | [diff] [blame] | 893 | SkVector offset = SkPoint::Make(SkIntToScalar(iTileR.fLeft), |
| 894 | SkIntToScalar(iTileR.fTop)); |
Brian Osman | a950a86 | 2017-02-06 16:48:57 -0500 | [diff] [blame] | 895 | SkRect rectToDraw = tileR; |
bsalomon | e553b64 | 2016-08-17 09:02:09 -0700 | [diff] [blame] | 896 | dstMatrix.mapRect(&rectToDraw); |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 897 | if (GrSamplerState::Filter::kNearest != params.filter() || bicubic) { |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 898 | SkIRect iClampRect; |
| 899 | |
reed | a5517e2 | 2015-07-14 10:54:12 -0700 | [diff] [blame] | 900 | if (SkCanvas::kFast_SrcRectConstraint == constraint) { |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 901 | // In bleed mode we want to always expand the tile on all edges |
| 902 | // but stay within the bitmap bounds |
| 903 | iClampRect = SkIRect::MakeWH(bitmap.width(), bitmap.height()); |
| 904 | } else { |
| 905 | // In texture-domain/clamp mode we only want to expand the |
| 906 | // tile on edges interior to "srcRect" (i.e., we want to |
| 907 | // not bleed across the original clamped edges) |
| 908 | srcRect.roundOut(&iClampRect); |
| 909 | } |
commit-bot@chromium.org | dec6150 | 2013-12-02 22:22:35 +0000 | [diff] [blame] | 910 | int outset = bicubic ? GrBicubicEffect::kFilterTexelPad : 1; |
| 911 | clamped_outset_with_offset(&iTileR, outset, &offset, iClampRect); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 912 | } |
| 913 | |
bsalomon | e553b64 | 2016-08-17 09:02:09 -0700 | [diff] [blame] | 914 | SkBitmap tmpB; |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 915 | if (bitmap.extractSubset(&tmpB, iTileR)) { |
| 916 | // now offset it to make it "local" to our tmp bitmap |
| 917 | tileR.offset(-offset.fX, -offset.fY); |
bsalomon | b1b0199 | 2015-11-18 10:56:08 -0800 | [diff] [blame] | 918 | // de-optimized this determination |
| 919 | bool needsTextureDomain = true; |
bsalomon | e553b64 | 2016-08-17 09:02:09 -0700 | [diff] [blame] | 920 | this->drawBitmapTile(tmpB, |
| 921 | viewMatrix, |
| 922 | rectToDraw, |
| 923 | tileR, |
Robert Phillips | e14d305 | 2017-02-15 13:18:21 -0500 | [diff] [blame] | 924 | params, |
bsalomon | e553b64 | 2016-08-17 09:02:09 -0700 | [diff] [blame] | 925 | *paint, |
| 926 | constraint, |
| 927 | bicubic, |
| 928 | needsTextureDomain); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 929 | } |
| 930 | } |
| 931 | } |
| 932 | } |
| 933 | |
bsalomon | e553b64 | 2016-08-17 09:02:09 -0700 | [diff] [blame] | 934 | void SkGpuDevice::drawBitmapTile(const SkBitmap& bitmap, |
| 935 | const SkMatrix& viewMatrix, |
| 936 | const SkRect& dstRect, |
| 937 | const SkRect& srcRect, |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 938 | const GrSamplerState& samplerState, |
bsalomon | e553b64 | 2016-08-17 09:02:09 -0700 | [diff] [blame] | 939 | const SkPaint& paint, |
| 940 | SkCanvas::SrcRectConstraint constraint, |
| 941 | bool bicubic, |
| 942 | bool needsTextureDomain) { |
bsalomon | 9c58654 | 2015-11-02 12:33:21 -0800 | [diff] [blame] | 943 | // We should have already handled bitmaps larger than the max texture size. |
Brian Salomon | c7fe0f7 | 2018-05-11 10:14:21 -0400 | [diff] [blame] | 944 | SkASSERT(bitmap.width() <= this->caps()->maxTextureSize() && |
| 945 | bitmap.height() <= this->caps()->maxTextureSize()); |
reed | c7ec7c9 | 2016-07-25 08:29:10 -0700 | [diff] [blame] | 946 | // We should be respecting the max tile size by the time we get here. |
Brian Salomon | c7fe0f7 | 2018-05-11 10:14:21 -0400 | [diff] [blame] | 947 | SkASSERT(bitmap.width() <= this->caps()->maxTileSize() && |
| 948 | bitmap.height() <= this->caps()->maxTileSize()); |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 949 | SkASSERT(!samplerState.isRepeated()); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 950 | |
Brian Salomon | 2a943df | 2018-05-04 13:43:19 -0400 | [diff] [blame] | 951 | SkScalar scales[2] = {1.f, 1.f}; |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 952 | sk_sp<GrTextureProxy> proxy = |
Brian Salomon | 2a943df | 2018-05-04 13:43:19 -0400 | [diff] [blame] | 953 | GrRefCachedBitmapTextureProxy(fContext.get(), bitmap, samplerState, scales); |
Robert Phillips | 7807580 | 2017-03-23 11:11:59 -0400 | [diff] [blame] | 954 | if (!proxy) { |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 955 | return; |
| 956 | } |
bsalomon | e553b64 | 2016-08-17 09:02:09 -0700 | [diff] [blame] | 957 | |
bsalomon | e553b64 | 2016-08-17 09:02:09 -0700 | [diff] [blame] | 958 | // Compute a matrix that maps the rect we will draw to the src rect. |
Brian Salomon | 2a943df | 2018-05-04 13:43:19 -0400 | [diff] [blame] | 959 | SkMatrix texMatrix = SkMatrix::MakeRectToRect(dstRect, srcRect, SkMatrix::kFill_ScaleToFit); |
| 960 | texMatrix.postScale(scales[0], scales[1]); |
joshualitt | 5f10b5c | 2015-07-09 10:24:35 -0700 | [diff] [blame] | 961 | |
| 962 | // Construct a GrPaint by setting the bitmap texture as the first effect and then configuring |
| 963 | // the rest from the SkPaint. |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 964 | std::unique_ptr<GrFragmentProcessor> fp; |
joshualitt | 5f10b5c | 2015-07-09 10:24:35 -0700 | [diff] [blame] | 965 | |
reed | a5517e2 | 2015-07-14 10:54:12 -0700 | [diff] [blame] | 966 | if (needsTextureDomain && (SkCanvas::kStrict_SrcRectConstraint == constraint)) { |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 967 | // Use a constrained texture domain to avoid color bleeding |
bsalomon | e553b64 | 2016-08-17 09:02:09 -0700 | [diff] [blame] | 968 | SkRect domain; |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 969 | if (srcRect.width() > SK_Scalar1) { |
Robert Phillips | e98234f | 2017-01-09 14:23:59 -0500 | [diff] [blame] | 970 | domain.fLeft = srcRect.fLeft + 0.5f; |
| 971 | domain.fRight = srcRect.fRight - 0.5f; |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 972 | } else { |
Robert Phillips | e98234f | 2017-01-09 14:23:59 -0500 | [diff] [blame] | 973 | domain.fLeft = domain.fRight = srcRect.centerX(); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 974 | } |
| 975 | if (srcRect.height() > SK_Scalar1) { |
Robert Phillips | e98234f | 2017-01-09 14:23:59 -0500 | [diff] [blame] | 976 | domain.fTop = srcRect.fTop + 0.5f; |
| 977 | domain.fBottom = srcRect.fBottom - 0.5f; |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 978 | } else { |
Robert Phillips | e98234f | 2017-01-09 14:23:59 -0500 | [diff] [blame] | 979 | domain.fTop = domain.fBottom = srcRect.centerY(); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 980 | } |
commit-bot@chromium.org | 7d7f314 | 2013-12-16 15:18:11 +0000 | [diff] [blame] | 981 | if (bicubic) { |
Brian Osman | e22dba8 | 2019-03-13 10:22:28 -0400 | [diff] [blame] | 982 | fp = GrBicubicEffect::Make(std::move(proxy), texMatrix, domain, bitmap.alphaType()); |
commit-bot@chromium.org | 7d7f314 | 2013-12-16 15:18:11 +0000 | [diff] [blame] | 983 | } else { |
Brian Osman | 2240be9 | 2017-10-18 13:15:13 -0400 | [diff] [blame] | 984 | fp = GrTextureDomainEffect::Make(std::move(proxy), texMatrix, domain, |
Brian Osman | 5e34167 | 2017-10-18 10:23:18 -0400 | [diff] [blame] | 985 | GrTextureDomain::kClamp_Mode, samplerState.filter()); |
commit-bot@chromium.org | 7d7f314 | 2013-12-16 15:18:11 +0000 | [diff] [blame] | 986 | } |
commit-bot@chromium.org | dec6150 | 2013-12-02 22:22:35 +0000 | [diff] [blame] | 987 | } else if (bicubic) { |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 988 | SkASSERT(GrSamplerState::Filter::kNearest == samplerState.filter()); |
| 989 | GrSamplerState::WrapMode wrapMode[2] = {samplerState.wrapModeX(), samplerState.wrapModeY()}; |
Brian Osman | e22dba8 | 2019-03-13 10:22:28 -0400 | [diff] [blame] | 990 | fp = GrBicubicEffect::Make(std::move(proxy), texMatrix, wrapMode, bitmap.alphaType()); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 991 | } else { |
Brian Osman | 2240be9 | 2017-10-18 13:15:13 -0400 | [diff] [blame] | 992 | fp = GrSimpleTextureEffect::Make(std::move(proxy), texMatrix, samplerState); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 993 | } |
| 994 | |
Brian Osman | 21fc5ce | 2018-08-27 20:36:19 +0000 | [diff] [blame] | 995 | fp = GrColorSpaceXformEffect::Make(std::move(fp), bitmap.colorSpace(), bitmap.alphaType(), |
Brian Salomon | f3569f0 | 2017-10-24 12:52:33 -0400 | [diff] [blame] | 996 | fRenderTargetContext->colorSpaceInfo().colorSpace()); |
joshualitt | 33a5fce | 2015-11-18 13:28:51 -0800 | [diff] [blame] | 997 | GrPaint grPaint; |
Brian Salomon | f3569f0 | 2017-10-24 12:52:33 -0400 | [diff] [blame] | 998 | if (!SkPaintToGrPaintWithTexture(this->context(), fRenderTargetContext->colorSpaceInfo(), paint, |
| 999 | viewMatrix, std::move(fp), |
| 1000 | kAlpha_8_SkColorType == bitmap.colorType(), &grPaint)) { |
bsalomon | bed83a6 | 2015-04-15 14:18:34 -0700 | [diff] [blame] | 1001 | return; |
| 1002 | } |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1003 | |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 1004 | // Coverage-based AA would cause seams between tiles. |
Chris Dalton | 3b51df1 | 2017-11-27 14:33:06 -0700 | [diff] [blame] | 1005 | GrAA aa = GrAA(paint.isAntiAlias() && |
| 1006 | GrFSAAType::kNone != fRenderTargetContext->fsaaType()); |
Brian Salomon | 0166cfd | 2017-03-13 17:58:25 -0400 | [diff] [blame] | 1007 | fRenderTargetContext->drawRect(this->clip(), std::move(grPaint), aa, viewMatrix, dstRect); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1008 | } |
| 1009 | |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 1010 | void SkGpuDevice::drawSprite(const SkBitmap& bitmap, |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1011 | int left, int top, const SkPaint& paint) { |
joshualitt | ce89400 | 2016-01-11 13:29:31 -0800 | [diff] [blame] | 1012 | ASSERT_SINGLE_OWNER |
Hal Canary | 144caf5 | 2016-11-07 17:57:18 -0500 | [diff] [blame] | 1013 | GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawSprite", fContext.get()); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1014 | |
Robert Phillips | 920d488 | 2019-03-04 15:16:44 -0500 | [diff] [blame] | 1015 | if (fContext->priv().abandoned()) { |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1016 | return; |
| 1017 | } |
| 1018 | |
Robert Phillips | e14d305 | 2017-02-15 13:18:21 -0500 | [diff] [blame] | 1019 | sk_sp<SkSpecialImage> srcImg = this->makeSpecial(bitmap); |
| 1020 | if (!srcImg) { |
| 1021 | return; |
joshualitt | 5f5a8d7 | 2015-02-25 14:09:45 -0800 | [diff] [blame] | 1022 | } |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1023 | |
Florin Malita | 53f77bd | 2017-04-28 13:48:37 -0400 | [diff] [blame] | 1024 | this->drawSpecial(srcImg.get(), left, top, paint, nullptr, SkMatrix::I()); |
robertphillips | 970587b | 2016-07-14 14:12:55 -0700 | [diff] [blame] | 1025 | } |
| 1026 | |
| 1027 | |
Robert Phillips | c100d48 | 2018-07-10 10:11:01 -0400 | [diff] [blame] | 1028 | void SkGpuDevice::drawSpecial(SkSpecialImage* special, int left, int top, const SkPaint& paint, |
Robert Phillips | 213ce18 | 2018-04-25 09:13:28 -0400 | [diff] [blame] | 1029 | SkImage* clipImage, const SkMatrix& clipMatrix) { |
robertphillips | 1b5f968 | 2016-07-15 08:01:12 -0700 | [diff] [blame] | 1030 | ASSERT_SINGLE_OWNER |
Hal Canary | 144caf5 | 2016-11-07 17:57:18 -0500 | [diff] [blame] | 1031 | GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawSpecial", fContext.get()); |
robertphillips | 970587b | 2016-07-14 14:12:55 -0700 | [diff] [blame] | 1032 | |
robertphillips | 970587b | 2016-07-14 14:12:55 -0700 | [diff] [blame] | 1033 | sk_sp<SkSpecialImage> result; |
| 1034 | if (paint.getImageFilter()) { |
Robert Phillips | c100d48 | 2018-07-10 10:11:01 -0400 | [diff] [blame] | 1035 | SkIPoint offset = { 0, 0 }; |
| 1036 | |
| 1037 | result = this->filterTexture(special, left, top, &offset, paint.getImageFilter()); |
robertphillips | 970587b | 2016-07-14 14:12:55 -0700 | [diff] [blame] | 1038 | if (!result) { |
| 1039 | return; |
| 1040 | } |
Robert Phillips | c100d48 | 2018-07-10 10:11:01 -0400 | [diff] [blame] | 1041 | |
| 1042 | left += offset.fX; |
| 1043 | top += offset.fY; |
robertphillips | 970587b | 2016-07-14 14:12:55 -0700 | [diff] [blame] | 1044 | } else { |
Robert Phillips | c100d48 | 2018-07-10 10:11:01 -0400 | [diff] [blame] | 1045 | result = sk_ref_sp(special); |
robertphillips | 970587b | 2016-07-14 14:12:55 -0700 | [diff] [blame] | 1046 | } |
| 1047 | |
| 1048 | SkASSERT(result->isTextureBacked()); |
Robert Phillips | 2c6d2bf | 2017-02-21 10:19:29 -0500 | [diff] [blame] | 1049 | sk_sp<GrTextureProxy> proxy = result->asTextureProxyRef(this->context()); |
Robert Phillips | 8e1c4e6 | 2017-02-19 12:27:01 -0500 | [diff] [blame] | 1050 | if (!proxy) { |
Robert Phillips | 833dcf4 | 2016-11-18 08:44:13 -0500 | [diff] [blame] | 1051 | return; |
| 1052 | } |
robertphillips | 970587b | 2016-07-14 14:12:55 -0700 | [diff] [blame] | 1053 | |
Robert Phillips | 8e1c4e6 | 2017-02-19 12:27:01 -0500 | [diff] [blame] | 1054 | const GrPixelConfig config = proxy->config(); |
| 1055 | |
Michael Ludwig | beb7cd2 | 2019-04-08 11:11:42 -0400 | [diff] [blame] | 1056 | SkMatrix ctm = this->ctm(); |
| 1057 | ctm.postTranslate(-SkIntToScalar(left), -SkIntToScalar(top)); |
| 1058 | |
robertphillips | 970587b | 2016-07-14 14:12:55 -0700 | [diff] [blame] | 1059 | SkPaint tmpUnfiltered(paint); |
Mike Reed | 2179b78 | 2018-02-07 11:59:57 -0500 | [diff] [blame] | 1060 | if (tmpUnfiltered.getMaskFilter()) { |
Florin Malita | c6c5ead | 2018-04-11 15:33:40 -0400 | [diff] [blame] | 1061 | tmpUnfiltered.setMaskFilter(tmpUnfiltered.getMaskFilter()->makeWithMatrix(ctm)); |
Mike Reed | 2179b78 | 2018-02-07 11:59:57 -0500 | [diff] [blame] | 1062 | } |
| 1063 | |
robertphillips | 970587b | 2016-07-14 14:12:55 -0700 | [diff] [blame] | 1064 | tmpUnfiltered.setImageFilter(nullptr); |
| 1065 | |
Brian Osman | 2240be9 | 2017-10-18 13:15:13 -0400 | [diff] [blame] | 1066 | auto fp = GrSimpleTextureEffect::Make(std::move(proxy), SkMatrix::I()); |
Brian Osman | 21fc5ce | 2018-08-27 20:36:19 +0000 | [diff] [blame] | 1067 | fp = GrColorSpaceXformEffect::Make(std::move(fp), result->getColorSpace(), result->alphaType(), |
Brian Salomon | f3569f0 | 2017-10-24 12:52:33 -0400 | [diff] [blame] | 1068 | fRenderTargetContext->colorSpaceInfo().colorSpace()); |
Robert Phillips | 8e1c4e6 | 2017-02-19 12:27:01 -0500 | [diff] [blame] | 1069 | if (GrPixelConfigIsAlphaOnly(config)) { |
Brian Salomon | 22af73f | 2017-01-26 11:25:12 -0500 | [diff] [blame] | 1070 | fp = GrFragmentProcessor::MakeInputPremulAndMulByOutput(std::move(fp)); |
bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 1071 | } else { |
Brian Salomon | c0d79e5 | 2019-04-10 15:02:11 -0400 | [diff] [blame] | 1072 | if (paint.getColor4f().isOpaque()) { |
| 1073 | fp = GrFragmentProcessor::OverrideInput(std::move(fp), SK_PMColor4fWHITE, false); |
| 1074 | } else { |
| 1075 | fp = GrFragmentProcessor::MulChildByInputAlpha(std::move(fp)); |
| 1076 | } |
bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 1077 | } |
Robert Phillips | 8e1c4e6 | 2017-02-19 12:27:01 -0500 | [diff] [blame] | 1078 | |
| 1079 | GrPaint grPaint; |
Brian Salomon | f3569f0 | 2017-10-24 12:52:33 -0400 | [diff] [blame] | 1080 | if (!SkPaintToGrPaintReplaceShader(this->context(), fRenderTargetContext->colorSpaceInfo(), |
| 1081 | tmpUnfiltered, std::move(fp), &grPaint)) { |
bsalomon | bed83a6 | 2015-04-15 14:18:34 -0700 | [diff] [blame] | 1082 | return; |
| 1083 | } |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1084 | |
robertphillips | 970587b | 2016-07-14 14:12:55 -0700 | [diff] [blame] | 1085 | const SkIRect& subset = result->subset(); |
Michael Ludwig | beb7cd2 | 2019-04-08 11:11:42 -0400 | [diff] [blame] | 1086 | SkRect dstRect = SkRect::Make(SkIRect::MakeXYWH(left, top, subset.width(), subset.height())); |
| 1087 | SkRect srcRect = SkRect::Make(subset); |
| 1088 | if (clipImage) { |
| 1089 | // Add the image as a simple texture effect applied to coverage. Accessing content outside |
| 1090 | // of the clip image should behave as if it were a decal (i.e. zero coverage). However, to |
| 1091 | // limit pixels touched and hardware checks, we draw the clip image geometry to get the |
| 1092 | // decal effect. |
| 1093 | GrSamplerState sampler = paint.getFilterQuality() > kNone_SkFilterQuality ? |
| 1094 | GrSamplerState::ClampBilerp() : GrSamplerState::ClampNearest(); |
| 1095 | sk_sp<GrTextureProxy> clipProxy = as_IB(clipImage)->asTextureProxyRef(this->context(), |
| 1096 | sampler, nullptr); |
| 1097 | // Fold clip matrix into ctm |
| 1098 | ctm.preConcat(clipMatrix); |
| 1099 | SkMatrix inverseClipMatrix; |
robertphillips | 970587b | 2016-07-14 14:12:55 -0700 | [diff] [blame] | 1100 | |
Michael Ludwig | beb7cd2 | 2019-04-08 11:11:42 -0400 | [diff] [blame] | 1101 | std::unique_ptr<GrFragmentProcessor> cfp; |
| 1102 | if (clipProxy && ctm.invert(&inverseClipMatrix)) { |
| 1103 | cfp = GrSimpleTextureEffect::Make(std::move(clipProxy), inverseClipMatrix, sampler); |
| 1104 | if (clipImage->colorType() != kAlpha_8_SkColorType) { |
| 1105 | cfp = GrFragmentProcessor::SwizzleOutput(std::move(cfp), GrSwizzle::AAAA()); |
| 1106 | } |
| 1107 | } |
| 1108 | |
| 1109 | if (cfp) { |
| 1110 | // If the grPaint already has coverage, this adds an additional stage that multiples |
| 1111 | // the image's alpha channel with the prior coverage. |
| 1112 | grPaint.addCoverageFragmentProcessor(std::move(cfp)); |
| 1113 | |
| 1114 | // Undo the offset that was needed for shader coord transforms to get the transform for |
| 1115 | // the actual drawn geometry. |
| 1116 | ctm.postTranslate(SkIntToScalar(left), SkIntToScalar(top)); |
| 1117 | inverseClipMatrix.preTranslate(-SkIntToScalar(left), -SkIntToScalar(top)); |
| 1118 | SkRect clipGeometry = SkRect::MakeWH(clipImage->width(), clipImage->height()); |
| 1119 | if (!clipGeometry.contains(inverseClipMatrix.mapRect(dstRect))) { |
| 1120 | // Draw the clip geometry since it is smaller, using dstRect as an extra scissor |
| 1121 | SkClipStack clip(this->cs()); |
| 1122 | clip.clipDevRect(SkIRect::MakeXYWH(left, top, subset.width(), subset.height()), |
| 1123 | SkClipOp::kIntersect); |
| 1124 | SkMatrix local = SkMatrix::Concat(SkMatrix::MakeRectToRect( |
| 1125 | dstRect, srcRect, SkMatrix::kFill_ScaleToFit), ctm); |
| 1126 | fRenderTargetContext->fillRectWithLocalMatrix(GrClipStackClip(&clip), |
| 1127 | std::move(grPaint), GrAA(paint.isAntiAlias()), ctm, clipGeometry, local); |
| 1128 | return; |
| 1129 | } |
| 1130 | // Else fall through and draw the subset since that is contained in the clip geometry |
| 1131 | } |
| 1132 | // Else some issue configuring the coverage FP, so just draw without the clip mask image |
| 1133 | } |
| 1134 | // Draw directly in screen space, possibly with an extra coverage processor |
| 1135 | fRenderTargetContext->fillRectToRect(this->clip(), std::move(grPaint), |
| 1136 | GrAA(paint.isAntiAlias()), SkMatrix::I(), dstRect, srcRect); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1137 | } |
| 1138 | |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 1139 | void SkGpuDevice::drawBitmapRect(const SkBitmap& bitmap, |
bsalomon | b1b0199 | 2015-11-18 10:56:08 -0800 | [diff] [blame] | 1140 | const SkRect* src, const SkRect& origDst, |
reed | 562fe47 | 2015-07-28 07:35:14 -0700 | [diff] [blame] | 1141 | const SkPaint& paint, SkCanvas::SrcRectConstraint constraint) { |
joshualitt | ce89400 | 2016-01-11 13:29:31 -0800 | [diff] [blame] | 1142 | ASSERT_SINGLE_OWNER |
bsalomon | b1b0199 | 2015-11-18 10:56:08 -0800 | [diff] [blame] | 1143 | // The src rect is inferred to be the bmp bounds if not provided. Otherwise, the src rect must |
| 1144 | // be clipped to the bmp bounds. To determine tiling parameters we need the filter mode which |
| 1145 | // in turn requires knowing the src-to-dst mapping. If the src was clipped to the bmp bounds |
| 1146 | // then we use the src-to-dst mapping to compute a new clipped dst rect. |
| 1147 | const SkRect* dst = &origDst; |
| 1148 | const SkRect bmpBounds = SkRect::MakeIWH(bitmap.width(), bitmap.height()); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1149 | // Compute matrix from the two rectangles |
bsalomon | b1b0199 | 2015-11-18 10:56:08 -0800 | [diff] [blame] | 1150 | if (!src) { |
| 1151 | src = &bmpBounds; |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1152 | } |
commit-bot@chromium.org | a7d89c8 | 2014-01-13 14:47:00 +0000 | [diff] [blame] | 1153 | |
bsalomon | b1b0199 | 2015-11-18 10:56:08 -0800 | [diff] [blame] | 1154 | SkMatrix srcToDstMatrix; |
| 1155 | if (!srcToDstMatrix.setRectToRect(*src, *dst, SkMatrix::kFill_ScaleToFit)) { |
| 1156 | return; |
| 1157 | } |
| 1158 | SkRect tmpSrc, tmpDst; |
| 1159 | if (src != &bmpBounds) { |
| 1160 | if (!bmpBounds.contains(*src)) { |
| 1161 | tmpSrc = *src; |
| 1162 | if (!tmpSrc.intersect(bmpBounds)) { |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1163 | return; // nothing to draw |
| 1164 | } |
bsalomon | b1b0199 | 2015-11-18 10:56:08 -0800 | [diff] [blame] | 1165 | src = &tmpSrc; |
| 1166 | srcToDstMatrix.mapRect(&tmpDst, *src); |
| 1167 | dst = &tmpDst; |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1168 | } |
| 1169 | } |
| 1170 | |
Brian Salomon | c7fe0f7 | 2018-05-11 10:14:21 -0400 | [diff] [blame] | 1171 | int maxTileSize = this->caps()->maxTileSize(); |
commit-bot@chromium.org | a7d89c8 | 2014-01-13 14:47:00 +0000 | [diff] [blame] | 1172 | |
bsalomon | b1b0199 | 2015-11-18 10:56:08 -0800 | [diff] [blame] | 1173 | // The tile code path doesn't currently support AA, so if the paint asked for aa and we could |
| 1174 | // draw untiled, then we bypass checking for tiling purely for optimization reasons. |
Brian Salomon | 7c8460e | 2017-05-12 11:36:10 -0400 | [diff] [blame] | 1175 | bool useCoverageAA = GrFSAAType::kUnifiedMSAA != fRenderTargetContext->fsaaType() && |
| 1176 | paint.isAntiAlias() && bitmap.width() <= maxTileSize && |
| 1177 | bitmap.height() <= maxTileSize; |
bsalomon | b1b0199 | 2015-11-18 10:56:08 -0800 | [diff] [blame] | 1178 | |
Brian Salomon | 7c8460e | 2017-05-12 11:36:10 -0400 | [diff] [blame] | 1179 | bool skipTileCheck = useCoverageAA || paint.getMaskFilter(); |
bsalomon | b1b0199 | 2015-11-18 10:56:08 -0800 | [diff] [blame] | 1180 | |
| 1181 | if (!skipTileCheck) { |
| 1182 | int tileSize; |
| 1183 | SkIRect clippedSrcRect; |
| 1184 | |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 1185 | GrSamplerState sampleState; |
bsalomon | b1b0199 | 2015-11-18 10:56:08 -0800 | [diff] [blame] | 1186 | bool doBicubic; |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 1187 | GrSamplerState::Filter textureFilterMode = GrSkFilterQualityToGrFilterMode( |
Brian Osman | db78cba | 2018-02-15 10:09:48 -0500 | [diff] [blame] | 1188 | paint.getFilterQuality(), this->ctm(), srcToDstMatrix, |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 1189 | fContext->priv().options().fSharpenMipmappedTextures, &doBicubic); |
bsalomon | b1b0199 | 2015-11-18 10:56:08 -0800 | [diff] [blame] | 1190 | |
| 1191 | int tileFilterPad; |
| 1192 | |
| 1193 | if (doBicubic) { |
| 1194 | tileFilterPad = GrBicubicEffect::kFilterTexelPad; |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 1195 | } else if (GrSamplerState::Filter::kNearest == textureFilterMode) { |
bsalomon | b1b0199 | 2015-11-18 10:56:08 -0800 | [diff] [blame] | 1196 | tileFilterPad = 0; |
| 1197 | } else { |
| 1198 | tileFilterPad = 1; |
| 1199 | } |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 1200 | sampleState.setFilterMode(textureFilterMode); |
bsalomon | b1b0199 | 2015-11-18 10:56:08 -0800 | [diff] [blame] | 1201 | |
Brian Salomon | c7fe0f7 | 2018-05-11 10:14:21 -0400 | [diff] [blame] | 1202 | int maxTileSizeForFilter = this->caps()->maxTileSize() - 2 * tileFilterPad; |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 1203 | if (this->shouldTileImageID(bitmap.getGenerationID(), bitmap.getSubset(), this->ctm(), |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 1204 | srcToDstMatrix, sampleState, src, maxTileSizeForFilter, |
| 1205 | &tileSize, &clippedSrcRect)) { |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 1206 | this->drawTiledBitmap(bitmap, this->ctm(), srcToDstMatrix, *src, clippedSrcRect, |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 1207 | sampleState, paint, constraint, tileSize, doBicubic); |
bsalomon | b1b0199 | 2015-11-18 10:56:08 -0800 | [diff] [blame] | 1208 | return; |
| 1209 | } |
commit-bot@chromium.org | a7d89c8 | 2014-01-13 14:47:00 +0000 | [diff] [blame] | 1210 | } |
Hal Canary | 144caf5 | 2016-11-07 17:57:18 -0500 | [diff] [blame] | 1211 | GrBitmapTextureMaker maker(fContext.get(), bitmap); |
Jim Van Verth | 30e0d7f | 2018-11-02 13:36:42 -0400 | [diff] [blame] | 1212 | this->drawTextureProducer(&maker, src, dst, constraint, this->ctm(), paint, true); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1213 | } |
| 1214 | |
robertphillips | 6451a0c | 2016-07-18 08:31:31 -0700 | [diff] [blame] | 1215 | sk_sp<SkSpecialImage> SkGpuDevice::makeSpecial(const SkBitmap& bitmap) { |
Robert Phillips | e14d305 | 2017-02-15 13:18:21 -0500 | [diff] [blame] | 1216 | // TODO: this makes a tight copy of 'bitmap' but it doesn't have to be (given SkSpecialImage's |
| 1217 | // semantics). Since this is cached we would have to bake the fit into the cache key though. |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 1218 | sk_sp<GrTextureProxy> proxy = GrMakeCachedBitmapProxy(fContext->priv().proxyProvider(), |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 1219 | bitmap); |
Robert Phillips | e14d305 | 2017-02-15 13:18:21 -0500 | [diff] [blame] | 1220 | if (!proxy) { |
robertphillips | 6451a0c | 2016-07-18 08:31:31 -0700 | [diff] [blame] | 1221 | return nullptr; |
| 1222 | } |
| 1223 | |
Robert Phillips | e14d305 | 2017-02-15 13:18:21 -0500 | [diff] [blame] | 1224 | const SkIRect rect = SkIRect::MakeWH(proxy->width(), proxy->height()); |
robertphillips | 6451a0c | 2016-07-18 08:31:31 -0700 | [diff] [blame] | 1225 | |
Robert Phillips | e14d305 | 2017-02-15 13:18:21 -0500 | [diff] [blame] | 1226 | // GrMakeCachedBitmapProxy creates a tight copy of 'bitmap' so we don't have to subset |
| 1227 | // the special image |
| 1228 | return SkSpecialImage::MakeDeferredFromGpu(fContext.get(), |
| 1229 | rect, |
| 1230 | bitmap.getGenerationID(), |
| 1231 | std::move(proxy), |
| 1232 | bitmap.refColorSpace(), |
| 1233 | &this->surfaceProps()); |
robertphillips | 6451a0c | 2016-07-18 08:31:31 -0700 | [diff] [blame] | 1234 | } |
| 1235 | |
reed | e51c356 | 2016-07-19 14:33:20 -0700 | [diff] [blame] | 1236 | sk_sp<SkSpecialImage> SkGpuDevice::makeSpecial(const SkImage* image) { |
robertphillips | 6451a0c | 2016-07-18 08:31:31 -0700 | [diff] [blame] | 1237 | SkPixmap pm; |
| 1238 | if (image->isTextureBacked()) { |
Robert Phillips | 6603a17 | 2019-03-05 12:35:44 -0500 | [diff] [blame] | 1239 | sk_sp<GrTextureProxy> proxy = as_IB(image)->asTextureProxyRef(this->context()); |
robertphillips | 6451a0c | 2016-07-18 08:31:31 -0700 | [diff] [blame] | 1240 | |
Robert Phillips | 6de9904 | 2017-01-31 11:31:39 -0500 | [diff] [blame] | 1241 | return SkSpecialImage::MakeDeferredFromGpu(fContext.get(), |
| 1242 | SkIRect::MakeWH(image->width(), image->height()), |
| 1243 | image->uniqueID(), |
| 1244 | std::move(proxy), |
Brian Salomon | 5ad6fd3 | 2019-03-21 15:30:08 -0400 | [diff] [blame] | 1245 | image->refColorSpace(), |
Robert Phillips | 6de9904 | 2017-01-31 11:31:39 -0500 | [diff] [blame] | 1246 | &this->surfaceProps()); |
robertphillips | 6451a0c | 2016-07-18 08:31:31 -0700 | [diff] [blame] | 1247 | } else if (image->peekPixels(&pm)) { |
| 1248 | SkBitmap bm; |
| 1249 | |
| 1250 | bm.installPixels(pm); |
| 1251 | return this->makeSpecial(bm); |
| 1252 | } else { |
| 1253 | return nullptr; |
| 1254 | } |
| 1255 | } |
| 1256 | |
| 1257 | sk_sp<SkSpecialImage> SkGpuDevice::snapSpecial() { |
Greg Daniel | be7fc46 | 2019-01-03 16:40:42 -0500 | [diff] [blame] | 1258 | // If we are wrapping a vulkan secondary command buffer, then we can't snap off a special image |
| 1259 | // since it would require us to make a copy of the underlying VkImage which we don't have access |
| 1260 | // to. Additionaly we can't stop and start the render pass that is used with the secondary |
| 1261 | // command buffer. |
| 1262 | if (this->accessRenderTargetContext()->wrapsVkSecondaryCB()) { |
| 1263 | return nullptr; |
| 1264 | } |
| 1265 | |
Robert Phillips | 63c6746 | 2017-02-15 14:19:01 -0500 | [diff] [blame] | 1266 | sk_sp<GrTextureProxy> proxy(this->accessRenderTargetContext()->asTextureProxyRef()); |
| 1267 | if (!proxy) { |
robertphillips | 04d6218 | 2016-07-15 12:21:33 -0700 | [diff] [blame] | 1268 | // When the device doesn't have a texture, we create a temporary texture. |
| 1269 | // TODO: we should actually only copy the portion of the source needed to apply the image |
| 1270 | // filter |
Robert Phillips | 63c6746 | 2017-02-15 14:19:01 -0500 | [diff] [blame] | 1271 | proxy = GrSurfaceProxy::Copy(fContext.get(), |
| 1272 | this->accessRenderTargetContext()->asSurfaceProxy(), |
Greg Daniel | 65c7f66 | 2017-10-30 13:39:09 -0400 | [diff] [blame] | 1273 | GrMipMapped::kNo, |
Brian Salomon | fee3f9b | 2018-12-19 12:34:12 -0500 | [diff] [blame] | 1274 | SkBackingFit::kApprox, |
Robert Phillips | 63c6746 | 2017-02-15 14:19:01 -0500 | [diff] [blame] | 1275 | SkBudgeted::kYes); |
| 1276 | if (!proxy) { |
robertphillips | 04d6218 | 2016-07-15 12:21:33 -0700 | [diff] [blame] | 1277 | return nullptr; |
| 1278 | } |
robertphillips | 1b5f968 | 2016-07-15 08:01:12 -0700 | [diff] [blame] | 1279 | } |
| 1280 | |
| 1281 | const SkImageInfo ii = this->imageInfo(); |
| 1282 | const SkIRect srcRect = SkIRect::MakeWH(ii.width(), ii.height()); |
| 1283 | |
Robert Phillips | e2f7d18 | 2016-12-15 09:23:05 -0500 | [diff] [blame] | 1284 | return SkSpecialImage::MakeDeferredFromGpu(fContext.get(), |
| 1285 | srcRect, |
| 1286 | kNeedNewImageUniqueID_SpecialImage, |
Robert Phillips | 63c6746 | 2017-02-15 14:19:01 -0500 | [diff] [blame] | 1287 | std::move(proxy), |
Robert Phillips | 70b49fd | 2017-01-13 11:21:36 -0500 | [diff] [blame] | 1288 | ii.refColorSpace(), |
Robert Phillips | e2f7d18 | 2016-12-15 09:23:05 -0500 | [diff] [blame] | 1289 | &this->surfaceProps()); |
robertphillips | 1b5f968 | 2016-07-15 08:01:12 -0700 | [diff] [blame] | 1290 | } |
| 1291 | |
Mike Reed | 148b7fd | 2018-12-18 17:38:18 -0500 | [diff] [blame] | 1292 | sk_sp<SkSpecialImage> SkGpuDevice::snapBackImage(const SkIRect& subset) { |
| 1293 | GrRenderTargetContext* rtc = this->accessRenderTargetContext(); |
Greg Daniel | be7fc46 | 2019-01-03 16:40:42 -0500 | [diff] [blame] | 1294 | |
| 1295 | // If we are wrapping a vulkan secondary command buffer, then we can't snap off a special image |
| 1296 | // since it would require us to make a copy of the underlying VkImage which we don't have access |
| 1297 | // to. Additionaly we can't stop and start the render pass that is used with the secondary |
| 1298 | // command buffer. |
| 1299 | if (rtc->wrapsVkSecondaryCB()) { |
Mike Reed | 148b7fd | 2018-12-18 17:38:18 -0500 | [diff] [blame] | 1300 | return nullptr; |
| 1301 | } |
| 1302 | |
Greg Daniel | be7fc46 | 2019-01-03 16:40:42 -0500 | [diff] [blame] | 1303 | |
Mike Reed | 148b7fd | 2018-12-18 17:38:18 -0500 | [diff] [blame] | 1304 | GrContext* ctx = this->context(); |
Greg Daniel | be7fc46 | 2019-01-03 16:40:42 -0500 | [diff] [blame] | 1305 | SkASSERT(rtc->asSurfaceProxy()); |
Mike Reed | 148b7fd | 2018-12-18 17:38:18 -0500 | [diff] [blame] | 1306 | |
Brian Salomon | fee3f9b | 2018-12-19 12:34:12 -0500 | [diff] [blame] | 1307 | auto srcProxy = |
| 1308 | GrSurfaceProxy::Copy(ctx, rtc->asSurfaceProxy(), rtc->mipMapped(), subset, |
| 1309 | SkBackingFit::kApprox, rtc->asSurfaceProxy()->isBudgeted()); |
Mike Reed | 148b7fd | 2018-12-18 17:38:18 -0500 | [diff] [blame] | 1310 | if (!srcProxy) { |
| 1311 | return nullptr; |
| 1312 | } |
| 1313 | |
| 1314 | // Note, can't move srcProxy since we also refer to this in the 2nd parameter |
| 1315 | return SkSpecialImage::MakeDeferredFromGpu(fContext.get(), |
| 1316 | SkIRect::MakeSize(srcProxy->isize()), |
| 1317 | kNeedNewImageUniqueID_SpecialImage, |
| 1318 | srcProxy, |
| 1319 | this->imageInfo().refColorSpace(), |
| 1320 | &this->surfaceProps()); |
| 1321 | } |
| 1322 | |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 1323 | void SkGpuDevice::drawDevice(SkBaseDevice* device, |
Mike Reed | 2179b78 | 2018-02-07 11:59:57 -0500 | [diff] [blame] | 1324 | int left, int top, const SkPaint& paint) { |
| 1325 | SkASSERT(!paint.getImageFilter()); |
reed | cf5c846 | 2016-07-20 12:28:40 -0700 | [diff] [blame] | 1326 | |
joshualitt | ce89400 | 2016-01-11 13:29:31 -0800 | [diff] [blame] | 1327 | ASSERT_SINGLE_OWNER |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1328 | // clear of the source device must occur before CHECK_SHOULD_DRAW |
Hal Canary | 144caf5 | 2016-11-07 17:57:18 -0500 | [diff] [blame] | 1329 | GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawDevice", fContext.get()); |
kkinnunen | 2e4414e | 2015-02-19 07:20:40 -0800 | [diff] [blame] | 1330 | |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1331 | // drawDevice is defined to be in device coords. |
robertphillips | 1b5f968 | 2016-07-15 08:01:12 -0700 | [diff] [blame] | 1332 | SkGpuDevice* dev = static_cast<SkGpuDevice*>(device); |
robertphillips | 6451a0c | 2016-07-18 08:31:31 -0700 | [diff] [blame] | 1333 | sk_sp<SkSpecialImage> srcImg(dev->snapSpecial()); |
robertphillips | 1b5f968 | 2016-07-15 08:01:12 -0700 | [diff] [blame] | 1334 | if (!srcImg) { |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1335 | return; |
| 1336 | } |
| 1337 | |
Mike Reed | 2179b78 | 2018-02-07 11:59:57 -0500 | [diff] [blame] | 1338 | this->drawSpecial(srcImg.get(), left, top, paint, nullptr, SkMatrix::I()); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1339 | } |
| 1340 | |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 1341 | void SkGpuDevice::drawImageRect(const SkImage* image, const SkRect* src, const SkRect& dst, |
| 1342 | const SkPaint& paint, SkCanvas::SrcRectConstraint constraint) { |
joshualitt | ce89400 | 2016-01-11 13:29:31 -0800 | [diff] [blame] | 1343 | ASSERT_SINGLE_OWNER |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 1344 | GrQuadAAFlags aaFlags = paint.isAntiAlias() ? GrQuadAAFlags::kAll : GrQuadAAFlags::kNone; |
Michael Ludwig | 7ae2ab5 | 2019-03-05 16:00:20 -0500 | [diff] [blame] | 1345 | this->drawImageQuad(image, src, &dst, nullptr, GrAA(paint.isAntiAlias()), aaFlags, nullptr, |
| 1346 | paint, constraint); |
bsalomon | 1cf6f9b | 2015-12-08 10:53:43 -0800 | [diff] [blame] | 1347 | } |
| 1348 | |
Leon Scroggins III | 57e1f02 | 2018-04-20 14:53:00 -0400 | [diff] [blame] | 1349 | // When drawing nine-patches or n-patches, cap the filter quality at kBilerp. |
| 1350 | static GrSamplerState::Filter compute_lattice_filter_mode(const SkPaint& paint) { |
| 1351 | if (paint.getFilterQuality() == kNone_SkFilterQuality) { |
| 1352 | return GrSamplerState::Filter::kNearest; |
| 1353 | } |
| 1354 | |
| 1355 | return GrSamplerState::Filter::kBilerp; |
| 1356 | } |
| 1357 | |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 1358 | void SkGpuDevice::drawImageNine(const SkImage* image, |
bsalomon | 2bbd0c6 | 2015-12-09 12:50:56 -0800 | [diff] [blame] | 1359 | const SkIRect& center, const SkRect& dst, const SkPaint& paint) { |
joshualitt | ce89400 | 2016-01-11 13:29:31 -0800 | [diff] [blame] | 1360 | ASSERT_SINGLE_OWNER |
reed | 2d5b714 | 2016-08-17 11:12:33 -0700 | [diff] [blame] | 1361 | uint32_t pinnedUniqueID; |
Brian Salomon | 2a943df | 2018-05-04 13:43:19 -0400 | [diff] [blame] | 1362 | auto iter = skstd::make_unique<SkLatticeIter>(image->width(), image->height(), center, dst); |
Robert Phillips | 6603a17 | 2019-03-05 12:35:44 -0500 | [diff] [blame] | 1363 | if (sk_sp<GrTextureProxy> proxy = as_IB(image)->refPinnedTextureProxy(this->context(), |
| 1364 | &pinnedUniqueID)) { |
Brian Salomon | 5ad6fd3 | 2019-03-21 15:30:08 -0400 | [diff] [blame] | 1365 | GrTextureAdjuster adjuster(this->context(), std::move(proxy), image->alphaType(), |
| 1366 | pinnedUniqueID, image->colorSpace()); |
Brian Salomon | 2a943df | 2018-05-04 13:43:19 -0400 | [diff] [blame] | 1367 | this->drawProducerLattice(&adjuster, std::move(iter), dst, paint); |
bsalomon | 2bbd0c6 | 2015-12-09 12:50:56 -0800 | [diff] [blame] | 1368 | } else { |
| 1369 | SkBitmap bm; |
Brian Osman | df7e075 | 2017-04-26 16:20:28 -0400 | [diff] [blame] | 1370 | if (image->isLazyGenerated()) { |
| 1371 | GrImageTextureMaker maker(fContext.get(), image, SkImage::kAllow_CachingHint); |
Brian Salomon | 2a943df | 2018-05-04 13:43:19 -0400 | [diff] [blame] | 1372 | this->drawProducerLattice(&maker, std::move(iter), dst, paint); |
Brian Osman | e50cdf0 | 2018-10-19 13:02:14 -0400 | [diff] [blame] | 1373 | } else if (as_IB(image)->getROPixels(&bm)) { |
Brian Salomon | 2a943df | 2018-05-04 13:43:19 -0400 | [diff] [blame] | 1374 | GrBitmapTextureMaker maker(fContext.get(), bm); |
| 1375 | this->drawProducerLattice(&maker, std::move(iter), dst, paint); |
bsalomon | 2bbd0c6 | 2015-12-09 12:50:56 -0800 | [diff] [blame] | 1376 | } |
| 1377 | } |
| 1378 | } |
| 1379 | |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 1380 | void SkGpuDevice::drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, |
bsalomon | 2bbd0c6 | 2015-12-09 12:50:56 -0800 | [diff] [blame] | 1381 | const SkRect& dst, const SkPaint& paint) { |
joshualitt | ce89400 | 2016-01-11 13:29:31 -0800 | [diff] [blame] | 1382 | ASSERT_SINGLE_OWNER |
Brian Salomon | 2a943df | 2018-05-04 13:43:19 -0400 | [diff] [blame] | 1383 | auto iter = skstd::make_unique<SkLatticeIter>(bitmap.width(), bitmap.height(), center, dst); |
Hal Canary | 144caf5 | 2016-11-07 17:57:18 -0500 | [diff] [blame] | 1384 | GrBitmapTextureMaker maker(fContext.get(), bitmap); |
Brian Salomon | 2a943df | 2018-05-04 13:43:19 -0400 | [diff] [blame] | 1385 | this->drawProducerLattice(&maker, std::move(iter), dst, paint); |
joshualitt | 33a5fce | 2015-11-18 13:28:51 -0800 | [diff] [blame] | 1386 | } |
| 1387 | |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 1388 | void SkGpuDevice::drawProducerLattice(GrTextureProducer* producer, |
Brian Salomon | 2a943df | 2018-05-04 13:43:19 -0400 | [diff] [blame] | 1389 | std::unique_ptr<SkLatticeIter> iter, const SkRect& dst, |
| 1390 | const SkPaint& origPaint) { |
Hal Canary | 144caf5 | 2016-11-07 17:57:18 -0500 | [diff] [blame] | 1391 | GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawProducerLattice", fContext.get()); |
Brian Salomon | 2a943df | 2018-05-04 13:43:19 -0400 | [diff] [blame] | 1392 | SkTCopyOnFirstWrite<SkPaint> paint(&origPaint); |
msarett | 10e3d9b | 2016-08-18 15:46:03 -0700 | [diff] [blame] | 1393 | |
Brian Salomon | 2a943df | 2018-05-04 13:43:19 -0400 | [diff] [blame] | 1394 | if (!producer->isAlphaOnly() && (paint->getColor() & 0x00FFFFFF) != 0x00FFFFFF) { |
| 1395 | paint.writable()->setColor(SkColorSetARGB(origPaint.getAlpha(), 0xFF, 0xFF, 0xFF)); |
| 1396 | } |
msarett | 10e3d9b | 2016-08-18 15:46:03 -0700 | [diff] [blame] | 1397 | GrPaint grPaint; |
Brian Salomon | 2a943df | 2018-05-04 13:43:19 -0400 | [diff] [blame] | 1398 | if (!SkPaintToGrPaintWithPrimitiveColor(this->context(), fRenderTargetContext->colorSpaceInfo(), |
| 1399 | *paint, &grPaint)) { |
msarett | 10e3d9b | 2016-08-18 15:46:03 -0700 | [diff] [blame] | 1400 | return; |
| 1401 | } |
| 1402 | |
Brian Salomon | 2a943df | 2018-05-04 13:43:19 -0400 | [diff] [blame] | 1403 | auto dstColorSpace = fRenderTargetContext->colorSpaceInfo().colorSpace(); |
| 1404 | const GrSamplerState::Filter filter = compute_lattice_filter_mode(*paint); |
Michael Ludwig | ddeed37 | 2019-02-20 16:50:10 -0500 | [diff] [blame] | 1405 | auto proxy = producer->refTextureProxyForParams(&filter, nullptr); |
Brian Salomon | a8daee8 | 2018-05-07 14:51:18 -0400 | [diff] [blame] | 1406 | if (!proxy) { |
| 1407 | return; |
| 1408 | } |
Brian Osman | 6064e1c | 2018-10-19 14:27:54 -0400 | [diff] [blame] | 1409 | auto csxf = GrColorSpaceXform::Make(producer->colorSpace(), producer->alphaType(), |
| 1410 | dstColorSpace, kPremul_SkAlphaType); |
Brian Salomon | 2a943df | 2018-05-04 13:43:19 -0400 | [diff] [blame] | 1411 | |
Brian Salomon | 0166cfd | 2017-03-13 17:58:25 -0400 | [diff] [blame] | 1412 | fRenderTargetContext->drawImageLattice(this->clip(), std::move(grPaint), this->ctm(), |
Brian Salomon | 2a943df | 2018-05-04 13:43:19 -0400 | [diff] [blame] | 1413 | std::move(proxy), std::move(csxf), filter, |
| 1414 | std::move(iter), dst); |
msarett | 10e3d9b | 2016-08-18 15:46:03 -0700 | [diff] [blame] | 1415 | } |
| 1416 | |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 1417 | void SkGpuDevice::drawImageLattice(const SkImage* image, |
msarett | 10e3d9b | 2016-08-18 15:46:03 -0700 | [diff] [blame] | 1418 | const SkCanvas::Lattice& lattice, const SkRect& dst, |
| 1419 | const SkPaint& paint) { |
| 1420 | ASSERT_SINGLE_OWNER |
| 1421 | uint32_t pinnedUniqueID; |
Brian Salomon | 2a943df | 2018-05-04 13:43:19 -0400 | [diff] [blame] | 1422 | auto iter = skstd::make_unique<SkLatticeIter>(lattice, dst); |
Robert Phillips | 6603a17 | 2019-03-05 12:35:44 -0500 | [diff] [blame] | 1423 | if (sk_sp<GrTextureProxy> proxy = as_IB(image)->refPinnedTextureProxy(this->context(), |
| 1424 | &pinnedUniqueID)) { |
Brian Salomon | 5ad6fd3 | 2019-03-21 15:30:08 -0400 | [diff] [blame] | 1425 | GrTextureAdjuster adjuster(this->context(), std::move(proxy), image->alphaType(), |
| 1426 | pinnedUniqueID, image->colorSpace()); |
Brian Salomon | 2a943df | 2018-05-04 13:43:19 -0400 | [diff] [blame] | 1427 | this->drawProducerLattice(&adjuster, std::move(iter), dst, paint); |
msarett | 10e3d9b | 2016-08-18 15:46:03 -0700 | [diff] [blame] | 1428 | } else { |
| 1429 | SkBitmap bm; |
Brian Osman | df7e075 | 2017-04-26 16:20:28 -0400 | [diff] [blame] | 1430 | if (image->isLazyGenerated()) { |
| 1431 | GrImageTextureMaker maker(fContext.get(), image, SkImage::kAllow_CachingHint); |
Brian Salomon | 2a943df | 2018-05-04 13:43:19 -0400 | [diff] [blame] | 1432 | this->drawProducerLattice(&maker, std::move(iter), dst, paint); |
Brian Osman | e50cdf0 | 2018-10-19 13:02:14 -0400 | [diff] [blame] | 1433 | } else if (as_IB(image)->getROPixels(&bm)) { |
Brian Salomon | 2a943df | 2018-05-04 13:43:19 -0400 | [diff] [blame] | 1434 | GrBitmapTextureMaker maker(fContext.get(), bm); |
| 1435 | this->drawProducerLattice(&maker, std::move(iter), dst, paint); |
msarett | 10e3d9b | 2016-08-18 15:46:03 -0700 | [diff] [blame] | 1436 | } |
| 1437 | } |
| 1438 | } |
| 1439 | |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 1440 | void SkGpuDevice::drawBitmapLattice(const SkBitmap& bitmap, |
msarett | 10e3d9b | 2016-08-18 15:46:03 -0700 | [diff] [blame] | 1441 | const SkCanvas::Lattice& lattice, const SkRect& dst, |
| 1442 | const SkPaint& paint) { |
| 1443 | ASSERT_SINGLE_OWNER |
Brian Salomon | 2a943df | 2018-05-04 13:43:19 -0400 | [diff] [blame] | 1444 | auto iter = skstd::make_unique<SkLatticeIter>(lattice, dst); |
Hal Canary | 144caf5 | 2016-11-07 17:57:18 -0500 | [diff] [blame] | 1445 | GrBitmapTextureMaker maker(fContext.get(), bitmap); |
Brian Salomon | 2a943df | 2018-05-04 13:43:19 -0400 | [diff] [blame] | 1446 | this->drawProducerLattice(&maker, std::move(iter), dst, paint); |
msarett | 10e3d9b | 2016-08-18 15:46:03 -0700 | [diff] [blame] | 1447 | } |
| 1448 | |
Brian Salomon | f3569f0 | 2017-10-24 12:52:33 -0400 | [diff] [blame] | 1449 | static bool init_vertices_paint(GrContext* context, const GrColorSpaceInfo& colorSpaceInfo, |
| 1450 | const SkPaint& skPaint, const SkMatrix& matrix, SkBlendMode bmode, |
Robert Phillips | 26c90e0 | 2017-03-14 14:39:29 -0400 | [diff] [blame] | 1451 | bool hasTexs, bool hasColors, GrPaint* grPaint) { |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 1452 | if (hasTexs && skPaint.getShader()) { |
| 1453 | if (hasColors) { |
| 1454 | // When there are texs and colors the shader and colors are combined using bmode. |
Brian Salomon | f3569f0 | 2017-10-24 12:52:33 -0400 | [diff] [blame] | 1455 | return SkPaintToGrPaintWithXfermode(context, colorSpaceInfo, skPaint, matrix, bmode, |
| 1456 | grPaint); |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 1457 | } else { |
| 1458 | // We have a shader, but no colors to blend it against. |
Brian Salomon | f3569f0 | 2017-10-24 12:52:33 -0400 | [diff] [blame] | 1459 | return SkPaintToGrPaint(context, colorSpaceInfo, skPaint, matrix, grPaint); |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 1460 | } |
| 1461 | } else { |
| 1462 | if (hasColors) { |
| 1463 | // We have colors, but either have no shader or no texture coords (which implies that |
| 1464 | // we should ignore the shader). |
Brian Salomon | f3569f0 | 2017-10-24 12:52:33 -0400 | [diff] [blame] | 1465 | return SkPaintToGrPaintWithPrimitiveColor(context, colorSpaceInfo, skPaint, grPaint); |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 1466 | } else { |
| 1467 | // No colors and no shaders. Just draw with the paint color. |
Brian Salomon | f3569f0 | 2017-10-24 12:52:33 -0400 | [diff] [blame] | 1468 | return SkPaintToGrPaintNoShader(context, colorSpaceInfo, skPaint, grPaint); |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 1469 | } |
| 1470 | } |
| 1471 | } |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1472 | |
Mike Reed | 887cdf1 | 2017-04-03 11:11:09 -0400 | [diff] [blame] | 1473 | void SkGpuDevice::wireframeVertices(SkVertices::VertexMode vmode, int vertexCount, |
Ruiqi Mao | 4ec72f7 | 2018-07-10 17:21:07 -0400 | [diff] [blame] | 1474 | const SkPoint vertices[], |
Ruiqi Mao | c97a339 | 2018-08-15 10:44:19 -0400 | [diff] [blame] | 1475 | const SkVertices::Bone bones[], int boneCount, |
Ruiqi Mao | 4ec72f7 | 2018-07-10 17:21:07 -0400 | [diff] [blame] | 1476 | SkBlendMode bmode, |
Mike Reed | 2f6b5a4 | 2017-03-19 15:04:17 -0400 | [diff] [blame] | 1477 | const uint16_t indices[], int indexCount, |
| 1478 | const SkPaint& paint) { |
joshualitt | ce89400 | 2016-01-11 13:29:31 -0800 | [diff] [blame] | 1479 | ASSERT_SINGLE_OWNER |
Mike Reed | 2f6b5a4 | 2017-03-19 15:04:17 -0400 | [diff] [blame] | 1480 | GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "wireframeVertices", fContext.get()); |
mtklein | 533eb78 | 2014-08-27 10:39:42 -0700 | [diff] [blame] | 1481 | |
Mike Reed | 2f6b5a4 | 2017-03-19 15:04:17 -0400 | [diff] [blame] | 1482 | SkPaint copy(paint); |
| 1483 | copy.setStyle(SkPaint::kStroke_Style); |
| 1484 | copy.setStrokeWidth(0); |
mtklein | 533eb78 | 2014-08-27 10:39:42 -0700 | [diff] [blame] | 1485 | |
Mike Reed | 2f6b5a4 | 2017-03-19 15:04:17 -0400 | [diff] [blame] | 1486 | GrPaint grPaint; |
| 1487 | // we ignore the shader since we have no texture coordinates. |
Brian Salomon | f3569f0 | 2017-10-24 12:52:33 -0400 | [diff] [blame] | 1488 | if (!SkPaintToGrPaintNoShader(this->context(), fRenderTargetContext->colorSpaceInfo(), copy, |
| 1489 | &grPaint)) { |
bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 1490 | return; |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1491 | } |
| 1492 | |
Mike Reed | 2f6b5a4 | 2017-03-19 15:04:17 -0400 | [diff] [blame] | 1493 | int triangleCount = 0; |
| 1494 | int n = (nullptr == indices) ? vertexCount : indexCount; |
| 1495 | switch (vmode) { |
Mike Reed | 887cdf1 | 2017-04-03 11:11:09 -0400 | [diff] [blame] | 1496 | case SkVertices::kTriangles_VertexMode: |
Mike Reed | 2f6b5a4 | 2017-03-19 15:04:17 -0400 | [diff] [blame] | 1497 | triangleCount = n / 3; |
| 1498 | break; |
Mike Reed | 887cdf1 | 2017-04-03 11:11:09 -0400 | [diff] [blame] | 1499 | case SkVertices::kTriangleStrip_VertexMode: |
Mike Reed | 2f6b5a4 | 2017-03-19 15:04:17 -0400 | [diff] [blame] | 1500 | triangleCount = n - 2; |
| 1501 | break; |
Brian Salomon | cccafe8 | 2018-04-28 16:13:08 -0400 | [diff] [blame] | 1502 | case SkVertices::kTriangleFan_VertexMode: |
| 1503 | SK_ABORT("Unexpected triangle fan."); |
| 1504 | break; |
Mike Reed | 2f6b5a4 | 2017-03-19 15:04:17 -0400 | [diff] [blame] | 1505 | } |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1506 | |
Mike Reed | 2f6b5a4 | 2017-03-19 15:04:17 -0400 | [diff] [blame] | 1507 | VertState state(vertexCount, indices, indexCount); |
| 1508 | VertState::Proc vertProc = state.chooseProc(vmode); |
| 1509 | |
| 1510 | //number of indices for lines per triangle with kLines |
| 1511 | indexCount = triangleCount * 6; |
| 1512 | |
Brian Osman | ae0c50c | 2017-05-25 16:56:34 -0400 | [diff] [blame] | 1513 | static constexpr SkVertices::VertexMode kIgnoredMode = SkVertices::kTriangles_VertexMode; |
| 1514 | SkVertices::Builder builder(kIgnoredMode, vertexCount, indexCount, 0); |
| 1515 | memcpy(builder.positions(), vertices, vertexCount * sizeof(SkPoint)); |
| 1516 | |
| 1517 | uint16_t* lineIndices = builder.indices(); |
Mike Reed | 2f6b5a4 | 2017-03-19 15:04:17 -0400 | [diff] [blame] | 1518 | int i = 0; |
| 1519 | while (vertProc(&state)) { |
| 1520 | lineIndices[i] = state.f0; |
| 1521 | lineIndices[i + 1] = state.f1; |
| 1522 | lineIndices[i + 2] = state.f1; |
| 1523 | lineIndices[i + 3] = state.f2; |
| 1524 | lineIndices[i + 4] = state.f2; |
| 1525 | lineIndices[i + 5] = state.f0; |
| 1526 | i += 6; |
bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 1527 | } |
Brian Osman | ae0c50c | 2017-05-25 16:56:34 -0400 | [diff] [blame] | 1528 | |
Chris Dalton | 3809bab | 2017-06-13 10:55:06 -0600 | [diff] [blame] | 1529 | GrPrimitiveType primitiveType = GrPrimitiveType::kLines; |
Brian Salomon | 0166cfd | 2017-03-13 17:58:25 -0400 | [diff] [blame] | 1530 | fRenderTargetContext->drawVertices(this->clip(), |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1531 | std::move(grPaint), |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 1532 | this->ctm(), |
Brian Osman | ae0c50c | 2017-05-25 16:56:34 -0400 | [diff] [blame] | 1533 | builder.detach(), |
Ruiqi Mao | 4ec72f7 | 2018-07-10 17:21:07 -0400 | [diff] [blame] | 1534 | bones, |
| 1535 | boneCount, |
Brian Osman | ae0c50c | 2017-05-25 16:56:34 -0400 | [diff] [blame] | 1536 | &primitiveType); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1537 | } |
| 1538 | |
Ruiqi Mao | c97a339 | 2018-08-15 10:44:19 -0400 | [diff] [blame] | 1539 | void SkGpuDevice::drawVertices(const SkVertices* vertices, const SkVertices::Bone bones[], |
| 1540 | int boneCount, SkBlendMode mode, const SkPaint& paint) { |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 1541 | ASSERT_SINGLE_OWNER |
Mike Reed | 2f6b5a4 | 2017-03-19 15:04:17 -0400 | [diff] [blame] | 1542 | GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawVertices", fContext.get()); |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 1543 | |
| 1544 | SkASSERT(vertices); |
| 1545 | GrPaint grPaint; |
Mike Reed | 5fa6645 | 2017-03-16 09:06:34 -0400 | [diff] [blame] | 1546 | bool hasColors = vertices->hasColors(); |
| 1547 | bool hasTexs = vertices->hasTexCoords(); |
Brian Osman | 0b403f8 | 2017-05-26 10:39:51 -0400 | [diff] [blame] | 1548 | if ((!hasTexs || !paint.getShader()) && !hasColors) { |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 1549 | // The dreaded wireframe mode. Fallback to drawVertices and go so slooooooow. |
Mike Reed | 2f6b5a4 | 2017-03-19 15:04:17 -0400 | [diff] [blame] | 1550 | this->wireframeVertices(vertices->mode(), vertices->vertexCount(), vertices->positions(), |
Ruiqi Mao | 4ec72f7 | 2018-07-10 17:21:07 -0400 | [diff] [blame] | 1551 | bones, boneCount, mode, vertices->indices(), vertices->indexCount(), |
| 1552 | paint); |
Brian Osman | 0b403f8 | 2017-05-26 10:39:51 -0400 | [diff] [blame] | 1553 | return; |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 1554 | } |
Brian Salomon | f3569f0 | 2017-10-24 12:52:33 -0400 | [diff] [blame] | 1555 | if (!init_vertices_paint(fContext.get(), fRenderTargetContext->colorSpaceInfo(), paint, |
| 1556 | this->ctm(), mode, hasTexs, hasColors, &grPaint)) { |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 1557 | return; |
| 1558 | } |
Brian Salomon | 0166cfd | 2017-03-13 17:58:25 -0400 | [diff] [blame] | 1559 | fRenderTargetContext->drawVertices(this->clip(), std::move(grPaint), this->ctm(), |
Ruiqi Mao | 4ec72f7 | 2018-07-10 17:21:07 -0400 | [diff] [blame] | 1560 | sk_ref_sp(const_cast<SkVertices*>(vertices)), |
| 1561 | bones, boneCount); |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 1562 | } |
| 1563 | |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1564 | /////////////////////////////////////////////////////////////////////////////// |
| 1565 | |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1566 | void SkGpuDevice::drawShadow(const SkPath& path, const SkDrawShadowRec& rec) { |
| 1567 | |
| 1568 | ASSERT_SINGLE_OWNER |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1569 | GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawShadow", fContext.get()); |
| 1570 | |
Jim Van Verth | b1b80f7 | 2018-01-18 15:19:13 -0500 | [diff] [blame] | 1571 | if (!fRenderTargetContext->drawFastShadow(this->clip(), this->ctm(), path, rec)) { |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1572 | // failed to find an accelerated case |
| 1573 | this->INHERITED::drawShadow(path, rec); |
| 1574 | } |
| 1575 | } |
| 1576 | |
| 1577 | /////////////////////////////////////////////////////////////////////////////// |
| 1578 | |
Brian Osman | 4d92b89 | 2019-03-24 00:53:23 +0000 | [diff] [blame] | 1579 | void SkGpuDevice::drawAtlas(const SkImage* atlas, const SkRSXform xform[], |
| 1580 | const SkRect texRect[], const SkColor colors[], int count, |
| 1581 | SkBlendMode mode, const SkPaint& paint) { |
| 1582 | ASSERT_SINGLE_OWNER |
Brian Osman | ddba4e6 | 2019-03-25 09:52:17 -0400 | [diff] [blame] | 1583 | GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawAtlas", fContext.get()); |
Brian Osman | 4d92b89 | 2019-03-24 00:53:23 +0000 | [diff] [blame] | 1584 | |
| 1585 | SkPaint p(paint); |
| 1586 | p.setShader(atlas->makeShader()); |
| 1587 | |
| 1588 | GrPaint grPaint; |
| 1589 | if (colors) { |
| 1590 | if (!SkPaintToGrPaintWithXfermode(this->context(), fRenderTargetContext->colorSpaceInfo(), |
| 1591 | p, this->ctm(), (SkBlendMode)mode, &grPaint)) { |
| 1592 | return; |
| 1593 | } |
| 1594 | } else { |
| 1595 | if (!SkPaintToGrPaint(this->context(), fRenderTargetContext->colorSpaceInfo(), p, |
| 1596 | this->ctm(), &grPaint)) { |
| 1597 | return; |
| 1598 | } |
| 1599 | } |
| 1600 | |
| 1601 | fRenderTargetContext->drawAtlas( |
| 1602 | this->clip(), std::move(grPaint), this->ctm(), count, xform, texRect, colors); |
| 1603 | } |
| 1604 | |
| 1605 | /////////////////////////////////////////////////////////////////////////////// |
| 1606 | |
Herb Derby | b935cf8 | 2018-07-26 16:54:18 -0400 | [diff] [blame] | 1607 | void SkGpuDevice::drawGlyphRunList(const SkGlyphRunList& glyphRunList) { |
Herb Derby | b983e6b | 2018-07-13 13:26:29 -0400 | [diff] [blame] | 1608 | ASSERT_SINGLE_OWNER |
| 1609 | GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawGlyphRunList", fContext.get()); |
Herb Derby | b983e6b | 2018-07-13 13:26:29 -0400 | [diff] [blame] | 1610 | |
Jim Van Verth | 87a3011 | 2018-09-24 16:13:58 -0400 | [diff] [blame] | 1611 | // Check for valid input |
| 1612 | const SkMatrix& ctm = this->ctm(); |
Mike Reed | 96345a2 | 2019-01-02 21:30:29 -0500 | [diff] [blame] | 1613 | if (!ctm.isFinite() || !glyphRunList.allFontsFinite()) { |
Jim Van Verth | 87a3011 | 2018-09-24 16:13:58 -0400 | [diff] [blame] | 1614 | return; |
| 1615 | } |
| 1616 | |
| 1617 | fRenderTargetContext->drawGlyphRunList(this->clip(), ctm, glyphRunList); |
Herb Derby | b983e6b | 2018-07-13 13:26:29 -0400 | [diff] [blame] | 1618 | } |
| 1619 | |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1620 | /////////////////////////////////////////////////////////////////////////////// |
| 1621 | |
Greg Daniel | 9ed1a2c | 2018-10-18 12:43:25 -0400 | [diff] [blame] | 1622 | void SkGpuDevice::drawDrawable(SkDrawable* drawable, const SkMatrix* matrix, SkCanvas* canvas) { |
Robert Phillips | 4217ea7 | 2019-01-30 13:08:28 -0500 | [diff] [blame] | 1623 | GrBackendApi api = this->context()->backend(); |
Greg Daniel | 9ed1a2c | 2018-10-18 12:43:25 -0400 | [diff] [blame] | 1624 | if (GrBackendApi::kVulkan == api) { |
| 1625 | const SkMatrix& ctm = canvas->getTotalMatrix(); |
| 1626 | const SkMatrix& combinedMatrix = matrix ? SkMatrix::Concat(ctm, *matrix) : ctm; |
| 1627 | std::unique_ptr<SkDrawable::GpuDrawHandler> gpuDraw = |
Derek Sollenberger | e6fb76b | 2019-01-10 13:19:06 -0500 | [diff] [blame] | 1628 | drawable->snapGpuDrawHandler(api, combinedMatrix, canvas->getDeviceClipBounds(), |
| 1629 | this->imageInfo()); |
Greg Daniel | 9ed1a2c | 2018-10-18 12:43:25 -0400 | [diff] [blame] | 1630 | if (gpuDraw) { |
Greg Daniel | 64cc9aa | 2018-10-19 13:54:56 -0400 | [diff] [blame] | 1631 | fRenderTargetContext->drawDrawable(std::move(gpuDraw), drawable->getBounds()); |
| 1632 | return; |
Greg Daniel | 9ed1a2c | 2018-10-18 12:43:25 -0400 | [diff] [blame] | 1633 | } |
| 1634 | } |
| 1635 | this->INHERITED::drawDrawable(drawable, matrix, canvas); |
| 1636 | } |
| 1637 | |
Greg Daniel | 64cc9aa | 2018-10-19 13:54:56 -0400 | [diff] [blame] | 1638 | |
Greg Daniel | 9ed1a2c | 2018-10-18 12:43:25 -0400 | [diff] [blame] | 1639 | /////////////////////////////////////////////////////////////////////////////// |
| 1640 | |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1641 | void SkGpuDevice::flush() { |
Greg Daniel | e6bfb7d | 2019-04-17 15:26:11 -0400 | [diff] [blame] | 1642 | this->flush(SkSurface::BackendSurfaceAccess::kNoAccess, GrFlushInfo()); |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 1643 | } |
| 1644 | |
Greg Daniel | e6bfb7d | 2019-04-17 15:26:11 -0400 | [diff] [blame] | 1645 | GrSemaphoresSubmitted SkGpuDevice::flush(SkSurface::BackendSurfaceAccess access, |
| 1646 | const GrFlushInfo& info) { |
joshualitt | ce89400 | 2016-01-11 13:29:31 -0800 | [diff] [blame] | 1647 | ASSERT_SINGLE_OWNER |
joshualitt | bc90735 | 2016-01-13 06:45:40 -0800 | [diff] [blame] | 1648 | |
Greg Daniel | e6bfb7d | 2019-04-17 15:26:11 -0400 | [diff] [blame] | 1649 | return fRenderTargetContext->flush(access, info); |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 1650 | } |
| 1651 | |
Greg Daniel | c64ee46 | 2017-06-15 16:59:49 -0400 | [diff] [blame] | 1652 | bool SkGpuDevice::wait(int numSemaphores, const GrBackendSemaphore* waitSemaphores) { |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 1653 | ASSERT_SINGLE_OWNER |
| 1654 | |
Greg Daniel | c64ee46 | 2017-06-15 16:59:49 -0400 | [diff] [blame] | 1655 | return fRenderTargetContext->waitOnSemaphores(numSemaphores, waitSemaphores); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1656 | } |
| 1657 | |
| 1658 | /////////////////////////////////////////////////////////////////////////////// |
| 1659 | |
reed | 76033be | 2015-03-14 10:54:31 -0700 | [diff] [blame] | 1660 | SkBaseDevice* SkGpuDevice::onCreateDevice(const CreateInfo& cinfo, const SkPaint*) { |
joshualitt | ce89400 | 2016-01-11 13:29:31 -0800 | [diff] [blame] | 1661 | ASSERT_SINGLE_OWNER |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1662 | |
robertphillips | ca6eafc | 2016-05-17 09:57:46 -0700 | [diff] [blame] | 1663 | SkSurfaceProps props(this->surfaceProps().flags(), cinfo.fPixelGeometry); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1664 | |
robertphillips | ca6eafc | 2016-05-17 09:57:46 -0700 | [diff] [blame] | 1665 | // layers are never drawn in repeat modes, so we can request an approx |
hcm | 4396fa5 | 2014-10-27 21:43:30 -0700 | [diff] [blame] | 1666 | // match and ignore any padding. |
robertphillips | ca6eafc | 2016-05-17 09:57:46 -0700 | [diff] [blame] | 1667 | SkBackingFit fit = kNever_TileUsage == cinfo.fTileUsage ? SkBackingFit::kApprox |
| 1668 | : SkBackingFit::kExact; |
bsalomon | afe3005 | 2015-01-16 07:32:33 -0800 | [diff] [blame] | 1669 | |
Brian Osman | 10fc6fd | 2018-03-02 11:01:10 -0500 | [diff] [blame] | 1670 | GrPixelConfig config = fRenderTargetContext->colorSpaceInfo().config(); |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 1671 | const GrBackendFormat& origFormat = fRenderTargetContext->asSurfaceProxy()->backendFormat(); |
| 1672 | GrBackendFormat format = origFormat.makeTexture2D(); |
| 1673 | if (!format.isValid()) { |
| 1674 | return nullptr; |
| 1675 | } |
Brian Osman | 10fc6fd | 2018-03-02 11:01:10 -0500 | [diff] [blame] | 1676 | if (kRGBA_1010102_GrPixelConfig == config) { |
| 1677 | // If the original device is 1010102, fall back to 8888 so that we have a usable alpha |
| 1678 | // channel in the layer. |
| 1679 | config = kRGBA_8888_GrPixelConfig; |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 1680 | format = |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 1681 | fContext->priv().caps()->getBackendFormatFromColorType(kRGBA_8888_SkColorType); |
Brian Osman | 10fc6fd | 2018-03-02 11:01:10 -0500 | [diff] [blame] | 1682 | } |
| 1683 | |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 1684 | sk_sp<GrRenderTargetContext> rtc(fContext->priv().makeDeferredRenderTargetContext( |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 1685 | format, fit, cinfo.fInfo.width(), cinfo.fInfo.height(), config, |
Brian Salomon | f3569f0 | 2017-10-24 12:52:33 -0400 | [diff] [blame] | 1686 | fRenderTargetContext->colorSpaceInfo().refColorSpace(), |
Greg Daniel | 45d6303 | 2017-10-30 13:41:26 -0400 | [diff] [blame] | 1687 | fRenderTargetContext->numStencilSamples(), GrMipMapped::kNo, |
| 1688 | kBottomLeft_GrSurfaceOrigin, &props)); |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1689 | if (!rtc) { |
Mike Klein | e54c75f | 2016-10-13 14:18:09 -0400 | [diff] [blame] | 1690 | return nullptr; |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1691 | } |
robertphillips | ca6eafc | 2016-05-17 09:57:46 -0700 | [diff] [blame] | 1692 | |
| 1693 | // Skia's convention is to only clear a device if it is non-opaque. |
| 1694 | InitContents init = cinfo.fInfo.isOpaque() ? kUninit_InitContents : kClear_InitContents; |
| 1695 | |
Robert Phillips | 9fab7e9 | 2016-11-17 12:45:04 -0500 | [diff] [blame] | 1696 | return SkGpuDevice::Make(fContext.get(), std::move(rtc), |
| 1697 | cinfo.fInfo.width(), cinfo.fInfo.height(), init).release(); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1698 | } |
| 1699 | |
reed | e8f3062 | 2016-03-23 18:59:25 -0700 | [diff] [blame] | 1700 | sk_sp<SkSurface> SkGpuDevice::makeSurface(const SkImageInfo& info, const SkSurfaceProps& props) { |
joshualitt | ce89400 | 2016-01-11 13:29:31 -0800 | [diff] [blame] | 1701 | ASSERT_SINGLE_OWNER |
bsalomon | afe3005 | 2015-01-16 07:32:33 -0800 | [diff] [blame] | 1702 | // TODO: Change the signature of newSurface to take a budgeted parameter. |
bsalomon | 5ec26ae | 2016-02-25 08:33:02 -0800 | [diff] [blame] | 1703 | static const SkBudgeted kBudgeted = SkBudgeted::kNo; |
Hal Canary | 144caf5 | 2016-11-07 17:57:18 -0500 | [diff] [blame] | 1704 | return SkSurface::MakeRenderTarget(fContext.get(), kBudgeted, info, |
Brian Salomon | 50e66d4 | 2017-05-15 16:28:07 -0400 | [diff] [blame] | 1705 | fRenderTargetContext->numStencilSamples(), |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1706 | fRenderTargetContext->origin(), &props); |
reed@google.com | 76f10a3 | 2014-02-05 15:32:21 +0000 | [diff] [blame] | 1707 | } |
| 1708 | |
senorblanco | 900c367 | 2016-04-27 11:31:23 -0700 | [diff] [blame] | 1709 | SkImageFilterCache* SkGpuDevice::getImageFilterCache() { |
joshualitt | ce89400 | 2016-01-11 13:29:31 -0800 | [diff] [blame] | 1710 | ASSERT_SINGLE_OWNER |
senorblanco | 55b6d8b | 2014-07-30 11:26:46 -0700 | [diff] [blame] | 1711 | // We always return a transient cache, so it is freed after each |
| 1712 | // filter traversal. |
brianosman | 04a44d0 | 2016-09-21 09:46:57 -0700 | [diff] [blame] | 1713 | return SkImageFilterCache::Create(SkImageFilterCache::kDefaultTransientSize); |
senorblanco | 55b6d8b | 2014-07-30 11:26:46 -0700 | [diff] [blame] | 1714 | } |
reed | f037e0b | 2014-10-30 11:34:15 -0700 | [diff] [blame] | 1715 | |