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