skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2011 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #include "SkGpuDevice.h" |
| 9 | |
robertphillips | ccb1b57 | 2015-05-27 11:02:55 -0700 | [diff] [blame] | 10 | #include "GrBlurUtils.h" |
kkinnunen | abcfab4 | 2015-02-22 22:53:44 -0800 | [diff] [blame] | 11 | #include "GrContext.h" |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 12 | #include "GrDrawContext.h" |
robertphillips | 2334fb6 | 2015-06-17 05:43:33 -0700 | [diff] [blame] | 13 | #include "GrFontScaler.h" |
kkinnunen | abcfab4 | 2015-02-22 22:53:44 -0800 | [diff] [blame] | 14 | #include "GrGpu.h" |
| 15 | #include "GrGpuResourcePriv.h" |
robertphillips | 98d709b | 2014-09-02 10:20:50 -0700 | [diff] [blame] | 16 | #include "GrLayerHoister.h" |
robertphillips | 274b4ba | 2014-09-04 07:24:18 -0700 | [diff] [blame] | 17 | #include "GrRecordReplaceDraw.h" |
egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 18 | #include "GrStrokeInfo.h" |
joshualitt | 8f94bb2 | 2015-04-28 07:04:11 -0700 | [diff] [blame] | 19 | #include "GrTextContext.h" |
egdaniel | bbcb38d | 2014-06-19 10:19:29 -0700 | [diff] [blame] | 20 | #include "GrTracing.h" |
robertphillips | 30d7841 | 2014-11-24 09:49:17 -0800 | [diff] [blame] | 21 | #include "SkCanvasPriv.h" |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 22 | #include "SkDrawProcs.h" |
kkinnunen | abcfab4 | 2015-02-22 22:53:44 -0800 | [diff] [blame] | 23 | #include "SkErrorInternals.h" |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 24 | #include "SkGlyphCache.h" |
kkinnunen | abcfab4 | 2015-02-22 22:53:44 -0800 | [diff] [blame] | 25 | #include "SkGrTexturePixelRef.h" |
reed | a85d4d0 | 2015-05-06 12:56:48 -0700 | [diff] [blame] | 26 | #include "SkImage_Base.h" |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 27 | #include "SkImageFilter.h" |
robertphillips | 8236591 | 2014-11-12 09:32:34 -0800 | [diff] [blame] | 28 | #include "SkLayerInfo.h" |
commit-bot@chromium.org | 8213970 | 2014-03-10 22:53:20 +0000 | [diff] [blame] | 29 | #include "SkMaskFilter.h" |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 30 | #include "SkPathEffect.h" |
commit-bot@chromium.org | 145d1c0 | 2014-03-16 19:46:36 +0000 | [diff] [blame] | 31 | #include "SkPicture.h" |
robertphillips | db53990 | 2014-07-01 08:47:04 -0700 | [diff] [blame] | 32 | #include "SkPictureData.h" |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 33 | #include "SkRRect.h" |
kkinnunen | abcfab4 | 2015-02-22 22:53:44 -0800 | [diff] [blame] | 34 | #include "SkRecord.h" |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 35 | #include "SkStroke.h" |
reed@google.com | 76f10a3 | 2014-02-05 15:32:21 +0000 | [diff] [blame] | 36 | #include "SkSurface.h" |
kkinnunen | abcfab4 | 2015-02-22 22:53:44 -0800 | [diff] [blame] | 37 | #include "SkSurface_Gpu.h" |
commit-bot@chromium.org | a7d89c8 | 2014-01-13 14:47:00 +0000 | [diff] [blame] | 38 | #include "SkTLazy.h" |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 39 | #include "SkUtils.h" |
commit-bot@chromium.org | 559a883 | 2014-05-30 10:08:22 +0000 | [diff] [blame] | 40 | #include "SkVertState.h" |
robertphillips | 320c923 | 2014-07-29 06:07:19 -0700 | [diff] [blame] | 41 | #include "SkXfermode.h" |
joshualitt | a61c817 | 2015-08-17 10:51:22 -0700 | [diff] [blame] | 42 | #include "batches/GrRectBatchFactory.h" |
kkinnunen | abcfab4 | 2015-02-22 22:53:44 -0800 | [diff] [blame] | 43 | #include "effects/GrBicubicEffect.h" |
| 44 | #include "effects/GrDashingEffect.h" |
| 45 | #include "effects/GrSimpleTextureEffect.h" |
| 46 | #include "effects/GrTextureDomain.h" |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 47 | |
reed | f037e0b | 2014-10-30 11:34:15 -0700 | [diff] [blame] | 48 | #if SK_SUPPORT_GPU |
| 49 | |
senorblanco | 55b6d8b | 2014-07-30 11:26:46 -0700 | [diff] [blame] | 50 | enum { kDefaultImageFilterCacheSize = 32 * 1024 * 1024 }; |
| 51 | |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 52 | #if 0 |
| 53 | extern bool (*gShouldDrawProc)(); |
joshualitt | 5531d51 | 2014-12-17 15:50:11 -0800 | [diff] [blame] | 54 | #define CHECK_SHOULD_DRAW(draw) \ |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 55 | do { \ |
| 56 | if (gShouldDrawProc && !gShouldDrawProc()) return; \ |
joshualitt | 5531d51 | 2014-12-17 15:50:11 -0800 | [diff] [blame] | 57 | this->prepareDraw(draw); \ |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 58 | } while (0) |
| 59 | #else |
joshualitt | 5531d51 | 2014-12-17 15:50:11 -0800 | [diff] [blame] | 60 | #define CHECK_SHOULD_DRAW(draw) this->prepareDraw(draw) |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 61 | #endif |
| 62 | |
| 63 | // This constant represents the screen alignment criterion in texels for |
| 64 | // requiring texture domain clamping to prevent color bleeding when drawing |
| 65 | // a sub region of a larger source image. |
commit-bot@chromium.org | 4b413c8 | 2013-11-25 19:44:07 +0000 | [diff] [blame] | 66 | #define COLOR_BLEED_TOLERANCE 0.001f |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 67 | |
| 68 | #define DO_DEFERRED_CLEAR() \ |
| 69 | do { \ |
bsalomon | afe3005 | 2015-01-16 07:32:33 -0800 | [diff] [blame] | 70 | if (fNeedClear) { \ |
| 71 | this->clearAll(); \ |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 72 | } \ |
| 73 | } while (false) \ |
| 74 | |
| 75 | /////////////////////////////////////////////////////////////////////////////// |
| 76 | |
| 77 | #define CHECK_FOR_ANNOTATION(paint) \ |
| 78 | do { if (paint.getAnnotation()) { return; } } while (0) |
| 79 | |
| 80 | /////////////////////////////////////////////////////////////////////////////// |
| 81 | |
bsalomon | bcf0a52 | 2014-10-08 08:40:09 -0700 | [diff] [blame] | 82 | // Helper for turning a bitmap into a texture. If the bitmap is GrTexture backed this |
| 83 | // just accesses the backing GrTexture. Otherwise, it creates a cached texture |
| 84 | // representation and releases it in the destructor. |
| 85 | class AutoBitmapTexture : public SkNoncopyable { |
Brian Salomon | 9323b8b | 2014-10-07 15:07:38 -0400 | [diff] [blame] | 86 | public: |
bsalomon | bcf0a52 | 2014-10-08 08:40:09 -0700 | [diff] [blame] | 87 | AutoBitmapTexture() {} |
robertphillips | dbe6074 | 2014-09-30 06:54:17 -0700 | [diff] [blame] | 88 | |
bsalomon | bcf0a52 | 2014-10-08 08:40:09 -0700 | [diff] [blame] | 89 | AutoBitmapTexture(GrContext* context, |
| 90 | const SkBitmap& bitmap, |
| 91 | const GrTextureParams* params, |
| 92 | GrTexture** texture) { |
Brian Salomon | 9323b8b | 2014-10-07 15:07:38 -0400 | [diff] [blame] | 93 | SkASSERT(texture); |
bsalomon | bcf0a52 | 2014-10-08 08:40:09 -0700 | [diff] [blame] | 94 | *texture = this->set(context, bitmap, params); |
Brian Salomon | 9323b8b | 2014-10-07 15:07:38 -0400 | [diff] [blame] | 95 | } |
| 96 | |
bsalomon | bcf0a52 | 2014-10-08 08:40:09 -0700 | [diff] [blame] | 97 | GrTexture* set(GrContext* context, |
Brian Salomon | 9323b8b | 2014-10-07 15:07:38 -0400 | [diff] [blame] | 98 | const SkBitmap& bitmap, |
| 99 | const GrTextureParams* params) { |
bsalomon | bcf0a52 | 2014-10-08 08:40:09 -0700 | [diff] [blame] | 100 | // Either get the texture directly from the bitmap, or else use the cache and |
| 101 | // remember to unref it. |
| 102 | if (GrTexture* bmpTexture = bitmap.getTexture()) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 103 | fTexture.reset(nullptr); |
bsalomon | bcf0a52 | 2014-10-08 08:40:09 -0700 | [diff] [blame] | 104 | return bmpTexture; |
| 105 | } else { |
| 106 | fTexture.reset(GrRefCachedBitmapTexture(context, bitmap, params)); |
| 107 | return fTexture.get(); |
Brian Salomon | 9323b8b | 2014-10-07 15:07:38 -0400 | [diff] [blame] | 108 | } |
Brian Salomon | 9323b8b | 2014-10-07 15:07:38 -0400 | [diff] [blame] | 109 | } |
| 110 | |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 111 | private: |
bsalomon | bcf0a52 | 2014-10-08 08:40:09 -0700 | [diff] [blame] | 112 | SkAutoTUnref<GrTexture> fTexture; |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 113 | }; |
| 114 | |
| 115 | /////////////////////////////////////////////////////////////////////////////// |
| 116 | |
| 117 | struct GrSkDrawProcs : public SkDrawProcs { |
| 118 | public: |
| 119 | GrContext* fContext; |
| 120 | GrTextContext* fTextContext; |
| 121 | GrFontScaler* fFontScaler; // cached in the skia glyphcache |
| 122 | }; |
| 123 | |
| 124 | /////////////////////////////////////////////////////////////////////////////// |
| 125 | |
bsalomon | 74f681d | 2015-06-23 14:38:48 -0700 | [diff] [blame] | 126 | /** Checks that the alpha type is legal and gets constructor flags. Returns false if device creation |
| 127 | should fail. */ |
| 128 | bool SkGpuDevice::CheckAlphaTypeAndGetFlags( |
| 129 | const SkImageInfo* info, SkGpuDevice::InitContents init, unsigned* flags) { |
| 130 | *flags = 0; |
| 131 | if (info) { |
| 132 | switch (info->alphaType()) { |
| 133 | case kPremul_SkAlphaType: |
| 134 | break; |
| 135 | case kOpaque_SkAlphaType: |
| 136 | *flags |= SkGpuDevice::kIsOpaque_Flag; |
| 137 | break; |
| 138 | default: // If it is unpremul or unknown don't try to render |
| 139 | return false; |
| 140 | } |
| 141 | } |
| 142 | if (kClear_InitContents == init) { |
| 143 | *flags |= kNeedClear_Flag; |
| 144 | } |
| 145 | return true; |
| 146 | } |
| 147 | |
| 148 | SkGpuDevice* SkGpuDevice::Create(GrRenderTarget* rt, const SkSurfaceProps* props, |
| 149 | InitContents init) { |
| 150 | return SkGpuDevice::Create(rt, rt->width(), rt->height(), props, init); |
senorblanco | d0d37ca | 2015-04-02 04:54:56 -0700 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | SkGpuDevice* SkGpuDevice::Create(GrRenderTarget* rt, int width, int height, |
bsalomon | 74f681d | 2015-06-23 14:38:48 -0700 | [diff] [blame] | 154 | const SkSurfaceProps* props, InitContents init) { |
bsalomon | afe3005 | 2015-01-16 07:32:33 -0800 | [diff] [blame] | 155 | if (!rt || rt->wasDestroyed()) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 156 | return nullptr; |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 157 | } |
bsalomon | 74f681d | 2015-06-23 14:38:48 -0700 | [diff] [blame] | 158 | unsigned flags; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 159 | if (!CheckAlphaTypeAndGetFlags(nullptr, init, &flags)) { |
| 160 | return nullptr; |
bsalomon | 74f681d | 2015-06-23 14:38:48 -0700 | [diff] [blame] | 161 | } |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 162 | return new SkGpuDevice(rt, width, height, props, flags); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 163 | } |
| 164 | |
bsalomon | 74f681d | 2015-06-23 14:38:48 -0700 | [diff] [blame] | 165 | SkGpuDevice* SkGpuDevice::Create(GrContext* context, SkSurface::Budgeted budgeted, |
| 166 | const SkImageInfo& info, int sampleCount, |
| 167 | const SkSurfaceProps* props, InitContents init) { |
| 168 | unsigned flags; |
| 169 | if (!CheckAlphaTypeAndGetFlags(&info, init, &flags)) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 170 | return nullptr; |
bsalomon | 74f681d | 2015-06-23 14:38:48 -0700 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | SkAutoTUnref<GrRenderTarget> rt(CreateRenderTarget(context, budgeted, info, sampleCount)); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 174 | if (nullptr == rt) { |
| 175 | return nullptr; |
bsalomon | 74f681d | 2015-06-23 14:38:48 -0700 | [diff] [blame] | 176 | } |
| 177 | |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 178 | return new SkGpuDevice(rt, info.width(), info.height(), props, flags); |
bsalomon | 74f681d | 2015-06-23 14:38:48 -0700 | [diff] [blame] | 179 | } |
| 180 | |
senorblanco | d0d37ca | 2015-04-02 04:54:56 -0700 | [diff] [blame] | 181 | SkGpuDevice::SkGpuDevice(GrRenderTarget* rt, int width, int height, |
| 182 | const SkSurfaceProps* props, unsigned flags) |
robertphillips | fcf7829 | 2015-06-19 11:49:52 -0700 | [diff] [blame] | 183 | : INHERITED(SkSurfacePropsCopyOrDefault(props)) |
reed | b2db898 | 2014-11-13 12:41:02 -0800 | [diff] [blame] | 184 | { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 185 | fDrawProcs = nullptr; |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 186 | |
bsalomon | afe3005 | 2015-01-16 07:32:33 -0800 | [diff] [blame] | 187 | fContext = SkRef(rt->getContext()); |
bsalomon | 74f681d | 2015-06-23 14:38:48 -0700 | [diff] [blame] | 188 | fNeedClear = SkToBool(flags & kNeedClear_Flag); |
| 189 | fOpaque = SkToBool(flags & kIsOpaque_Flag); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 190 | |
bsalomon | afe3005 | 2015-01-16 07:32:33 -0800 | [diff] [blame] | 191 | fRenderTarget = SkRef(rt); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 192 | |
bsalomon | 74f681d | 2015-06-23 14:38:48 -0700 | [diff] [blame] | 193 | SkAlphaType at = fOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType; |
| 194 | SkImageInfo info = rt->surfacePriv().info(at).makeWH(width, height); |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 195 | SkPixelRef* pr = new SkGrPixelRef(info, rt); |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame] | 196 | fLegacyBitmap.setInfo(info); |
reed | 89443ab | 2014-06-27 11:34:19 -0700 | [diff] [blame] | 197 | fLegacyBitmap.setPixelRef(pr)->unref(); |
kkinnunen | c6cb56f | 2014-06-24 00:12:27 -0700 | [diff] [blame] | 198 | |
robertphillips | c9a3706 | 2015-09-01 08:34:28 -0700 | [diff] [blame] | 199 | fDrawContext.reset(fContext->drawContext(&this->surfaceProps())); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 200 | } |
| 201 | |
kkinnunen | abcfab4 | 2015-02-22 22:53:44 -0800 | [diff] [blame] | 202 | GrRenderTarget* SkGpuDevice::CreateRenderTarget(GrContext* context, SkSurface::Budgeted budgeted, |
| 203 | const SkImageInfo& origInfo, int sampleCount) { |
commit-bot@chromium.org | 15a1405 | 2014-02-16 00:59:25 +0000 | [diff] [blame] | 204 | if (kUnknown_SkColorType == origInfo.colorType() || |
| 205 | origInfo.width() < 0 || origInfo.height() < 0) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 206 | return nullptr; |
commit-bot@chromium.org | 15a1405 | 2014-02-16 00:59:25 +0000 | [diff] [blame] | 207 | } |
| 208 | |
bsalomon | afe3005 | 2015-01-16 07:32:33 -0800 | [diff] [blame] | 209 | if (!context) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 210 | return nullptr; |
bsalomon | afe3005 | 2015-01-16 07:32:33 -0800 | [diff] [blame] | 211 | } |
| 212 | |
reed | e5ea500 | 2014-09-03 11:54:58 -0700 | [diff] [blame] | 213 | SkColorType ct = origInfo.colorType(); |
| 214 | SkAlphaType at = origInfo.alphaType(); |
reed | e5ea500 | 2014-09-03 11:54:58 -0700 | [diff] [blame] | 215 | if (kRGB_565_SkColorType == ct) { |
| 216 | at = kOpaque_SkAlphaType; // force this setting |
bsalomon | afe3005 | 2015-01-16 07:32:33 -0800 | [diff] [blame] | 217 | } else if (ct != kBGRA_8888_SkColorType && ct != kRGBA_8888_SkColorType) { |
| 218 | // Fall back from whatever ct was to default of kRGBA or kBGRA which is aliased as kN32 |
reed | e5ea500 | 2014-09-03 11:54:58 -0700 | [diff] [blame] | 219 | ct = kN32_SkColorType; |
bsalomon | afe3005 | 2015-01-16 07:32:33 -0800 | [diff] [blame] | 220 | } |
| 221 | if (kOpaque_SkAlphaType != at) { |
| 222 | at = kPremul_SkAlphaType; // force this setting |
commit-bot@chromium.org | 15a1405 | 2014-02-16 00:59:25 +0000 | [diff] [blame] | 223 | } |
reed | e5ea500 | 2014-09-03 11:54:58 -0700 | [diff] [blame] | 224 | const SkImageInfo info = SkImageInfo::Make(origInfo.width(), origInfo.height(), ct, at); |
commit-bot@chromium.org | 15a1405 | 2014-02-16 00:59:25 +0000 | [diff] [blame] | 225 | |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 226 | GrSurfaceDesc desc; |
| 227 | desc.fFlags = kRenderTarget_GrSurfaceFlag; |
commit-bot@chromium.org | 15a1405 | 2014-02-16 00:59:25 +0000 | [diff] [blame] | 228 | desc.fWidth = info.width(); |
| 229 | desc.fHeight = info.height(); |
commit-bot@chromium.org | 3adcc34 | 2014-04-23 19:18:09 +0000 | [diff] [blame] | 230 | desc.fConfig = SkImageInfo2GrPixelConfig(info); |
commit-bot@chromium.org | 15a1405 | 2014-02-16 00:59:25 +0000 | [diff] [blame] | 231 | desc.fSampleCnt = sampleCount; |
bsalomon | d309e7a | 2015-04-30 14:18:54 -0700 | [diff] [blame] | 232 | GrTexture* texture = context->textureProvider()->createTexture( |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 233 | desc, SkToBool(budgeted), nullptr, 0); |
| 234 | if (nullptr == texture) { |
| 235 | return nullptr; |
kkinnunen | abcfab4 | 2015-02-22 22:53:44 -0800 | [diff] [blame] | 236 | } |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 237 | SkASSERT(nullptr != texture->asRenderTarget()); |
kkinnunen | abcfab4 | 2015-02-22 22:53:44 -0800 | [diff] [blame] | 238 | return texture->asRenderTarget(); |
| 239 | } |
commit-bot@chromium.org | 15a1405 | 2014-02-16 00:59:25 +0000 | [diff] [blame] | 240 | |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 241 | SkGpuDevice::~SkGpuDevice() { |
| 242 | if (fDrawProcs) { |
| 243 | delete fDrawProcs; |
| 244 | } |
skia.committer@gmail.com | d2ac07b | 2014-01-25 07:01:49 +0000 | [diff] [blame] | 245 | |
bsalomon | 32d0b3b | 2014-08-29 07:50:23 -0700 | [diff] [blame] | 246 | fRenderTarget->unref(); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 247 | fContext->unref(); |
| 248 | } |
| 249 | |
| 250 | /////////////////////////////////////////////////////////////////////////////// |
| 251 | |
commit-bot@chromium.org | a713f9c | 2014-03-17 21:31:26 +0000 | [diff] [blame] | 252 | bool SkGpuDevice::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes, |
| 253 | int x, int y) { |
| 254 | DO_DEFERRED_CLEAR(); |
| 255 | |
| 256 | // TODO: teach fRenderTarget to take ImageInfo directly to specify the src pixels |
commit-bot@chromium.org | 3adcc34 | 2014-04-23 19:18:09 +0000 | [diff] [blame] | 257 | GrPixelConfig config = SkImageInfo2GrPixelConfig(dstInfo); |
commit-bot@chromium.org | a713f9c | 2014-03-17 21:31:26 +0000 | [diff] [blame] | 258 | if (kUnknown_GrPixelConfig == config) { |
| 259 | return false; |
| 260 | } |
| 261 | |
| 262 | uint32_t flags = 0; |
| 263 | if (kUnpremul_SkAlphaType == dstInfo.alphaType()) { |
| 264 | flags = GrContext::kUnpremul_PixelOpsFlag; |
| 265 | } |
bsalomon | 74f681d | 2015-06-23 14:38:48 -0700 | [diff] [blame] | 266 | return fRenderTarget->readPixels(x, y, dstInfo.width(), dstInfo.height(), config, dstPixels, |
| 267 | dstRowBytes, flags); |
commit-bot@chromium.org | a713f9c | 2014-03-17 21:31:26 +0000 | [diff] [blame] | 268 | } |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 269 | |
commit-bot@chromium.org | 4cd9e21 | 2014-03-07 03:25:16 +0000 | [diff] [blame] | 270 | bool SkGpuDevice::onWritePixels(const SkImageInfo& info, const void* pixels, size_t rowBytes, |
| 271 | int x, int y) { |
| 272 | // TODO: teach fRenderTarget to take ImageInfo directly to specify the src pixels |
commit-bot@chromium.org | 3adcc34 | 2014-04-23 19:18:09 +0000 | [diff] [blame] | 273 | GrPixelConfig config = SkImageInfo2GrPixelConfig(info); |
commit-bot@chromium.org | 4cd9e21 | 2014-03-07 03:25:16 +0000 | [diff] [blame] | 274 | if (kUnknown_GrPixelConfig == config) { |
| 275 | return false; |
| 276 | } |
| 277 | uint32_t flags = 0; |
| 278 | if (kUnpremul_SkAlphaType == info.alphaType()) { |
| 279 | flags = GrContext::kUnpremul_PixelOpsFlag; |
| 280 | } |
| 281 | fRenderTarget->writePixels(x, y, info.width(), info.height(), config, pixels, rowBytes, flags); |
| 282 | |
| 283 | // 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] | 284 | fLegacyBitmap.notifyPixelsChanged(); |
commit-bot@chromium.org | 4cd9e21 | 2014-03-07 03:25:16 +0000 | [diff] [blame] | 285 | |
| 286 | return true; |
| 287 | } |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 288 | |
senorblanco@chromium.org | b7b7eb3 | 2014-03-19 18:24:04 +0000 | [diff] [blame] | 289 | const SkBitmap& SkGpuDevice::onAccessBitmap() { |
| 290 | DO_DEFERRED_CLEAR(); |
reed | 89443ab | 2014-06-27 11:34:19 -0700 | [diff] [blame] | 291 | return fLegacyBitmap; |
senorblanco@chromium.org | b7b7eb3 | 2014-03-19 18:24:04 +0000 | [diff] [blame] | 292 | } |
| 293 | |
reed | 41e010c | 2015-06-09 12:16:53 -0700 | [diff] [blame] | 294 | bool SkGpuDevice::onAccessPixels(SkPixmap* pmap) { |
| 295 | DO_DEFERRED_CLEAR(); |
| 296 | // For compatibility with clients the know we're backed w/ a bitmap, and want to inspect its |
| 297 | // genID. When we can hide/remove that fact, we can eliminate this call to notify. |
| 298 | // ... ugh. |
| 299 | fLegacyBitmap.notifyPixelsChanged(); |
| 300 | return false; |
| 301 | } |
| 302 | |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 303 | void SkGpuDevice::onAttachToCanvas(SkCanvas* canvas) { |
| 304 | INHERITED::onAttachToCanvas(canvas); |
| 305 | |
| 306 | // Canvas promises that this ptr is valid until onDetachFromCanvas is called |
joshualitt | 44701df | 2015-02-23 14:44:57 -0800 | [diff] [blame] | 307 | fClipStack.reset(SkRef(canvas->getClipStack())); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | void SkGpuDevice::onDetachFromCanvas() { |
| 311 | INHERITED::onDetachFromCanvas(); |
joshualitt | 570d2f8 | 2015-02-25 13:19:48 -0800 | [diff] [blame] | 312 | fClip.reset(); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 313 | fClipStack.reset(nullptr); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 314 | } |
| 315 | |
| 316 | // call this every draw call, to ensure that the context reflects our state, |
| 317 | // and not the state from some other canvas/device |
joshualitt | 5531d51 | 2014-12-17 15:50:11 -0800 | [diff] [blame] | 318 | void SkGpuDevice::prepareDraw(const SkDraw& draw) { |
joshualitt | 44701df | 2015-02-23 14:44:57 -0800 | [diff] [blame] | 319 | SkASSERT(fClipStack.get()); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 320 | |
joshualitt | 44701df | 2015-02-23 14:44:57 -0800 | [diff] [blame] | 321 | SkASSERT(draw.fClipStack && draw.fClipStack == fClipStack); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 322 | |
joshualitt | 570d2f8 | 2015-02-25 13:19:48 -0800 | [diff] [blame] | 323 | fClip.setClipStack(fClipStack, &this->getOrigin()); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 324 | |
| 325 | DO_DEFERRED_CLEAR(); |
| 326 | } |
| 327 | |
| 328 | GrRenderTarget* SkGpuDevice::accessRenderTarget() { |
robertphillips | 7156b09 | 2015-05-14 08:54:12 -0700 | [diff] [blame] | 329 | DO_DEFERRED_CLEAR(); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 330 | return fRenderTarget; |
| 331 | } |
| 332 | |
reed | 8eddfb5 | 2014-12-04 07:50:14 -0800 | [diff] [blame] | 333 | void SkGpuDevice::clearAll() { |
| 334 | GrColor color = 0; |
| 335 | GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::clearAll", fContext); |
| 336 | SkIRect rect = SkIRect::MakeWH(this->width(), this->height()); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 337 | fDrawContext->clear(fRenderTarget, &rect, color, true); |
bsalomon | afe3005 | 2015-01-16 07:32:33 -0800 | [diff] [blame] | 338 | fNeedClear = false; |
reed | 8eddfb5 | 2014-12-04 07:50:14 -0800 | [diff] [blame] | 339 | } |
| 340 | |
kkinnunen | abcfab4 | 2015-02-22 22:53:44 -0800 | [diff] [blame] | 341 | void SkGpuDevice::replaceRenderTarget(bool shouldRetainContent) { |
| 342 | // Caller must have accessed the render target, because it knows the rt must be replaced. |
| 343 | SkASSERT(!fNeedClear); |
| 344 | |
| 345 | SkSurface::Budgeted budgeted = |
| 346 | fRenderTarget->resourcePriv().isBudgeted() ? SkSurface::kYes_Budgeted |
| 347 | : SkSurface::kNo_Budgeted; |
| 348 | |
| 349 | SkAutoTUnref<GrRenderTarget> newRT(CreateRenderTarget( |
vbuzinov | dded696 | 2015-06-12 08:59:45 -0700 | [diff] [blame] | 350 | fRenderTarget->getContext(), budgeted, this->imageInfo(), fRenderTarget->desc().fSampleCnt)); |
kkinnunen | abcfab4 | 2015-02-22 22:53:44 -0800 | [diff] [blame] | 351 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 352 | if (nullptr == newRT) { |
kkinnunen | abcfab4 | 2015-02-22 22:53:44 -0800 | [diff] [blame] | 353 | return; |
| 354 | } |
| 355 | |
| 356 | if (shouldRetainContent) { |
| 357 | if (fRenderTarget->wasDestroyed()) { |
| 358 | return; |
| 359 | } |
| 360 | this->context()->copySurface(newRT, fRenderTarget); |
| 361 | } |
| 362 | |
| 363 | SkASSERT(fRenderTarget != newRT); |
| 364 | |
| 365 | fRenderTarget->unref(); |
| 366 | fRenderTarget = newRT.detach(); |
| 367 | |
bsalomon | 74f681d | 2015-06-23 14:38:48 -0700 | [diff] [blame] | 368 | #ifdef SK_DEBUG |
| 369 | SkImageInfo info = fRenderTarget->surfacePriv().info(fOpaque ? kOpaque_SkAlphaType : |
| 370 | kPremul_SkAlphaType); |
| 371 | SkASSERT(info == fLegacyBitmap.info()); |
| 372 | #endif |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 373 | SkPixelRef* pr = new SkGrPixelRef(fLegacyBitmap.info(), fRenderTarget); |
kkinnunen | abcfab4 | 2015-02-22 22:53:44 -0800 | [diff] [blame] | 374 | fLegacyBitmap.setPixelRef(pr)->unref(); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 375 | |
robertphillips | c9a3706 | 2015-09-01 08:34:28 -0700 | [diff] [blame] | 376 | fDrawContext.reset(fRenderTarget->getContext()->drawContext(&this->surfaceProps())); |
kkinnunen | abcfab4 | 2015-02-22 22:53:44 -0800 | [diff] [blame] | 377 | } |
| 378 | |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 379 | /////////////////////////////////////////////////////////////////////////////// |
| 380 | |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 381 | void SkGpuDevice::drawPaint(const SkDraw& draw, const SkPaint& paint) { |
joshualitt | 5531d51 | 2014-12-17 15:50:11 -0800 | [diff] [blame] | 382 | CHECK_SHOULD_DRAW(draw); |
egdaniel | d78a168 | 2014-07-09 10:41:26 -0700 | [diff] [blame] | 383 | GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawPaint", fContext); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 384 | |
| 385 | GrPaint grPaint; |
bsalomon | bed83a6 | 2015-04-15 14:18:34 -0700 | [diff] [blame] | 386 | if (!SkPaint2GrPaint(this->context(), fRenderTarget, paint, *draw.fMatrix, true, &grPaint)) { |
| 387 | return; |
| 388 | } |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 389 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 390 | fDrawContext->drawPaint(fRenderTarget, fClip, grPaint, *draw.fMatrix); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 391 | } |
| 392 | |
| 393 | // must be in SkCanvas::PointMode order |
| 394 | static const GrPrimitiveType gPointMode2PrimtiveType[] = { |
| 395 | kPoints_GrPrimitiveType, |
| 396 | kLines_GrPrimitiveType, |
| 397 | kLineStrip_GrPrimitiveType |
| 398 | }; |
| 399 | |
ethannicholas | 330bb95 | 2015-07-17 06:44:02 -0700 | [diff] [blame] | 400 | // suppress antialiasing on axis-aligned integer-coordinate lines |
| 401 | static bool needs_antialiasing(SkCanvas::PointMode mode, size_t count, const SkPoint pts[]) { |
| 402 | if (mode == SkCanvas::PointMode::kPoints_PointMode) { |
| 403 | return false; |
| 404 | } |
| 405 | if (count == 2) { |
| 406 | // We do not antialias as long as the primary axis of the line is integer-aligned, even if |
| 407 | // the other coordinates are not. This does mean the two end pixels of the line will be |
| 408 | // sharp even when they shouldn't be, but turning antialiasing on (as things stand |
| 409 | // currently) means that the line will turn into a two-pixel-wide blur. While obviously a |
| 410 | // more complete fix is possible down the road, for the time being we accept the error on |
| 411 | // the two end pixels as being the lesser of two evils. |
| 412 | if (pts[0].fX == pts[1].fX) { |
| 413 | return ((int) pts[0].fX) != pts[0].fX; |
| 414 | } |
| 415 | if (pts[0].fY == pts[1].fY) { |
| 416 | return ((int) pts[0].fY) != pts[0].fY; |
| 417 | } |
| 418 | } |
| 419 | return true; |
| 420 | } |
| 421 | |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 422 | void SkGpuDevice::drawPoints(const SkDraw& draw, SkCanvas::PointMode mode, |
| 423 | size_t count, const SkPoint pts[], const SkPaint& paint) { |
| 424 | CHECK_FOR_ANNOTATION(paint); |
joshualitt | 5531d51 | 2014-12-17 15:50:11 -0800 | [diff] [blame] | 425 | CHECK_SHOULD_DRAW(draw); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 426 | |
| 427 | SkScalar width = paint.getStrokeWidth(); |
| 428 | if (width < 0) { |
| 429 | return; |
| 430 | } |
| 431 | |
commit-bot@chromium.org | 628ed0b | 2014-05-19 14:32:49 +0000 | [diff] [blame] | 432 | if (paint.getPathEffect() && 2 == count && SkCanvas::kLines_PointMode == mode) { |
egdaniel | e61c411 | 2014-06-12 10:24:21 -0700 | [diff] [blame] | 433 | GrStrokeInfo strokeInfo(paint, SkPaint::kStroke_Style); |
| 434 | GrPaint grPaint; |
bsalomon | bed83a6 | 2015-04-15 14:18:34 -0700 | [diff] [blame] | 435 | if (!SkPaint2GrPaint(this->context(), fRenderTarget, paint, *draw.fMatrix, true, |
| 436 | &grPaint)) { |
| 437 | return; |
| 438 | } |
egdaniel | e61c411 | 2014-06-12 10:24:21 -0700 | [diff] [blame] | 439 | SkPath path; |
jvanverth | b3eb687 | 2014-10-24 07:12:51 -0700 | [diff] [blame] | 440 | path.setIsVolatile(true); |
egdaniel | e61c411 | 2014-06-12 10:24:21 -0700 | [diff] [blame] | 441 | path.moveTo(pts[0]); |
| 442 | path.lineTo(pts[1]); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 443 | fDrawContext->drawPath(fRenderTarget, fClip, grPaint, *draw.fMatrix, path, strokeInfo); |
egdaniel | e61c411 | 2014-06-12 10:24:21 -0700 | [diff] [blame] | 444 | return; |
commit-bot@chromium.org | 628ed0b | 2014-05-19 14:32:49 +0000 | [diff] [blame] | 445 | } |
| 446 | |
ethannicholas | 330bb95 | 2015-07-17 06:44:02 -0700 | [diff] [blame] | 447 | // 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] | 448 | // else we let the SkDraw call our drawPath() |
ethannicholas | 330bb95 | 2015-07-17 06:44:02 -0700 | [diff] [blame] | 449 | if (width > 0 || paint.getPathEffect() || paint.getMaskFilter() || |
| 450 | (paint.isAntiAlias() && needs_antialiasing(mode, count, pts))) { |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 451 | draw.drawPoints(mode, count, pts, paint, true); |
| 452 | return; |
| 453 | } |
| 454 | |
| 455 | GrPaint grPaint; |
bsalomon | bed83a6 | 2015-04-15 14:18:34 -0700 | [diff] [blame] | 456 | if (!SkPaint2GrPaint(this->context(), fRenderTarget, paint, *draw.fMatrix, true, &grPaint)) { |
| 457 | return; |
| 458 | } |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 459 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 460 | fDrawContext->drawVertices(fRenderTarget, |
| 461 | fClip, |
| 462 | grPaint, |
| 463 | *draw.fMatrix, |
| 464 | gPointMode2PrimtiveType[mode], |
| 465 | SkToS32(count), |
| 466 | (SkPoint*)pts, |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 467 | nullptr, |
| 468 | nullptr, |
| 469 | nullptr, |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 470 | 0); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 471 | } |
| 472 | |
| 473 | /////////////////////////////////////////////////////////////////////////////// |
| 474 | |
| 475 | void SkGpuDevice::drawRect(const SkDraw& draw, const SkRect& rect, |
| 476 | const SkPaint& paint) { |
egdaniel | bbcb38d | 2014-06-19 10:19:29 -0700 | [diff] [blame] | 477 | GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawRect", fContext); |
| 478 | |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 479 | CHECK_FOR_ANNOTATION(paint); |
joshualitt | 5531d51 | 2014-12-17 15:50:11 -0800 | [diff] [blame] | 480 | CHECK_SHOULD_DRAW(draw); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 481 | |
| 482 | bool doStroke = paint.getStyle() != SkPaint::kFill_Style; |
| 483 | SkScalar width = paint.getStrokeWidth(); |
| 484 | |
| 485 | /* |
| 486 | We have special code for hairline strokes, miter-strokes, bevel-stroke |
| 487 | and fills. Anything else we just call our path code. |
| 488 | */ |
| 489 | bool usePath = doStroke && width > 0 && |
| 490 | (paint.getStrokeJoin() == SkPaint::kRound_Join || |
| 491 | (paint.getStrokeJoin() == SkPaint::kBevel_Join && rect.isEmpty())); |
egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 492 | |
robertphillips | d8aa59d | 2015-08-05 09:07:12 -0700 | [diff] [blame] | 493 | // a few other reasons we might need to call drawPath... |
| 494 | if (paint.getMaskFilter() || |
| 495 | paint.getStyle() == SkPaint::kStrokeAndFill_Style) { // we can't both stroke and fill rects |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 496 | usePath = true; |
| 497 | } |
egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 498 | |
joshualitt | 5531d51 | 2014-12-17 15:50:11 -0800 | [diff] [blame] | 499 | if (!usePath && paint.isAntiAlias() && !draw.fMatrix->rectStaysRect()) { |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 500 | usePath = true; |
| 501 | } |
| 502 | |
egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 503 | GrStrokeInfo strokeInfo(paint); |
| 504 | |
| 505 | const SkPathEffect* pe = paint.getPathEffect(); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 506 | if (!usePath && pe && !strokeInfo.isDashed()) { |
egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 507 | usePath = true; |
| 508 | } |
| 509 | |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 510 | if (usePath) { |
| 511 | SkPath path; |
jvanverth | b3eb687 | 2014-10-24 07:12:51 -0700 | [diff] [blame] | 512 | path.setIsVolatile(true); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 513 | path.addRect(rect); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 514 | this->drawPath(draw, path, paint, nullptr, true); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 515 | return; |
| 516 | } |
| 517 | |
| 518 | GrPaint grPaint; |
bsalomon | bed83a6 | 2015-04-15 14:18:34 -0700 | [diff] [blame] | 519 | if (!SkPaint2GrPaint(this->context(), fRenderTarget, paint, *draw.fMatrix, true, &grPaint)) { |
| 520 | return; |
| 521 | } |
Mike Klein | 744fb73 | 2014-06-23 15:13:26 -0400 | [diff] [blame] | 522 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 523 | fDrawContext->drawRect(fRenderTarget, fClip, grPaint, *draw.fMatrix, rect, &strokeInfo); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 524 | } |
| 525 | |
| 526 | /////////////////////////////////////////////////////////////////////////////// |
| 527 | |
| 528 | void SkGpuDevice::drawRRect(const SkDraw& draw, const SkRRect& rect, |
joshualitt | 5531d51 | 2014-12-17 15:50:11 -0800 | [diff] [blame] | 529 | const SkPaint& paint) { |
egdaniel | d78a168 | 2014-07-09 10:41:26 -0700 | [diff] [blame] | 530 | GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawRRect", fContext); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 531 | CHECK_FOR_ANNOTATION(paint); |
joshualitt | 5531d51 | 2014-12-17 15:50:11 -0800 | [diff] [blame] | 532 | CHECK_SHOULD_DRAW(draw); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 533 | |
commit-bot@chromium.org | 8213970 | 2014-03-10 22:53:20 +0000 | [diff] [blame] | 534 | GrPaint grPaint; |
bsalomon | bed83a6 | 2015-04-15 14:18:34 -0700 | [diff] [blame] | 535 | if (!SkPaint2GrPaint(this->context(), fRenderTarget, paint, *draw.fMatrix, true, &grPaint)) { |
| 536 | return; |
| 537 | } |
Mike Klein | 744fb73 | 2014-06-23 15:13:26 -0400 | [diff] [blame] | 538 | |
egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 539 | GrStrokeInfo strokeInfo(paint); |
commit-bot@chromium.org | 8213970 | 2014-03-10 22:53:20 +0000 | [diff] [blame] | 540 | if (paint.getMaskFilter()) { |
| 541 | // try to hit the fast path for drawing filtered round rects |
| 542 | |
| 543 | SkRRect devRRect; |
joshualitt | 5531d51 | 2014-12-17 15:50:11 -0800 | [diff] [blame] | 544 | if (rect.transform(*draw.fMatrix, &devRRect)) { |
commit-bot@chromium.org | 8213970 | 2014-03-10 22:53:20 +0000 | [diff] [blame] | 545 | if (devRRect.allCornersCircular()) { |
| 546 | SkRect maskRect; |
| 547 | if (paint.getMaskFilter()->canFilterMaskGPU(devRRect.rect(), |
joshualitt | 5531d51 | 2014-12-17 15:50:11 -0800 | [diff] [blame] | 548 | draw.fClip->getBounds(), |
| 549 | *draw.fMatrix, |
| 550 | &maskRect)) { |
commit-bot@chromium.org | 8213970 | 2014-03-10 22:53:20 +0000 | [diff] [blame] | 551 | SkIRect finalIRect; |
| 552 | maskRect.roundOut(&finalIRect); |
| 553 | if (draw.fClip->quickReject(finalIRect)) { |
| 554 | // clipped out |
| 555 | return; |
| 556 | } |
robertphillips | ff0ca5e | 2015-07-22 11:54:44 -0700 | [diff] [blame] | 557 | if (paint.getMaskFilter()->directFilterRRectMaskGPU(fContext->textureProvider(), |
| 558 | fDrawContext, |
joshualitt | 25d9c15 | 2015-02-18 12:29:52 -0800 | [diff] [blame] | 559 | fRenderTarget, |
| 560 | &grPaint, |
joshualitt | 570d2f8 | 2015-02-25 13:19:48 -0800 | [diff] [blame] | 561 | fClip, |
joshualitt | 5531d51 | 2014-12-17 15:50:11 -0800 | [diff] [blame] | 562 | *draw.fMatrix, |
kkinnunen | d156d36 | 2015-05-18 22:23:54 -0700 | [diff] [blame] | 563 | strokeInfo, |
egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 564 | devRRect)) { |
commit-bot@chromium.org | 8213970 | 2014-03-10 22:53:20 +0000 | [diff] [blame] | 565 | return; |
| 566 | } |
| 567 | } |
| 568 | |
| 569 | } |
| 570 | } |
| 571 | |
| 572 | } |
| 573 | |
egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 574 | bool usePath = false; |
| 575 | |
| 576 | if (paint.getMaskFilter()) { |
| 577 | usePath = true; |
| 578 | } else { |
| 579 | const SkPathEffect* pe = paint.getPathEffect(); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 580 | if (pe && !strokeInfo.isDashed()) { |
egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 581 | usePath = true; |
| 582 | } |
| 583 | } |
| 584 | |
| 585 | |
| 586 | if (usePath) { |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 587 | SkPath path; |
jvanverth | b3eb687 | 2014-10-24 07:12:51 -0700 | [diff] [blame] | 588 | path.setIsVolatile(true); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 589 | path.addRRect(rect); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 590 | this->drawPath(draw, path, paint, nullptr, true); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 591 | return; |
| 592 | } |
Mike Klein | 744fb73 | 2014-06-23 15:13:26 -0400 | [diff] [blame] | 593 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 594 | fDrawContext->drawRRect(fRenderTarget, fClip, grPaint, *draw.fMatrix, rect, strokeInfo); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 595 | } |
| 596 | |
commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 597 | void SkGpuDevice::drawDRRect(const SkDraw& draw, const SkRRect& outer, |
joshualitt | 5531d51 | 2014-12-17 15:50:11 -0800 | [diff] [blame] | 598 | const SkRRect& inner, const SkPaint& paint) { |
commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 599 | SkStrokeRec stroke(paint); |
| 600 | if (stroke.isFillStyle()) { |
| 601 | |
| 602 | CHECK_FOR_ANNOTATION(paint); |
joshualitt | 5531d51 | 2014-12-17 15:50:11 -0800 | [diff] [blame] | 603 | CHECK_SHOULD_DRAW(draw); |
commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 604 | |
| 605 | GrPaint grPaint; |
bsalomon | bed83a6 | 2015-04-15 14:18:34 -0700 | [diff] [blame] | 606 | if (!SkPaint2GrPaint(this->context(), fRenderTarget, paint, *draw.fMatrix, true, |
| 607 | &grPaint)) { |
| 608 | return; |
| 609 | } |
commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 610 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 611 | if (nullptr == paint.getMaskFilter() && nullptr == paint.getPathEffect()) { |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 612 | fDrawContext->drawDRRect(fRenderTarget, fClip, grPaint, *draw.fMatrix, outer, inner); |
commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 613 | return; |
| 614 | } |
| 615 | } |
| 616 | |
| 617 | SkPath path; |
jvanverth | b3eb687 | 2014-10-24 07:12:51 -0700 | [diff] [blame] | 618 | path.setIsVolatile(true); |
commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 619 | path.addRRect(outer); |
| 620 | path.addRRect(inner); |
| 621 | path.setFillType(SkPath::kEvenOdd_FillType); |
| 622 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 623 | this->drawPath(draw, path, paint, nullptr, true); |
commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 624 | } |
| 625 | |
| 626 | |
commit-bot@chromium.org | 8213970 | 2014-03-10 22:53:20 +0000 | [diff] [blame] | 627 | ///////////////////////////////////////////////////////////////////////////// |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 628 | |
| 629 | void SkGpuDevice::drawOval(const SkDraw& draw, const SkRect& oval, |
| 630 | const SkPaint& paint) { |
egdaniel | d78a168 | 2014-07-09 10:41:26 -0700 | [diff] [blame] | 631 | GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawOval", fContext); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 632 | CHECK_FOR_ANNOTATION(paint); |
joshualitt | 5531d51 | 2014-12-17 15:50:11 -0800 | [diff] [blame] | 633 | CHECK_SHOULD_DRAW(draw); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 634 | |
egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 635 | GrStrokeInfo strokeInfo(paint); |
| 636 | |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 637 | bool usePath = false; |
| 638 | // some basic reasons we might need to call drawPath... |
egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 639 | if (paint.getMaskFilter()) { |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 640 | usePath = true; |
egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 641 | } else { |
| 642 | const SkPathEffect* pe = paint.getPathEffect(); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 643 | if (pe && !strokeInfo.isDashed()) { |
egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 644 | usePath = true; |
| 645 | } |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 646 | } |
| 647 | |
| 648 | if (usePath) { |
| 649 | SkPath path; |
jvanverth | b3eb687 | 2014-10-24 07:12:51 -0700 | [diff] [blame] | 650 | path.setIsVolatile(true); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 651 | path.addOval(oval); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 652 | this->drawPath(draw, path, paint, nullptr, true); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 653 | return; |
| 654 | } |
| 655 | |
| 656 | GrPaint grPaint; |
bsalomon | bed83a6 | 2015-04-15 14:18:34 -0700 | [diff] [blame] | 657 | if (!SkPaint2GrPaint(this->context(), fRenderTarget, paint, *draw.fMatrix, true, &grPaint)) { |
| 658 | return; |
| 659 | } |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 660 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 661 | fDrawContext->drawOval(fRenderTarget, fClip, grPaint, *draw.fMatrix, oval, strokeInfo); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 662 | } |
| 663 | |
| 664 | #include "SkMaskFilter.h" |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 665 | |
| 666 | /////////////////////////////////////////////////////////////////////////////// |
| 667 | |
robertphillips | ccb1b57 | 2015-05-27 11:02:55 -0700 | [diff] [blame] | 668 | static SkBitmap wrap_texture(GrTexture* texture, int width, int height) { |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 669 | SkBitmap result; |
senorblanco | d0d37ca | 2015-04-02 04:54:56 -0700 | [diff] [blame] | 670 | result.setInfo(SkImageInfo::MakeN32Premul(width, height)); |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 671 | result.setPixelRef(new SkGrPixelRef(result.info(), texture))->unref(); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 672 | return result; |
| 673 | } |
| 674 | |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 675 | void SkGpuDevice::drawPath(const SkDraw& draw, const SkPath& origSrcPath, |
| 676 | const SkPaint& paint, const SkMatrix* prePathMatrix, |
| 677 | bool pathIsMutable) { |
| 678 | CHECK_FOR_ANNOTATION(paint); |
joshualitt | 5531d51 | 2014-12-17 15:50:11 -0800 | [diff] [blame] | 679 | CHECK_SHOULD_DRAW(draw); |
egdaniel | d78a168 | 2014-07-09 10:41:26 -0700 | [diff] [blame] | 680 | GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawPath", fContext); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 681 | |
robertphillips | ccb1b57 | 2015-05-27 11:02:55 -0700 | [diff] [blame] | 682 | GrBlurUtils::drawPathWithMaskFilter(fContext, fDrawContext, fRenderTarget, |
| 683 | fClip, origSrcPath, paint, |
| 684 | *draw.fMatrix, prePathMatrix, |
| 685 | draw.fClip->getBounds(), pathIsMutable); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 686 | } |
| 687 | |
| 688 | static const int kBmpSmallTileSize = 1 << 10; |
| 689 | |
| 690 | static inline int get_tile_count(const SkIRect& srcRect, int tileSize) { |
| 691 | int tilesX = (srcRect.fRight / tileSize) - (srcRect.fLeft / tileSize) + 1; |
| 692 | int tilesY = (srcRect.fBottom / tileSize) - (srcRect.fTop / tileSize) + 1; |
| 693 | return tilesX * tilesY; |
| 694 | } |
| 695 | |
| 696 | static int determine_tile_size(const SkBitmap& bitmap, const SkIRect& src, int maxTileSize) { |
| 697 | if (maxTileSize <= kBmpSmallTileSize) { |
| 698 | return maxTileSize; |
| 699 | } |
| 700 | |
| 701 | size_t maxTileTotalTileSize = get_tile_count(src, maxTileSize); |
| 702 | size_t smallTotalTileSize = get_tile_count(src, kBmpSmallTileSize); |
| 703 | |
| 704 | maxTileTotalTileSize *= maxTileSize * maxTileSize; |
| 705 | smallTotalTileSize *= kBmpSmallTileSize * kBmpSmallTileSize; |
| 706 | |
| 707 | if (maxTileTotalTileSize > 2 * smallTotalTileSize) { |
| 708 | return kBmpSmallTileSize; |
| 709 | } else { |
| 710 | return maxTileSize; |
| 711 | } |
| 712 | } |
| 713 | |
| 714 | // Given a bitmap, an optional src rect, and a context with a clip and matrix determine what |
| 715 | // pixels from the bitmap are necessary. |
bsalomon | 74f681d | 2015-06-23 14:38:48 -0700 | [diff] [blame] | 716 | static void determine_clipped_src_rect(const GrRenderTarget* rt, |
joshualitt | 570d2f8 | 2015-02-25 13:19:48 -0800 | [diff] [blame] | 717 | const GrClip& clip, |
joshualitt | 5531d51 | 2014-12-17 15:50:11 -0800 | [diff] [blame] | 718 | const SkMatrix& viewMatrix, |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 719 | const SkBitmap& bitmap, |
| 720 | const SkRect* srcRectPtr, |
| 721 | SkIRect* clippedSrcIRect) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 722 | clip.getConservativeBounds(rt, clippedSrcIRect, nullptr); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 723 | SkMatrix inv; |
joshualitt | 5531d51 | 2014-12-17 15:50:11 -0800 | [diff] [blame] | 724 | if (!viewMatrix.invert(&inv)) { |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 725 | clippedSrcIRect->setEmpty(); |
| 726 | return; |
| 727 | } |
| 728 | SkRect clippedSrcRect = SkRect::Make(*clippedSrcIRect); |
| 729 | inv.mapRect(&clippedSrcRect); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 730 | if (srcRectPtr) { |
commit-bot@chromium.org | a7d89c8 | 2014-01-13 14:47:00 +0000 | [diff] [blame] | 731 | // we've setup src space 0,0 to map to the top left of the src rect. |
| 732 | clippedSrcRect.offset(srcRectPtr->fLeft, srcRectPtr->fTop); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 733 | if (!clippedSrcRect.intersect(*srcRectPtr)) { |
| 734 | clippedSrcIRect->setEmpty(); |
| 735 | return; |
| 736 | } |
| 737 | } |
| 738 | clippedSrcRect.roundOut(clippedSrcIRect); |
| 739 | SkIRect bmpBounds = SkIRect::MakeWH(bitmap.width(), bitmap.height()); |
| 740 | if (!clippedSrcIRect->intersect(bmpBounds)) { |
| 741 | clippedSrcIRect->setEmpty(); |
| 742 | } |
| 743 | } |
| 744 | |
| 745 | bool SkGpuDevice::shouldTileBitmap(const SkBitmap& bitmap, |
joshualitt | 5531d51 | 2014-12-17 15:50:11 -0800 | [diff] [blame] | 746 | const SkMatrix& viewMatrix, |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 747 | const GrTextureParams& params, |
| 748 | const SkRect* srcRectPtr, |
| 749 | int maxTileSize, |
| 750 | int* tileSize, |
| 751 | SkIRect* clippedSrcRect) const { |
| 752 | // if bitmap is explictly texture backed then just use the texture |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 753 | if (bitmap.getTexture()) { |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 754 | return false; |
| 755 | } |
| 756 | |
| 757 | // if it's larger than the max tile size, then we have no choice but tiling. |
| 758 | if (bitmap.width() > maxTileSize || bitmap.height() > maxTileSize) { |
bsalomon | 74f681d | 2015-06-23 14:38:48 -0700 | [diff] [blame] | 759 | determine_clipped_src_rect(fRenderTarget, fClip, viewMatrix, bitmap, |
joshualitt | 570d2f8 | 2015-02-25 13:19:48 -0800 | [diff] [blame] | 760 | srcRectPtr, clippedSrcRect); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 761 | *tileSize = determine_tile_size(bitmap, *clippedSrcRect, maxTileSize); |
| 762 | return true; |
| 763 | } |
| 764 | |
| 765 | if (bitmap.width() * bitmap.height() < 4 * kBmpSmallTileSize * kBmpSmallTileSize) { |
| 766 | return false; |
| 767 | } |
| 768 | |
| 769 | // if the entire texture is already in our cache then no reason to tile it |
| 770 | if (GrIsBitmapInCache(fContext, bitmap, ¶ms)) { |
| 771 | return false; |
| 772 | } |
| 773 | |
| 774 | // At this point we know we could do the draw by uploading the entire bitmap |
| 775 | // as a texture. However, if the texture would be large compared to the |
| 776 | // cache size and we don't require most of it for this draw then tile to |
| 777 | // reduce the amount of upload and cache spill. |
| 778 | |
| 779 | // assumption here is that sw bitmap size is a good proxy for its size as |
| 780 | // a texture |
| 781 | size_t bmpSize = bitmap.getSize(); |
| 782 | size_t cacheSize; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 783 | fContext->getResourceCacheLimits(nullptr, &cacheSize); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 784 | if (bmpSize < cacheSize / 2) { |
| 785 | return false; |
| 786 | } |
| 787 | |
| 788 | // Figure out how much of the src we will need based on the src rect and clipping. |
bsalomon | 74f681d | 2015-06-23 14:38:48 -0700 | [diff] [blame] | 789 | determine_clipped_src_rect(fRenderTarget, fClip, viewMatrix, bitmap, srcRectPtr, |
joshualitt | 25d9c15 | 2015-02-18 12:29:52 -0800 | [diff] [blame] | 790 | clippedSrcRect); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 791 | *tileSize = kBmpSmallTileSize; // already know whole bitmap fits in one max sized tile. |
| 792 | size_t usedTileBytes = get_tile_count(*clippedSrcRect, kBmpSmallTileSize) * |
| 793 | kBmpSmallTileSize * kBmpSmallTileSize; |
| 794 | |
| 795 | return usedTileBytes < 2 * bmpSize; |
| 796 | } |
| 797 | |
commit-bot@chromium.org | a7d89c8 | 2014-01-13 14:47:00 +0000 | [diff] [blame] | 798 | void SkGpuDevice::drawBitmap(const SkDraw& origDraw, |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 799 | const SkBitmap& bitmap, |
| 800 | const SkMatrix& m, |
| 801 | const SkPaint& paint) { |
commit-bot@chromium.org | a7d89c8 | 2014-01-13 14:47:00 +0000 | [diff] [blame] | 802 | SkMatrix concat; |
| 803 | SkTCopyOnFirstWrite<SkDraw> draw(origDraw); |
| 804 | if (!m.isIdentity()) { |
| 805 | concat.setConcat(*draw->fMatrix, m); |
| 806 | draw.writable()->fMatrix = &concat; |
| 807 | } |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 808 | this->drawBitmapCommon(*draw, bitmap, nullptr, nullptr, paint, SkCanvas::kStrict_SrcRectConstraint); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 809 | } |
| 810 | |
commit-bot@chromium.org | dec6150 | 2013-12-02 22:22:35 +0000 | [diff] [blame] | 811 | // 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] | 812 | // 'clamp'. 'offset' is adjusted to remain positioned over the top-left corner |
| 813 | // of 'iRect' for all possible outsets/clamps. |
commit-bot@chromium.org | dec6150 | 2013-12-02 22:22:35 +0000 | [diff] [blame] | 814 | static inline void clamped_outset_with_offset(SkIRect* iRect, |
| 815 | int outset, |
| 816 | SkPoint* offset, |
| 817 | const SkIRect& clamp) { |
| 818 | iRect->outset(outset, outset); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 819 | |
commit-bot@chromium.org | dec6150 | 2013-12-02 22:22:35 +0000 | [diff] [blame] | 820 | int leftClampDelta = clamp.fLeft - iRect->fLeft; |
| 821 | if (leftClampDelta > 0) { |
| 822 | offset->fX -= outset - leftClampDelta; |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 823 | iRect->fLeft = clamp.fLeft; |
| 824 | } else { |
commit-bot@chromium.org | dec6150 | 2013-12-02 22:22:35 +0000 | [diff] [blame] | 825 | offset->fX -= outset; |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 826 | } |
commit-bot@chromium.org | dec6150 | 2013-12-02 22:22:35 +0000 | [diff] [blame] | 827 | |
| 828 | int topClampDelta = clamp.fTop - iRect->fTop; |
| 829 | if (topClampDelta > 0) { |
| 830 | offset->fY -= outset - topClampDelta; |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 831 | iRect->fTop = clamp.fTop; |
| 832 | } else { |
commit-bot@chromium.org | dec6150 | 2013-12-02 22:22:35 +0000 | [diff] [blame] | 833 | offset->fY -= outset; |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 834 | } |
| 835 | |
| 836 | if (iRect->fRight > clamp.fRight) { |
| 837 | iRect->fRight = clamp.fRight; |
| 838 | } |
| 839 | if (iRect->fBottom > clamp.fBottom) { |
| 840 | iRect->fBottom = clamp.fBottom; |
| 841 | } |
| 842 | } |
| 843 | |
commit-bot@chromium.org | a17773f | 2014-05-09 13:53:38 +0000 | [diff] [blame] | 844 | static bool has_aligned_samples(const SkRect& srcRect, |
| 845 | const SkRect& transformedRect) { |
| 846 | // detect pixel disalignment |
| 847 | if (SkScalarAbs(SkScalarRoundToScalar(transformedRect.left()) - |
| 848 | transformedRect.left()) < COLOR_BLEED_TOLERANCE && |
| 849 | SkScalarAbs(SkScalarRoundToScalar(transformedRect.top()) - |
| 850 | transformedRect.top()) < COLOR_BLEED_TOLERANCE && |
| 851 | SkScalarAbs(transformedRect.width() - srcRect.width()) < |
| 852 | COLOR_BLEED_TOLERANCE && |
| 853 | SkScalarAbs(transformedRect.height() - srcRect.height()) < |
| 854 | COLOR_BLEED_TOLERANCE) { |
| 855 | return true; |
| 856 | } |
| 857 | return false; |
| 858 | } |
| 859 | |
| 860 | static bool may_color_bleed(const SkRect& srcRect, |
| 861 | const SkRect& transformedRect, |
robertphillips | 1accc4c | 2015-07-20 10:22:29 -0700 | [diff] [blame] | 862 | const SkMatrix& m, |
| 863 | bool isMSAA) { |
commit-bot@chromium.org | a17773f | 2014-05-09 13:53:38 +0000 | [diff] [blame] | 864 | // Only gets called if has_aligned_samples returned false. |
| 865 | // So we can assume that sampling is axis aligned but not texel aligned. |
| 866 | SkASSERT(!has_aligned_samples(srcRect, transformedRect)); |
| 867 | SkRect innerSrcRect(srcRect), innerTransformedRect, |
| 868 | outerTransformedRect(transformedRect); |
robertphillips | 1accc4c | 2015-07-20 10:22:29 -0700 | [diff] [blame] | 869 | if (isMSAA) { |
| 870 | innerSrcRect.inset(SK_Scalar1, SK_Scalar1); |
| 871 | } else { |
| 872 | innerSrcRect.inset(SK_ScalarHalf, SK_ScalarHalf); |
| 873 | } |
commit-bot@chromium.org | a17773f | 2014-05-09 13:53:38 +0000 | [diff] [blame] | 874 | m.mapRect(&innerTransformedRect, innerSrcRect); |
| 875 | |
| 876 | // The gap between outerTransformedRect and innerTransformedRect |
| 877 | // represents the projection of the source border area, which is |
| 878 | // problematic for color bleeding. We must check whether any |
| 879 | // destination pixels sample the border area. |
| 880 | outerTransformedRect.inset(COLOR_BLEED_TOLERANCE, COLOR_BLEED_TOLERANCE); |
| 881 | innerTransformedRect.outset(COLOR_BLEED_TOLERANCE, COLOR_BLEED_TOLERANCE); |
| 882 | SkIRect outer, inner; |
| 883 | outerTransformedRect.round(&outer); |
| 884 | innerTransformedRect.round(&inner); |
| 885 | // If the inner and outer rects round to the same result, it means the |
| 886 | // border does not overlap any pixel centers. Yay! |
| 887 | return inner != outer; |
| 888 | } |
| 889 | |
| 890 | static bool needs_texture_domain(const SkBitmap& bitmap, |
| 891 | const SkRect& srcRect, |
| 892 | GrTextureParams ¶ms, |
| 893 | const SkMatrix& contextMatrix, |
robertphillips | 1accc4c | 2015-07-20 10:22:29 -0700 | [diff] [blame] | 894 | bool bicubic, |
| 895 | bool isMSAA) { |
commit-bot@chromium.org | a17773f | 2014-05-09 13:53:38 +0000 | [diff] [blame] | 896 | bool needsTextureDomain = false; |
senorblanco | d0d37ca | 2015-04-02 04:54:56 -0700 | [diff] [blame] | 897 | GrTexture* tex = bitmap.getTexture(); |
| 898 | int width = tex ? tex->width() : bitmap.width(); |
| 899 | int height = tex ? tex->height() : bitmap.height(); |
commit-bot@chromium.org | a17773f | 2014-05-09 13:53:38 +0000 | [diff] [blame] | 900 | |
| 901 | if (bicubic || params.filterMode() != GrTextureParams::kNone_FilterMode) { |
| 902 | // Need texture domain if drawing a sub rect |
senorblanco | d0d37ca | 2015-04-02 04:54:56 -0700 | [diff] [blame] | 903 | needsTextureDomain = srcRect.width() < width || |
| 904 | srcRect.height() < height; |
commit-bot@chromium.org | a17773f | 2014-05-09 13:53:38 +0000 | [diff] [blame] | 905 | if (!bicubic && needsTextureDomain && contextMatrix.rectStaysRect()) { |
| 906 | // sampling is axis-aligned |
| 907 | SkRect transformedRect; |
| 908 | contextMatrix.mapRect(&transformedRect, srcRect); |
| 909 | |
| 910 | if (has_aligned_samples(srcRect, transformedRect)) { |
| 911 | params.setFilterMode(GrTextureParams::kNone_FilterMode); |
| 912 | needsTextureDomain = false; |
| 913 | } else { |
robertphillips | 1accc4c | 2015-07-20 10:22:29 -0700 | [diff] [blame] | 914 | needsTextureDomain = may_color_bleed(srcRect, transformedRect, |
| 915 | contextMatrix, isMSAA); |
commit-bot@chromium.org | a17773f | 2014-05-09 13:53:38 +0000 | [diff] [blame] | 916 | } |
| 917 | } |
| 918 | } |
| 919 | return needsTextureDomain; |
| 920 | } |
| 921 | |
joshualitt | a61c817 | 2015-08-17 10:51:22 -0700 | [diff] [blame] | 922 | static void draw_aa_bitmap(GrDrawContext* drawContext, GrContext* context, |
| 923 | GrRenderTarget* renderTarget, const GrClip& clip, |
| 924 | const SkMatrix& viewMatrix, const SkMatrix& srcRectToDstRect, |
| 925 | const SkPaint& paint, const SkBitmap* bitmapPtr, const SkSize& dstSize) { |
| 926 | SkShader::TileMode tm[] = { |
| 927 | SkShader::kClamp_TileMode, |
| 928 | SkShader::kClamp_TileMode, |
| 929 | }; |
| 930 | |
| 931 | bool doBicubic; |
| 932 | GrTextureParams::FilterMode textureFilterMode = |
| 933 | GrSkFilterQualityToGrFilterMode(paint.getFilterQuality(), viewMatrix, |
| 934 | srcRectToDstRect, |
| 935 | &doBicubic); |
| 936 | |
| 937 | // Setup texture to wrap bitmap |
| 938 | GrTextureParams params(tm, textureFilterMode); |
| 939 | SkAutoTUnref<GrTexture> texture(GrRefCachedBitmapTexture(context, *bitmapPtr, ¶ms)); |
| 940 | |
| 941 | if (!texture) { |
| 942 | SkErrorInternals::SetError(kInternalError_SkError, |
| 943 | "Couldn't convert bitmap to texture."); |
| 944 | return; |
| 945 | } |
| 946 | |
| 947 | // Setup paint |
| 948 | GrColor paintColor = (kAlpha_8_SkColorType == bitmapPtr->colorType()) ? |
| 949 | SkColor2GrColor(paint.getColor()) : |
| 950 | SkColor2GrColorJustAlpha(paint.getColor()); |
| 951 | |
| 952 | GrPaint grPaint; |
| 953 | |
| 954 | // Create and insert texture effect |
| 955 | SkAutoTUnref<const GrFragmentProcessor> fp; |
| 956 | if (doBicubic) { |
| 957 | fp.reset(GrBicubicEffect::Create(grPaint.getProcessorDataManager(), texture, |
| 958 | SkMatrix::I(), |
| 959 | tm)); |
| 960 | } else { |
| 961 | fp.reset(GrSimpleTextureEffect::Create(grPaint.getProcessorDataManager(), texture, |
| 962 | SkMatrix::I(), params)); |
| 963 | } |
| 964 | |
| 965 | // The bitmap read has to be first |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 966 | grPaint.addColorFragmentProcessor(fp); |
joshualitt | a61c817 | 2015-08-17 10:51:22 -0700 | [diff] [blame] | 967 | if (!SkPaint2GrPaintNoShader(context, renderTarget, paint, SkColor2GrColor(paint.getColor()), |
| 968 | false, &grPaint)) { |
| 969 | return; |
| 970 | } |
| 971 | |
| 972 | grPaint.setColor(paintColor); |
| 973 | |
| 974 | // Setup dst rect and final matrix |
| 975 | SkRect dstRect = {0, 0, dstSize.fWidth, dstSize.fHeight}; |
| 976 | |
| 977 | SkRect devRect; |
| 978 | viewMatrix.mapRect(&devRect, dstRect); |
| 979 | |
| 980 | SkMatrix matrix; |
| 981 | matrix.setIDiv(bitmapPtr->width(), bitmapPtr->height()); |
| 982 | |
| 983 | SkMatrix dstRectToSrcRect; |
| 984 | if (!srcRectToDstRect.invert(&dstRectToSrcRect)) { |
| 985 | return; |
| 986 | } |
| 987 | matrix.preConcat(dstRectToSrcRect); |
| 988 | |
joshualitt | d2b23e0 | 2015-08-21 10:53:34 -0700 | [diff] [blame] | 989 | SkAutoTUnref<GrDrawBatch> batch(GrRectBatchFactory::CreateAAFill(grPaint.getColor(), |
joshualitt | a61c817 | 2015-08-17 10:51:22 -0700 | [diff] [blame] | 990 | viewMatrix, |
| 991 | matrix, |
| 992 | dstRect, |
| 993 | devRect)); |
| 994 | |
| 995 | drawContext->drawBatch(renderTarget, clip, grPaint, batch); |
| 996 | } |
| 997 | |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 998 | void SkGpuDevice::drawBitmapCommon(const SkDraw& draw, |
| 999 | const SkBitmap& bitmap, |
| 1000 | const SkRect* srcRectPtr, |
commit-bot@chromium.org | a7d89c8 | 2014-01-13 14:47:00 +0000 | [diff] [blame] | 1001 | const SkSize* dstSizePtr, |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1002 | const SkPaint& paint, |
reed | a5517e2 | 2015-07-14 10:54:12 -0700 | [diff] [blame] | 1003 | SkCanvas::SrcRectConstraint constraint) { |
joshualitt | 5531d51 | 2014-12-17 15:50:11 -0800 | [diff] [blame] | 1004 | CHECK_SHOULD_DRAW(draw); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1005 | |
| 1006 | SkRect srcRect; |
commit-bot@chromium.org | a7d89c8 | 2014-01-13 14:47:00 +0000 | [diff] [blame] | 1007 | SkSize dstSize; |
commit-bot@chromium.org | dec6150 | 2013-12-02 22:22:35 +0000 | [diff] [blame] | 1008 | // If there is no src rect, or the src rect contains the entire bitmap then we're effectively |
| 1009 | // in the (easier) bleed case, so update flags. |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1010 | if (nullptr == srcRectPtr) { |
commit-bot@chromium.org | a7d89c8 | 2014-01-13 14:47:00 +0000 | [diff] [blame] | 1011 | SkScalar w = SkIntToScalar(bitmap.width()); |
| 1012 | SkScalar h = SkIntToScalar(bitmap.height()); |
| 1013 | dstSize.fWidth = w; |
| 1014 | dstSize.fHeight = h; |
| 1015 | srcRect.set(0, 0, w, h); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1016 | } else { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 1017 | SkASSERT(dstSizePtr); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1018 | srcRect = *srcRectPtr; |
commit-bot@chromium.org | a7d89c8 | 2014-01-13 14:47:00 +0000 | [diff] [blame] | 1019 | dstSize = *dstSizePtr; |
senorblanco | d0d37ca | 2015-04-02 04:54:56 -0700 | [diff] [blame] | 1020 | } |
| 1021 | GrTexture* tex = bitmap.getTexture(); |
| 1022 | int width = tex ? tex->width() : bitmap.width(); |
| 1023 | int height = tex ? tex->height() : bitmap.height(); |
| 1024 | if (srcRect.fLeft <= 0 && srcRect.fTop <= 0 && |
| 1025 | srcRect.fRight >= width && srcRect.fBottom >= height) { |
reed | a5517e2 | 2015-07-14 10:54:12 -0700 | [diff] [blame] | 1026 | constraint = SkCanvas::kFast_SrcRectConstraint; |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1027 | } |
| 1028 | |
derekf | 367e186 | 2014-12-02 11:02:06 -0800 | [diff] [blame] | 1029 | // If the render target is not msaa and draw is antialiased, we call |
| 1030 | // drawRect instead of drawing on the render target directly. |
| 1031 | // FIXME: the tiled bitmap code path doesn't currently support |
| 1032 | // anti-aliased edges, we work around that for now by drawing directly |
| 1033 | // if the image size exceeds maximum texture size. |
bsalomon | 7622863 | 2015-05-29 08:02:10 -0700 | [diff] [blame] | 1034 | int maxTextureSize = fContext->caps()->maxTextureSize(); |
joshualitt | 1a899c9 | 2015-08-17 11:53:44 -0700 | [diff] [blame] | 1035 | bool drawAA = !fRenderTarget->isUnifiedMultisampled() && |
| 1036 | paint.isAntiAlias() && |
| 1037 | bitmap.width() <= maxTextureSize && |
| 1038 | bitmap.height() <= maxTextureSize; |
derekf | 367e186 | 2014-12-02 11:02:06 -0800 | [diff] [blame] | 1039 | |
joshualitt | 1a899c9 | 2015-08-17 11:53:44 -0700 | [diff] [blame] | 1040 | if (paint.getMaskFilter() || drawAA) { |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1041 | // Convert the bitmap to a shader so that the rect can be drawn |
| 1042 | // through drawRect, which supports mask filters. |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1043 | SkBitmap tmp; // subset of bitmap, if necessary |
| 1044 | const SkBitmap* bitmapPtr = &bitmap; |
joshualitt | a61c817 | 2015-08-17 10:51:22 -0700 | [diff] [blame] | 1045 | SkMatrix srcRectToDstRect; |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 1046 | if (srcRectPtr) { |
joshualitt | a61c817 | 2015-08-17 10:51:22 -0700 | [diff] [blame] | 1047 | srcRectToDstRect.setTranslate(-srcRectPtr->fLeft, -srcRectPtr->fTop); |
| 1048 | srcRectToDstRect.postScale(dstSize.fWidth / srcRectPtr->width(), |
| 1049 | dstSize.fHeight / srcRectPtr->height()); |
commit-bot@chromium.org | d6ca4ac | 2013-11-22 20:34:59 +0000 | [diff] [blame] | 1050 | // In bleed mode we position and trim the bitmap based on the src rect which is |
| 1051 | // already accounted for in 'm' and 'srcRect'. In clamp mode we need to chop out |
| 1052 | // the desired portion of the bitmap and then update 'm' and 'srcRect' to |
| 1053 | // compensate. |
reed | a5517e2 | 2015-07-14 10:54:12 -0700 | [diff] [blame] | 1054 | if (SkCanvas::kStrict_SrcRectConstraint == constraint) { |
commit-bot@chromium.org | d6ca4ac | 2013-11-22 20:34:59 +0000 | [diff] [blame] | 1055 | SkIRect iSrc; |
| 1056 | srcRect.roundOut(&iSrc); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1057 | |
commit-bot@chromium.org | d6ca4ac | 2013-11-22 20:34:59 +0000 | [diff] [blame] | 1058 | SkPoint offset = SkPoint::Make(SkIntToScalar(iSrc.fLeft), |
| 1059 | SkIntToScalar(iSrc.fTop)); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1060 | |
commit-bot@chromium.org | d6ca4ac | 2013-11-22 20:34:59 +0000 | [diff] [blame] | 1061 | if (!bitmap.extractSubset(&tmp, iSrc)) { |
| 1062 | return; // extraction failed |
| 1063 | } |
| 1064 | bitmapPtr = &tmp; |
| 1065 | srcRect.offset(-offset.fX, -offset.fY); |
commit-bot@chromium.org | a7d89c8 | 2014-01-13 14:47:00 +0000 | [diff] [blame] | 1066 | |
commit-bot@chromium.org | d6ca4ac | 2013-11-22 20:34:59 +0000 | [diff] [blame] | 1067 | // The source rect has changed so update the matrix |
joshualitt | a61c817 | 2015-08-17 10:51:22 -0700 | [diff] [blame] | 1068 | srcRectToDstRect.preTranslate(offset.fX, offset.fY); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1069 | } |
commit-bot@chromium.org | a7d89c8 | 2014-01-13 14:47:00 +0000 | [diff] [blame] | 1070 | } else { |
joshualitt | a61c817 | 2015-08-17 10:51:22 -0700 | [diff] [blame] | 1071 | srcRectToDstRect.reset(); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1072 | } |
| 1073 | |
joshualitt | a61c817 | 2015-08-17 10:51:22 -0700 | [diff] [blame] | 1074 | // If we have a maskfilter then we can't batch, so we take a slow path. However, we fast |
| 1075 | // path the case where we are drawing an AA rect so we can batch many drawImageRect calls |
| 1076 | if (paint.getMaskFilter()) { |
| 1077 | SkPaint paintWithShader(paint); |
| 1078 | paintWithShader.setShader(SkShader::CreateBitmapShader(*bitmapPtr, |
| 1079 | SkShader::kClamp_TileMode, SkShader::kClamp_TileMode, |
| 1080 | &srcRectToDstRect))->unref(); |
| 1081 | SkRect dstRect = {0, 0, dstSize.fWidth, dstSize.fHeight}; |
| 1082 | this->drawRect(draw, dstRect, paintWithShader); |
| 1083 | } else { |
| 1084 | draw_aa_bitmap(fDrawContext, fContext, fRenderTarget, fClip, *draw.fMatrix, |
| 1085 | srcRectToDstRect, paint, bitmapPtr, dstSize); |
| 1086 | } |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1087 | |
| 1088 | return; |
| 1089 | } |
| 1090 | |
commit-bot@chromium.org | a7d89c8 | 2014-01-13 14:47:00 +0000 | [diff] [blame] | 1091 | // If there is no mask filter than it is OK to handle the src rect -> dst rect scaling using |
| 1092 | // the view matrix rather than a local matrix. |
| 1093 | SkMatrix m; |
| 1094 | m.setScale(dstSize.fWidth / srcRect.width(), |
| 1095 | dstSize.fHeight / srcRect.height()); |
joshualitt | 5531d51 | 2014-12-17 15:50:11 -0800 | [diff] [blame] | 1096 | SkMatrix viewM = *draw.fMatrix; |
| 1097 | viewM.preConcat(m); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1098 | |
| 1099 | GrTextureParams params; |
joshualitt | 9bc3954 | 2015-08-12 12:57:54 -0700 | [diff] [blame] | 1100 | bool doBicubic; |
| 1101 | GrTextureParams::FilterMode textureFilterMode = |
| 1102 | GrSkFilterQualityToGrFilterMode(paint.getFilterQuality(), viewM, SkMatrix::I(), |
| 1103 | &doBicubic); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1104 | |
commit-bot@chromium.org | 9927bd3 | 2014-05-20 17:51:13 +0000 | [diff] [blame] | 1105 | int tileFilterPad; |
| 1106 | if (doBicubic) { |
| 1107 | tileFilterPad = GrBicubicEffect::kFilterTexelPad; |
| 1108 | } else if (GrTextureParams::kNone_FilterMode == textureFilterMode) { |
| 1109 | tileFilterPad = 0; |
| 1110 | } else { |
| 1111 | tileFilterPad = 1; |
| 1112 | } |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1113 | params.setFilterMode(textureFilterMode); |
| 1114 | |
bsalomon | 7622863 | 2015-05-29 08:02:10 -0700 | [diff] [blame] | 1115 | int maxTileSize = fContext->caps()->maxTextureSize() - 2 * tileFilterPad; |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1116 | int tileSize; |
| 1117 | |
| 1118 | SkIRect clippedSrcRect; |
joshualitt | 5531d51 | 2014-12-17 15:50:11 -0800 | [diff] [blame] | 1119 | if (this->shouldTileBitmap(bitmap, viewM, params, srcRectPtr, maxTileSize, &tileSize, |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1120 | &clippedSrcRect)) { |
reed | a5517e2 | 2015-07-14 10:54:12 -0700 | [diff] [blame] | 1121 | this->drawTiledBitmap(bitmap, viewM, srcRect, clippedSrcRect, params, paint, constraint, |
joshualitt | 5531d51 | 2014-12-17 15:50:11 -0800 | [diff] [blame] | 1122 | tileSize, doBicubic); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1123 | } else { |
| 1124 | // take the simple case |
commit-bot@chromium.org | a17773f | 2014-05-09 13:53:38 +0000 | [diff] [blame] | 1125 | bool needsTextureDomain = needs_texture_domain(bitmap, |
| 1126 | srcRect, |
| 1127 | params, |
joshualitt | 5531d51 | 2014-12-17 15:50:11 -0800 | [diff] [blame] | 1128 | viewM, |
robertphillips | 1accc4c | 2015-07-20 10:22:29 -0700 | [diff] [blame] | 1129 | doBicubic, |
| 1130 | fRenderTarget->isUnifiedMultisampled()); |
commit-bot@chromium.org | a17773f | 2014-05-09 13:53:38 +0000 | [diff] [blame] | 1131 | this->internalDrawBitmap(bitmap, |
joshualitt | 5531d51 | 2014-12-17 15:50:11 -0800 | [diff] [blame] | 1132 | viewM, |
commit-bot@chromium.org | a17773f | 2014-05-09 13:53:38 +0000 | [diff] [blame] | 1133 | srcRect, |
| 1134 | params, |
| 1135 | paint, |
reed | a5517e2 | 2015-07-14 10:54:12 -0700 | [diff] [blame] | 1136 | constraint, |
commit-bot@chromium.org | a17773f | 2014-05-09 13:53:38 +0000 | [diff] [blame] | 1137 | doBicubic, |
| 1138 | needsTextureDomain); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1139 | } |
| 1140 | } |
| 1141 | |
| 1142 | // Break 'bitmap' into several tiles to draw it since it has already |
| 1143 | // been determined to be too large to fit in VRAM |
| 1144 | void SkGpuDevice::drawTiledBitmap(const SkBitmap& bitmap, |
joshualitt | 5531d51 | 2014-12-17 15:50:11 -0800 | [diff] [blame] | 1145 | const SkMatrix& viewMatrix, |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1146 | const SkRect& srcRect, |
| 1147 | const SkIRect& clippedSrcIRect, |
| 1148 | const GrTextureParams& params, |
| 1149 | const SkPaint& paint, |
reed | a5517e2 | 2015-07-14 10:54:12 -0700 | [diff] [blame] | 1150 | SkCanvas::SrcRectConstraint constraint, |
commit-bot@chromium.org | dec6150 | 2013-12-02 22:22:35 +0000 | [diff] [blame] | 1151 | int tileSize, |
| 1152 | bool bicubic) { |
commit-bot@chromium.org | 9d5e3f1 | 2014-05-01 21:23:19 +0000 | [diff] [blame] | 1153 | // The following pixel lock is technically redundant, but it is desirable |
| 1154 | // to lock outside of the tile loop to prevent redecoding the whole image |
| 1155 | // at each tile in cases where 'bitmap' holds an SkDiscardablePixelRef that |
| 1156 | // is larger than the limit of the discardable memory pool. |
| 1157 | SkAutoLockPixels alp(bitmap); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1158 | SkRect clippedSrcRect = SkRect::Make(clippedSrcIRect); |
| 1159 | |
| 1160 | int nx = bitmap.width() / tileSize; |
| 1161 | int ny = bitmap.height() / tileSize; |
| 1162 | for (int x = 0; x <= nx; x++) { |
| 1163 | for (int y = 0; y <= ny; y++) { |
| 1164 | SkRect tileR; |
| 1165 | tileR.set(SkIntToScalar(x * tileSize), |
| 1166 | SkIntToScalar(y * tileSize), |
| 1167 | SkIntToScalar((x + 1) * tileSize), |
| 1168 | SkIntToScalar((y + 1) * tileSize)); |
| 1169 | |
| 1170 | if (!SkRect::Intersects(tileR, clippedSrcRect)) { |
| 1171 | continue; |
| 1172 | } |
| 1173 | |
| 1174 | if (!tileR.intersect(srcRect)) { |
| 1175 | continue; |
| 1176 | } |
| 1177 | |
| 1178 | SkBitmap tmpB; |
| 1179 | SkIRect iTileR; |
| 1180 | tileR.roundOut(&iTileR); |
| 1181 | SkPoint offset = SkPoint::Make(SkIntToScalar(iTileR.fLeft), |
| 1182 | SkIntToScalar(iTileR.fTop)); |
| 1183 | |
commit-bot@chromium.org | a7d89c8 | 2014-01-13 14:47:00 +0000 | [diff] [blame] | 1184 | // 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] | 1185 | SkMatrix viewM = viewMatrix; |
commit-bot@chromium.org | a7d89c8 | 2014-01-13 14:47:00 +0000 | [diff] [blame] | 1186 | SkMatrix tmpM; |
commit-bot@chromium.org | a7d89c8 | 2014-01-13 14:47:00 +0000 | [diff] [blame] | 1187 | tmpM.setTranslate(offset.fX - srcRect.fLeft, offset.fY - srcRect.fTop); |
joshualitt | 5531d51 | 2014-12-17 15:50:11 -0800 | [diff] [blame] | 1188 | viewM.preConcat(tmpM); |
commit-bot@chromium.org | a7d89c8 | 2014-01-13 14:47:00 +0000 | [diff] [blame] | 1189 | |
robertphillips | ec8bb94 | 2014-11-21 10:16:25 -0800 | [diff] [blame] | 1190 | if (GrTextureParams::kNone_FilterMode != params.filterMode() || bicubic) { |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1191 | SkIRect iClampRect; |
| 1192 | |
reed | a5517e2 | 2015-07-14 10:54:12 -0700 | [diff] [blame] | 1193 | if (SkCanvas::kFast_SrcRectConstraint == constraint) { |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1194 | // In bleed mode we want to always expand the tile on all edges |
| 1195 | // but stay within the bitmap bounds |
| 1196 | iClampRect = SkIRect::MakeWH(bitmap.width(), bitmap.height()); |
| 1197 | } else { |
| 1198 | // In texture-domain/clamp mode we only want to expand the |
| 1199 | // tile on edges interior to "srcRect" (i.e., we want to |
| 1200 | // not bleed across the original clamped edges) |
| 1201 | srcRect.roundOut(&iClampRect); |
| 1202 | } |
commit-bot@chromium.org | dec6150 | 2013-12-02 22:22:35 +0000 | [diff] [blame] | 1203 | int outset = bicubic ? GrBicubicEffect::kFilterTexelPad : 1; |
| 1204 | clamped_outset_with_offset(&iTileR, outset, &offset, iClampRect); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1205 | } |
| 1206 | |
| 1207 | if (bitmap.extractSubset(&tmpB, iTileR)) { |
| 1208 | // now offset it to make it "local" to our tmp bitmap |
| 1209 | tileR.offset(-offset.fX, -offset.fY); |
commit-bot@chromium.org | a17773f | 2014-05-09 13:53:38 +0000 | [diff] [blame] | 1210 | GrTextureParams paramsTemp = params; |
robertphillips | 1accc4c | 2015-07-20 10:22:29 -0700 | [diff] [blame] | 1211 | bool needsTextureDomain = needs_texture_domain( |
| 1212 | bitmap, srcRect, paramsTemp, |
| 1213 | viewM, bicubic, |
| 1214 | fRenderTarget->isUnifiedMultisampled()); |
commit-bot@chromium.org | a17773f | 2014-05-09 13:53:38 +0000 | [diff] [blame] | 1215 | this->internalDrawBitmap(tmpB, |
joshualitt | 5531d51 | 2014-12-17 15:50:11 -0800 | [diff] [blame] | 1216 | viewM, |
commit-bot@chromium.org | a17773f | 2014-05-09 13:53:38 +0000 | [diff] [blame] | 1217 | tileR, |
| 1218 | paramsTemp, |
| 1219 | paint, |
reed | a5517e2 | 2015-07-14 10:54:12 -0700 | [diff] [blame] | 1220 | constraint, |
commit-bot@chromium.org | a17773f | 2014-05-09 13:53:38 +0000 | [diff] [blame] | 1221 | bicubic, |
| 1222 | needsTextureDomain); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1223 | } |
| 1224 | } |
| 1225 | } |
| 1226 | } |
| 1227 | |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1228 | |
| 1229 | /* |
| 1230 | * This is called by drawBitmap(), which has to handle images that may be too |
| 1231 | * large to be represented by a single texture. |
| 1232 | * |
| 1233 | * internalDrawBitmap assumes that the specified bitmap will fit in a texture |
| 1234 | * and that non-texture portion of the GrPaint has already been setup. |
| 1235 | */ |
| 1236 | void SkGpuDevice::internalDrawBitmap(const SkBitmap& bitmap, |
joshualitt | 5531d51 | 2014-12-17 15:50:11 -0800 | [diff] [blame] | 1237 | const SkMatrix& viewMatrix, |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1238 | const SkRect& srcRect, |
| 1239 | const GrTextureParams& params, |
| 1240 | const SkPaint& paint, |
reed | a5517e2 | 2015-07-14 10:54:12 -0700 | [diff] [blame] | 1241 | SkCanvas::SrcRectConstraint constraint, |
commit-bot@chromium.org | a17773f | 2014-05-09 13:53:38 +0000 | [diff] [blame] | 1242 | bool bicubic, |
| 1243 | bool needsTextureDomain) { |
bsalomon | 7622863 | 2015-05-29 08:02:10 -0700 | [diff] [blame] | 1244 | SkASSERT(bitmap.width() <= fContext->caps()->maxTextureSize() && |
| 1245 | bitmap.height() <= fContext->caps()->maxTextureSize()); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1246 | |
| 1247 | GrTexture* texture; |
bsalomon | bcf0a52 | 2014-10-08 08:40:09 -0700 | [diff] [blame] | 1248 | AutoBitmapTexture abt(fContext, bitmap, ¶ms, &texture); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1249 | if (nullptr == texture) { |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1250 | return; |
| 1251 | } |
| 1252 | |
commit-bot@chromium.org | a7d89c8 | 2014-01-13 14:47:00 +0000 | [diff] [blame] | 1253 | SkRect dstRect = {0, 0, srcRect.width(), srcRect.height() }; |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1254 | SkRect paintRect; |
| 1255 | SkScalar wInv = SkScalarInvert(SkIntToScalar(texture->width())); |
| 1256 | SkScalar hInv = SkScalarInvert(SkIntToScalar(texture->height())); |
| 1257 | paintRect.setLTRB(SkScalarMul(srcRect.fLeft, wInv), |
| 1258 | SkScalarMul(srcRect.fTop, hInv), |
| 1259 | SkScalarMul(srcRect.fRight, wInv), |
| 1260 | SkScalarMul(srcRect.fBottom, hInv)); |
| 1261 | |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1262 | SkRect textureDomain = SkRect::MakeEmpty(); |
joshualitt | 5f10b5c | 2015-07-09 10:24:35 -0700 | [diff] [blame] | 1263 | |
| 1264 | // Construct a GrPaint by setting the bitmap texture as the first effect and then configuring |
| 1265 | // the rest from the SkPaint. |
| 1266 | GrPaint grPaint; |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 1267 | SkAutoTUnref<GrFragmentProcessor> fp; |
joshualitt | 5f10b5c | 2015-07-09 10:24:35 -0700 | [diff] [blame] | 1268 | |
reed | a5517e2 | 2015-07-14 10:54:12 -0700 | [diff] [blame] | 1269 | if (needsTextureDomain && (SkCanvas::kStrict_SrcRectConstraint == constraint)) { |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1270 | // Use a constrained texture domain to avoid color bleeding |
| 1271 | SkScalar left, top, right, bottom; |
| 1272 | if (srcRect.width() > SK_Scalar1) { |
| 1273 | SkScalar border = SK_ScalarHalf / texture->width(); |
| 1274 | left = paintRect.left() + border; |
| 1275 | right = paintRect.right() - border; |
| 1276 | } else { |
| 1277 | left = right = SkScalarHalf(paintRect.left() + paintRect.right()); |
| 1278 | } |
| 1279 | if (srcRect.height() > SK_Scalar1) { |
| 1280 | SkScalar border = SK_ScalarHalf / texture->height(); |
| 1281 | top = paintRect.top() + border; |
| 1282 | bottom = paintRect.bottom() - border; |
| 1283 | } else { |
| 1284 | top = bottom = SkScalarHalf(paintRect.top() + paintRect.bottom()); |
| 1285 | } |
| 1286 | textureDomain.setLTRB(left, top, right, bottom); |
commit-bot@chromium.org | 7d7f314 | 2013-12-16 15:18:11 +0000 | [diff] [blame] | 1287 | if (bicubic) { |
joshualitt | 5f10b5c | 2015-07-09 10:24:35 -0700 | [diff] [blame] | 1288 | fp.reset(GrBicubicEffect::Create(grPaint.getProcessorDataManager(), texture, |
| 1289 | SkMatrix::I(), textureDomain)); |
commit-bot@chromium.org | 7d7f314 | 2013-12-16 15:18:11 +0000 | [diff] [blame] | 1290 | } else { |
joshualitt | 5f10b5c | 2015-07-09 10:24:35 -0700 | [diff] [blame] | 1291 | fp.reset(GrTextureDomainEffect::Create(grPaint.getProcessorDataManager(), |
| 1292 | texture, |
joshualitt | 5531d51 | 2014-12-17 15:50:11 -0800 | [diff] [blame] | 1293 | SkMatrix::I(), |
| 1294 | textureDomain, |
| 1295 | GrTextureDomain::kClamp_Mode, |
| 1296 | params.filterMode())); |
commit-bot@chromium.org | 7d7f314 | 2013-12-16 15:18:11 +0000 | [diff] [blame] | 1297 | } |
commit-bot@chromium.org | dec6150 | 2013-12-02 22:22:35 +0000 | [diff] [blame] | 1298 | } else if (bicubic) { |
commit-bot@chromium.org | bc91fd7 | 2013-12-10 12:53:39 +0000 | [diff] [blame] | 1299 | SkASSERT(GrTextureParams::kNone_FilterMode == params.filterMode()); |
| 1300 | SkShader::TileMode tileModes[2] = { params.getTileModeX(), params.getTileModeY() }; |
joshualitt | 5f10b5c | 2015-07-09 10:24:35 -0700 | [diff] [blame] | 1301 | fp.reset(GrBicubicEffect::Create(grPaint.getProcessorDataManager(), texture, SkMatrix::I(), |
| 1302 | tileModes)); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1303 | } else { |
joshualitt | 5f10b5c | 2015-07-09 10:24:35 -0700 | [diff] [blame] | 1304 | fp.reset(GrSimpleTextureEffect::Create(grPaint.getProcessorDataManager(), texture, |
| 1305 | SkMatrix::I(), params)); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1306 | } |
| 1307 | |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 1308 | grPaint.addColorFragmentProcessor(fp); |
reed | 0689d7b | 2014-06-14 05:30:20 -0700 | [diff] [blame] | 1309 | bool alphaOnly = !(kAlpha_8_SkColorType == bitmap.colorType()); |
bsalomon | 83d081a | 2014-07-08 09:56:10 -0700 | [diff] [blame] | 1310 | GrColor paintColor = (alphaOnly) ? SkColor2GrColorJustAlpha(paint.getColor()) : |
| 1311 | SkColor2GrColor(paint.getColor()); |
bsalomon | bed83a6 | 2015-04-15 14:18:34 -0700 | [diff] [blame] | 1312 | if (!SkPaint2GrPaintNoShader(this->context(), fRenderTarget, paint, paintColor, false, |
| 1313 | &grPaint)) { |
| 1314 | return; |
| 1315 | } |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1316 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1317 | fDrawContext->drawNonAARectToRect(fRenderTarget, fClip, grPaint, viewMatrix, dstRect, |
| 1318 | paintRect); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1319 | } |
| 1320 | |
fmalita | 2d97bc1 | 2014-11-20 10:44:58 -0800 | [diff] [blame] | 1321 | bool SkGpuDevice::filterTexture(GrContext* context, GrTexture* texture, |
senorblanco | d0d37ca | 2015-04-02 04:54:56 -0700 | [diff] [blame] | 1322 | int width, int height, |
fmalita | 2d97bc1 | 2014-11-20 10:44:58 -0800 | [diff] [blame] | 1323 | const SkImageFilter* filter, |
| 1324 | const SkImageFilter::Context& ctx, |
| 1325 | SkBitmap* result, SkIPoint* offset) { |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1326 | SkASSERT(filter); |
fmalita | 2d97bc1 | 2014-11-20 10:44:58 -0800 | [diff] [blame] | 1327 | |
robertphillips | efbffed | 2015-06-22 12:06:08 -0700 | [diff] [blame] | 1328 | SkImageFilter::Proxy proxy(this); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1329 | |
| 1330 | if (filter->canFilterImageGPU()) { |
senorblanco | d0d37ca | 2015-04-02 04:54:56 -0700 | [diff] [blame] | 1331 | return filter->filterImageGPU(&proxy, wrap_texture(texture, width, height), |
| 1332 | ctx, result, offset); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1333 | } else { |
| 1334 | return false; |
| 1335 | } |
| 1336 | } |
| 1337 | |
| 1338 | void SkGpuDevice::drawSprite(const SkDraw& draw, const SkBitmap& bitmap, |
| 1339 | int left, int top, const SkPaint& paint) { |
| 1340 | // drawSprite is defined to be in device coords. |
joshualitt | 5531d51 | 2014-12-17 15:50:11 -0800 | [diff] [blame] | 1341 | CHECK_SHOULD_DRAW(draw); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1342 | |
| 1343 | SkAutoLockPixels alp(bitmap, !bitmap.getTexture()); |
| 1344 | if (!bitmap.getTexture() && !bitmap.readyToDraw()) { |
| 1345 | return; |
| 1346 | } |
| 1347 | |
| 1348 | int w = bitmap.width(); |
| 1349 | int h = bitmap.height(); |
| 1350 | |
| 1351 | GrTexture* texture; |
| 1352 | // draw sprite uses the default texture params |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1353 | AutoBitmapTexture abt(fContext, bitmap, nullptr, &texture); |
joshualitt | 5f5a8d7 | 2015-02-25 14:09:45 -0800 | [diff] [blame] | 1354 | if (!texture) { |
| 1355 | return; |
| 1356 | } |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1357 | |
| 1358 | SkImageFilter* filter = paint.getImageFilter(); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1359 | // This bitmap will own the filtered result as a texture. |
| 1360 | SkBitmap filteredBitmap; |
| 1361 | |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 1362 | if (filter) { |
senorblanco@chromium.org | 6776b82 | 2014-01-03 21:48:22 +0000 | [diff] [blame] | 1363 | SkIPoint offset = SkIPoint::Make(0, 0); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1364 | SkMatrix matrix(*draw.fMatrix); |
| 1365 | matrix.postTranslate(SkIntToScalar(-left), SkIntToScalar(-top)); |
senorblanco@chromium.org | 4cb543d | 2014-03-14 15:44:01 +0000 | [diff] [blame] | 1366 | SkIRect clipBounds = SkIRect::MakeWH(bitmap.width(), bitmap.height()); |
senorblanco | be129b2 | 2014-08-08 07:14:35 -0700 | [diff] [blame] | 1367 | SkAutoTUnref<SkImageFilter::Cache> cache(getImageFilterCache()); |
senorblanco | 55b6d8b | 2014-07-30 11:26:46 -0700 | [diff] [blame] | 1368 | // This cache is transient, and is freed (along with all its contained |
| 1369 | // textures) when it goes out of scope. |
commit-bot@chromium.org | f7efa50 | 2014-04-11 18:57:00 +0000 | [diff] [blame] | 1370 | SkImageFilter::Context ctx(matrix, clipBounds, cache); |
senorblanco | d0d37ca | 2015-04-02 04:54:56 -0700 | [diff] [blame] | 1371 | if (this->filterTexture(fContext, texture, w, h, filter, ctx, &filteredBitmap, |
fmalita | 2d97bc1 | 2014-11-20 10:44:58 -0800 | [diff] [blame] | 1372 | &offset)) { |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1373 | texture = (GrTexture*) filteredBitmap.getTexture(); |
| 1374 | w = filteredBitmap.width(); |
| 1375 | h = filteredBitmap.height(); |
senorblanco@chromium.org | 6776b82 | 2014-01-03 21:48:22 +0000 | [diff] [blame] | 1376 | left += offset.x(); |
| 1377 | top += offset.y(); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1378 | } else { |
| 1379 | return; |
| 1380 | } |
| 1381 | } |
| 1382 | |
| 1383 | GrPaint grPaint; |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 1384 | grPaint.addColorTextureProcessor(texture, SkMatrix::I()); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1385 | |
bsalomon | bed83a6 | 2015-04-15 14:18:34 -0700 | [diff] [blame] | 1386 | if (!SkPaint2GrPaintNoShader(this->context(), fRenderTarget, paint, |
| 1387 | SkColor2GrColorJustAlpha(paint.getColor()), false, &grPaint)) { |
| 1388 | return; |
| 1389 | } |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1390 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1391 | fDrawContext->drawNonAARectToRect(fRenderTarget, |
| 1392 | fClip, |
| 1393 | grPaint, |
| 1394 | SkMatrix::I(), |
| 1395 | SkRect::MakeXYWH(SkIntToScalar(left), |
| 1396 | SkIntToScalar(top), |
| 1397 | SkIntToScalar(w), |
| 1398 | SkIntToScalar(h)), |
| 1399 | SkRect::MakeXYWH(0, |
| 1400 | 0, |
| 1401 | SK_Scalar1 * w / texture->width(), |
| 1402 | SK_Scalar1 * h / texture->height())); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1403 | } |
| 1404 | |
commit-bot@chromium.org | a7d89c8 | 2014-01-13 14:47:00 +0000 | [diff] [blame] | 1405 | void SkGpuDevice::drawBitmapRect(const SkDraw& origDraw, const SkBitmap& bitmap, |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1406 | const SkRect* src, const SkRect& dst, |
reed | 562fe47 | 2015-07-28 07:35:14 -0700 | [diff] [blame] | 1407 | const SkPaint& paint, SkCanvas::SrcRectConstraint constraint) { |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1408 | SkMatrix matrix; |
| 1409 | SkRect bitmapBounds, tmpSrc; |
| 1410 | |
| 1411 | bitmapBounds.set(0, 0, |
| 1412 | SkIntToScalar(bitmap.width()), |
| 1413 | SkIntToScalar(bitmap.height())); |
| 1414 | |
| 1415 | // Compute matrix from the two rectangles |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 1416 | if (src) { |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1417 | tmpSrc = *src; |
| 1418 | } else { |
| 1419 | tmpSrc = bitmapBounds; |
| 1420 | } |
commit-bot@chromium.org | a7d89c8 | 2014-01-13 14:47:00 +0000 | [diff] [blame] | 1421 | |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1422 | matrix.setRectToRect(tmpSrc, dst, SkMatrix::kFill_ScaleToFit); |
| 1423 | |
| 1424 | // clip the tmpSrc to the bounds of the bitmap. No check needed if src==null. |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 1425 | if (src) { |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1426 | if (!bitmapBounds.contains(tmpSrc)) { |
| 1427 | if (!tmpSrc.intersect(bitmapBounds)) { |
| 1428 | return; // nothing to draw |
| 1429 | } |
| 1430 | } |
| 1431 | } |
| 1432 | |
commit-bot@chromium.org | a7d89c8 | 2014-01-13 14:47:00 +0000 | [diff] [blame] | 1433 | SkRect tmpDst; |
| 1434 | matrix.mapRect(&tmpDst, tmpSrc); |
| 1435 | |
| 1436 | SkTCopyOnFirstWrite<SkDraw> draw(origDraw); |
| 1437 | if (0 != tmpDst.fLeft || 0 != tmpDst.fTop) { |
| 1438 | // Translate so that tempDst's top left is at the origin. |
| 1439 | matrix = *origDraw.fMatrix; |
| 1440 | matrix.preTranslate(tmpDst.fLeft, tmpDst.fTop); |
| 1441 | draw.writable()->fMatrix = &matrix; |
| 1442 | } |
| 1443 | SkSize dstSize; |
| 1444 | dstSize.fWidth = tmpDst.width(); |
| 1445 | dstSize.fHeight = tmpDst.height(); |
| 1446 | |
reed | a5517e2 | 2015-07-14 10:54:12 -0700 | [diff] [blame] | 1447 | this->drawBitmapCommon(*draw, bitmap, &tmpSrc, &dstSize, paint, constraint); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1448 | } |
| 1449 | |
| 1450 | void SkGpuDevice::drawDevice(const SkDraw& draw, SkBaseDevice* device, |
| 1451 | int x, int y, const SkPaint& paint) { |
| 1452 | // clear of the source device must occur before CHECK_SHOULD_DRAW |
egdaniel | d78a168 | 2014-07-09 10:41:26 -0700 | [diff] [blame] | 1453 | GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawDevice", fContext); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1454 | SkGpuDevice* dev = static_cast<SkGpuDevice*>(device); |
kkinnunen | 2e4414e | 2015-02-19 07:20:40 -0800 | [diff] [blame] | 1455 | |
| 1456 | // TODO: If the source device covers the whole of this device, we could |
| 1457 | // omit fNeedsClear -related flushing. |
| 1458 | // TODO: if source needs clear, we could maybe omit the draw fully. |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1459 | |
| 1460 | // drawDevice is defined to be in device coords. |
joshualitt | 5531d51 | 2014-12-17 15:50:11 -0800 | [diff] [blame] | 1461 | CHECK_SHOULD_DRAW(draw); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1462 | |
| 1463 | GrRenderTarget* devRT = dev->accessRenderTarget(); |
| 1464 | GrTexture* devTex; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1465 | if (nullptr == (devTex = devRT->asTexture())) { |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1466 | return; |
| 1467 | } |
| 1468 | |
robertphillips | 7b9e8a4 | 2014-12-11 08:20:31 -0800 | [diff] [blame] | 1469 | const SkImageInfo ii = dev->imageInfo(); |
| 1470 | int w = ii.width(); |
| 1471 | int h = ii.height(); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1472 | |
| 1473 | SkImageFilter* filter = paint.getImageFilter(); |
| 1474 | // This bitmap will own the filtered result as a texture. |
| 1475 | SkBitmap filteredBitmap; |
| 1476 | |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 1477 | if (filter) { |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1478 | SkIPoint offset = SkIPoint::Make(0, 0); |
| 1479 | SkMatrix matrix(*draw.fMatrix); |
| 1480 | matrix.postTranslate(SkIntToScalar(-x), SkIntToScalar(-y)); |
senorblanco@chromium.org | 4cb543d | 2014-03-14 15:44:01 +0000 | [diff] [blame] | 1481 | SkIRect clipBounds = SkIRect::MakeWH(devTex->width(), devTex->height()); |
senorblanco | 55b6d8b | 2014-07-30 11:26:46 -0700 | [diff] [blame] | 1482 | // This cache is transient, and is freed (along with all its contained |
| 1483 | // textures) when it goes out of scope. |
senorblanco | be129b2 | 2014-08-08 07:14:35 -0700 | [diff] [blame] | 1484 | SkAutoTUnref<SkImageFilter::Cache> cache(getImageFilterCache()); |
commit-bot@chromium.org | f7efa50 | 2014-04-11 18:57:00 +0000 | [diff] [blame] | 1485 | SkImageFilter::Context ctx(matrix, clipBounds, cache); |
senorblanco | d0d37ca | 2015-04-02 04:54:56 -0700 | [diff] [blame] | 1486 | if (this->filterTexture(fContext, devTex, device->width(), device->height(), |
| 1487 | filter, ctx, &filteredBitmap, &offset)) { |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1488 | devTex = filteredBitmap.getTexture(); |
| 1489 | w = filteredBitmap.width(); |
| 1490 | h = filteredBitmap.height(); |
| 1491 | x += offset.fX; |
| 1492 | y += offset.fY; |
| 1493 | } else { |
| 1494 | return; |
| 1495 | } |
| 1496 | } |
| 1497 | |
| 1498 | GrPaint grPaint; |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 1499 | grPaint.addColorTextureProcessor(devTex, SkMatrix::I()); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1500 | |
bsalomon | bed83a6 | 2015-04-15 14:18:34 -0700 | [diff] [blame] | 1501 | if (!SkPaint2GrPaintNoShader(this->context(), fRenderTarget, paint, |
| 1502 | SkColor2GrColorJustAlpha(paint.getColor()), false, &grPaint)) { |
| 1503 | return; |
| 1504 | } |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1505 | |
| 1506 | SkRect dstRect = SkRect::MakeXYWH(SkIntToScalar(x), |
| 1507 | SkIntToScalar(y), |
| 1508 | SkIntToScalar(w), |
| 1509 | SkIntToScalar(h)); |
| 1510 | |
| 1511 | // The device being drawn may not fill up its texture (e.g. saveLayer uses approximate |
| 1512 | // scratch texture). |
| 1513 | SkRect srcRect = SkRect::MakeWH(SK_Scalar1 * w / devTex->width(), |
| 1514 | SK_Scalar1 * h / devTex->height()); |
| 1515 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1516 | fDrawContext->drawNonAARectToRect(fRenderTarget, fClip, grPaint, SkMatrix::I(), dstRect, |
| 1517 | srcRect); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1518 | } |
| 1519 | |
commit-bot@chromium.org | ae761f7 | 2014-02-05 22:32:02 +0000 | [diff] [blame] | 1520 | bool SkGpuDevice::canHandleImageFilter(const SkImageFilter* filter) { |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1521 | return filter->canFilterImageGPU(); |
| 1522 | } |
| 1523 | |
commit-bot@chromium.org | ae761f7 | 2014-02-05 22:32:02 +0000 | [diff] [blame] | 1524 | bool SkGpuDevice::filterImage(const SkImageFilter* filter, const SkBitmap& src, |
senorblanco@chromium.org | 4cb543d | 2014-03-14 15:44:01 +0000 | [diff] [blame] | 1525 | const SkImageFilter::Context& ctx, |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1526 | SkBitmap* result, SkIPoint* offset) { |
| 1527 | // want explicitly our impl, so guard against a subclass of us overriding it |
| 1528 | if (!this->SkGpuDevice::canHandleImageFilter(filter)) { |
| 1529 | return false; |
| 1530 | } |
| 1531 | |
| 1532 | SkAutoLockPixels alp(src, !src.getTexture()); |
| 1533 | if (!src.getTexture() && !src.readyToDraw()) { |
| 1534 | return false; |
| 1535 | } |
| 1536 | |
| 1537 | GrTexture* texture; |
| 1538 | // We assume here that the filter will not attempt to tile the src. Otherwise, this cache lookup |
| 1539 | // must be pushed upstack. |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1540 | AutoBitmapTexture abt(fContext, src, nullptr, &texture); |
robertphillips | f83be82 | 2015-04-30 08:55:06 -0700 | [diff] [blame] | 1541 | if (!texture) { |
| 1542 | return false; |
| 1543 | } |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1544 | |
senorblanco | d0d37ca | 2015-04-02 04:54:56 -0700 | [diff] [blame] | 1545 | return this->filterTexture(fContext, texture, src.width(), src.height(), |
| 1546 | filter, ctx, result, offset); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1547 | } |
| 1548 | |
reed | a85d4d0 | 2015-05-06 12:56:48 -0700 | [diff] [blame] | 1549 | static bool wrap_as_bm(const SkImage* image, SkBitmap* bm) { |
bsalomon | 5581236 | 2015-06-10 08:49:28 -0700 | [diff] [blame] | 1550 | GrTexture* tex = as_IB(image)->getTexture(); |
reed | a85d4d0 | 2015-05-06 12:56:48 -0700 | [diff] [blame] | 1551 | if (tex) { |
reed | 8b26b99 | 2015-05-07 15:36:17 -0700 | [diff] [blame] | 1552 | GrWrapTextureInBitmap(tex, image->width(), image->height(), image->isOpaque(), bm); |
| 1553 | return true; |
reed | a85d4d0 | 2015-05-06 12:56:48 -0700 | [diff] [blame] | 1554 | } else { |
reed | 8b26b99 | 2015-05-07 15:36:17 -0700 | [diff] [blame] | 1555 | return as_IB(image)->getROPixels(bm); |
reed | a85d4d0 | 2015-05-06 12:56:48 -0700 | [diff] [blame] | 1556 | } |
reed | a85d4d0 | 2015-05-06 12:56:48 -0700 | [diff] [blame] | 1557 | } |
| 1558 | |
| 1559 | void SkGpuDevice::drawImage(const SkDraw& draw, const SkImage* image, SkScalar x, SkScalar y, |
| 1560 | const SkPaint& paint) { |
| 1561 | SkBitmap bm; |
| 1562 | if (wrap_as_bm(image, &bm)) { |
| 1563 | this->drawBitmap(draw, bm, SkMatrix::MakeTrans(x, y), paint); |
| 1564 | } |
| 1565 | } |
| 1566 | |
| 1567 | void SkGpuDevice::drawImageRect(const SkDraw& draw, const SkImage* image, const SkRect* src, |
reed | a5517e2 | 2015-07-14 10:54:12 -0700 | [diff] [blame] | 1568 | const SkRect& dst, const SkPaint& paint, |
| 1569 | SkCanvas::SrcRectConstraint constraint) { |
reed | a85d4d0 | 2015-05-06 12:56:48 -0700 | [diff] [blame] | 1570 | SkBitmap bm; |
| 1571 | if (wrap_as_bm(image, &bm)) { |
reed | 562fe47 | 2015-07-28 07:35:14 -0700 | [diff] [blame] | 1572 | this->drawBitmapRect(draw, bm, src, dst, paint, constraint); |
reed | a85d4d0 | 2015-05-06 12:56:48 -0700 | [diff] [blame] | 1573 | } |
| 1574 | } |
| 1575 | |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1576 | /////////////////////////////////////////////////////////////////////////////// |
| 1577 | |
| 1578 | // must be in SkCanvas::VertexMode order |
| 1579 | static const GrPrimitiveType gVertexMode2PrimitiveType[] = { |
| 1580 | kTriangles_GrPrimitiveType, |
| 1581 | kTriangleStrip_GrPrimitiveType, |
| 1582 | kTriangleFan_GrPrimitiveType, |
| 1583 | }; |
| 1584 | |
| 1585 | void SkGpuDevice::drawVertices(const SkDraw& draw, SkCanvas::VertexMode vmode, |
| 1586 | int vertexCount, const SkPoint vertices[], |
| 1587 | const SkPoint texs[], const SkColor colors[], |
| 1588 | SkXfermode* xmode, |
| 1589 | const uint16_t indices[], int indexCount, |
| 1590 | const SkPaint& paint) { |
joshualitt | 5531d51 | 2014-12-17 15:50:11 -0800 | [diff] [blame] | 1591 | CHECK_SHOULD_DRAW(draw); |
egdaniel | d78a168 | 2014-07-09 10:41:26 -0700 | [diff] [blame] | 1592 | GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawVertices", fContext); |
mtklein | 533eb78 | 2014-08-27 10:39:42 -0700 | [diff] [blame] | 1593 | |
dandov | 32a311b | 2014-07-15 19:46:26 -0700 | [diff] [blame] | 1594 | const uint16_t* outIndices; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1595 | SkAutoTDeleteArray<uint16_t> outAlloc(nullptr); |
dandov | 32a311b | 2014-07-15 19:46:26 -0700 | [diff] [blame] | 1596 | GrPrimitiveType primType; |
| 1597 | GrPaint grPaint; |
bsalomon | a098dd4 | 2014-08-06 11:01:44 -0700 | [diff] [blame] | 1598 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1599 | // If both textures and vertex-colors are nullptr, strokes hairlines with the paint's color. |
| 1600 | if ((nullptr == texs || nullptr == paint.getShader()) && nullptr == colors) { |
mtklein | 533eb78 | 2014-08-27 10:39:42 -0700 | [diff] [blame] | 1601 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1602 | texs = nullptr; |
mtklein | 533eb78 | 2014-08-27 10:39:42 -0700 | [diff] [blame] | 1603 | |
commit-bot@chromium.org | 559a883 | 2014-05-30 10:08:22 +0000 | [diff] [blame] | 1604 | SkPaint copy(paint); |
| 1605 | copy.setStyle(SkPaint::kStroke_Style); |
| 1606 | copy.setStrokeWidth(0); |
mtklein | 533eb78 | 2014-08-27 10:39:42 -0700 | [diff] [blame] | 1607 | |
dandov | 32a311b | 2014-07-15 19:46:26 -0700 | [diff] [blame] | 1608 | // we ignore the shader if texs is null. |
bsalomon | bed83a6 | 2015-04-15 14:18:34 -0700 | [diff] [blame] | 1609 | if (!SkPaint2GrPaintNoShader(this->context(), fRenderTarget, copy, |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1610 | SkColor2GrColor(copy.getColor()), nullptr == colors, &grPaint)) { |
bsalomon | bed83a6 | 2015-04-15 14:18:34 -0700 | [diff] [blame] | 1611 | return; |
| 1612 | } |
commit-bot@chromium.org | 559a883 | 2014-05-30 10:08:22 +0000 | [diff] [blame] | 1613 | |
dandov | 32a311b | 2014-07-15 19:46:26 -0700 | [diff] [blame] | 1614 | primType = kLines_GrPrimitiveType; |
| 1615 | int triangleCount = 0; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1616 | int n = (nullptr == indices) ? vertexCount : indexCount; |
dandov | 32a311b | 2014-07-15 19:46:26 -0700 | [diff] [blame] | 1617 | switch (vmode) { |
| 1618 | case SkCanvas::kTriangles_VertexMode: |
bsalomon | a098dd4 | 2014-08-06 11:01:44 -0700 | [diff] [blame] | 1619 | triangleCount = n / 3; |
dandov | 32a311b | 2014-07-15 19:46:26 -0700 | [diff] [blame] | 1620 | break; |
| 1621 | case SkCanvas::kTriangleStrip_VertexMode: |
| 1622 | case SkCanvas::kTriangleFan_VertexMode: |
bsalomon | a098dd4 | 2014-08-06 11:01:44 -0700 | [diff] [blame] | 1623 | triangleCount = n - 2; |
dandov | 32a311b | 2014-07-15 19:46:26 -0700 | [diff] [blame] | 1624 | break; |
| 1625 | } |
mtklein | 533eb78 | 2014-08-27 10:39:42 -0700 | [diff] [blame] | 1626 | |
commit-bot@chromium.org | 559a883 | 2014-05-30 10:08:22 +0000 | [diff] [blame] | 1627 | VertState state(vertexCount, indices, indexCount); |
| 1628 | VertState::Proc vertProc = state.chooseProc(vmode); |
mtklein | 533eb78 | 2014-08-27 10:39:42 -0700 | [diff] [blame] | 1629 | |
dandov | 32a311b | 2014-07-15 19:46:26 -0700 | [diff] [blame] | 1630 | //number of indices for lines per triangle with kLines |
| 1631 | indexCount = triangleCount * 6; |
mtklein | 533eb78 | 2014-08-27 10:39:42 -0700 | [diff] [blame] | 1632 | |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 1633 | outAlloc.reset(new uint16_t[indexCount]); |
dandov | 32a311b | 2014-07-15 19:46:26 -0700 | [diff] [blame] | 1634 | outIndices = outAlloc.get(); |
| 1635 | uint16_t* auxIndices = outAlloc.get(); |
commit-bot@chromium.org | 559a883 | 2014-05-30 10:08:22 +0000 | [diff] [blame] | 1636 | int i = 0; |
| 1637 | while (vertProc(&state)) { |
dandov | 32a311b | 2014-07-15 19:46:26 -0700 | [diff] [blame] | 1638 | auxIndices[i] = state.f0; |
| 1639 | auxIndices[i + 1] = state.f1; |
| 1640 | auxIndices[i + 2] = state.f1; |
| 1641 | auxIndices[i + 3] = state.f2; |
| 1642 | auxIndices[i + 4] = state.f2; |
| 1643 | auxIndices[i + 5] = state.f0; |
commit-bot@chromium.org | 559a883 | 2014-05-30 10:08:22 +0000 | [diff] [blame] | 1644 | i += 6; |
| 1645 | } |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1646 | } else { |
dandov | 32a311b | 2014-07-15 19:46:26 -0700 | [diff] [blame] | 1647 | outIndices = indices; |
| 1648 | primType = gVertexMode2PrimitiveType[vmode]; |
mtklein | 533eb78 | 2014-08-27 10:39:42 -0700 | [diff] [blame] | 1649 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1650 | if (nullptr == texs || nullptr == paint.getShader()) { |
bsalomon | bed83a6 | 2015-04-15 14:18:34 -0700 | [diff] [blame] | 1651 | if (!SkPaint2GrPaintNoShader(this->context(), fRenderTarget, paint, |
| 1652 | SkColor2GrColor(paint.getColor()), |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1653 | nullptr == colors, &grPaint)) { |
bsalomon | bed83a6 | 2015-04-15 14:18:34 -0700 | [diff] [blame] | 1654 | return; |
| 1655 | } |
dandov | 32a311b | 2014-07-15 19:46:26 -0700 | [diff] [blame] | 1656 | } else { |
bsalomon | bed83a6 | 2015-04-15 14:18:34 -0700 | [diff] [blame] | 1657 | if (!SkPaint2GrPaint(this->context(), fRenderTarget, paint, *draw.fMatrix, |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1658 | nullptr == colors, &grPaint)) { |
bsalomon | bed83a6 | 2015-04-15 14:18:34 -0700 | [diff] [blame] | 1659 | return; |
| 1660 | } |
dandov | 32a311b | 2014-07-15 19:46:26 -0700 | [diff] [blame] | 1661 | } |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1662 | } |
| 1663 | |
mtklein | 2583b62 | 2014-06-04 08:20:41 -0700 | [diff] [blame] | 1664 | #if 0 |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 1665 | if (xmode && texs && colors) { |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1666 | if (!SkXfermode::IsMode(xmode, SkXfermode::kModulate_Mode)) { |
| 1667 | SkDebugf("Unsupported vertex-color/texture xfer mode.\n"); |
mtklein | 2583b62 | 2014-06-04 08:20:41 -0700 | [diff] [blame] | 1668 | return; |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1669 | } |
| 1670 | } |
mtklein | 2583b62 | 2014-06-04 08:20:41 -0700 | [diff] [blame] | 1671 | #endif |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1672 | |
| 1673 | SkAutoSTMalloc<128, GrColor> convertedColors(0); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 1674 | if (colors) { |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1675 | // need to convert byte order and from non-PM to PM |
| 1676 | convertedColors.reset(vertexCount); |
commit-bot@chromium.org | c93e681 | 2014-05-23 08:09:26 +0000 | [diff] [blame] | 1677 | SkColor color; |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1678 | for (int i = 0; i < vertexCount; ++i) { |
commit-bot@chromium.org | c93e681 | 2014-05-23 08:09:26 +0000 | [diff] [blame] | 1679 | color = colors[i]; |
| 1680 | if (paint.getAlpha() != 255) { |
| 1681 | color = SkColorSetA(color, SkMulDiv255Round(SkColorGetA(color), paint.getAlpha())); |
| 1682 | } |
| 1683 | convertedColors[i] = SkColor2GrColor(color); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1684 | } |
| 1685 | colors = convertedColors.get(); |
| 1686 | } |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1687 | fDrawContext->drawVertices(fRenderTarget, |
| 1688 | fClip, |
| 1689 | grPaint, |
| 1690 | *draw.fMatrix, |
| 1691 | primType, |
| 1692 | vertexCount, |
| 1693 | vertices, |
| 1694 | texs, |
| 1695 | colors, |
| 1696 | outIndices, |
| 1697 | indexCount); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1698 | } |
| 1699 | |
| 1700 | /////////////////////////////////////////////////////////////////////////////// |
| 1701 | |
jvanverth | 31ff762 | 2015-08-07 10:09:28 -0700 | [diff] [blame] | 1702 | void SkGpuDevice::drawAtlas(const SkDraw& draw, const SkImage* atlas, const SkRSXform xform[], |
reed | ca10953 | 2015-06-25 16:25:25 -0700 | [diff] [blame] | 1703 | const SkRect texRect[], const SkColor colors[], int count, |
| 1704 | SkXfermode::Mode mode, const SkPaint& paint) { |
| 1705 | if (paint.isAntiAlias()) { |
jvanverth | 31ff762 | 2015-08-07 10:09:28 -0700 | [diff] [blame] | 1706 | this->INHERITED::drawAtlas(draw, atlas, xform, texRect, colors, count, mode, paint); |
reed | ca10953 | 2015-06-25 16:25:25 -0700 | [diff] [blame] | 1707 | return; |
| 1708 | } |
| 1709 | |
jvanverth | 31ff762 | 2015-08-07 10:09:28 -0700 | [diff] [blame] | 1710 | CHECK_SHOULD_DRAW(draw); |
| 1711 | GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawText", fContext); |
| 1712 | |
reed | ca10953 | 2015-06-25 16:25:25 -0700 | [diff] [blame] | 1713 | SkPaint p(paint); |
| 1714 | p.setShader(atlas->newShader(SkShader::kClamp_TileMode, SkShader::kClamp_TileMode))->unref(); |
| 1715 | |
jvanverth | 31ff762 | 2015-08-07 10:09:28 -0700 | [diff] [blame] | 1716 | GrPaint grPaint; |
| 1717 | if (!SkPaint2GrPaint(this->context(), fRenderTarget, p, *draw.fMatrix, !colors, &grPaint)) { |
| 1718 | return; |
reed | ca10953 | 2015-06-25 16:25:25 -0700 | [diff] [blame] | 1719 | } |
jvanverth | 31ff762 | 2015-08-07 10:09:28 -0700 | [diff] [blame] | 1720 | |
| 1721 | SkDEBUGCODE(this->validate();) |
| 1722 | |
| 1723 | #if 0 |
robertphillips | 29ccdf8 | 2015-07-24 10:20:45 -0700 | [diff] [blame] | 1724 | if (colors) { |
jvanverth | 31ff762 | 2015-08-07 10:09:28 -0700 | [diff] [blame] | 1725 | if (SkXfermode::kModulate_Mode != mode) { |
| 1726 | SkDebugf("Unsupported vertex-color/texture xfer mode.\n"); |
| 1727 | return; |
robertphillips | 29ccdf8 | 2015-07-24 10:20:45 -0700 | [diff] [blame] | 1728 | } |
| 1729 | } |
jvanverth | 31ff762 | 2015-08-07 10:09:28 -0700 | [diff] [blame] | 1730 | #endif |
| 1731 | |
| 1732 | fDrawContext->drawAtlas(fRenderTarget, fClip, grPaint, *draw.fMatrix, |
| 1733 | count, xform, texRect, colors); |
reed | ca10953 | 2015-06-25 16:25:25 -0700 | [diff] [blame] | 1734 | } |
| 1735 | |
| 1736 | /////////////////////////////////////////////////////////////////////////////// |
| 1737 | |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1738 | void SkGpuDevice::drawText(const SkDraw& draw, const void* text, |
joshualitt | 5531d51 | 2014-12-17 15:50:11 -0800 | [diff] [blame] | 1739 | size_t byteLength, SkScalar x, SkScalar y, |
| 1740 | const SkPaint& paint) { |
| 1741 | CHECK_SHOULD_DRAW(draw); |
egdaniel | d78a168 | 2014-07-09 10:41:26 -0700 | [diff] [blame] | 1742 | GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawText", fContext); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1743 | |
jvanverth | 8c27a18 | 2014-10-14 08:45:50 -0700 | [diff] [blame] | 1744 | GrPaint grPaint; |
bsalomon | bed83a6 | 2015-04-15 14:18:34 -0700 | [diff] [blame] | 1745 | if (!SkPaint2GrPaint(this->context(), fRenderTarget, paint, *draw.fMatrix, true, &grPaint)) { |
| 1746 | return; |
| 1747 | } |
commit-bot@chromium.org | 8128d8c | 2013-12-19 16:12:25 +0000 | [diff] [blame] | 1748 | |
jvanverth | 8c27a18 | 2014-10-14 08:45:50 -0700 | [diff] [blame] | 1749 | SkDEBUGCODE(this->validate();) |
commit-bot@chromium.org | 8128d8c | 2013-12-19 16:12:25 +0000 | [diff] [blame] | 1750 | |
robertphillips | 2334fb6 | 2015-06-17 05:43:33 -0700 | [diff] [blame] | 1751 | fDrawContext->drawText(fRenderTarget, fClip, grPaint, paint, *draw.fMatrix, |
joshualitt | 6e8cd96 | 2015-03-20 10:30:14 -0700 | [diff] [blame] | 1752 | (const char *)text, byteLength, x, y, draw.fClip->getBounds()); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1753 | } |
| 1754 | |
fmalita | 05c4a43 | 2014-09-29 06:29:53 -0700 | [diff] [blame] | 1755 | void SkGpuDevice::drawPosText(const SkDraw& draw, const void* text, size_t byteLength, |
| 1756 | const SkScalar pos[], int scalarsPerPos, |
| 1757 | const SkPoint& offset, const SkPaint& paint) { |
egdaniel | bbcb38d | 2014-06-19 10:19:29 -0700 | [diff] [blame] | 1758 | GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawPosText", fContext); |
joshualitt | 5531d51 | 2014-12-17 15:50:11 -0800 | [diff] [blame] | 1759 | CHECK_SHOULD_DRAW(draw); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1760 | |
jvanverth | 8c27a18 | 2014-10-14 08:45:50 -0700 | [diff] [blame] | 1761 | GrPaint grPaint; |
bsalomon | bed83a6 | 2015-04-15 14:18:34 -0700 | [diff] [blame] | 1762 | if (!SkPaint2GrPaint(this->context(), fRenderTarget, paint, *draw.fMatrix, true, &grPaint)) { |
| 1763 | return; |
| 1764 | } |
commit-bot@chromium.org | 8128d8c | 2013-12-19 16:12:25 +0000 | [diff] [blame] | 1765 | |
jvanverth | 8c27a18 | 2014-10-14 08:45:50 -0700 | [diff] [blame] | 1766 | SkDEBUGCODE(this->validate();) |
commit-bot@chromium.org | 8128d8c | 2013-12-19 16:12:25 +0000 | [diff] [blame] | 1767 | |
robertphillips | 2334fb6 | 2015-06-17 05:43:33 -0700 | [diff] [blame] | 1768 | fDrawContext->drawPosText(fRenderTarget, fClip, grPaint, paint, *draw.fMatrix, |
joshualitt | 6e8cd96 | 2015-03-20 10:30:14 -0700 | [diff] [blame] | 1769 | (const char *)text, byteLength, pos, scalarsPerPos, offset, |
| 1770 | draw.fClip->getBounds()); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1771 | } |
| 1772 | |
joshualitt | 9c32818 | 2015-03-23 08:13:04 -0700 | [diff] [blame] | 1773 | void SkGpuDevice::drawTextBlob(const SkDraw& draw, const SkTextBlob* blob, SkScalar x, SkScalar y, |
| 1774 | const SkPaint& paint, SkDrawFilter* drawFilter) { |
| 1775 | GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawTextBlob", fContext); |
| 1776 | CHECK_SHOULD_DRAW(draw); |
| 1777 | |
| 1778 | SkDEBUGCODE(this->validate();) |
| 1779 | |
robertphillips | 2334fb6 | 2015-06-17 05:43:33 -0700 | [diff] [blame] | 1780 | fDrawContext->drawTextBlob(fRenderTarget, fClip, paint, *draw.fMatrix, |
robertphillips | ccb1b57 | 2015-05-27 11:02:55 -0700 | [diff] [blame] | 1781 | blob, x, y, drawFilter, draw.fClip->getBounds()); |
joshualitt | 9c32818 | 2015-03-23 08:13:04 -0700 | [diff] [blame] | 1782 | } |
| 1783 | |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1784 | /////////////////////////////////////////////////////////////////////////////// |
| 1785 | |
reed | b2db898 | 2014-11-13 12:41:02 -0800 | [diff] [blame] | 1786 | bool SkGpuDevice::onShouldDisableLCD(const SkPaint& paint) const { |
robertphillips | 9c240a1 | 2015-05-28 07:45:59 -0700 | [diff] [blame] | 1787 | return GrTextContext::ShouldDisableLCD(paint); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1788 | } |
| 1789 | |
| 1790 | void SkGpuDevice::flush() { |
| 1791 | DO_DEFERRED_CLEAR(); |
bsalomon | c49e868 | 2015-06-30 11:37:35 -0700 | [diff] [blame] | 1792 | fRenderTarget->prepareForExternalIO(); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1793 | } |
| 1794 | |
| 1795 | /////////////////////////////////////////////////////////////////////////////// |
| 1796 | |
reed | 76033be | 2015-03-14 10:54:31 -0700 | [diff] [blame] | 1797 | SkBaseDevice* SkGpuDevice::onCreateDevice(const CreateInfo& cinfo, const SkPaint*) { |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 1798 | GrSurfaceDesc desc; |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1799 | desc.fConfig = fRenderTarget->config(); |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 1800 | desc.fFlags = kRenderTarget_GrSurfaceFlag; |
fmalita | 6987dca | 2014-11-13 08:33:37 -0800 | [diff] [blame] | 1801 | desc.fWidth = cinfo.fInfo.width(); |
| 1802 | desc.fHeight = cinfo.fInfo.height(); |
vbuzinov | dded696 | 2015-06-12 08:59:45 -0700 | [diff] [blame] | 1803 | desc.fSampleCnt = fRenderTarget->desc().fSampleCnt; |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1804 | |
| 1805 | SkAutoTUnref<GrTexture> texture; |
| 1806 | // Skia's convention is to only clear a device if it is non-opaque. |
bsalomon | 74f681d | 2015-06-23 14:38:48 -0700 | [diff] [blame] | 1807 | InitContents init = cinfo.fInfo.isOpaque() ? kUninit_InitContents : kClear_InitContents; |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1808 | |
hcm | 4396fa5 | 2014-10-27 21:43:30 -0700 | [diff] [blame] | 1809 | // layers are never draw in repeat modes, so we can request an approx |
| 1810 | // match and ignore any padding. |
bsalomon | eae6200 | 2015-07-31 13:59:30 -0700 | [diff] [blame] | 1811 | if (kNever_TileUsage == cinfo.fTileUsage) { |
| 1812 | texture.reset(fContext->textureProvider()->createApproxTexture(desc)); |
| 1813 | } else { |
| 1814 | texture.reset(fContext->textureProvider()->createTexture(desc, true)); |
| 1815 | } |
bsalomon | afe3005 | 2015-01-16 07:32:33 -0800 | [diff] [blame] | 1816 | |
| 1817 | if (texture) { |
robertphillips | 7b05ff1 | 2015-06-19 14:14:54 -0700 | [diff] [blame] | 1818 | SkSurfaceProps props(this->surfaceProps().flags(), cinfo.fPixelGeometry); |
senorblanco | d0d37ca | 2015-04-02 04:54:56 -0700 | [diff] [blame] | 1819 | return SkGpuDevice::Create( |
bsalomon | 74f681d | 2015-06-23 14:38:48 -0700 | [diff] [blame] | 1820 | texture->asRenderTarget(), cinfo.fInfo.width(), cinfo.fInfo.height(), &props, init); |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1821 | } else { |
joshualitt | 5f5a8d7 | 2015-02-25 14:09:45 -0800 | [diff] [blame] | 1822 | SkErrorInternals::SetError( kInternalError_SkError, |
reed | 61f501f | 2015-04-29 08:34:00 -0700 | [diff] [blame] | 1823 | "---- failed to create gpu device texture [%d %d]\n", |
joshualitt | 5f5a8d7 | 2015-02-25 14:09:45 -0800 | [diff] [blame] | 1824 | cinfo.fInfo.width(), cinfo.fInfo.height()); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1825 | return nullptr; |
skia.committer@gmail.com | 11a253b | 2013-11-12 07:02:05 +0000 | [diff] [blame] | 1826 | } |
| 1827 | } |
| 1828 | |
reed | 4a8126e | 2014-09-22 07:29:03 -0700 | [diff] [blame] | 1829 | SkSurface* SkGpuDevice::newSurface(const SkImageInfo& info, const SkSurfaceProps& props) { |
bsalomon | afe3005 | 2015-01-16 07:32:33 -0800 | [diff] [blame] | 1830 | // TODO: Change the signature of newSurface to take a budgeted parameter. |
| 1831 | static const SkSurface::Budgeted kBudgeted = SkSurface::kNo_Budgeted; |
vbuzinov | dded696 | 2015-06-12 08:59:45 -0700 | [diff] [blame] | 1832 | return SkSurface::NewRenderTarget(fContext, kBudgeted, info, fRenderTarget->desc().fSampleCnt, |
bsalomon | afe3005 | 2015-01-16 07:32:33 -0800 | [diff] [blame] | 1833 | &props); |
reed@google.com | 76f10a3 | 2014-02-05 15:32:21 +0000 | [diff] [blame] | 1834 | } |
| 1835 | |
robertphillips | 30d2cc6 | 2014-09-24 08:52:18 -0700 | [diff] [blame] | 1836 | bool SkGpuDevice::EXPERIMENTAL_drawPicture(SkCanvas* mainCanvas, const SkPicture* mainPicture, |
reed | d5fa1a4 | 2014-08-09 11:08:05 -0700 | [diff] [blame] | 1837 | const SkMatrix* matrix, const SkPaint* paint) { |
robertphillips | 63242d7 | 2014-12-04 08:31:02 -0800 | [diff] [blame] | 1838 | #ifndef SK_IGNORE_GPU_LAYER_HOISTING |
robertphillips | 30d7841 | 2014-11-24 09:49:17 -0800 | [diff] [blame] | 1839 | // todo: should handle this natively |
| 1840 | if (paint) { |
reed | d5fa1a4 | 2014-08-09 11:08:05 -0700 | [diff] [blame] | 1841 | return false; |
| 1842 | } |
| 1843 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1844 | const SkBigPicture::AccelData* data = nullptr; |
mtklein | 9db912c | 2015-05-19 11:11:26 -0700 | [diff] [blame] | 1845 | if (const SkBigPicture* bp = mainPicture->asSkBigPicture()) { |
| 1846 | data = bp->accelData(); |
| 1847 | } |
robertphillips | 81f71b6 | 2014-11-11 04:54:49 -0800 | [diff] [blame] | 1848 | if (!data) { |
| 1849 | return false; |
| 1850 | } |
| 1851 | |
robertphillips | e5524cd | 2015-02-20 12:30:26 -0800 | [diff] [blame] | 1852 | const SkLayerInfo *gpuData = static_cast<const SkLayerInfo*>(data); |
| 1853 | if (0 == gpuData->numBlocks()) { |
| 1854 | return false; |
commit-bot@chromium.org | 8ddc26b | 2014-03-31 17:55:12 +0000 | [diff] [blame] | 1855 | } |
| 1856 | |
robertphillips | fd61ed0 | 2014-10-28 07:21:44 -0700 | [diff] [blame] | 1857 | SkTDArray<GrHoistedLayer> atlasedNeedRendering, atlasedRecycled; |
robertphillips | 1c4c528 | 2014-09-18 12:03:15 -0700 | [diff] [blame] | 1858 | |
robertphillips | e5524cd | 2015-02-20 12:30:26 -0800 | [diff] [blame] | 1859 | SkIRect iBounds; |
| 1860 | if (!mainCanvas->getClipDeviceBounds(&iBounds)) { |
| 1861 | return false; |
| 1862 | } |
| 1863 | |
| 1864 | SkRect clipBounds = SkRect::Make(iBounds); |
| 1865 | |
| 1866 | SkMatrix initialMatrix = mainCanvas->getTotalMatrix(); |
| 1867 | |
robertphillips | fd61ed0 | 2014-10-28 07:21:44 -0700 | [diff] [blame] | 1868 | GrLayerHoister::FindLayersToAtlas(fContext, mainPicture, |
robertphillips | 30d7841 | 2014-11-24 09:49:17 -0800 | [diff] [blame] | 1869 | initialMatrix, |
robertphillips | fd61ed0 | 2014-10-28 07:21:44 -0700 | [diff] [blame] | 1870 | clipBounds, |
robertphillips | a63f32e | 2014-11-10 08:10:42 -0800 | [diff] [blame] | 1871 | &atlasedNeedRendering, &atlasedRecycled, |
vbuzinov | dded696 | 2015-06-12 08:59:45 -0700 | [diff] [blame] | 1872 | fRenderTarget->numColorSamples()); |
robertphillips | fd61ed0 | 2014-10-28 07:21:44 -0700 | [diff] [blame] | 1873 | |
| 1874 | GrLayerHoister::DrawLayersToAtlas(fContext, atlasedNeedRendering); |
| 1875 | |
| 1876 | SkTDArray<GrHoistedLayer> needRendering, recycled; |
| 1877 | |
robertphillips | e5524cd | 2015-02-20 12:30:26 -0800 | [diff] [blame] | 1878 | SkAutoCanvasMatrixPaint acmp(mainCanvas, matrix, paint, mainPicture->cullRect()); |
| 1879 | |
robertphillips | fd61ed0 | 2014-10-28 07:21:44 -0700 | [diff] [blame] | 1880 | GrLayerHoister::FindLayersToHoist(fContext, mainPicture, |
robertphillips | 30d7841 | 2014-11-24 09:49:17 -0800 | [diff] [blame] | 1881 | initialMatrix, |
robertphillips | fd61ed0 | 2014-10-28 07:21:44 -0700 | [diff] [blame] | 1882 | clipBounds, |
robertphillips | a63f32e | 2014-11-10 08:10:42 -0800 | [diff] [blame] | 1883 | &needRendering, &recycled, |
vbuzinov | dded696 | 2015-06-12 08:59:45 -0700 | [diff] [blame] | 1884 | fRenderTarget->numColorSamples()); |
robertphillips | fd61ed0 | 2014-10-28 07:21:44 -0700 | [diff] [blame] | 1885 | |
| 1886 | GrLayerHoister::DrawLayers(fContext, needRendering); |
robertphillips@google.com | beb1af2 | 2014-05-07 21:31:09 +0000 | [diff] [blame] | 1887 | |
robertphillips | 64bf767 | 2014-08-21 13:07:35 -0700 | [diff] [blame] | 1888 | // Render the entire picture using new layers |
robertphillips | e99d499 | 2014-12-03 07:33:57 -0800 | [diff] [blame] | 1889 | GrRecordReplaceDraw(mainPicture, mainCanvas, fContext->getLayerCache(), |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1890 | initialMatrix, nullptr); |
robertphillips | 64bf767 | 2014-08-21 13:07:35 -0700 | [diff] [blame] | 1891 | |
robertphillips | fd61ed0 | 2014-10-28 07:21:44 -0700 | [diff] [blame] | 1892 | GrLayerHoister::UnlockLayers(fContext, needRendering); |
| 1893 | GrLayerHoister::UnlockLayers(fContext, recycled); |
| 1894 | GrLayerHoister::UnlockLayers(fContext, atlasedNeedRendering); |
| 1895 | GrLayerHoister::UnlockLayers(fContext, atlasedRecycled); |
robertphillips | 64bf767 | 2014-08-21 13:07:35 -0700 | [diff] [blame] | 1896 | |
| 1897 | return true; |
robertphillips | 63242d7 | 2014-12-04 08:31:02 -0800 | [diff] [blame] | 1898 | #else |
| 1899 | return false; |
| 1900 | #endif |
robertphillips | 64bf767 | 2014-08-21 13:07:35 -0700 | [diff] [blame] | 1901 | } |
| 1902 | |
senorblanco | be129b2 | 2014-08-08 07:14:35 -0700 | [diff] [blame] | 1903 | SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { |
senorblanco | 55b6d8b | 2014-07-30 11:26:46 -0700 | [diff] [blame] | 1904 | // We always return a transient cache, so it is freed after each |
| 1905 | // filter traversal. |
senorblanco | be129b2 | 2014-08-08 07:14:35 -0700 | [diff] [blame] | 1906 | return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); |
senorblanco | 55b6d8b | 2014-07-30 11:26:46 -0700 | [diff] [blame] | 1907 | } |
reed | f037e0b | 2014-10-30 11:34:15 -0700 | [diff] [blame] | 1908 | |
| 1909 | #endif |