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