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