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