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