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