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