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