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" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 34 | #include "src/gpu/GrBitmapTextureMaker.h" |
| 35 | #include "src/gpu/GrBlurUtils.h" |
| 36 | #include "src/gpu/GrContextPriv.h" |
| 37 | #include "src/gpu/GrGpu.h" |
Brian Salomon | f2ebdd9 | 2019-09-30 12:15:30 -0400 | [diff] [blame] | 38 | #include "src/gpu/GrImageInfo.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 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 | |
Brian Salomon | 4bc0c1f | 2019-09-30 15:12:27 -0400 | [diff] [blame] | 90 | SkColorType ct = GrColorTypeToSkColorType(renderTargetContext->colorInfo().colorType()); |
Robert Phillips | d470e1b | 2019-09-04 15:05:35 -0400 | [diff] [blame] | 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 | 4bc0c1f | 2019-09-30 15:12:27 -0400 | [diff] [blame] | 120 | SkColorType colorType = GrColorTypeToSkColorType(context->colorInfo().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 | 4bc0c1f | 2019-09-30 15:12:27 -0400 | [diff] [blame] | 123 | context->colorInfo().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 | |
Michael Ludwig | c89d1b5 | 2019-10-18 11:32:56 -0400 | [diff] [blame] | 165 | SkMatrix matrix = this->localToDevice(); |
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 | 4bc0c1f | 2019-09-30 15:12:27 -0400 | [diff] [blame] | 169 | SkColorType colorType = GrColorTypeToSkColorType(fRenderTargetContext->colorInfo().colorType()); |
Brian Salomon | bd3d8d3 | 2019-07-02 09:16:28 -0400 | [diff] [blame] | 170 | if (colorType == kUnknown_SkColorType) { |
| 171 | colorType = kRGBA_8888_SkColorType; |
Brian Osman | a50205f | 2018-07-06 13:57:01 -0400 | [diff] [blame] | 172 | } |
Michael Ludwig | 03f9ca3 | 2019-08-14 14:35:15 -0400 | [diff] [blame] | 173 | SkImageFilter_Base::Context ctx(matrix, clipBounds, cache.get(), colorType, |
Brian Salomon | 4bc0c1f | 2019-09-30 15:12:27 -0400 | [diff] [blame] | 174 | fRenderTargetContext->colorInfo().colorSpace(), srcImg); |
robertphillips | 970587b | 2016-07-14 14:12:55 -0700 | [diff] [blame] | 175 | |
Michael Ludwig | ea07123 | 2019-08-26 10:52:15 -0400 | [diff] [blame] | 176 | return as_IFB(filter)->filterImage(ctx).imageAndOffset(offset); |
robertphillips | 970587b | 2016-07-14 14:12:55 -0700 | [diff] [blame] | 177 | } |
| 178 | |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 179 | /////////////////////////////////////////////////////////////////////////////// |
| 180 | |
Mike Reed | 353196f | 2017-07-21 11:01:18 -0400 | [diff] [blame] | 181 | bool SkGpuDevice::onReadPixels(const SkPixmap& pm, int x, int y) { |
joshualitt | ce89400 | 2016-01-11 13:29:31 -0800 | [diff] [blame] | 182 | ASSERT_SINGLE_OWNER |
commit-bot@chromium.org | a713f9c | 2014-03-17 21:31:26 +0000 | [diff] [blame] | 183 | |
Mike Reed | 353196f | 2017-07-21 11:01:18 -0400 | [diff] [blame] | 184 | if (!SkImageInfoValidConversion(pm.info(), this->imageInfo())) { |
Matt Sarett | cb6266b | 2017-01-17 10:48:53 -0500 | [diff] [blame] | 185 | return false; |
| 186 | } |
| 187 | |
Brian Salomon | 1d43530 | 2019-07-01 13:05:28 -0400 | [diff] [blame] | 188 | 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] | 189 | } |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 190 | |
Mike Reed | 353196f | 2017-07-21 11:01:18 -0400 | [diff] [blame] | 191 | bool SkGpuDevice::onWritePixels(const SkPixmap& pm, int x, int y) { |
joshualitt | ce89400 | 2016-01-11 13:29:31 -0800 | [diff] [blame] | 192 | ASSERT_SINGLE_OWNER |
robertphillips | 1da3ecd | 2016-08-31 14:54:15 -0700 | [diff] [blame] | 193 | |
Mike Reed | 353196f | 2017-07-21 11:01:18 -0400 | [diff] [blame] | 194 | if (!SkImageInfoValidConversion(this->imageInfo(), pm.info())) { |
Matt Sarett | cb6266b | 2017-01-17 10:48:53 -0500 | [diff] [blame] | 195 | return false; |
| 196 | } |
| 197 | |
Brian Salomon | 1d43530 | 2019-07-01 13:05:28 -0400 | [diff] [blame] | 198 | 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] | 199 | } |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 200 | |
reed | 41e010c | 2015-06-09 12:16:53 -0700 | [diff] [blame] | 201 | bool SkGpuDevice::onAccessPixels(SkPixmap* pmap) { |
joshualitt | ce89400 | 2016-01-11 13:29:31 -0800 | [diff] [blame] | 202 | ASSERT_SINGLE_OWNER |
reed | 41e010c | 2015-06-09 12:16:53 -0700 | [diff] [blame] | 203 | return false; |
| 204 | } |
| 205 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 206 | GrRenderTargetContext* SkGpuDevice::accessRenderTargetContext() { |
robertphillips | 175dd9b | 2016-04-28 14:32:04 -0700 | [diff] [blame] | 207 | ASSERT_SINGLE_OWNER |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 208 | return fRenderTargetContext.get(); |
robertphillips | 175dd9b | 2016-04-28 14:32:04 -0700 | [diff] [blame] | 209 | } |
| 210 | |
reed | 8eddfb5 | 2014-12-04 07:50:14 -0800 | [diff] [blame] | 211 | void SkGpuDevice::clearAll() { |
joshualitt | ce89400 | 2016-01-11 13:29:31 -0800 | [diff] [blame] | 212 | ASSERT_SINGLE_OWNER |
Hal Canary | 144caf5 | 2016-11-07 17:57:18 -0500 | [diff] [blame] | 213 | GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "clearAll", fContext.get()); |
Robert Phillips | 784b7bf | 2016-12-09 13:35:02 -0500 | [diff] [blame] | 214 | |
reed | 8eddfb5 | 2014-12-04 07:50:14 -0800 | [diff] [blame] | 215 | SkIRect rect = SkIRect::MakeWH(this->width(), this->height()); |
Brian Osman | 9a9baae | 2018-11-05 15:06:26 -0500 | [diff] [blame] | 216 | fRenderTargetContext->clear(&rect, SK_PMColor4fTRANSPARENT, |
| 217 | GrRenderTargetContext::CanClearFullscreen::kYes); |
reed | 8eddfb5 | 2014-12-04 07:50:14 -0800 | [diff] [blame] | 218 | } |
| 219 | |
Brian Salomon | bf6b979 | 2019-08-21 09:38:10 -0400 | [diff] [blame] | 220 | void SkGpuDevice::replaceRenderTargetContext(std::unique_ptr<GrRenderTargetContext> rtc, |
Brian Salomon | aad8315 | 2019-05-24 10:16:35 -0400 | [diff] [blame] | 221 | bool shouldRetainContent) { |
| 222 | SkASSERT(rtc->width() == this->width()); |
| 223 | SkASSERT(rtc->height() == this->height()); |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 224 | SkASSERT(rtc->numSamples() == fRenderTargetContext->numSamples()); |
Brian Salomon | aad8315 | 2019-05-24 10:16:35 -0400 | [diff] [blame] | 225 | SkASSERT(rtc->asSurfaceProxy()->priv().isExact()); |
| 226 | if (shouldRetainContent) { |
| 227 | if (this->context()->abandoned()) { |
| 228 | return; |
| 229 | } |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame] | 230 | |
| 231 | SkASSERT(fRenderTargetContext->asTextureProxy()); |
| 232 | SkAssertResult(rtc->blitTexture(fRenderTargetContext->asTextureProxy(), |
Brian Salomon | 078e8fa | 2019-11-22 04:10:18 +0000 | [diff] [blame^] | 233 | fRenderTargetContext->colorInfo().colorType(), |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame] | 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; |
Michael Ludwig | c89d1b5 | 2019-10-18 11:32:56 -0400 | [diff] [blame] | 268 | if (!SkPaintToGrPaint(this->context(), fRenderTargetContext->colorInfo(), paint, |
| 269 | this->localToDevice(), &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 | |
Michael Ludwig | c89d1b5 | 2019-10-18 11:32:56 -0400 | [diff] [blame] | 273 | fRenderTargetContext->drawPaint(this->clip(), std::move(grPaint), this->localToDevice()); |
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 | 4bc0c1f | 2019-09-30 15:12:27 -0400 | [diff] [blame] | 300 | if (!SkPaintToGrPaint(this->context(), fRenderTargetContext->colorInfo(), paint, |
Michael Ludwig | c89d1b5 | 2019-10-18 11:32:56 -0400 | [diff] [blame] | 301 | this->localToDevice(), &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()), |
Michael Ludwig | c89d1b5 | 2019-10-18 11:32:56 -0400 | [diff] [blame] | 309 | this->localToDevice(), 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]; |
Michael Ludwig | c89d1b5 | 2019-10-18 11:32:56 -0400 | [diff] [blame] | 314 | bool isHairline = (0 == width) || |
| 315 | (1 == width && this->localToDevice().getMinMaxScales(scales) && |
| 316 | SkScalarNearlyEqual(scales[0], 1.f) && 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); |
Michael Ludwig | c89d1b5 | 2019-10-18 11:32:56 -0400 | [diff] [blame] | 323 | draw.fMatrix = &this->localToDevice(); |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 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 | |
Michael Ludwig | c89d1b5 | 2019-10-18 11:32:56 -0400 | [diff] [blame] | 331 | const SkMatrix* viewMatrix = &this->localToDevice(); |
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 | 4bc0c1f | 2019-09-30 15:12:27 -0400 | [diff] [blame] | 345 | if (!SkPaintToGrPaint(this->context(), fRenderTargetContext->colorInfo(), paint, *viewMatrix, |
| 346 | &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(), |
Michael Ludwig | c89d1b5 | 2019-10-18 11:32:56 -0400 | [diff] [blame] | 371 | this->clip(), paint, this->localToDevice(), shape); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 372 | return; |
| 373 | } |
| 374 | |
| 375 | GrPaint grPaint; |
Michael Ludwig | c89d1b5 | 2019-10-18 11:32:56 -0400 | [diff] [blame] | 376 | if (!SkPaintToGrPaint(this->context(), fRenderTargetContext->colorInfo(), paint, |
| 377 | this->localToDevice(), &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()), |
Michael Ludwig | c89d1b5 | 2019-10-18 11:32:56 -0400 | [diff] [blame] | 382 | this->localToDevice(), 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 | |
Brian Salomon | 4bc0c1f | 2019-09-30 15:12:27 -0400 | [diff] [blame] | 391 | SkPMColor4f dstColor = SkColor4fPrepForDst(color, fRenderTargetContext->colorInfo()).premul(); |
Michael Ludwig | 7545190 | 2019-01-23 11:14:29 -0500 | [diff] [blame] | 392 | |
| 393 | GrPaint grPaint; |
| 394 | grPaint.setColor4f(dstColor); |
| 395 | if (mode != SkBlendMode::kSrcOver) { |
| 396 | grPaint.setXPFactory(SkBlendMode_AsXPFactory(mode)); |
| 397 | } |
| 398 | |
Michael Ludwig | 136f45a | 2019-02-19 11:44:41 -0500 | [diff] [blame] | 399 | // 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] | 400 | GrQuadAAFlags grAA = SkToGrQuadAAFlags(aaFlags); |
Michael Ludwig | 390f0cc | 2019-03-19 09:16:38 -0400 | [diff] [blame] | 401 | if (clip) { |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 402 | // Use fillQuadWithEdgeAA |
| 403 | fRenderTargetContext->fillQuadWithEdgeAA(this->clip(), std::move(grPaint), GrAA::kYes, grAA, |
Michael Ludwig | c89d1b5 | 2019-10-18 11:32:56 -0400 | [diff] [blame] | 404 | this->localToDevice(), clip, nullptr); |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 405 | } else { |
| 406 | // Use fillRectWithEdgeAA to preserve mathematical properties of dst being rectangular |
| 407 | fRenderTargetContext->fillRectWithEdgeAA(this->clip(), std::move(grPaint), GrAA::kYes, grAA, |
Michael Ludwig | c89d1b5 | 2019-10-18 11:32:56 -0400 | [diff] [blame] | 408 | this->localToDevice(), rect); |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 409 | } |
Michael Ludwig | 7545190 | 2019-01-23 11:14:29 -0500 | [diff] [blame] | 410 | } |
| 411 | |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 412 | /////////////////////////////////////////////////////////////////////////////// |
| 413 | |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 414 | void SkGpuDevice::drawRRect(const SkRRect& rrect, const SkPaint& paint) { |
joshualitt | ce89400 | 2016-01-11 13:29:31 -0800 | [diff] [blame] | 415 | ASSERT_SINGLE_OWNER |
Hal Canary | 144caf5 | 2016-11-07 17:57:18 -0500 | [diff] [blame] | 416 | GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawRRect", fContext.get()); |
Robert Phillips | 27927a5 | 2018-08-20 13:18:12 -0400 | [diff] [blame] | 417 | |
Mike Reed | 80747ef | 2018-01-23 15:29:32 -0500 | [diff] [blame] | 418 | SkMaskFilterBase* mf = as_MFB(paint.getMaskFilter()); |
Mike Reed | bfadcf0 | 2018-01-20 22:24:21 +0000 | [diff] [blame] | 419 | if (mf) { |
| 420 | if (mf->hasFragmentProcessor()) { |
| 421 | mf = nullptr; // already handled in SkPaintToGrPaint |
| 422 | } |
Robert Phillips | a29a956 | 2016-10-20 09:40:55 -0400 | [diff] [blame] | 423 | } |
| 424 | |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 425 | GrStyle style(paint); |
commit-bot@chromium.org | 8213970 | 2014-03-10 22:53:20 +0000 | [diff] [blame] | 426 | |
Robert Phillips | a29a956 | 2016-10-20 09:40:55 -0400 | [diff] [blame] | 427 | if (mf || style.pathEffect()) { |
robertphillips | ff55b49 | 2015-11-24 07:56:59 -0800 | [diff] [blame] | 428 | // A path effect will presumably transform this rrect into something else. |
Robert Phillips | 27927a5 | 2018-08-20 13:18:12 -0400 | [diff] [blame] | 429 | GrShape shape(rrect, style); |
| 430 | |
Robert Phillips | 27927a5 | 2018-08-20 13:18:12 -0400 | [diff] [blame] | 431 | GrBlurUtils::drawShapeWithMaskFilter(fContext.get(), fRenderTargetContext.get(), |
Michael Ludwig | c89d1b5 | 2019-10-18 11:32:56 -0400 | [diff] [blame] | 432 | this->clip(), paint, this->localToDevice(), shape); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 433 | return; |
| 434 | } |
Mike Klein | 744fb73 | 2014-06-23 15:13:26 -0400 | [diff] [blame] | 435 | |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 436 | SkASSERT(!style.pathEffect()); |
robertphillips | 514450c | 2015-11-24 05:36:02 -0800 | [diff] [blame] | 437 | |
Robert Phillips | a522d66 | 2018-08-23 13:50:16 -0400 | [diff] [blame] | 438 | GrPaint grPaint; |
Michael Ludwig | c89d1b5 | 2019-10-18 11:32:56 -0400 | [diff] [blame] | 439 | if (!SkPaintToGrPaint(this->context(), fRenderTargetContext->colorInfo(), paint, |
| 440 | this->localToDevice(), &grPaint)) { |
Robert Phillips | a522d66 | 2018-08-23 13:50:16 -0400 | [diff] [blame] | 441 | return; |
| 442 | } |
| 443 | |
Chris Dalton | 3b51df1 | 2017-11-27 14:33:06 -0700 | [diff] [blame] | 444 | fRenderTargetContext->drawRRect(this->clip(), std::move(grPaint), GrAA(paint.isAntiAlias()), |
Michael Ludwig | c89d1b5 | 2019-10-18 11:32:56 -0400 | [diff] [blame] | 445 | this->localToDevice(), rrect, style); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 446 | } |
| 447 | |
robertphillips | d770610 | 2016-02-25 09:28:08 -0800 | [diff] [blame] | 448 | |
Robert Phillips | 20390c3 | 2018-08-17 11:01:03 -0400 | [diff] [blame] | 449 | void SkGpuDevice::drawDRRect(const SkRRect& outer, const SkRRect& inner, const SkPaint& paint) { |
joshualitt | ce89400 | 2016-01-11 13:29:31 -0800 | [diff] [blame] | 450 | ASSERT_SINGLE_OWNER |
Hal Canary | 144caf5 | 2016-11-07 17:57:18 -0500 | [diff] [blame] | 451 | GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawDRRect", fContext.get()); |
robertphillips | d770610 | 2016-02-25 09:28:08 -0800 | [diff] [blame] | 452 | if (outer.isEmpty()) { |
| 453 | return; |
| 454 | } |
| 455 | |
| 456 | if (inner.isEmpty()) { |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 457 | return this->drawRRect(outer, paint); |
robertphillips | d770610 | 2016-02-25 09:28:08 -0800 | [diff] [blame] | 458 | } |
| 459 | |
commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 460 | SkStrokeRec stroke(paint); |
commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 461 | |
robertphillips | 0e7029e | 2015-11-30 05:45:06 -0800 | [diff] [blame] | 462 | if (stroke.isFillStyle() && !paint.getMaskFilter() && !paint.getPathEffect()) { |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 463 | GrPaint grPaint; |
Brian Salomon | 4bc0c1f | 2019-09-30 15:12:27 -0400 | [diff] [blame] | 464 | if (!SkPaintToGrPaint(this->context(), fRenderTargetContext->colorInfo(), paint, |
Michael Ludwig | c89d1b5 | 2019-10-18 11:32:56 -0400 | [diff] [blame] | 465 | this->localToDevice(), &grPaint)) { |
bsalomon | bed83a6 | 2015-04-15 14:18:34 -0700 | [diff] [blame] | 466 | return; |
| 467 | } |
robertphillips | 0009589 | 2016-02-29 13:50:40 -0800 | [diff] [blame] | 468 | |
Brian Salomon | 0166cfd | 2017-03-13 17:58:25 -0400 | [diff] [blame] | 469 | fRenderTargetContext->drawDRRect(this->clip(), std::move(grPaint), |
Michael Ludwig | c89d1b5 | 2019-10-18 11:32:56 -0400 | [diff] [blame] | 470 | GrAA(paint.isAntiAlias()), this->localToDevice(), |
| 471 | 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(), |
Michael Ludwig | c89d1b5 | 2019-10-18 11:32:56 -0400 | [diff] [blame] | 486 | paint, this->localToDevice(), 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; |
Michael Ludwig | c89d1b5 | 2019-10-18 11:32:56 -0400 | [diff] [blame] | 501 | if (!SkPaintToGrPaint(this->context(), fRenderTargetContext->colorInfo(), paint, |
| 502 | this->localToDevice(), &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()), |
Michael Ludwig | c89d1b5 | 2019-10-18 11:32:56 -0400 | [diff] [blame] | 507 | this->localToDevice(), 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; |
Michael Ludwig | c89d1b5 | 2019-10-18 11:32:56 -0400 | [diff] [blame] | 521 | if (!SkPaintToGrPaint(this->context(), fRenderTargetContext->colorInfo(), paint, |
| 522 | this->localToDevice(), &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()), |
Michael Ludwig | c89d1b5 | 2019-10-18 11:32:56 -0400 | [diff] [blame] | 527 | this->localToDevice(), 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; |
Michael Ludwig | c89d1b5 | 2019-10-18 11:32:56 -0400 | [diff] [blame] | 539 | if (!SkPaintToGrPaint(this->context(), fRenderTargetContext->colorInfo(), paint, |
| 540 | this->localToDevice(), &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()), |
Michael Ludwig | c89d1b5 | 2019-10-18 11:32:56 -0400 | [diff] [blame] | 545 | this->localToDevice(), 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 | |
Michael Ludwig | c89d1b5 | 2019-10-18 11:32:56 -0400 | [diff] [blame] | 592 | m.postConcat(this->localToDevice()); |
robertphillips | 0851d2d | 2016-06-02 05:21:34 -0700 | [diff] [blame] | 593 | |
| 594 | GrPaint grPaint; |
Brian Salomon | 4bc0c1f | 2019-09-30 15:12:27 -0400 | [diff] [blame] | 595 | if (!SkPaintToGrPaint(this->context(), fRenderTargetContext->colorInfo(), newPaint, m, |
Brian Salomon | f3569f0 | 2017-10-24 12:52:33 -0400 | [diff] [blame] | 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() && |
Michael Ludwig | c89d1b5 | 2019-10-18 11:32:56 -0400 | [diff] [blame] | 610 | this->localToDevice().preservesRightAngles() && origSrcPath.isLine(points)) { |
robertphillips | 0851d2d | 2016-06-02 05:21:34 -0700 | [diff] [blame] | 611 | // Path-based stroking looks better for thin rects |
Michael Ludwig | c89d1b5 | 2019-10-18 11:32:56 -0400 | [diff] [blame] | 612 | SkScalar strokeWidth = this->localToDevice().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; |
Brian Salomon | 4bc0c1f | 2019-09-30 15:12:27 -0400 | [diff] [blame] | 625 | if (!SkPaintToGrPaint(this->context(), fRenderTargetContext->colorInfo(), paint, |
Michael Ludwig | c89d1b5 | 2019-10-18 11:32:56 -0400 | [diff] [blame] | 626 | this->localToDevice(), &grPaint)) { |
Brian Salomon | a3cf365 | 2018-01-03 15:11:00 -0500 | [diff] [blame] | 627 | return; |
| 628 | } |
| 629 | fRenderTargetContext->drawPath(this->clip(), std::move(grPaint), GrAA(paint.isAntiAlias()), |
Michael Ludwig | c89d1b5 | 2019-10-18 11:32:56 -0400 | [diff] [blame] | 630 | this->localToDevice(), origSrcPath, GrStyle(paint)); |
Brian Salomon | a3cf365 | 2018-01-03 15:11:00 -0500 | [diff] [blame] | 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(), |
Michael Ludwig | c89d1b5 | 2019-10-18 11:32:56 -0400 | [diff] [blame] | 638 | paint, this->localToDevice(), 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, |
Brian Salomon | 9f2b86c | 2019-10-22 10:37:46 -0400 | [diff] [blame] | 673 | const SkISize& imageDimensions, |
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); |
Brian Salomon | 9f2b86c | 2019-10-22 10:37:46 -0400 | [diff] [blame] | 691 | SkIRect bmpBounds = SkIRect::MakeSize(imageDimensions); |
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 | |
Brian Salomon | 078e8fa | 2019-11-22 04:10:18 +0000 | [diff] [blame^] | 935 | GrColorType srcColorType = SkColorTypeToGrColorType(bitmap.colorType()); |
Greg Daniel | c594e62 | 2019-10-15 14:01:49 -0400 | [diff] [blame] | 936 | |
joshualitt | 5f10b5c | 2015-07-09 10:24:35 -0700 | [diff] [blame] | 937 | // Construct a GrPaint by setting the bitmap texture as the first effect and then configuring |
| 938 | // the rest from the SkPaint. |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 939 | std::unique_ptr<GrFragmentProcessor> fp; |
joshualitt | 5f10b5c | 2015-07-09 10:24:35 -0700 | [diff] [blame] | 940 | |
reed | a5517e2 | 2015-07-14 10:54:12 -0700 | [diff] [blame] | 941 | if (needsTextureDomain && (SkCanvas::kStrict_SrcRectConstraint == constraint)) { |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 942 | // Use a constrained texture domain to avoid color bleeding |
bsalomon | e553b64 | 2016-08-17 09:02:09 -0700 | [diff] [blame] | 943 | SkRect domain; |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 944 | if (srcRect.width() > SK_Scalar1) { |
Robert Phillips | e98234f | 2017-01-09 14:23:59 -0500 | [diff] [blame] | 945 | domain.fLeft = srcRect.fLeft + 0.5f; |
| 946 | domain.fRight = srcRect.fRight - 0.5f; |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 947 | } else { |
Robert Phillips | e98234f | 2017-01-09 14:23:59 -0500 | [diff] [blame] | 948 | domain.fLeft = domain.fRight = srcRect.centerX(); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 949 | } |
| 950 | if (srcRect.height() > SK_Scalar1) { |
Robert Phillips | e98234f | 2017-01-09 14:23:59 -0500 | [diff] [blame] | 951 | domain.fTop = srcRect.fTop + 0.5f; |
| 952 | domain.fBottom = srcRect.fBottom - 0.5f; |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 953 | } else { |
Robert Phillips | e98234f | 2017-01-09 14:23:59 -0500 | [diff] [blame] | 954 | domain.fTop = domain.fBottom = srcRect.centerY(); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 955 | } |
commit-bot@chromium.org | 7d7f314 | 2013-12-16 15:18:11 +0000 | [diff] [blame] | 956 | if (bicubic) { |
Brian Salomon | a86fc7a | 2019-05-28 20:42:58 -0400 | [diff] [blame] | 957 | static constexpr auto kDir = GrBicubicEffect::Direction::kXY; |
Brian Salomon | 078e8fa | 2019-11-22 04:10:18 +0000 | [diff] [blame^] | 958 | fp = GrBicubicEffect::Make(std::move(proxy), srcColorType, texMatrix, domain, kDir, |
| 959 | bitmap.alphaType()); |
commit-bot@chromium.org | 7d7f314 | 2013-12-16 15:18:11 +0000 | [diff] [blame] | 960 | } else { |
Brian Salomon | 078e8fa | 2019-11-22 04:10:18 +0000 | [diff] [blame^] | 961 | fp = GrTextureDomainEffect::Make(std::move(proxy), srcColorType, texMatrix, domain, |
Michael Ludwig | 170de01 | 2019-11-15 21:55:18 +0000 | [diff] [blame] | 962 | GrTextureDomain::kClamp_Mode, samplerState.filter()); |
commit-bot@chromium.org | 7d7f314 | 2013-12-16 15:18:11 +0000 | [diff] [blame] | 963 | } |
commit-bot@chromium.org | dec6150 | 2013-12-02 22:22:35 +0000 | [diff] [blame] | 964 | } else if (bicubic) { |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 965 | SkASSERT(GrSamplerState::Filter::kNearest == samplerState.filter()); |
| 966 | GrSamplerState::WrapMode wrapMode[2] = {samplerState.wrapModeX(), samplerState.wrapModeY()}; |
Brian Salomon | a86fc7a | 2019-05-28 20:42:58 -0400 | [diff] [blame] | 967 | static constexpr auto kDir = GrBicubicEffect::Direction::kXY; |
Brian Salomon | 078e8fa | 2019-11-22 04:10:18 +0000 | [diff] [blame^] | 968 | fp = GrBicubicEffect::Make(std::move(proxy), srcColorType, texMatrix, wrapMode, kDir, |
| 969 | bitmap.alphaType()); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 970 | } else { |
Brian Salomon | 078e8fa | 2019-11-22 04:10:18 +0000 | [diff] [blame^] | 971 | fp = GrSimpleTextureEffect::Make(std::move(proxy), srcColorType, texMatrix, samplerState); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 972 | } |
| 973 | |
Brian Osman | 21fc5ce | 2018-08-27 20:36:19 +0000 | [diff] [blame] | 974 | fp = GrColorSpaceXformEffect::Make(std::move(fp), bitmap.colorSpace(), bitmap.alphaType(), |
Brian Salomon | 4bc0c1f | 2019-09-30 15:12:27 -0400 | [diff] [blame] | 975 | fRenderTargetContext->colorInfo().colorSpace()); |
joshualitt | 33a5fce | 2015-11-18 13:28:51 -0800 | [diff] [blame] | 976 | GrPaint grPaint; |
Brian Salomon | 4bc0c1f | 2019-09-30 15:12:27 -0400 | [diff] [blame] | 977 | if (!SkPaintToGrPaintWithTexture(this->context(), fRenderTargetContext->colorInfo(), paint, |
Brian Salomon | f3569f0 | 2017-10-24 12:52:33 -0400 | [diff] [blame] | 978 | viewMatrix, std::move(fp), |
| 979 | kAlpha_8_SkColorType == bitmap.colorType(), &grPaint)) { |
bsalomon | bed83a6 | 2015-04-15 14:18:34 -0700 | [diff] [blame] | 980 | return; |
| 981 | } |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 982 | |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 983 | // Coverage-based AA would cause seams between tiles. |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 984 | GrAA aa = GrAA(paint.isAntiAlias() && fRenderTargetContext->numSamples() > 1); |
Brian Salomon | 0166cfd | 2017-03-13 17:58:25 -0400 | [diff] [blame] | 985 | fRenderTargetContext->drawRect(this->clip(), std::move(grPaint), aa, viewMatrix, dstRect); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 986 | } |
| 987 | |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 988 | void SkGpuDevice::drawSprite(const SkBitmap& bitmap, |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 989 | int left, int top, const SkPaint& paint) { |
joshualitt | ce89400 | 2016-01-11 13:29:31 -0800 | [diff] [blame] | 990 | ASSERT_SINGLE_OWNER |
Hal Canary | 144caf5 | 2016-11-07 17:57:18 -0500 | [diff] [blame] | 991 | GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawSprite", fContext.get()); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 992 | |
Robert Phillips | 920d488 | 2019-03-04 15:16:44 -0500 | [diff] [blame] | 993 | if (fContext->priv().abandoned()) { |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 994 | return; |
| 995 | } |
| 996 | |
Robert Phillips | e14d305 | 2017-02-15 13:18:21 -0500 | [diff] [blame] | 997 | sk_sp<SkSpecialImage> srcImg = this->makeSpecial(bitmap); |
| 998 | if (!srcImg) { |
| 999 | return; |
joshualitt | 5f5a8d7 | 2015-02-25 14:09:45 -0800 | [diff] [blame] | 1000 | } |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1001 | |
Florin Malita | 53f77bd | 2017-04-28 13:48:37 -0400 | [diff] [blame] | 1002 | this->drawSpecial(srcImg.get(), left, top, paint, nullptr, SkMatrix::I()); |
robertphillips | 970587b | 2016-07-14 14:12:55 -0700 | [diff] [blame] | 1003 | } |
| 1004 | |
| 1005 | |
Robert Phillips | c100d48 | 2018-07-10 10:11:01 -0400 | [diff] [blame] | 1006 | void SkGpuDevice::drawSpecial(SkSpecialImage* special, int left, int top, const SkPaint& paint, |
Robert Phillips | 213ce18 | 2018-04-25 09:13:28 -0400 | [diff] [blame] | 1007 | SkImage* clipImage, const SkMatrix& clipMatrix) { |
robertphillips | 1b5f968 | 2016-07-15 08:01:12 -0700 | [diff] [blame] | 1008 | ASSERT_SINGLE_OWNER |
Hal Canary | 144caf5 | 2016-11-07 17:57:18 -0500 | [diff] [blame] | 1009 | GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawSpecial", fContext.get()); |
robertphillips | 970587b | 2016-07-14 14:12:55 -0700 | [diff] [blame] | 1010 | |
robertphillips | 970587b | 2016-07-14 14:12:55 -0700 | [diff] [blame] | 1011 | sk_sp<SkSpecialImage> result; |
| 1012 | if (paint.getImageFilter()) { |
Robert Phillips | c100d48 | 2018-07-10 10:11:01 -0400 | [diff] [blame] | 1013 | SkIPoint offset = { 0, 0 }; |
| 1014 | |
| 1015 | result = this->filterTexture(special, left, top, &offset, paint.getImageFilter()); |
robertphillips | 970587b | 2016-07-14 14:12:55 -0700 | [diff] [blame] | 1016 | if (!result) { |
| 1017 | return; |
| 1018 | } |
Robert Phillips | c100d48 | 2018-07-10 10:11:01 -0400 | [diff] [blame] | 1019 | |
| 1020 | left += offset.fX; |
| 1021 | top += offset.fY; |
robertphillips | 970587b | 2016-07-14 14:12:55 -0700 | [diff] [blame] | 1022 | } else { |
Robert Phillips | c100d48 | 2018-07-10 10:11:01 -0400 | [diff] [blame] | 1023 | result = sk_ref_sp(special); |
robertphillips | 970587b | 2016-07-14 14:12:55 -0700 | [diff] [blame] | 1024 | } |
| 1025 | |
| 1026 | SkASSERT(result->isTextureBacked()); |
Robert Phillips | 2c6d2bf | 2017-02-21 10:19:29 -0500 | [diff] [blame] | 1027 | sk_sp<GrTextureProxy> proxy = result->asTextureProxyRef(this->context()); |
Robert Phillips | 8e1c4e6 | 2017-02-19 12:27:01 -0500 | [diff] [blame] | 1028 | if (!proxy) { |
Robert Phillips | 833dcf4 | 2016-11-18 08:44:13 -0500 | [diff] [blame] | 1029 | return; |
| 1030 | } |
robertphillips | 970587b | 2016-07-14 14:12:55 -0700 | [diff] [blame] | 1031 | |
Michael Ludwig | c89d1b5 | 2019-10-18 11:32:56 -0400 | [diff] [blame] | 1032 | SkMatrix ctm = this->localToDevice(); |
Michael Ludwig | beb7cd2 | 2019-04-08 11:11:42 -0400 | [diff] [blame] | 1033 | ctm.postTranslate(-SkIntToScalar(left), -SkIntToScalar(top)); |
| 1034 | |
robertphillips | 970587b | 2016-07-14 14:12:55 -0700 | [diff] [blame] | 1035 | SkPaint tmpUnfiltered(paint); |
Mike Reed | 2179b78 | 2018-02-07 11:59:57 -0500 | [diff] [blame] | 1036 | if (tmpUnfiltered.getMaskFilter()) { |
Florin Malita | c6c5ead | 2018-04-11 15:33:40 -0400 | [diff] [blame] | 1037 | tmpUnfiltered.setMaskFilter(tmpUnfiltered.getMaskFilter()->makeWithMatrix(ctm)); |
Mike Reed | 2179b78 | 2018-02-07 11:59:57 -0500 | [diff] [blame] | 1038 | } |
| 1039 | |
robertphillips | 970587b | 2016-07-14 14:12:55 -0700 | [diff] [blame] | 1040 | tmpUnfiltered.setImageFilter(nullptr); |
| 1041 | |
Brian Salomon | 078e8fa | 2019-11-22 04:10:18 +0000 | [diff] [blame^] | 1042 | GrColorType srcColorType = SkColorTypeToGrColorType(result->colorType()); |
| 1043 | auto fp = GrSimpleTextureEffect::Make(std::move(proxy), srcColorType, SkMatrix::I()); |
Brian Osman | 21fc5ce | 2018-08-27 20:36:19 +0000 | [diff] [blame] | 1044 | fp = GrColorSpaceXformEffect::Make(std::move(fp), result->getColorSpace(), result->alphaType(), |
Brian Salomon | 4bc0c1f | 2019-09-30 15:12:27 -0400 | [diff] [blame] | 1045 | fRenderTargetContext->colorInfo().colorSpace()); |
Greg Daniel | a4828a1 | 2019-10-11 13:51:02 -0400 | [diff] [blame] | 1046 | if (GrColorTypeIsAlphaOnly(SkColorTypeToGrColorType(result->colorType()))) { |
Brian Salomon | 22af73f | 2017-01-26 11:25:12 -0500 | [diff] [blame] | 1047 | fp = GrFragmentProcessor::MakeInputPremulAndMulByOutput(std::move(fp)); |
bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 1048 | } else { |
Brian Salomon | c0d79e5 | 2019-04-10 15:02:11 -0400 | [diff] [blame] | 1049 | if (paint.getColor4f().isOpaque()) { |
| 1050 | fp = GrFragmentProcessor::OverrideInput(std::move(fp), SK_PMColor4fWHITE, false); |
| 1051 | } else { |
| 1052 | fp = GrFragmentProcessor::MulChildByInputAlpha(std::move(fp)); |
| 1053 | } |
bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 1054 | } |
Robert Phillips | 8e1c4e6 | 2017-02-19 12:27:01 -0500 | [diff] [blame] | 1055 | |
| 1056 | GrPaint grPaint; |
Brian Salomon | 4bc0c1f | 2019-09-30 15:12:27 -0400 | [diff] [blame] | 1057 | if (!SkPaintToGrPaintReplaceShader(this->context(), fRenderTargetContext->colorInfo(), |
Brian Salomon | f3569f0 | 2017-10-24 12:52:33 -0400 | [diff] [blame] | 1058 | tmpUnfiltered, std::move(fp), &grPaint)) { |
bsalomon | bed83a6 | 2015-04-15 14:18:34 -0700 | [diff] [blame] | 1059 | return; |
| 1060 | } |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1061 | |
robertphillips | 970587b | 2016-07-14 14:12:55 -0700 | [diff] [blame] | 1062 | const SkIRect& subset = result->subset(); |
Michael Ludwig | beb7cd2 | 2019-04-08 11:11:42 -0400 | [diff] [blame] | 1063 | SkRect dstRect = SkRect::Make(SkIRect::MakeXYWH(left, top, subset.width(), subset.height())); |
| 1064 | SkRect srcRect = SkRect::Make(subset); |
| 1065 | if (clipImage) { |
| 1066 | // Add the image as a simple texture effect applied to coverage. Accessing content outside |
| 1067 | // of the clip image should behave as if it were a decal (i.e. zero coverage). However, to |
| 1068 | // limit pixels touched and hardware checks, we draw the clip image geometry to get the |
| 1069 | // decal effect. |
| 1070 | GrSamplerState sampler = paint.getFilterQuality() > kNone_SkFilterQuality ? |
| 1071 | GrSamplerState::ClampBilerp() : GrSamplerState::ClampNearest(); |
| 1072 | sk_sp<GrTextureProxy> clipProxy = as_IB(clipImage)->asTextureProxyRef(this->context(), |
| 1073 | sampler, nullptr); |
| 1074 | // Fold clip matrix into ctm |
| 1075 | ctm.preConcat(clipMatrix); |
| 1076 | SkMatrix inverseClipMatrix; |
robertphillips | 970587b | 2016-07-14 14:12:55 -0700 | [diff] [blame] | 1077 | |
Michael Ludwig | beb7cd2 | 2019-04-08 11:11:42 -0400 | [diff] [blame] | 1078 | std::unique_ptr<GrFragmentProcessor> cfp; |
| 1079 | if (clipProxy && ctm.invert(&inverseClipMatrix)) { |
Greg Daniel | c594e62 | 2019-10-15 14:01:49 -0400 | [diff] [blame] | 1080 | GrColorType srcColorType = SkColorTypeToGrColorType(clipImage->colorType()); |
Brian Salomon | 078e8fa | 2019-11-22 04:10:18 +0000 | [diff] [blame^] | 1081 | cfp = GrSimpleTextureEffect::Make(std::move(clipProxy), srcColorType, inverseClipMatrix, |
| 1082 | sampler); |
Greg Daniel | c594e62 | 2019-10-15 14:01:49 -0400 | [diff] [blame] | 1083 | if (srcColorType != GrColorType::kAlpha_8) { |
Michael Ludwig | beb7cd2 | 2019-04-08 11:11:42 -0400 | [diff] [blame] | 1084 | cfp = GrFragmentProcessor::SwizzleOutput(std::move(cfp), GrSwizzle::AAAA()); |
| 1085 | } |
| 1086 | } |
| 1087 | |
| 1088 | if (cfp) { |
| 1089 | // If the grPaint already has coverage, this adds an additional stage that multiples |
| 1090 | // the image's alpha channel with the prior coverage. |
| 1091 | grPaint.addCoverageFragmentProcessor(std::move(cfp)); |
| 1092 | |
| 1093 | // Undo the offset that was needed for shader coord transforms to get the transform for |
| 1094 | // the actual drawn geometry. |
| 1095 | ctm.postTranslate(SkIntToScalar(left), SkIntToScalar(top)); |
| 1096 | inverseClipMatrix.preTranslate(-SkIntToScalar(left), -SkIntToScalar(top)); |
| 1097 | SkRect clipGeometry = SkRect::MakeWH(clipImage->width(), clipImage->height()); |
| 1098 | if (!clipGeometry.contains(inverseClipMatrix.mapRect(dstRect))) { |
| 1099 | // Draw the clip geometry since it is smaller, using dstRect as an extra scissor |
| 1100 | SkClipStack clip(this->cs()); |
| 1101 | clip.clipDevRect(SkIRect::MakeXYWH(left, top, subset.width(), subset.height()), |
| 1102 | SkClipOp::kIntersect); |
| 1103 | SkMatrix local = SkMatrix::Concat(SkMatrix::MakeRectToRect( |
| 1104 | dstRect, srcRect, SkMatrix::kFill_ScaleToFit), ctm); |
| 1105 | fRenderTargetContext->fillRectWithLocalMatrix(GrClipStackClip(&clip), |
| 1106 | std::move(grPaint), GrAA(paint.isAntiAlias()), ctm, clipGeometry, local); |
| 1107 | return; |
| 1108 | } |
| 1109 | // Else fall through and draw the subset since that is contained in the clip geometry |
| 1110 | } |
| 1111 | // Else some issue configuring the coverage FP, so just draw without the clip mask image |
| 1112 | } |
| 1113 | // Draw directly in screen space, possibly with an extra coverage processor |
| 1114 | fRenderTargetContext->fillRectToRect(this->clip(), std::move(grPaint), |
| 1115 | GrAA(paint.isAntiAlias()), SkMatrix::I(), dstRect, srcRect); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1116 | } |
| 1117 | |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 1118 | void SkGpuDevice::drawBitmapRect(const SkBitmap& bitmap, |
bsalomon | b1b0199 | 2015-11-18 10:56:08 -0800 | [diff] [blame] | 1119 | const SkRect* src, const SkRect& origDst, |
reed | 562fe47 | 2015-07-28 07:35:14 -0700 | [diff] [blame] | 1120 | const SkPaint& paint, SkCanvas::SrcRectConstraint constraint) { |
joshualitt | ce89400 | 2016-01-11 13:29:31 -0800 | [diff] [blame] | 1121 | ASSERT_SINGLE_OWNER |
bsalomon | b1b0199 | 2015-11-18 10:56:08 -0800 | [diff] [blame] | 1122 | // The src rect is inferred to be the bmp bounds if not provided. Otherwise, the src rect must |
| 1123 | // be clipped to the bmp bounds. To determine tiling parameters we need the filter mode which |
| 1124 | // in turn requires knowing the src-to-dst mapping. If the src was clipped to the bmp bounds |
| 1125 | // then we use the src-to-dst mapping to compute a new clipped dst rect. |
| 1126 | const SkRect* dst = &origDst; |
| 1127 | const SkRect bmpBounds = SkRect::MakeIWH(bitmap.width(), bitmap.height()); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1128 | // Compute matrix from the two rectangles |
bsalomon | b1b0199 | 2015-11-18 10:56:08 -0800 | [diff] [blame] | 1129 | if (!src) { |
| 1130 | src = &bmpBounds; |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1131 | } |
commit-bot@chromium.org | a7d89c8 | 2014-01-13 14:47:00 +0000 | [diff] [blame] | 1132 | |
bsalomon | b1b0199 | 2015-11-18 10:56:08 -0800 | [diff] [blame] | 1133 | SkMatrix srcToDstMatrix; |
| 1134 | if (!srcToDstMatrix.setRectToRect(*src, *dst, SkMatrix::kFill_ScaleToFit)) { |
| 1135 | return; |
| 1136 | } |
| 1137 | SkRect tmpSrc, tmpDst; |
| 1138 | if (src != &bmpBounds) { |
| 1139 | if (!bmpBounds.contains(*src)) { |
| 1140 | tmpSrc = *src; |
| 1141 | if (!tmpSrc.intersect(bmpBounds)) { |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1142 | return; // nothing to draw |
| 1143 | } |
bsalomon | b1b0199 | 2015-11-18 10:56:08 -0800 | [diff] [blame] | 1144 | src = &tmpSrc; |
| 1145 | srcToDstMatrix.mapRect(&tmpDst, *src); |
| 1146 | dst = &tmpDst; |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1147 | } |
| 1148 | } |
| 1149 | |
Brian Salomon | c7fe0f7 | 2018-05-11 10:14:21 -0400 | [diff] [blame] | 1150 | int maxTileSize = this->caps()->maxTileSize(); |
commit-bot@chromium.org | a7d89c8 | 2014-01-13 14:47:00 +0000 | [diff] [blame] | 1151 | |
bsalomon | b1b0199 | 2015-11-18 10:56:08 -0800 | [diff] [blame] | 1152 | // The tile code path doesn't currently support AA, so if the paint asked for aa and we could |
| 1153 | // draw untiled, then we bypass checking for tiling purely for optimization reasons. |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 1154 | bool useCoverageAA = fRenderTargetContext->numSamples() <= 1 && |
Brian Salomon | 7c8460e | 2017-05-12 11:36:10 -0400 | [diff] [blame] | 1155 | paint.isAntiAlias() && bitmap.width() <= maxTileSize && |
| 1156 | bitmap.height() <= maxTileSize; |
bsalomon | b1b0199 | 2015-11-18 10:56:08 -0800 | [diff] [blame] | 1157 | |
Brian Salomon | 7c8460e | 2017-05-12 11:36:10 -0400 | [diff] [blame] | 1158 | bool skipTileCheck = useCoverageAA || paint.getMaskFilter(); |
bsalomon | b1b0199 | 2015-11-18 10:56:08 -0800 | [diff] [blame] | 1159 | |
| 1160 | if (!skipTileCheck) { |
| 1161 | int tileSize; |
| 1162 | SkIRect clippedSrcRect; |
| 1163 | |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 1164 | GrSamplerState sampleState; |
bsalomon | b1b0199 | 2015-11-18 10:56:08 -0800 | [diff] [blame] | 1165 | bool doBicubic; |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 1166 | GrSamplerState::Filter textureFilterMode = GrSkFilterQualityToGrFilterMode( |
Michael Ludwig | c89d1b5 | 2019-10-18 11:32:56 -0400 | [diff] [blame] | 1167 | bitmap.width(), bitmap.height(), paint.getFilterQuality(), this->localToDevice(), |
Chris Dalton | 309c6c0 | 2019-08-13 10:32:47 -0600 | [diff] [blame] | 1168 | srcToDstMatrix, fContext->priv().options().fSharpenMipmappedTextures, &doBicubic); |
bsalomon | b1b0199 | 2015-11-18 10:56:08 -0800 | [diff] [blame] | 1169 | |
| 1170 | int tileFilterPad; |
| 1171 | |
| 1172 | if (doBicubic) { |
| 1173 | tileFilterPad = GrBicubicEffect::kFilterTexelPad; |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 1174 | } else if (GrSamplerState::Filter::kNearest == textureFilterMode) { |
bsalomon | b1b0199 | 2015-11-18 10:56:08 -0800 | [diff] [blame] | 1175 | tileFilterPad = 0; |
| 1176 | } else { |
| 1177 | tileFilterPad = 1; |
| 1178 | } |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 1179 | sampleState.setFilterMode(textureFilterMode); |
bsalomon | b1b0199 | 2015-11-18 10:56:08 -0800 | [diff] [blame] | 1180 | |
Brian Salomon | c7fe0f7 | 2018-05-11 10:14:21 -0400 | [diff] [blame] | 1181 | int maxTileSizeForFilter = this->caps()->maxTileSize() - 2 * tileFilterPad; |
Michael Ludwig | c89d1b5 | 2019-10-18 11:32:56 -0400 | [diff] [blame] | 1182 | if (this->shouldTileImageID(bitmap.getGenerationID(), bitmap.getSubset(), |
| 1183 | this->localToDevice(), srcToDstMatrix, sampleState, src, |
| 1184 | maxTileSizeForFilter, &tileSize, &clippedSrcRect)) { |
| 1185 | this->drawTiledBitmap(bitmap, this->localToDevice(), srcToDstMatrix, *src, clippedSrcRect, |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 1186 | sampleState, paint, constraint, tileSize, doBicubic); |
bsalomon | b1b0199 | 2015-11-18 10:56:08 -0800 | [diff] [blame] | 1187 | return; |
| 1188 | } |
commit-bot@chromium.org | a7d89c8 | 2014-01-13 14:47:00 +0000 | [diff] [blame] | 1189 | } |
Hal Canary | 144caf5 | 2016-11-07 17:57:18 -0500 | [diff] [blame] | 1190 | GrBitmapTextureMaker maker(fContext.get(), bitmap); |
Michael Ludwig | c89d1b5 | 2019-10-18 11:32:56 -0400 | [diff] [blame] | 1191 | this->drawTextureProducer(&maker, src, dst, constraint, this->localToDevice(), paint, true); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1192 | } |
| 1193 | |
robertphillips | 6451a0c | 2016-07-18 08:31:31 -0700 | [diff] [blame] | 1194 | sk_sp<SkSpecialImage> SkGpuDevice::makeSpecial(const SkBitmap& bitmap) { |
Robert Phillips | e14d305 | 2017-02-15 13:18:21 -0500 | [diff] [blame] | 1195 | // TODO: this makes a tight copy of 'bitmap' but it doesn't have to be (given SkSpecialImage's |
| 1196 | // 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] | 1197 | sk_sp<GrTextureProxy> proxy = GrMakeCachedBitmapProxy(fContext->priv().proxyProvider(), |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 1198 | bitmap); |
Robert Phillips | e14d305 | 2017-02-15 13:18:21 -0500 | [diff] [blame] | 1199 | if (!proxy) { |
robertphillips | 6451a0c | 2016-07-18 08:31:31 -0700 | [diff] [blame] | 1200 | return nullptr; |
| 1201 | } |
| 1202 | |
Brian Salomon | 9f2b86c | 2019-10-22 10:37:46 -0400 | [diff] [blame] | 1203 | const SkIRect rect = SkIRect::MakeSize(proxy->dimensions()); |
robertphillips | 6451a0c | 2016-07-18 08:31:31 -0700 | [diff] [blame] | 1204 | |
Robert Phillips | e14d305 | 2017-02-15 13:18:21 -0500 | [diff] [blame] | 1205 | // GrMakeCachedBitmapProxy creates a tight copy of 'bitmap' so we don't have to subset |
| 1206 | // the special image |
| 1207 | return SkSpecialImage::MakeDeferredFromGpu(fContext.get(), |
| 1208 | rect, |
| 1209 | bitmap.getGenerationID(), |
| 1210 | std::move(proxy), |
Robert Phillips | 40b05c3 | 2019-09-20 12:40:55 -0400 | [diff] [blame] | 1211 | SkColorTypeToGrColorType(bitmap.colorType()), |
Robert Phillips | e14d305 | 2017-02-15 13:18:21 -0500 | [diff] [blame] | 1212 | bitmap.refColorSpace(), |
| 1213 | &this->surfaceProps()); |
robertphillips | 6451a0c | 2016-07-18 08:31:31 -0700 | [diff] [blame] | 1214 | } |
| 1215 | |
reed | e51c356 | 2016-07-19 14:33:20 -0700 | [diff] [blame] | 1216 | sk_sp<SkSpecialImage> SkGpuDevice::makeSpecial(const SkImage* image) { |
robertphillips | 6451a0c | 2016-07-18 08:31:31 -0700 | [diff] [blame] | 1217 | SkPixmap pm; |
| 1218 | if (image->isTextureBacked()) { |
Robert Phillips | 6603a17 | 2019-03-05 12:35:44 -0500 | [diff] [blame] | 1219 | sk_sp<GrTextureProxy> proxy = as_IB(image)->asTextureProxyRef(this->context()); |
robertphillips | 6451a0c | 2016-07-18 08:31:31 -0700 | [diff] [blame] | 1220 | |
Robert Phillips | 6de9904 | 2017-01-31 11:31:39 -0500 | [diff] [blame] | 1221 | return SkSpecialImage::MakeDeferredFromGpu(fContext.get(), |
| 1222 | SkIRect::MakeWH(image->width(), image->height()), |
| 1223 | image->uniqueID(), |
| 1224 | std::move(proxy), |
Robert Phillips | 40b05c3 | 2019-09-20 12:40:55 -0400 | [diff] [blame] | 1225 | SkColorTypeToGrColorType(image->colorType()), |
Brian Salomon | 5ad6fd3 | 2019-03-21 15:30:08 -0400 | [diff] [blame] | 1226 | image->refColorSpace(), |
Robert Phillips | 6de9904 | 2017-01-31 11:31:39 -0500 | [diff] [blame] | 1227 | &this->surfaceProps()); |
robertphillips | 6451a0c | 2016-07-18 08:31:31 -0700 | [diff] [blame] | 1228 | } else if (image->peekPixels(&pm)) { |
| 1229 | SkBitmap bm; |
| 1230 | |
| 1231 | bm.installPixels(pm); |
| 1232 | return this->makeSpecial(bm); |
| 1233 | } else { |
| 1234 | return nullptr; |
| 1235 | } |
| 1236 | } |
| 1237 | |
Michael Ludwig | ac35212 | 2019-08-28 21:03:05 +0000 | [diff] [blame] | 1238 | sk_sp<SkSpecialImage> SkGpuDevice::snapSpecial(const SkIRect& subset, bool forceCopy) { |
Mike Reed | 148b7fd | 2018-12-18 17:38:18 -0500 | [diff] [blame] | 1239 | GrRenderTargetContext* rtc = this->accessRenderTargetContext(); |
Greg Daniel | be7fc46 | 2019-01-03 16:40:42 -0500 | [diff] [blame] | 1240 | |
| 1241 | // If we are wrapping a vulkan secondary command buffer, then we can't snap off a special image |
| 1242 | // since it would require us to make a copy of the underlying VkImage which we don't have access |
| 1243 | // to. Additionaly we can't stop and start the render pass that is used with the secondary |
| 1244 | // command buffer. |
| 1245 | if (rtc->wrapsVkSecondaryCB()) { |
Mike Reed | 148b7fd | 2018-12-18 17:38:18 -0500 | [diff] [blame] | 1246 | return nullptr; |
| 1247 | } |
| 1248 | |
Greg Daniel | be7fc46 | 2019-01-03 16:40:42 -0500 | [diff] [blame] | 1249 | SkASSERT(rtc->asSurfaceProxy()); |
Mike Reed | 148b7fd | 2018-12-18 17:38:18 -0500 | [diff] [blame] | 1250 | |
Michael Ludwig | ac35212 | 2019-08-28 21:03:05 +0000 | [diff] [blame] | 1251 | SkIRect finalSubset = subset; |
| 1252 | sk_sp<GrTextureProxy> proxy(rtc->asTextureProxyRef()); |
| 1253 | if (forceCopy || !proxy) { |
| 1254 | // When the device doesn't have a texture, or a copy is requested, we create a temporary |
| 1255 | // texture that matches the device contents |
| 1256 | proxy = GrSurfaceProxy::Copy(fContext.get(), |
| 1257 | rtc->asSurfaceProxy(), |
Brian Salomon | 078e8fa | 2019-11-22 04:10:18 +0000 | [diff] [blame^] | 1258 | rtc->colorInfo().colorType(), |
Michael Ludwig | ac35212 | 2019-08-28 21:03:05 +0000 | [diff] [blame] | 1259 | GrMipMapped::kNo, // Don't auto generate mips |
| 1260 | subset, |
| 1261 | SkBackingFit::kApprox, |
| 1262 | SkBudgeted::kYes); // Always budgeted |
| 1263 | if (!proxy) { |
| 1264 | return nullptr; |
| 1265 | } |
| 1266 | |
| 1267 | // Since this copied only the requested subset, the special image wrapping the proxy no |
| 1268 | // longer needs the original subset. |
Brian Salomon | 9f2b86c | 2019-10-22 10:37:46 -0400 | [diff] [blame] | 1269 | finalSubset = SkIRect::MakeSize(proxy->dimensions()); |
Mike Reed | 148b7fd | 2018-12-18 17:38:18 -0500 | [diff] [blame] | 1270 | } |
| 1271 | |
Robert Phillips | 40b05c3 | 2019-09-20 12:40:55 -0400 | [diff] [blame] | 1272 | GrColorType ct = SkColorTypeToGrColorType(this->imageInfo().colorType()); |
| 1273 | |
Mike Reed | 148b7fd | 2018-12-18 17:38:18 -0500 | [diff] [blame] | 1274 | return SkSpecialImage::MakeDeferredFromGpu(fContext.get(), |
Michael Ludwig | ac35212 | 2019-08-28 21:03:05 +0000 | [diff] [blame] | 1275 | finalSubset, |
Mike Reed | 148b7fd | 2018-12-18 17:38:18 -0500 | [diff] [blame] | 1276 | kNeedNewImageUniqueID_SpecialImage, |
Michael Ludwig | ac35212 | 2019-08-28 21:03:05 +0000 | [diff] [blame] | 1277 | std::move(proxy), |
Robert Phillips | 40b05c3 | 2019-09-20 12:40:55 -0400 | [diff] [blame] | 1278 | ct, |
Mike Reed | 148b7fd | 2018-12-18 17:38:18 -0500 | [diff] [blame] | 1279 | this->imageInfo().refColorSpace(), |
| 1280 | &this->surfaceProps()); |
| 1281 | } |
| 1282 | |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 1283 | void SkGpuDevice::drawDevice(SkBaseDevice* device, |
Mike Reed | 2179b78 | 2018-02-07 11:59:57 -0500 | [diff] [blame] | 1284 | int left, int top, const SkPaint& paint) { |
| 1285 | SkASSERT(!paint.getImageFilter()); |
reed | cf5c846 | 2016-07-20 12:28:40 -0700 | [diff] [blame] | 1286 | |
joshualitt | ce89400 | 2016-01-11 13:29:31 -0800 | [diff] [blame] | 1287 | ASSERT_SINGLE_OWNER |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1288 | // clear of the source device must occur before CHECK_SHOULD_DRAW |
Hal Canary | 144caf5 | 2016-11-07 17:57:18 -0500 | [diff] [blame] | 1289 | GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawDevice", fContext.get()); |
kkinnunen | 2e4414e | 2015-02-19 07:20:40 -0800 | [diff] [blame] | 1290 | |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1291 | // drawDevice is defined to be in device coords. |
robertphillips | 1b5f968 | 2016-07-15 08:01:12 -0700 | [diff] [blame] | 1292 | SkGpuDevice* dev = static_cast<SkGpuDevice*>(device); |
Michael Ludwig | ac35212 | 2019-08-28 21:03:05 +0000 | [diff] [blame] | 1293 | sk_sp<SkSpecialImage> srcImg(dev->snapSpecial(SkIRect::MakeWH(dev->width(), dev->height()))); |
robertphillips | 1b5f968 | 2016-07-15 08:01:12 -0700 | [diff] [blame] | 1294 | if (!srcImg) { |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1295 | return; |
| 1296 | } |
| 1297 | |
Mike Reed | 2179b78 | 2018-02-07 11:59:57 -0500 | [diff] [blame] | 1298 | this->drawSpecial(srcImg.get(), left, top, paint, nullptr, SkMatrix::I()); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1299 | } |
| 1300 | |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 1301 | void SkGpuDevice::drawImageRect(const SkImage* image, const SkRect* src, const SkRect& dst, |
| 1302 | const SkPaint& paint, SkCanvas::SrcRectConstraint constraint) { |
joshualitt | ce89400 | 2016-01-11 13:29:31 -0800 | [diff] [blame] | 1303 | ASSERT_SINGLE_OWNER |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 1304 | GrQuadAAFlags aaFlags = paint.isAntiAlias() ? GrQuadAAFlags::kAll : GrQuadAAFlags::kNone; |
Michael Ludwig | 7ae2ab5 | 2019-03-05 16:00:20 -0500 | [diff] [blame] | 1305 | this->drawImageQuad(image, src, &dst, nullptr, GrAA(paint.isAntiAlias()), aaFlags, nullptr, |
| 1306 | paint, constraint); |
bsalomon | 1cf6f9b | 2015-12-08 10:53:43 -0800 | [diff] [blame] | 1307 | } |
| 1308 | |
Leon Scroggins III | 57e1f02 | 2018-04-20 14:53:00 -0400 | [diff] [blame] | 1309 | // When drawing nine-patches or n-patches, cap the filter quality at kBilerp. |
| 1310 | static GrSamplerState::Filter compute_lattice_filter_mode(const SkPaint& paint) { |
| 1311 | if (paint.getFilterQuality() == kNone_SkFilterQuality) { |
| 1312 | return GrSamplerState::Filter::kNearest; |
| 1313 | } |
| 1314 | |
| 1315 | return GrSamplerState::Filter::kBilerp; |
| 1316 | } |
| 1317 | |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 1318 | void SkGpuDevice::drawImageNine(const SkImage* image, |
bsalomon | 2bbd0c6 | 2015-12-09 12:50:56 -0800 | [diff] [blame] | 1319 | const SkIRect& center, const SkRect& dst, const SkPaint& paint) { |
joshualitt | ce89400 | 2016-01-11 13:29:31 -0800 | [diff] [blame] | 1320 | ASSERT_SINGLE_OWNER |
reed | 2d5b714 | 2016-08-17 11:12:33 -0700 | [diff] [blame] | 1321 | uint32_t pinnedUniqueID; |
Brian Salomon | 2a943df | 2018-05-04 13:43:19 -0400 | [diff] [blame] | 1322 | auto iter = skstd::make_unique<SkLatticeIter>(image->width(), image->height(), center, dst); |
Robert Phillips | 6603a17 | 2019-03-05 12:35:44 -0500 | [diff] [blame] | 1323 | if (sk_sp<GrTextureProxy> proxy = as_IB(image)->refPinnedTextureProxy(this->context(), |
| 1324 | &pinnedUniqueID)) { |
Brian Salomon | d628747 | 2019-06-24 15:50:07 -0400 | [diff] [blame] | 1325 | GrTextureAdjuster adjuster(this->context(), std::move(proxy), |
Brian Salomon | 1a217eb | 2019-10-24 10:50:36 -0400 | [diff] [blame] | 1326 | image->imageInfo().colorInfo(), pinnedUniqueID); |
Brian Salomon | 2a943df | 2018-05-04 13:43:19 -0400 | [diff] [blame] | 1327 | this->drawProducerLattice(&adjuster, std::move(iter), dst, paint); |
bsalomon | 2bbd0c6 | 2015-12-09 12:50:56 -0800 | [diff] [blame] | 1328 | } else { |
| 1329 | SkBitmap bm; |
Brian Osman | df7e075 | 2017-04-26 16:20:28 -0400 | [diff] [blame] | 1330 | if (image->isLazyGenerated()) { |
| 1331 | GrImageTextureMaker maker(fContext.get(), image, SkImage::kAllow_CachingHint); |
Brian Salomon | 2a943df | 2018-05-04 13:43:19 -0400 | [diff] [blame] | 1332 | this->drawProducerLattice(&maker, std::move(iter), dst, paint); |
Brian Osman | e50cdf0 | 2018-10-19 13:02:14 -0400 | [diff] [blame] | 1333 | } else if (as_IB(image)->getROPixels(&bm)) { |
Brian Salomon | 2a943df | 2018-05-04 13:43:19 -0400 | [diff] [blame] | 1334 | GrBitmapTextureMaker maker(fContext.get(), bm); |
| 1335 | this->drawProducerLattice(&maker, std::move(iter), dst, paint); |
bsalomon | 2bbd0c6 | 2015-12-09 12:50:56 -0800 | [diff] [blame] | 1336 | } |
| 1337 | } |
| 1338 | } |
| 1339 | |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 1340 | void SkGpuDevice::drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, |
bsalomon | 2bbd0c6 | 2015-12-09 12:50:56 -0800 | [diff] [blame] | 1341 | const SkRect& dst, const SkPaint& paint) { |
joshualitt | ce89400 | 2016-01-11 13:29:31 -0800 | [diff] [blame] | 1342 | ASSERT_SINGLE_OWNER |
Brian Salomon | 2a943df | 2018-05-04 13:43:19 -0400 | [diff] [blame] | 1343 | auto iter = skstd::make_unique<SkLatticeIter>(bitmap.width(), bitmap.height(), center, dst); |
Hal Canary | 144caf5 | 2016-11-07 17:57:18 -0500 | [diff] [blame] | 1344 | GrBitmapTextureMaker maker(fContext.get(), bitmap); |
Brian Salomon | 2a943df | 2018-05-04 13:43:19 -0400 | [diff] [blame] | 1345 | this->drawProducerLattice(&maker, std::move(iter), dst, paint); |
joshualitt | 33a5fce | 2015-11-18 13:28:51 -0800 | [diff] [blame] | 1346 | } |
| 1347 | |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 1348 | void SkGpuDevice::drawProducerLattice(GrTextureProducer* producer, |
Brian Salomon | 2a943df | 2018-05-04 13:43:19 -0400 | [diff] [blame] | 1349 | std::unique_ptr<SkLatticeIter> iter, const SkRect& dst, |
| 1350 | const SkPaint& origPaint) { |
Hal Canary | 144caf5 | 2016-11-07 17:57:18 -0500 | [diff] [blame] | 1351 | GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawProducerLattice", fContext.get()); |
Brian Salomon | 2a943df | 2018-05-04 13:43:19 -0400 | [diff] [blame] | 1352 | SkTCopyOnFirstWrite<SkPaint> paint(&origPaint); |
msarett | 10e3d9b | 2016-08-18 15:46:03 -0700 | [diff] [blame] | 1353 | |
Brian Salomon | 2a943df | 2018-05-04 13:43:19 -0400 | [diff] [blame] | 1354 | if (!producer->isAlphaOnly() && (paint->getColor() & 0x00FFFFFF) != 0x00FFFFFF) { |
| 1355 | paint.writable()->setColor(SkColorSetARGB(origPaint.getAlpha(), 0xFF, 0xFF, 0xFF)); |
| 1356 | } |
msarett | 10e3d9b | 2016-08-18 15:46:03 -0700 | [diff] [blame] | 1357 | GrPaint grPaint; |
Brian Salomon | 4bc0c1f | 2019-09-30 15:12:27 -0400 | [diff] [blame] | 1358 | if (!SkPaintToGrPaintWithPrimitiveColor(this->context(), fRenderTargetContext->colorInfo(), |
Brian Salomon | 2a943df | 2018-05-04 13:43:19 -0400 | [diff] [blame] | 1359 | *paint, &grPaint)) { |
msarett | 10e3d9b | 2016-08-18 15:46:03 -0700 | [diff] [blame] | 1360 | return; |
| 1361 | } |
| 1362 | |
Brian Salomon | 4bc0c1f | 2019-09-30 15:12:27 -0400 | [diff] [blame] | 1363 | auto dstColorSpace = fRenderTargetContext->colorInfo().colorSpace(); |
Brian Salomon | 2a943df | 2018-05-04 13:43:19 -0400 | [diff] [blame] | 1364 | const GrSamplerState::Filter filter = compute_lattice_filter_mode(*paint); |
Michael Ludwig | ddeed37 | 2019-02-20 16:50:10 -0500 | [diff] [blame] | 1365 | auto proxy = producer->refTextureProxyForParams(&filter, nullptr); |
Brian Salomon | a8daee8 | 2018-05-07 14:51:18 -0400 | [diff] [blame] | 1366 | if (!proxy) { |
| 1367 | return; |
| 1368 | } |
Brian Osman | 6064e1c | 2018-10-19 14:27:54 -0400 | [diff] [blame] | 1369 | auto csxf = GrColorSpaceXform::Make(producer->colorSpace(), producer->alphaType(), |
| 1370 | dstColorSpace, kPremul_SkAlphaType); |
Brian Salomon | 2a943df | 2018-05-04 13:43:19 -0400 | [diff] [blame] | 1371 | |
Michael Ludwig | c89d1b5 | 2019-10-18 11:32:56 -0400 | [diff] [blame] | 1372 | fRenderTargetContext->drawImageLattice(this->clip(), std::move(grPaint), this->localToDevice(), |
Greg Daniel | c594e62 | 2019-10-15 14:01:49 -0400 | [diff] [blame] | 1373 | std::move(proxy), producer->colorType(), std::move(csxf), |
| 1374 | filter, std::move(iter), dst); |
msarett | 10e3d9b | 2016-08-18 15:46:03 -0700 | [diff] [blame] | 1375 | } |
| 1376 | |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 1377 | void SkGpuDevice::drawImageLattice(const SkImage* image, |
msarett | 10e3d9b | 2016-08-18 15:46:03 -0700 | [diff] [blame] | 1378 | const SkCanvas::Lattice& lattice, const SkRect& dst, |
| 1379 | const SkPaint& paint) { |
| 1380 | ASSERT_SINGLE_OWNER |
| 1381 | uint32_t pinnedUniqueID; |
Brian Salomon | 2a943df | 2018-05-04 13:43:19 -0400 | [diff] [blame] | 1382 | auto iter = skstd::make_unique<SkLatticeIter>(lattice, dst); |
Robert Phillips | 6603a17 | 2019-03-05 12:35:44 -0500 | [diff] [blame] | 1383 | if (sk_sp<GrTextureProxy> proxy = as_IB(image)->refPinnedTextureProxy(this->context(), |
| 1384 | &pinnedUniqueID)) { |
Brian Salomon | d628747 | 2019-06-24 15:50:07 -0400 | [diff] [blame] | 1385 | GrTextureAdjuster adjuster(this->context(), std::move(proxy), |
Brian Salomon | 1a217eb | 2019-10-24 10:50:36 -0400 | [diff] [blame] | 1386 | image->imageInfo().colorInfo(), pinnedUniqueID); |
Brian Salomon | 2a943df | 2018-05-04 13:43:19 -0400 | [diff] [blame] | 1387 | this->drawProducerLattice(&adjuster, std::move(iter), dst, paint); |
msarett | 10e3d9b | 2016-08-18 15:46:03 -0700 | [diff] [blame] | 1388 | } else { |
| 1389 | SkBitmap bm; |
Brian Osman | df7e075 | 2017-04-26 16:20:28 -0400 | [diff] [blame] | 1390 | if (image->isLazyGenerated()) { |
| 1391 | GrImageTextureMaker maker(fContext.get(), image, SkImage::kAllow_CachingHint); |
Brian Salomon | 2a943df | 2018-05-04 13:43:19 -0400 | [diff] [blame] | 1392 | this->drawProducerLattice(&maker, std::move(iter), dst, paint); |
Brian Osman | e50cdf0 | 2018-10-19 13:02:14 -0400 | [diff] [blame] | 1393 | } else if (as_IB(image)->getROPixels(&bm)) { |
Brian Salomon | 2a943df | 2018-05-04 13:43:19 -0400 | [diff] [blame] | 1394 | GrBitmapTextureMaker maker(fContext.get(), bm); |
| 1395 | this->drawProducerLattice(&maker, std::move(iter), dst, paint); |
msarett | 10e3d9b | 2016-08-18 15:46:03 -0700 | [diff] [blame] | 1396 | } |
| 1397 | } |
| 1398 | } |
| 1399 | |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 1400 | void SkGpuDevice::drawBitmapLattice(const SkBitmap& bitmap, |
msarett | 10e3d9b | 2016-08-18 15:46:03 -0700 | [diff] [blame] | 1401 | const SkCanvas::Lattice& lattice, const SkRect& dst, |
| 1402 | const SkPaint& paint) { |
| 1403 | ASSERT_SINGLE_OWNER |
Brian Salomon | 2a943df | 2018-05-04 13:43:19 -0400 | [diff] [blame] | 1404 | auto iter = skstd::make_unique<SkLatticeIter>(lattice, dst); |
Hal Canary | 144caf5 | 2016-11-07 17:57:18 -0500 | [diff] [blame] | 1405 | GrBitmapTextureMaker maker(fContext.get(), bitmap); |
Brian Salomon | 2a943df | 2018-05-04 13:43:19 -0400 | [diff] [blame] | 1406 | this->drawProducerLattice(&maker, std::move(iter), dst, paint); |
msarett | 10e3d9b | 2016-08-18 15:46:03 -0700 | [diff] [blame] | 1407 | } |
| 1408 | |
Brian Salomon | 4bc0c1f | 2019-09-30 15:12:27 -0400 | [diff] [blame] | 1409 | static bool init_vertices_paint(GrContext* context, const GrColorInfo& colorInfo, |
Brian Salomon | f3569f0 | 2017-10-24 12:52:33 -0400 | [diff] [blame] | 1410 | const SkPaint& skPaint, const SkMatrix& matrix, SkBlendMode bmode, |
Robert Phillips | 26c90e0 | 2017-03-14 14:39:29 -0400 | [diff] [blame] | 1411 | bool hasTexs, bool hasColors, GrPaint* grPaint) { |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 1412 | if (hasTexs && skPaint.getShader()) { |
| 1413 | if (hasColors) { |
| 1414 | // When there are texs and colors the shader and colors are combined using bmode. |
Brian Salomon | 4bc0c1f | 2019-09-30 15:12:27 -0400 | [diff] [blame] | 1415 | return SkPaintToGrPaintWithXfermode(context, colorInfo, skPaint, matrix, bmode, |
Brian Salomon | f3569f0 | 2017-10-24 12:52:33 -0400 | [diff] [blame] | 1416 | grPaint); |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 1417 | } else { |
| 1418 | // We have a shader, but no colors to blend it against. |
Brian Salomon | 4bc0c1f | 2019-09-30 15:12:27 -0400 | [diff] [blame] | 1419 | return SkPaintToGrPaint(context, colorInfo, skPaint, matrix, grPaint); |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 1420 | } |
| 1421 | } else { |
| 1422 | if (hasColors) { |
| 1423 | // We have colors, but either have no shader or no texture coords (which implies that |
| 1424 | // we should ignore the shader). |
Brian Salomon | 4bc0c1f | 2019-09-30 15:12:27 -0400 | [diff] [blame] | 1425 | return SkPaintToGrPaintWithPrimitiveColor(context, colorInfo, skPaint, grPaint); |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 1426 | } else { |
| 1427 | // No colors and no shaders. Just draw with the paint color. |
Brian Salomon | 4bc0c1f | 2019-09-30 15:12:27 -0400 | [diff] [blame] | 1428 | return SkPaintToGrPaintNoShader(context, colorInfo, skPaint, grPaint); |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 1429 | } |
| 1430 | } |
| 1431 | } |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1432 | |
Mike Reed | 887cdf1 | 2017-04-03 11:11:09 -0400 | [diff] [blame] | 1433 | void SkGpuDevice::wireframeVertices(SkVertices::VertexMode vmode, int vertexCount, |
Ruiqi Mao | 4ec72f7 | 2018-07-10 17:21:07 -0400 | [diff] [blame] | 1434 | const SkPoint vertices[], |
Ruiqi Mao | c97a339 | 2018-08-15 10:44:19 -0400 | [diff] [blame] | 1435 | const SkVertices::Bone bones[], int boneCount, |
Ruiqi Mao | 4ec72f7 | 2018-07-10 17:21:07 -0400 | [diff] [blame] | 1436 | SkBlendMode bmode, |
Mike Reed | 2f6b5a4 | 2017-03-19 15:04:17 -0400 | [diff] [blame] | 1437 | const uint16_t indices[], int indexCount, |
| 1438 | const SkPaint& paint) { |
joshualitt | ce89400 | 2016-01-11 13:29:31 -0800 | [diff] [blame] | 1439 | ASSERT_SINGLE_OWNER |
Mike Reed | 2f6b5a4 | 2017-03-19 15:04:17 -0400 | [diff] [blame] | 1440 | GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "wireframeVertices", fContext.get()); |
mtklein | 533eb78 | 2014-08-27 10:39:42 -0700 | [diff] [blame] | 1441 | |
Mike Reed | 2f6b5a4 | 2017-03-19 15:04:17 -0400 | [diff] [blame] | 1442 | SkPaint copy(paint); |
| 1443 | copy.setStyle(SkPaint::kStroke_Style); |
| 1444 | copy.setStrokeWidth(0); |
mtklein | 533eb78 | 2014-08-27 10:39:42 -0700 | [diff] [blame] | 1445 | |
Mike Reed | 2f6b5a4 | 2017-03-19 15:04:17 -0400 | [diff] [blame] | 1446 | GrPaint grPaint; |
| 1447 | // we ignore the shader since we have no texture coordinates. |
Brian Salomon | 4bc0c1f | 2019-09-30 15:12:27 -0400 | [diff] [blame] | 1448 | if (!SkPaintToGrPaintNoShader(this->context(), fRenderTargetContext->colorInfo(), copy, |
Brian Salomon | f3569f0 | 2017-10-24 12:52:33 -0400 | [diff] [blame] | 1449 | &grPaint)) { |
bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 1450 | return; |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1451 | } |
| 1452 | |
Mike Reed | 2f6b5a4 | 2017-03-19 15:04:17 -0400 | [diff] [blame] | 1453 | int triangleCount = 0; |
| 1454 | int n = (nullptr == indices) ? vertexCount : indexCount; |
| 1455 | switch (vmode) { |
Mike Reed | 887cdf1 | 2017-04-03 11:11:09 -0400 | [diff] [blame] | 1456 | case SkVertices::kTriangles_VertexMode: |
Mike Reed | 2f6b5a4 | 2017-03-19 15:04:17 -0400 | [diff] [blame] | 1457 | triangleCount = n / 3; |
| 1458 | break; |
Mike Reed | 887cdf1 | 2017-04-03 11:11:09 -0400 | [diff] [blame] | 1459 | case SkVertices::kTriangleStrip_VertexMode: |
Mike Reed | 2f6b5a4 | 2017-03-19 15:04:17 -0400 | [diff] [blame] | 1460 | triangleCount = n - 2; |
| 1461 | break; |
Brian Salomon | cccafe8 | 2018-04-28 16:13:08 -0400 | [diff] [blame] | 1462 | case SkVertices::kTriangleFan_VertexMode: |
| 1463 | SK_ABORT("Unexpected triangle fan."); |
| 1464 | break; |
Mike Reed | 2f6b5a4 | 2017-03-19 15:04:17 -0400 | [diff] [blame] | 1465 | } |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1466 | |
Mike Reed | 2f6b5a4 | 2017-03-19 15:04:17 -0400 | [diff] [blame] | 1467 | VertState state(vertexCount, indices, indexCount); |
| 1468 | VertState::Proc vertProc = state.chooseProc(vmode); |
| 1469 | |
| 1470 | //number of indices for lines per triangle with kLines |
| 1471 | indexCount = triangleCount * 6; |
| 1472 | |
Brian Osman | ae0c50c | 2017-05-25 16:56:34 -0400 | [diff] [blame] | 1473 | static constexpr SkVertices::VertexMode kIgnoredMode = SkVertices::kTriangles_VertexMode; |
| 1474 | SkVertices::Builder builder(kIgnoredMode, vertexCount, indexCount, 0); |
| 1475 | memcpy(builder.positions(), vertices, vertexCount * sizeof(SkPoint)); |
| 1476 | |
| 1477 | uint16_t* lineIndices = builder.indices(); |
Mike Reed | 2f6b5a4 | 2017-03-19 15:04:17 -0400 | [diff] [blame] | 1478 | int i = 0; |
| 1479 | while (vertProc(&state)) { |
| 1480 | lineIndices[i] = state.f0; |
| 1481 | lineIndices[i + 1] = state.f1; |
| 1482 | lineIndices[i + 2] = state.f1; |
| 1483 | lineIndices[i + 3] = state.f2; |
| 1484 | lineIndices[i + 4] = state.f2; |
| 1485 | lineIndices[i + 5] = state.f0; |
| 1486 | i += 6; |
bsalomon | f1b7a1d | 2015-09-28 06:26:28 -0700 | [diff] [blame] | 1487 | } |
Brian Osman | ae0c50c | 2017-05-25 16:56:34 -0400 | [diff] [blame] | 1488 | |
Chris Dalton | 3809bab | 2017-06-13 10:55:06 -0600 | [diff] [blame] | 1489 | GrPrimitiveType primitiveType = GrPrimitiveType::kLines; |
Brian Salomon | 0166cfd | 2017-03-13 17:58:25 -0400 | [diff] [blame] | 1490 | fRenderTargetContext->drawVertices(this->clip(), |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 1491 | std::move(grPaint), |
Michael Ludwig | c89d1b5 | 2019-10-18 11:32:56 -0400 | [diff] [blame] | 1492 | this->localToDevice(), |
Brian Osman | ae0c50c | 2017-05-25 16:56:34 -0400 | [diff] [blame] | 1493 | builder.detach(), |
Ruiqi Mao | 4ec72f7 | 2018-07-10 17:21:07 -0400 | [diff] [blame] | 1494 | bones, |
| 1495 | boneCount, |
Brian Osman | ae0c50c | 2017-05-25 16:56:34 -0400 | [diff] [blame] | 1496 | &primitiveType); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1497 | } |
| 1498 | |
Ruiqi Mao | c97a339 | 2018-08-15 10:44:19 -0400 | [diff] [blame] | 1499 | void SkGpuDevice::drawVertices(const SkVertices* vertices, const SkVertices::Bone bones[], |
| 1500 | int boneCount, SkBlendMode mode, const SkPaint& paint) { |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 1501 | ASSERT_SINGLE_OWNER |
Mike Reed | 2f6b5a4 | 2017-03-19 15:04:17 -0400 | [diff] [blame] | 1502 | GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawVertices", fContext.get()); |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 1503 | |
| 1504 | SkASSERT(vertices); |
| 1505 | GrPaint grPaint; |
Mike Reed | 5fa6645 | 2017-03-16 09:06:34 -0400 | [diff] [blame] | 1506 | bool hasColors = vertices->hasColors(); |
| 1507 | bool hasTexs = vertices->hasTexCoords(); |
Brian Osman | 0b403f8 | 2017-05-26 10:39:51 -0400 | [diff] [blame] | 1508 | if ((!hasTexs || !paint.getShader()) && !hasColors) { |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 1509 | // The dreaded wireframe mode. Fallback to drawVertices and go so slooooooow. |
Mike Reed | 2f6b5a4 | 2017-03-19 15:04:17 -0400 | [diff] [blame] | 1510 | this->wireframeVertices(vertices->mode(), vertices->vertexCount(), vertices->positions(), |
Ruiqi Mao | 4ec72f7 | 2018-07-10 17:21:07 -0400 | [diff] [blame] | 1511 | bones, boneCount, mode, vertices->indices(), vertices->indexCount(), |
| 1512 | paint); |
Brian Osman | 0b403f8 | 2017-05-26 10:39:51 -0400 | [diff] [blame] | 1513 | return; |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 1514 | } |
Michael Ludwig | c89d1b5 | 2019-10-18 11:32:56 -0400 | [diff] [blame] | 1515 | if (!init_vertices_paint(fContext.get(), fRenderTargetContext->colorInfo(), paint, |
| 1516 | this->localToDevice(), mode, hasTexs, hasColors, &grPaint)) { |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 1517 | return; |
| 1518 | } |
Michael Ludwig | c89d1b5 | 2019-10-18 11:32:56 -0400 | [diff] [blame] | 1519 | fRenderTargetContext->drawVertices(this->clip(), std::move(grPaint), this->localToDevice(), |
Ruiqi Mao | 4ec72f7 | 2018-07-10 17:21:07 -0400 | [diff] [blame] | 1520 | sk_ref_sp(const_cast<SkVertices*>(vertices)), |
| 1521 | bones, boneCount); |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 1522 | } |
| 1523 | |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1524 | /////////////////////////////////////////////////////////////////////////////// |
| 1525 | |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1526 | void SkGpuDevice::drawShadow(const SkPath& path, const SkDrawShadowRec& rec) { |
| 1527 | |
| 1528 | ASSERT_SINGLE_OWNER |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1529 | GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawShadow", fContext.get()); |
| 1530 | |
Michael Ludwig | c89d1b5 | 2019-10-18 11:32:56 -0400 | [diff] [blame] | 1531 | if (!fRenderTargetContext->drawFastShadow(this->clip(), this->localToDevice(), path, rec)) { |
Jim Van Verth | 3af1af9 | 2017-05-18 15:06:54 -0400 | [diff] [blame] | 1532 | // failed to find an accelerated case |
| 1533 | this->INHERITED::drawShadow(path, rec); |
| 1534 | } |
| 1535 | } |
| 1536 | |
| 1537 | /////////////////////////////////////////////////////////////////////////////// |
| 1538 | |
Brian Osman | 4d92b89 | 2019-03-24 00:53:23 +0000 | [diff] [blame] | 1539 | void SkGpuDevice::drawAtlas(const SkImage* atlas, const SkRSXform xform[], |
| 1540 | const SkRect texRect[], const SkColor colors[], int count, |
| 1541 | SkBlendMode mode, const SkPaint& paint) { |
| 1542 | ASSERT_SINGLE_OWNER |
Brian Osman | ddba4e6 | 2019-03-25 09:52:17 -0400 | [diff] [blame] | 1543 | GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawAtlas", fContext.get()); |
Brian Osman | 4d92b89 | 2019-03-24 00:53:23 +0000 | [diff] [blame] | 1544 | |
| 1545 | SkPaint p(paint); |
| 1546 | p.setShader(atlas->makeShader()); |
| 1547 | |
| 1548 | GrPaint grPaint; |
| 1549 | if (colors) { |
Brian Salomon | 4bc0c1f | 2019-09-30 15:12:27 -0400 | [diff] [blame] | 1550 | if (!SkPaintToGrPaintWithXfermode(this->context(), fRenderTargetContext->colorInfo(), p, |
Michael Ludwig | c89d1b5 | 2019-10-18 11:32:56 -0400 | [diff] [blame] | 1551 | this->localToDevice(), (SkBlendMode)mode, &grPaint)) { |
Brian Osman | 4d92b89 | 2019-03-24 00:53:23 +0000 | [diff] [blame] | 1552 | return; |
| 1553 | } |
| 1554 | } else { |
Michael Ludwig | c89d1b5 | 2019-10-18 11:32:56 -0400 | [diff] [blame] | 1555 | if (!SkPaintToGrPaint(this->context(), fRenderTargetContext->colorInfo(), p, |
| 1556 | this->localToDevice(), &grPaint)) { |
Brian Osman | 4d92b89 | 2019-03-24 00:53:23 +0000 | [diff] [blame] | 1557 | return; |
| 1558 | } |
| 1559 | } |
| 1560 | |
| 1561 | fRenderTargetContext->drawAtlas( |
Michael Ludwig | c89d1b5 | 2019-10-18 11:32:56 -0400 | [diff] [blame] | 1562 | this->clip(), std::move(grPaint), this->localToDevice(), count, xform, texRect, colors); |
Brian Osman | 4d92b89 | 2019-03-24 00:53:23 +0000 | [diff] [blame] | 1563 | } |
| 1564 | |
| 1565 | /////////////////////////////////////////////////////////////////////////////// |
| 1566 | |
Herb Derby | b935cf8 | 2018-07-26 16:54:18 -0400 | [diff] [blame] | 1567 | void SkGpuDevice::drawGlyphRunList(const SkGlyphRunList& glyphRunList) { |
Herb Derby | b983e6b | 2018-07-13 13:26:29 -0400 | [diff] [blame] | 1568 | ASSERT_SINGLE_OWNER |
| 1569 | GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawGlyphRunList", fContext.get()); |
Herb Derby | b983e6b | 2018-07-13 13:26:29 -0400 | [diff] [blame] | 1570 | |
Jim Van Verth | 87a3011 | 2018-09-24 16:13:58 -0400 | [diff] [blame] | 1571 | // Check for valid input |
Michael Ludwig | c89d1b5 | 2019-10-18 11:32:56 -0400 | [diff] [blame] | 1572 | if (!this->localToDevice().isFinite() || !glyphRunList.allFontsFinite()) { |
Jim Van Verth | 87a3011 | 2018-09-24 16:13:58 -0400 | [diff] [blame] | 1573 | return; |
| 1574 | } |
| 1575 | |
Michael Ludwig | c89d1b5 | 2019-10-18 11:32:56 -0400 | [diff] [blame] | 1576 | fRenderTargetContext->drawGlyphRunList(this->clip(), this->localToDevice(), glyphRunList); |
Herb Derby | b983e6b | 2018-07-13 13:26:29 -0400 | [diff] [blame] | 1577 | } |
| 1578 | |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1579 | /////////////////////////////////////////////////////////////////////////////// |
| 1580 | |
Greg Daniel | 9ed1a2c | 2018-10-18 12:43:25 -0400 | [diff] [blame] | 1581 | void SkGpuDevice::drawDrawable(SkDrawable* drawable, const SkMatrix* matrix, SkCanvas* canvas) { |
Robert Phillips | 4217ea7 | 2019-01-30 13:08:28 -0500 | [diff] [blame] | 1582 | GrBackendApi api = this->context()->backend(); |
Greg Daniel | 9ed1a2c | 2018-10-18 12:43:25 -0400 | [diff] [blame] | 1583 | if (GrBackendApi::kVulkan == api) { |
| 1584 | const SkMatrix& ctm = canvas->getTotalMatrix(); |
| 1585 | const SkMatrix& combinedMatrix = matrix ? SkMatrix::Concat(ctm, *matrix) : ctm; |
| 1586 | std::unique_ptr<SkDrawable::GpuDrawHandler> gpuDraw = |
Derek Sollenberger | e6fb76b | 2019-01-10 13:19:06 -0500 | [diff] [blame] | 1587 | drawable->snapGpuDrawHandler(api, combinedMatrix, canvas->getDeviceClipBounds(), |
| 1588 | this->imageInfo()); |
Greg Daniel | 9ed1a2c | 2018-10-18 12:43:25 -0400 | [diff] [blame] | 1589 | if (gpuDraw) { |
Greg Daniel | 64cc9aa | 2018-10-19 13:54:56 -0400 | [diff] [blame] | 1590 | fRenderTargetContext->drawDrawable(std::move(gpuDraw), drawable->getBounds()); |
| 1591 | return; |
Greg Daniel | 9ed1a2c | 2018-10-18 12:43:25 -0400 | [diff] [blame] | 1592 | } |
| 1593 | } |
| 1594 | this->INHERITED::drawDrawable(drawable, matrix, canvas); |
| 1595 | } |
| 1596 | |
Greg Daniel | 64cc9aa | 2018-10-19 13:54:56 -0400 | [diff] [blame] | 1597 | |
Greg Daniel | 9ed1a2c | 2018-10-18 12:43:25 -0400 | [diff] [blame] | 1598 | /////////////////////////////////////////////////////////////////////////////// |
| 1599 | |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1600 | void SkGpuDevice::flush() { |
Greg Daniel | e6bfb7d | 2019-04-17 15:26:11 -0400 | [diff] [blame] | 1601 | this->flush(SkSurface::BackendSurfaceAccess::kNoAccess, GrFlushInfo()); |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 1602 | } |
| 1603 | |
Greg Daniel | e6bfb7d | 2019-04-17 15:26:11 -0400 | [diff] [blame] | 1604 | GrSemaphoresSubmitted SkGpuDevice::flush(SkSurface::BackendSurfaceAccess access, |
| 1605 | const GrFlushInfo& info) { |
joshualitt | ce89400 | 2016-01-11 13:29:31 -0800 | [diff] [blame] | 1606 | ASSERT_SINGLE_OWNER |
joshualitt | bc90735 | 2016-01-13 06:45:40 -0800 | [diff] [blame] | 1607 | |
Greg Daniel | e6bfb7d | 2019-04-17 15:26:11 -0400 | [diff] [blame] | 1608 | return fRenderTargetContext->flush(access, info); |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 1609 | } |
| 1610 | |
Greg Daniel | c64ee46 | 2017-06-15 16:59:49 -0400 | [diff] [blame] | 1611 | bool SkGpuDevice::wait(int numSemaphores, const GrBackendSemaphore* waitSemaphores) { |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 1612 | ASSERT_SINGLE_OWNER |
| 1613 | |
Greg Daniel | c64ee46 | 2017-06-15 16:59:49 -0400 | [diff] [blame] | 1614 | return fRenderTargetContext->waitOnSemaphores(numSemaphores, waitSemaphores); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1615 | } |
| 1616 | |
| 1617 | /////////////////////////////////////////////////////////////////////////////// |
| 1618 | |
reed | 76033be | 2015-03-14 10:54:31 -0700 | [diff] [blame] | 1619 | SkBaseDevice* SkGpuDevice::onCreateDevice(const CreateInfo& cinfo, const SkPaint*) { |
joshualitt | ce89400 | 2016-01-11 13:29:31 -0800 | [diff] [blame] | 1620 | ASSERT_SINGLE_OWNER |
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 | SkSurfaceProps props(this->surfaceProps().flags(), cinfo.fPixelGeometry); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1623 | |
robertphillips | ca6eafc | 2016-05-17 09:57:46 -0700 | [diff] [blame] | 1624 | // layers are never drawn in repeat modes, so we can request an approx |
hcm | 4396fa5 | 2014-10-27 21:43:30 -0700 | [diff] [blame] | 1625 | // match and ignore any padding. |
robertphillips | ca6eafc | 2016-05-17 09:57:46 -0700 | [diff] [blame] | 1626 | SkBackingFit fit = kNever_TileUsage == cinfo.fTileUsage ? SkBackingFit::kApprox |
| 1627 | : SkBackingFit::kExact; |
bsalomon | afe3005 | 2015-01-16 07:32:33 -0800 | [diff] [blame] | 1628 | |
Brian Osman | d7a5975 | 2019-09-20 11:16:58 -0400 | [diff] [blame] | 1629 | SkASSERT(cinfo.fInfo.colorType() != kRGBA_1010102_SkColorType); |
Brian Osman | 10fc6fd | 2018-03-02 11:01:10 -0500 | [diff] [blame] | 1630 | |
Brian Osman | c248659 | 2019-09-20 13:32:51 -0400 | [diff] [blame] | 1631 | auto rtc = fContext->priv().makeDeferredRenderTargetContextWithFallback( |
Brian Salomon | d628747 | 2019-06-24 15:50:07 -0400 | [diff] [blame] | 1632 | fit, |
| 1633 | cinfo.fInfo.width(), |
| 1634 | cinfo.fInfo.height(), |
Brian Osman | d7a5975 | 2019-09-20 11:16:58 -0400 | [diff] [blame] | 1635 | SkColorTypeToGrColorType(cinfo.fInfo.colorType()), |
Brian Salomon | 4bc0c1f | 2019-09-30 15:12:27 -0400 | [diff] [blame] | 1636 | fRenderTargetContext->colorInfo().refColorSpace(), |
Brian Salomon | d628747 | 2019-06-24 15:50:07 -0400 | [diff] [blame] | 1637 | fRenderTargetContext->numSamples(), |
| 1638 | GrMipMapped::kNo, |
| 1639 | kBottomLeft_GrSurfaceOrigin, |
| 1640 | &props, |
| 1641 | SkBudgeted::kYes, |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 1642 | fRenderTargetContext->asSurfaceProxy()->isProtected() ? GrProtected::kYes |
Brian Salomon | bf6b979 | 2019-08-21 09:38:10 -0400 | [diff] [blame] | 1643 | : GrProtected::kNo); |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1644 | if (!rtc) { |
Mike Klein | e54c75f | 2016-10-13 14:18:09 -0400 | [diff] [blame] | 1645 | return nullptr; |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1646 | } |
robertphillips | ca6eafc | 2016-05-17 09:57:46 -0700 | [diff] [blame] | 1647 | |
| 1648 | // Skia's convention is to only clear a device if it is non-opaque. |
| 1649 | InitContents init = cinfo.fInfo.isOpaque() ? kUninit_InitContents : kClear_InitContents; |
| 1650 | |
Brian Salomon | bf6b979 | 2019-08-21 09:38:10 -0400 | [diff] [blame] | 1651 | return SkGpuDevice::Make(fContext.get(), std::move(rtc), init).release(); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1652 | } |
| 1653 | |
reed | e8f3062 | 2016-03-23 18:59:25 -0700 | [diff] [blame] | 1654 | sk_sp<SkSurface> SkGpuDevice::makeSurface(const SkImageInfo& info, const SkSurfaceProps& props) { |
joshualitt | ce89400 | 2016-01-11 13:29:31 -0800 | [diff] [blame] | 1655 | ASSERT_SINGLE_OWNER |
bsalomon | afe3005 | 2015-01-16 07:32:33 -0800 | [diff] [blame] | 1656 | // TODO: Change the signature of newSurface to take a budgeted parameter. |
bsalomon | 5ec26ae | 2016-02-25 08:33:02 -0800 | [diff] [blame] | 1657 | static const SkBudgeted kBudgeted = SkBudgeted::kNo; |
Hal Canary | 144caf5 | 2016-11-07 17:57:18 -0500 | [diff] [blame] | 1658 | return SkSurface::MakeRenderTarget(fContext.get(), kBudgeted, info, |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 1659 | fRenderTargetContext->numSamples(), |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1660 | fRenderTargetContext->origin(), &props); |
reed@google.com | 76f10a3 | 2014-02-05 15:32:21 +0000 | [diff] [blame] | 1661 | } |
| 1662 | |
senorblanco | 900c367 | 2016-04-27 11:31:23 -0700 | [diff] [blame] | 1663 | SkImageFilterCache* SkGpuDevice::getImageFilterCache() { |
joshualitt | ce89400 | 2016-01-11 13:29:31 -0800 | [diff] [blame] | 1664 | ASSERT_SINGLE_OWNER |
senorblanco | 55b6d8b | 2014-07-30 11:26:46 -0700 | [diff] [blame] | 1665 | // We always return a transient cache, so it is freed after each |
| 1666 | // filter traversal. |
brianosman | 04a44d0 | 2016-09-21 09:46:57 -0700 | [diff] [blame] | 1667 | return SkImageFilterCache::Create(SkImageFilterCache::kDefaultTransientSize); |
senorblanco | 55b6d8b | 2014-07-30 11:26:46 -0700 | [diff] [blame] | 1668 | } |
reed | f037e0b | 2014-10-30 11:34:15 -0700 | [diff] [blame] | 1669 | |