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