epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 2 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 3 | * Copyright 2011 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
bsalomon@google.com | 1fadb20 | 2011-12-12 16:10:08 +0000 | [diff] [blame] | 9 | #include "GrContext.h" |
| 10 | |
jvanverth@google.com | bfe2b9d | 2013-09-06 16:57:29 +0000 | [diff] [blame] | 11 | #include "GrAARectRenderer.h" |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 12 | #include "GrAtlasTextContext.h" |
joshualitt | 0823bfa | 2015-02-27 10:06:15 -0800 | [diff] [blame] | 13 | #include "GrBatch.h" |
joshualitt | 7c3a2f8 | 2015-03-31 13:32:05 -0700 | [diff] [blame] | 14 | #include "GrBatchFontCache.h" |
joshualitt | 0823bfa | 2015-02-27 10:06:15 -0800 | [diff] [blame] | 15 | #include "GrBatchTarget.h" |
tomhudson@google.com | 278cbb4 | 2011-06-30 19:37:01 +0000 | [diff] [blame] | 16 | #include "GrBufferAllocPool.h" |
joshualitt | 5478d42 | 2014-11-14 16:00:38 -0800 | [diff] [blame] | 17 | #include "GrDefaultGeoProcFactory.h" |
bsalomon | 453cf40 | 2014-11-11 14:15:57 -0800 | [diff] [blame] | 18 | #include "GrGpuResource.h" |
bsalomon | 3582d3e | 2015-02-13 14:20:05 -0800 | [diff] [blame] | 19 | #include "GrGpuResourcePriv.h" |
commit-bot@chromium.org | 4784182 | 2014-03-27 14:19:17 +0000 | [diff] [blame] | 20 | #include "GrDrawTargetCaps.h" |
joshualitt | 5478d42 | 2014-11-14 16:00:38 -0800 | [diff] [blame] | 21 | #include "GrGpu.h" |
commit-bot@chromium.org | dcb8ef9 | 2014-03-27 11:26:10 +0000 | [diff] [blame] | 22 | #include "GrIndexBuffer.h" |
commit-bot@chromium.org | 4784182 | 2014-03-27 14:19:17 +0000 | [diff] [blame] | 23 | #include "GrInOrderDrawBuffer.h" |
robertphillips@google.com | e930a07 | 2014-04-03 00:34:27 +0000 | [diff] [blame] | 24 | #include "GrLayerCache.h" |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 25 | #include "GrOvalRenderer.h" |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 26 | #include "GrPathRenderer.h" |
tomhudson@google.com | d22b6e4 | 2011-06-24 15:53:40 +0000 | [diff] [blame] | 27 | #include "GrPathUtils.h" |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 28 | #include "GrRenderTargetPriv.h" |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 29 | #include "GrResourceCache.h" |
bsalomon | d309e7a | 2015-04-30 14:18:54 -0700 | [diff] [blame^] | 30 | #include "GrResourceProvider.h" |
robertphillips@google.com | 72176b2 | 2012-05-23 13:19:12 +0000 | [diff] [blame] | 31 | #include "GrSoftwarePathRenderer.h" |
kkinnunen | c6cb56f | 2014-06-24 00:12:27 -0700 | [diff] [blame] | 32 | #include "GrStencilAndCoverTextContext.h" |
egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 33 | #include "GrStrokeInfo.h" |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame] | 34 | #include "GrSurfacePriv.h" |
joshualitt | b7133be | 2015-04-08 09:08:31 -0700 | [diff] [blame] | 35 | #include "GrTextBlobCache.h" |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame] | 36 | #include "GrTexturePriv.h" |
egdaniel | bbcb38d | 2014-06-19 10:19:29 -0700 | [diff] [blame] | 37 | #include "GrTraceMarker.h" |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 38 | #include "GrTracing.h" |
egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 39 | #include "SkDashPathPriv.h" |
bsalomon | 81beccc | 2014-10-13 12:32:55 -0700 | [diff] [blame] | 40 | #include "SkConfig8888.h" |
reed@google.com | 7111d46 | 2014-03-25 16:20:24 +0000 | [diff] [blame] | 41 | #include "SkGr.h" |
commit-bot@chromium.org | 4784182 | 2014-03-27 14:19:17 +0000 | [diff] [blame] | 42 | #include "SkRRect.h" |
sugoi@google.com | 5f74cf8 | 2012-12-17 21:16:45 +0000 | [diff] [blame] | 43 | #include "SkStrokeRec.h" |
commit-bot@chromium.org | dcb8ef9 | 2014-03-27 11:26:10 +0000 | [diff] [blame] | 44 | #include "SkTLazy.h" |
commit-bot@chromium.org | 4784182 | 2014-03-27 14:19:17 +0000 | [diff] [blame] | 45 | #include "SkTLS.h" |
commit-bot@chromium.org | 933e65d | 2014-03-20 20:00:24 +0000 | [diff] [blame] | 46 | #include "SkTraceEvent.h" |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 47 | |
joshualitt | 5478d42 | 2014-11-14 16:00:38 -0800 | [diff] [blame] | 48 | #include "effects/GrConfigConversionEffect.h" |
| 49 | #include "effects/GrDashingEffect.h" |
| 50 | #include "effects/GrSingleTextureEffect.h" |
| 51 | |
bsalomon@google.com | 6036149 | 2012-03-15 17:47:06 +0000 | [diff] [blame] | 52 | static const size_t DRAW_BUFFER_VBPOOL_BUFFER_SIZE = 1 << 15; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 53 | static const int DRAW_BUFFER_VBPOOL_PREALLOC_BUFFERS = 4; |
| 54 | |
bsalomon@google.com | 1d4edd3 | 2012-08-16 18:36:06 +0000 | [diff] [blame] | 55 | static const size_t DRAW_BUFFER_IBPOOL_BUFFER_SIZE = 1 << 11; |
| 56 | static const int DRAW_BUFFER_IBPOOL_PREALLOC_BUFFERS = 4; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 57 | |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 58 | #define ASSERT_OWNED_RESOURCE(R) SkASSERT(!(R) || (R)->getContext() == this) |
joshualitt | 5f5a8d7 | 2015-02-25 14:09:45 -0800 | [diff] [blame] | 59 | #define RETURN_IF_ABANDONED if (!fDrawBuffer) { return; } |
| 60 | #define RETURN_FALSE_IF_ABANDONED if (!fDrawBuffer) { return false; } |
| 61 | #define RETURN_NULL_IF_ABANDONED if (!fDrawBuffer) { return NULL; } |
bsalomon@google.com | bc4b654 | 2011-11-19 13:56:11 +0000 | [diff] [blame] | 62 | |
bsalomon | f21dab9 | 2014-11-13 13:33:28 -0800 | [diff] [blame] | 63 | class GrContext::AutoCheckFlush { |
| 64 | public: |
| 65 | AutoCheckFlush(GrContext* context) : fContext(context) { SkASSERT(context); } |
| 66 | |
| 67 | ~AutoCheckFlush() { |
| 68 | if (fContext->fFlushToReduceCacheSize) { |
| 69 | fContext->flush(); |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | private: |
| 74 | GrContext* fContext; |
| 75 | }; |
| 76 | |
krajcevski | 9c6d4d7 | 2014-08-12 07:26:25 -0700 | [diff] [blame] | 77 | GrContext* GrContext::Create(GrBackend backend, GrBackendContext backendContext, |
| 78 | const Options* opts) { |
| 79 | GrContext* context; |
| 80 | if (NULL == opts) { |
| 81 | context = SkNEW_ARGS(GrContext, (Options())); |
| 82 | } else { |
| 83 | context = SkNEW_ARGS(GrContext, (*opts)); |
| 84 | } |
| 85 | |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 86 | if (context->init(backend, backendContext)) { |
| 87 | return context; |
| 88 | } else { |
| 89 | context->unref(); |
| 90 | return NULL; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 91 | } |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 92 | } |
| 93 | |
krajcevski | 9c6d4d7 | 2014-08-12 07:26:25 -0700 | [diff] [blame] | 94 | GrContext::GrContext(const Options& opts) : fOptions(opts) { |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 95 | fGpu = NULL; |
bsalomon | d309e7a | 2015-04-30 14:18:54 -0700 | [diff] [blame^] | 96 | fResourceCache = NULL; |
| 97 | fResourceProvider = NULL; |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 98 | fPathRendererChain = NULL; |
| 99 | fSoftwarePathRenderer = NULL; |
joshualitt | 7c3a2f8 | 2015-03-31 13:32:05 -0700 | [diff] [blame] | 100 | fBatchFontCache = NULL; |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 101 | fDrawBuffer = NULL; |
| 102 | fDrawBufferVBAllocPool = NULL; |
| 103 | fDrawBufferIBAllocPool = NULL; |
bsalomon | f21dab9 | 2014-11-13 13:33:28 -0800 | [diff] [blame] | 104 | fFlushToReduceCacheSize = false; |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 105 | fAARectRenderer = NULL; |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 106 | fOvalRenderer = NULL; |
robertphillips@google.com | 44a91dc | 2013-07-25 15:32:06 +0000 | [diff] [blame] | 107 | fMaxTextureSizeOverride = 1 << 20; |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | bool GrContext::init(GrBackend backend, GrBackendContext backendContext) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 111 | SkASSERT(NULL == fGpu); |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 112 | |
| 113 | fGpu = GrGpu::Create(backend, backendContext, this); |
| 114 | if (NULL == fGpu) { |
| 115 | return false; |
| 116 | } |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 117 | this->initCommon(); |
| 118 | return true; |
| 119 | } |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 120 | |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 121 | void GrContext::initCommon() { |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 122 | fResourceCache = SkNEW(GrResourceCache); |
| 123 | fResourceCache->setOverBudgetCallback(OverBudgetCB, this); |
bsalomon | d309e7a | 2015-04-30 14:18:54 -0700 | [diff] [blame^] | 124 | fResourceProvider = SkNEW_ARGS(GrResourceProvider, (fGpu, fResourceCache)); |
commit-bot@chromium.org | 1836d33 | 2013-07-16 22:55:03 +0000 | [diff] [blame] | 125 | |
robertphillips | 4ec84da | 2014-06-24 13:10:43 -0700 | [diff] [blame] | 126 | fLayerCache.reset(SkNEW_ARGS(GrLayerCache, (this))); |
robertphillips@google.com | e930a07 | 2014-04-03 00:34:27 +0000 | [diff] [blame] | 127 | |
joshualitt | b44293e | 2014-10-28 08:12:18 -0700 | [diff] [blame] | 128 | fAARectRenderer = SkNEW_ARGS(GrAARectRenderer, (fGpu)); |
joshualitt | 5531d51 | 2014-12-17 15:50:11 -0800 | [diff] [blame] | 129 | fOvalRenderer = SkNEW_ARGS(GrOvalRenderer, (fGpu)); |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 130 | |
| 131 | fDidTestPMConversions = false; |
| 132 | |
| 133 | this->setupDrawBuffer(); |
joshualitt | 7c3a2f8 | 2015-03-31 13:32:05 -0700 | [diff] [blame] | 134 | |
| 135 | // GrBatchFontCache will eventually replace GrFontCache |
joshualitt | 62db8ba | 2015-04-09 08:22:37 -0700 | [diff] [blame] | 136 | fBatchFontCache = SkNEW_ARGS(GrBatchFontCache, (this)); |
joshualitt | b7133be | 2015-04-08 09:08:31 -0700 | [diff] [blame] | 137 | |
joshualitt | 0db6dfa | 2015-04-10 07:01:30 -0700 | [diff] [blame] | 138 | fTextBlobCache.reset(SkNEW_ARGS(GrTextBlobCache, (TextBlobCacheOverBudgetCB, this))); |
bsalomon@google.com | c0af317 | 2012-06-15 14:10:09 +0000 | [diff] [blame] | 139 | } |
| 140 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 141 | GrContext::~GrContext() { |
bsalomon@google.com | 733c062 | 2013-04-24 17:59:32 +0000 | [diff] [blame] | 142 | if (NULL == fGpu) { |
| 143 | return; |
| 144 | } |
| 145 | |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 146 | this->flush(); |
robertphillips@google.com | 5acc0e3 | 2012-05-17 12:01:02 +0000 | [diff] [blame] | 147 | |
robertphillips@google.com | 950b1b0 | 2013-10-21 17:37:28 +0000 | [diff] [blame] | 148 | for (int i = 0; i < fCleanUpData.count(); ++i) { |
| 149 | (*fCleanUpData[i].fFunc)(this, fCleanUpData[i].fInfo); |
| 150 | } |
| 151 | |
bsalomon | d309e7a | 2015-04-30 14:18:54 -0700 | [diff] [blame^] | 152 | SkDELETE(fResourceProvider); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 153 | SkDELETE(fResourceCache); |
joshualitt | 7c3a2f8 | 2015-03-31 13:32:05 -0700 | [diff] [blame] | 154 | SkDELETE(fBatchFontCache); |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 155 | SkDELETE(fDrawBuffer); |
| 156 | SkDELETE(fDrawBufferVBAllocPool); |
| 157 | SkDELETE(fDrawBufferIBAllocPool); |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 158 | |
robertphillips@google.com | f6747b0 | 2012-06-12 00:32:28 +0000 | [diff] [blame] | 159 | fAARectRenderer->unref(); |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 160 | fOvalRenderer->unref(); |
robertphillips@google.com | f6747b0 | 2012-06-12 00:32:28 +0000 | [diff] [blame] | 161 | |
bsalomon@google.com | 205d460 | 2011-04-25 12:43:45 +0000 | [diff] [blame] | 162 | fGpu->unref(); |
commit-bot@chromium.org | a4de8c2 | 2013-09-09 13:38:37 +0000 | [diff] [blame] | 163 | SkSafeUnref(fPathRendererChain); |
| 164 | SkSafeUnref(fSoftwarePathRenderer); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 165 | } |
| 166 | |
bsalomon | 2354f84 | 2014-07-28 13:48:36 -0700 | [diff] [blame] | 167 | void GrContext::abandonContext() { |
bsalomon | d309e7a | 2015-04-30 14:18:54 -0700 | [diff] [blame^] | 168 | fResourceProvider->abandon(); |
bsalomon@google.com | 205d460 | 2011-04-25 12:43:45 +0000 | [diff] [blame] | 169 | // abandon first to so destructors |
| 170 | // don't try to free the resources in the API. |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 171 | fResourceCache->abandonAll(); |
bsalomon | c8dc1f7 | 2014-08-21 13:02:13 -0700 | [diff] [blame] | 172 | |
robertphillips | e337130 | 2014-09-17 06:01:06 -0700 | [diff] [blame] | 173 | fGpu->contextAbandoned(); |
bsalomon@google.com | 205d460 | 2011-04-25 12:43:45 +0000 | [diff] [blame] | 174 | |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 175 | // a path renderer may be holding onto resources that |
| 176 | // are now unusable |
commit-bot@chromium.org | a4de8c2 | 2013-09-09 13:38:37 +0000 | [diff] [blame] | 177 | SkSafeSetNull(fPathRendererChain); |
| 178 | SkSafeSetNull(fSoftwarePathRenderer); |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 179 | |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 180 | delete fDrawBuffer; |
| 181 | fDrawBuffer = NULL; |
bsalomon@google.com | 205d460 | 2011-04-25 12:43:45 +0000 | [diff] [blame] | 182 | |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 183 | delete fDrawBufferVBAllocPool; |
| 184 | fDrawBufferVBAllocPool = NULL; |
bsalomon@google.com | 205d460 | 2011-04-25 12:43:45 +0000 | [diff] [blame] | 185 | |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 186 | delete fDrawBufferIBAllocPool; |
| 187 | fDrawBufferIBAllocPool = NULL; |
| 188 | |
robertphillips@google.com | f6747b0 | 2012-06-12 00:32:28 +0000 | [diff] [blame] | 189 | fAARectRenderer->reset(); |
commit-bot@chromium.org | ef284a8 | 2013-07-11 22:29:29 +0000 | [diff] [blame] | 190 | fOvalRenderer->reset(); |
bsalomon@google.com | 205d460 | 2011-04-25 12:43:45 +0000 | [diff] [blame] | 191 | |
joshualitt | 7c3a2f8 | 2015-03-31 13:32:05 -0700 | [diff] [blame] | 192 | fBatchFontCache->freeAll(); |
robertphillips@google.com | e930a07 | 2014-04-03 00:34:27 +0000 | [diff] [blame] | 193 | fLayerCache->freeAll(); |
joshualitt | 26ffc00 | 2015-04-16 11:24:04 -0700 | [diff] [blame] | 194 | fTextBlobCache->freeAll(); |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 195 | } |
| 196 | |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 197 | void GrContext::resetContext(uint32_t state) { |
| 198 | fGpu->markContextDirty(state); |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | void GrContext::freeGpuResources() { |
| 202 | this->flush(); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 203 | |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 204 | if (fDrawBuffer) { |
bsalomon | c8dc1f7 | 2014-08-21 13:02:13 -0700 | [diff] [blame] | 205 | fDrawBuffer->purgeResources(); |
| 206 | } |
robertphillips@google.com | ff17584 | 2012-05-14 19:31:39 +0000 | [diff] [blame] | 207 | |
robertphillips@google.com | f6747b0 | 2012-06-12 00:32:28 +0000 | [diff] [blame] | 208 | fAARectRenderer->reset(); |
commit-bot@chromium.org | ef284a8 | 2013-07-11 22:29:29 +0000 | [diff] [blame] | 209 | fOvalRenderer->reset(); |
robertphillips@google.com | f6747b0 | 2012-06-12 00:32:28 +0000 | [diff] [blame] | 210 | |
joshualitt | 7c3a2f8 | 2015-03-31 13:32:05 -0700 | [diff] [blame] | 211 | fBatchFontCache->freeAll(); |
robertphillips@google.com | e930a07 | 2014-04-03 00:34:27 +0000 | [diff] [blame] | 212 | fLayerCache->freeAll(); |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 213 | // a path renderer may be holding onto resources |
commit-bot@chromium.org | a4de8c2 | 2013-09-09 13:38:37 +0000 | [diff] [blame] | 214 | SkSafeSetNull(fPathRendererChain); |
| 215 | SkSafeSetNull(fSoftwarePathRenderer); |
bsalomon | 3033b9f | 2015-04-13 11:09:56 -0700 | [diff] [blame] | 216 | |
| 217 | fResourceCache->purgeAllUnlocked(); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 218 | } |
| 219 | |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 220 | void GrContext::getResourceCacheUsage(int* resourceCount, size_t* resourceBytes) const { |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 221 | if (resourceCount) { |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 222 | *resourceCount = fResourceCache->getBudgetedResourceCount(); |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 223 | } |
| 224 | if (resourceBytes) { |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 225 | *resourceBytes = fResourceCache->getBudgetedResourceBytes(); |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 226 | } |
commit-bot@chromium.org | d8a57af | 2014-03-19 21:19:16 +0000 | [diff] [blame] | 227 | } |
| 228 | |
kkinnunen | c6cb56f | 2014-06-24 00:12:27 -0700 | [diff] [blame] | 229 | GrTextContext* GrContext::createTextContext(GrRenderTarget* renderTarget, |
joshualitt | 6e8cd96 | 2015-03-20 10:30:14 -0700 | [diff] [blame] | 230 | SkGpuDevice* gpuDevice, |
kkinnunen | c6cb56f | 2014-06-24 00:12:27 -0700 | [diff] [blame] | 231 | const SkDeviceProperties& |
| 232 | leakyProperties, |
| 233 | bool enableDistanceFieldFonts) { |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 234 | if (fGpu->caps()->shaderCaps()->pathRenderingSupport() && renderTarget->isMultisampled()) { |
egdaniel | 8dc7c3a | 2015-04-16 11:22:42 -0700 | [diff] [blame] | 235 | GrStencilAttachment* sb = renderTarget->renderTargetPriv().attachStencilAttachment(); |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 236 | if (sb) { |
joshualitt | 6e8cd96 | 2015-03-20 10:30:14 -0700 | [diff] [blame] | 237 | return GrStencilAndCoverTextContext::Create(this, gpuDevice, leakyProperties); |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 238 | } |
jvanverth | 8c27a18 | 2014-10-14 08:45:50 -0700 | [diff] [blame] | 239 | } |
| 240 | |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 241 | return GrAtlasTextContext::Create(this, gpuDevice, leakyProperties, enableDistanceFieldFonts); |
kkinnunen | c6cb56f | 2014-06-24 00:12:27 -0700 | [diff] [blame] | 242 | } |
| 243 | |
bsalomon@google.com | fea37b5 | 2011-04-25 15:51:06 +0000 | [diff] [blame] | 244 | //////////////////////////////////////////////////////////////////////////////// |
| 245 | |
bsalomon | d2a6f4e | 2015-02-04 10:55:54 -0800 | [diff] [blame] | 246 | bool GrContext::isConfigTexturable(GrPixelConfig config) const { |
| 247 | return fGpu->caps()->isConfigTexturable(config); |
| 248 | } |
| 249 | |
| 250 | bool GrContext::npotTextureTileSupport() const { |
| 251 | return fGpu->caps()->npotTextureTileSupport(); |
| 252 | } |
| 253 | |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 254 | void GrContext::OverBudgetCB(void* data) { |
bsalomon | 66a450f | 2014-11-13 13:19:10 -0800 | [diff] [blame] | 255 | SkASSERT(data); |
bsalomon | f21dab9 | 2014-11-13 13:33:28 -0800 | [diff] [blame] | 256 | |
bsalomon | 66a450f | 2014-11-13 13:19:10 -0800 | [diff] [blame] | 257 | GrContext* context = reinterpret_cast<GrContext*>(data); |
bsalomon | f21dab9 | 2014-11-13 13:33:28 -0800 | [diff] [blame] | 258 | |
| 259 | // Flush the InOrderDrawBuffer to possibly free up some textures |
| 260 | context->fFlushToReduceCacheSize = true; |
commit-bot@chromium.org | cae27fe | 2013-07-10 10:14:35 +0000 | [diff] [blame] | 261 | } |
| 262 | |
joshualitt | 0db6dfa | 2015-04-10 07:01:30 -0700 | [diff] [blame] | 263 | void GrContext::TextBlobCacheOverBudgetCB(void* data) { |
| 264 | SkASSERT(data); |
| 265 | |
| 266 | // Unlike the GrResourceCache, TextBlobs are drawn at the SkGpuDevice level, therefore they |
| 267 | // cannot use fFlushTorReduceCacheSize because it uses AutoCheckFlush. The solution is to move |
| 268 | // drawText calls to below the GrContext level, but this is not trivial because they call |
| 269 | // drawPath on SkGpuDevice |
| 270 | GrContext* context = reinterpret_cast<GrContext*>(data); |
| 271 | context->flush(); |
| 272 | } |
| 273 | |
bsalomon@google.com | 9195836 | 2011-06-13 17:58:13 +0000 | [diff] [blame] | 274 | int GrContext::getMaxTextureSize() const { |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 275 | return SkTMin(fGpu->caps()->maxTextureSize(), fMaxTextureSizeOverride); |
bsalomon@google.com | 9195836 | 2011-06-13 17:58:13 +0000 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | int GrContext::getMaxRenderTargetSize() const { |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 279 | return fGpu->caps()->maxRenderTargetSize(); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 280 | } |
| 281 | |
bsalomon@google.com | 8a70eef | 2013-03-19 13:58:55 +0000 | [diff] [blame] | 282 | int GrContext::getMaxSampleCount() const { |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 283 | return fGpu->caps()->maxSampleCount(); |
bsalomon@google.com | 8a70eef | 2013-03-19 13:58:55 +0000 | [diff] [blame] | 284 | } |
| 285 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 286 | /////////////////////////////////////////////////////////////////////////////// |
| 287 | |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 288 | void GrContext::clear(const SkIRect* rect, |
bsalomon@google.com | 07ea2db | 2012-08-17 14:06:49 +0000 | [diff] [blame] | 289 | const GrColor color, |
robertphillips@google.com | 56ce48a | 2013-10-31 21:44:25 +0000 | [diff] [blame] | 290 | bool canIgnoreRect, |
bsalomon | 41ebbdd | 2014-08-04 08:31:39 -0700 | [diff] [blame] | 291 | GrRenderTarget* renderTarget) { |
joshualitt | 5f5a8d7 | 2015-02-25 14:09:45 -0800 | [diff] [blame] | 292 | RETURN_IF_ABANDONED |
bsalomon | 41ebbdd | 2014-08-04 08:31:39 -0700 | [diff] [blame] | 293 | ASSERT_OWNED_RESOURCE(renderTarget); |
bsalomon | 89c6298 | 2014-11-03 12:08:42 -0800 | [diff] [blame] | 294 | SkASSERT(renderTarget); |
| 295 | |
bsalomon | f21dab9 | 2014-11-13 13:33:28 -0800 | [diff] [blame] | 296 | AutoCheckFlush acf(this); |
egdaniel | d78a168 | 2014-07-09 10:41:26 -0700 | [diff] [blame] | 297 | GR_CREATE_TRACE_MARKER_CONTEXT("GrContext::clear", this); |
joshualitt | 570d2f8 | 2015-02-25 13:19:48 -0800 | [diff] [blame] | 298 | GrDrawTarget* target = this->prepareToDraw(); |
bsalomon | 41ebbdd | 2014-08-04 08:31:39 -0700 | [diff] [blame] | 299 | if (NULL == target) { |
| 300 | return; |
| 301 | } |
| 302 | target->clear(rect, color, canIgnoreRect, renderTarget); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 303 | } |
| 304 | |
joshualitt | 25d9c15 | 2015-02-18 12:29:52 -0800 | [diff] [blame] | 305 | void GrContext::drawPaint(GrRenderTarget* rt, |
joshualitt | 570d2f8 | 2015-02-25 13:19:48 -0800 | [diff] [blame] | 306 | const GrClip& clip, |
joshualitt | 25d9c15 | 2015-02-18 12:29:52 -0800 | [diff] [blame] | 307 | const GrPaint& origPaint, |
| 308 | const SkMatrix& viewMatrix) { |
joshualitt | 5f5a8d7 | 2015-02-25 14:09:45 -0800 | [diff] [blame] | 309 | RETURN_IF_ABANDONED |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 310 | // set rect to be big enough to fill the space, but not super-huge, so we |
| 311 | // don't overflow fixed-point implementations |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 312 | SkRect r; |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 313 | r.setLTRB(0, 0, |
joshualitt | 25d9c15 | 2015-02-18 12:29:52 -0800 | [diff] [blame] | 314 | SkIntToScalar(rt->width()), |
| 315 | SkIntToScalar(rt->height())); |
bsalomon@google.com | 5dc26b9 | 2012-10-11 19:32:32 +0000 | [diff] [blame] | 316 | SkTCopyOnFirstWrite<GrPaint> paint(origPaint); |
joshualitt | 8fc6c2d | 2014-12-22 15:27:05 -0800 | [diff] [blame] | 317 | |
| 318 | // by definition this fills the entire clip, no need for AA |
| 319 | if (paint->isAntiAlias()) { |
| 320 | paint.writable()->setAntiAlias(false); |
| 321 | } |
| 322 | |
| 323 | bool isPerspective = viewMatrix.hasPerspective(); |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 324 | |
bsalomon@google.com | 4f83be8 | 2011-09-12 13:52:51 +0000 | [diff] [blame] | 325 | // We attempt to map r by the inverse matrix and draw that. mapRect will |
| 326 | // map the four corners and bound them with a new rect. This will not |
| 327 | // produce a correct result for some perspective matrices. |
joshualitt | 8fc6c2d | 2014-12-22 15:27:05 -0800 | [diff] [blame] | 328 | if (!isPerspective) { |
joshualitt | 5531d51 | 2014-12-17 15:50:11 -0800 | [diff] [blame] | 329 | SkMatrix inverse; |
| 330 | if (!viewMatrix.invert(&inverse)) { |
tfarina | 38406c8 | 2014-10-31 07:11:12 -0700 | [diff] [blame] | 331 | SkDebugf("Could not invert matrix\n"); |
bsalomon@google.com | 8c2fe99 | 2011-09-13 15:27:18 +0000 | [diff] [blame] | 332 | return; |
| 333 | } |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 334 | inverse.mapRect(&r); |
joshualitt | 570d2f8 | 2015-02-25 13:19:48 -0800 | [diff] [blame] | 335 | this->drawRect(rt, clip, *paint, viewMatrix, r); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 336 | } else { |
joshualitt | 8fc6c2d | 2014-12-22 15:27:05 -0800 | [diff] [blame] | 337 | SkMatrix localMatrix; |
| 338 | if (!viewMatrix.invert(&localMatrix)) { |
tfarina | 38406c8 | 2014-10-31 07:11:12 -0700 | [diff] [blame] | 339 | SkDebugf("Could not invert matrix\n"); |
bsalomon@google.com | 3cbaa2d | 2012-10-12 14:51:52 +0000 | [diff] [blame] | 340 | return; |
bsalomon@google.com | 8c2fe99 | 2011-09-13 15:27:18 +0000 | [diff] [blame] | 341 | } |
joshualitt | 8fc6c2d | 2014-12-22 15:27:05 -0800 | [diff] [blame] | 342 | |
| 343 | AutoCheckFlush acf(this); |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 344 | GrPipelineBuilder pipelineBuilder; |
joshualitt | 570d2f8 | 2015-02-25 13:19:48 -0800 | [diff] [blame] | 345 | GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, clip, paint, &acf); |
joshualitt | 8fc6c2d | 2014-12-22 15:27:05 -0800 | [diff] [blame] | 346 | if (NULL == target) { |
| 347 | return; |
| 348 | } |
| 349 | |
| 350 | GR_CREATE_TRACE_MARKER("GrContext::drawPaintWithPerspective", target); |
joshualitt | 44701df | 2015-02-23 14:44:57 -0800 | [diff] [blame] | 351 | target->drawRect(&pipelineBuilder, |
| 352 | paint->getColor(), |
| 353 | SkMatrix::I(), |
| 354 | r, |
| 355 | NULL, |
| 356 | &localMatrix); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 357 | } |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 358 | } |
| 359 | |
bsalomon@google.com | 205d460 | 2011-04-25 12:43:45 +0000 | [diff] [blame] | 360 | //////////////////////////////////////////////////////////////////////////////// |
| 361 | |
bsalomon | c30aaa0 | 2014-08-13 07:15:29 -0700 | [diff] [blame] | 362 | static inline bool is_irect(const SkRect& r) { |
tfarina | 38406c8 | 2014-10-31 07:11:12 -0700 | [diff] [blame] | 363 | return SkScalarIsInt(r.fLeft) && SkScalarIsInt(r.fTop) && |
| 364 | SkScalarIsInt(r.fRight) && SkScalarIsInt(r.fBottom); |
bsalomon | c30aaa0 | 2014-08-13 07:15:29 -0700 | [diff] [blame] | 365 | } |
| 366 | |
bsalomon@google.com | 205d460 | 2011-04-25 12:43:45 +0000 | [diff] [blame] | 367 | static bool apply_aa_to_rect(GrDrawTarget* target, |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 368 | GrPipelineBuilder* pipelineBuilder, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 369 | SkRect* devBoundRect, |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 370 | const SkRect& rect, |
robertphillips@google.com | df3695e | 2013-04-09 14:01:44 +0000 | [diff] [blame] | 371 | SkScalar strokeWidth, |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 372 | const SkMatrix& combinedMatrix, |
| 373 | GrColor color) { |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 374 | if (pipelineBuilder->getRenderTarget()->isMultisampled()) { |
bsalomon@google.com | 205d460 | 2011-04-25 12:43:45 +0000 | [diff] [blame] | 375 | return false; |
| 376 | } |
| 377 | |
robertphillips@google.com | 4b140b5 | 2013-05-02 17:13:13 +0000 | [diff] [blame] | 378 | #if defined(SHADER_AA_FILL_RECT) || !defined(IGNORE_ROT_AA_RECT_OPT) |
robertphillips@google.com | df3695e | 2013-04-09 14:01:44 +0000 | [diff] [blame] | 379 | if (strokeWidth >= 0) { |
| 380 | #endif |
commit-bot@chromium.org | 24ab3b0 | 2013-08-14 21:56:37 +0000 | [diff] [blame] | 381 | if (!combinedMatrix.preservesAxisAlignment()) { |
robertphillips@google.com | df3695e | 2013-04-09 14:01:44 +0000 | [diff] [blame] | 382 | return false; |
| 383 | } |
bsalomon@google.com | 205d460 | 2011-04-25 12:43:45 +0000 | [diff] [blame] | 384 | |
robertphillips@google.com | 4b140b5 | 2013-05-02 17:13:13 +0000 | [diff] [blame] | 385 | #if defined(SHADER_AA_FILL_RECT) || !defined(IGNORE_ROT_AA_RECT_OPT) |
robertphillips@google.com | df3695e | 2013-04-09 14:01:44 +0000 | [diff] [blame] | 386 | } else { |
commit-bot@chromium.org | 24ab3b0 | 2013-08-14 21:56:37 +0000 | [diff] [blame] | 387 | if (!combinedMatrix.preservesRightAngles()) { |
robertphillips@google.com | df3695e | 2013-04-09 14:01:44 +0000 | [diff] [blame] | 388 | return false; |
| 389 | } |
bsalomon@google.com | 205d460 | 2011-04-25 12:43:45 +0000 | [diff] [blame] | 390 | } |
robertphillips@google.com | df3695e | 2013-04-09 14:01:44 +0000 | [diff] [blame] | 391 | #endif |
bsalomon@google.com | 205d460 | 2011-04-25 12:43:45 +0000 | [diff] [blame] | 392 | |
commit-bot@chromium.org | 24ab3b0 | 2013-08-14 21:56:37 +0000 | [diff] [blame] | 393 | combinedMatrix.mapRect(devBoundRect, rect); |
derekf | e638d1c | 2014-12-02 13:51:29 -0800 | [diff] [blame] | 394 | if (!combinedMatrix.rectStaysRect()) { |
| 395 | return true; |
| 396 | } |
| 397 | |
bsalomon | c30aaa0 | 2014-08-13 07:15:29 -0700 | [diff] [blame] | 398 | if (strokeWidth < 0) { |
| 399 | return !is_irect(*devBoundRect); |
| 400 | } |
robertphillips@google.com | 28ac96e | 2013-05-13 13:38:35 +0000 | [diff] [blame] | 401 | |
bsalomon | 9c0822a | 2014-08-11 11:07:48 -0700 | [diff] [blame] | 402 | return true; |
bsalomon@google.com | 205d460 | 2011-04-25 12:43:45 +0000 | [diff] [blame] | 403 | } |
| 404 | |
commit-bot@chromium.org | 24ab3b0 | 2013-08-14 21:56:37 +0000 | [diff] [blame] | 405 | static inline bool rect_contains_inclusive(const SkRect& rect, const SkPoint& point) { |
| 406 | return point.fX >= rect.fLeft && point.fX <= rect.fRight && |
| 407 | point.fY >= rect.fTop && point.fY <= rect.fBottom; |
| 408 | } |
| 409 | |
joshualitt | 0823bfa | 2015-02-27 10:06:15 -0800 | [diff] [blame] | 410 | class StrokeRectBatch : public GrBatch { |
| 411 | public: |
| 412 | struct Geometry { |
| 413 | GrColor fColor; |
| 414 | SkMatrix fViewMatrix; |
| 415 | SkRect fRect; |
| 416 | SkScalar fStrokeWidth; |
| 417 | }; |
| 418 | |
| 419 | static GrBatch* Create(const Geometry& geometry) { |
| 420 | return SkNEW_ARGS(StrokeRectBatch, (geometry)); |
| 421 | } |
| 422 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 423 | const char* name() const override { return "StrokeRectBatch"; } |
joshualitt | 0823bfa | 2015-02-27 10:06:15 -0800 | [diff] [blame] | 424 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 425 | void getInvariantOutputColor(GrInitInvariantOutput* out) const override { |
joshualitt | 0823bfa | 2015-02-27 10:06:15 -0800 | [diff] [blame] | 426 | // When this is called on a batch, there is only one geometry bundle |
| 427 | out->setKnownFourComponents(fGeoData[0].fColor); |
| 428 | } |
| 429 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 430 | void getInvariantOutputCoverage(GrInitInvariantOutput* out) const override { |
joshualitt | 0823bfa | 2015-02-27 10:06:15 -0800 | [diff] [blame] | 431 | out->setKnownSingleComponent(0xff); |
| 432 | } |
| 433 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 434 | void initBatchTracker(const GrPipelineInfo& init) override { |
joshualitt | 0823bfa | 2015-02-27 10:06:15 -0800 | [diff] [blame] | 435 | // Handle any color overrides |
| 436 | if (init.fColorIgnored) { |
| 437 | fGeoData[0].fColor = GrColor_ILLEGAL; |
| 438 | } else if (GrColor_ILLEGAL != init.fOverrideColor) { |
| 439 | fGeoData[0].fColor = init.fOverrideColor; |
| 440 | } |
| 441 | |
| 442 | // setup batch properties |
| 443 | fBatch.fColorIgnored = init.fColorIgnored; |
| 444 | fBatch.fColor = fGeoData[0].fColor; |
| 445 | fBatch.fUsesLocalCoords = init.fUsesLocalCoords; |
| 446 | fBatch.fCoverageIgnored = init.fCoverageIgnored; |
| 447 | } |
| 448 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 449 | void generateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeline) override { |
joshualitt | 0823bfa | 2015-02-27 10:06:15 -0800 | [diff] [blame] | 450 | SkAutoTUnref<const GrGeometryProcessor> gp( |
| 451 | GrDefaultGeoProcFactory::Create(GrDefaultGeoProcFactory::kPosition_GPType, |
| 452 | this->color(), |
| 453 | this->viewMatrix(), |
| 454 | SkMatrix::I())); |
| 455 | |
| 456 | batchTarget->initDraw(gp, pipeline); |
| 457 | |
| 458 | // TODO this is hacky, but the only way we have to initialize the GP is to use the |
| 459 | // GrPipelineInfo struct so we can generate the correct shader. Once we have GrBatch |
| 460 | // everywhere we can remove this nastiness |
| 461 | GrPipelineInfo init; |
| 462 | init.fColorIgnored = fBatch.fColorIgnored; |
| 463 | init.fOverrideColor = GrColor_ILLEGAL; |
| 464 | init.fCoverageIgnored = fBatch.fCoverageIgnored; |
| 465 | init.fUsesLocalCoords = this->usesLocalCoords(); |
| 466 | gp->initBatchTracker(batchTarget->currentBatchTracker(), init); |
| 467 | |
| 468 | size_t vertexStride = gp->getVertexStride(); |
| 469 | |
| 470 | SkASSERT(vertexStride == sizeof(GrDefaultGeoProcFactory::PositionAttr)); |
| 471 | |
| 472 | Geometry& args = fGeoData[0]; |
| 473 | |
| 474 | int vertexCount = kVertsPerHairlineRect; |
| 475 | if (args.fStrokeWidth > 0) { |
| 476 | vertexCount = kVertsPerStrokeRect; |
| 477 | } |
| 478 | |
| 479 | const GrVertexBuffer* vertexBuffer; |
| 480 | int firstVertex; |
| 481 | |
| 482 | void* vertices = batchTarget->vertexPool()->makeSpace(vertexStride, |
| 483 | vertexCount, |
| 484 | &vertexBuffer, |
| 485 | &firstVertex); |
| 486 | |
joshualitt | 4b31de8 | 2015-03-05 14:33:41 -0800 | [diff] [blame] | 487 | if (!vertices) { |
| 488 | SkDebugf("Could not allocate vertices\n"); |
| 489 | return; |
| 490 | } |
| 491 | |
joshualitt | 0823bfa | 2015-02-27 10:06:15 -0800 | [diff] [blame] | 492 | SkPoint* vertex = reinterpret_cast<SkPoint*>(vertices); |
| 493 | |
| 494 | GrPrimitiveType primType; |
| 495 | |
| 496 | if (args.fStrokeWidth > 0) {; |
| 497 | primType = kTriangleStrip_GrPrimitiveType; |
| 498 | args.fRect.sort(); |
| 499 | this->setStrokeRectStrip(vertex, args.fRect, args.fStrokeWidth); |
| 500 | } else { |
| 501 | // hairline |
| 502 | primType = kLineStrip_GrPrimitiveType; |
| 503 | vertex[0].set(args.fRect.fLeft, args.fRect.fTop); |
| 504 | vertex[1].set(args.fRect.fRight, args.fRect.fTop); |
| 505 | vertex[2].set(args.fRect.fRight, args.fRect.fBottom); |
| 506 | vertex[3].set(args.fRect.fLeft, args.fRect.fBottom); |
| 507 | vertex[4].set(args.fRect.fLeft, args.fRect.fTop); |
| 508 | } |
| 509 | |
| 510 | GrDrawTarget::DrawInfo drawInfo; |
| 511 | drawInfo.setPrimitiveType(primType); |
| 512 | drawInfo.setVertexBuffer(vertexBuffer); |
| 513 | drawInfo.setStartVertex(firstVertex); |
| 514 | drawInfo.setVertexCount(vertexCount); |
| 515 | drawInfo.setStartIndex(0); |
| 516 | drawInfo.setIndexCount(0); |
| 517 | drawInfo.setInstanceCount(0); |
| 518 | drawInfo.setVerticesPerInstance(0); |
| 519 | drawInfo.setIndicesPerInstance(0); |
| 520 | batchTarget->draw(drawInfo); |
| 521 | } |
| 522 | |
| 523 | SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } |
| 524 | |
| 525 | private: |
| 526 | StrokeRectBatch(const Geometry& geometry) { |
| 527 | this->initClassID<StrokeRectBatch>(); |
| 528 | |
| 529 | fBatch.fHairline = geometry.fStrokeWidth == 0; |
| 530 | |
| 531 | fGeoData.push_back(geometry); |
| 532 | } |
| 533 | |
| 534 | /* create a triangle strip that strokes the specified rect. There are 8 |
| 535 | unique vertices, but we repeat the last 2 to close up. Alternatively we |
| 536 | could use an indices array, and then only send 8 verts, but not sure that |
| 537 | would be faster. |
| 538 | */ |
| 539 | void setStrokeRectStrip(SkPoint verts[10], const SkRect& rect, SkScalar width) { |
| 540 | const SkScalar rad = SkScalarHalf(width); |
| 541 | // TODO we should be able to enable this assert, but we'd have to filter these draws |
| 542 | // this is a bug |
| 543 | //SkASSERT(rad < rect.width() / 2 && rad < rect.height() / 2); |
| 544 | |
| 545 | verts[0].set(rect.fLeft + rad, rect.fTop + rad); |
| 546 | verts[1].set(rect.fLeft - rad, rect.fTop - rad); |
| 547 | verts[2].set(rect.fRight - rad, rect.fTop + rad); |
| 548 | verts[3].set(rect.fRight + rad, rect.fTop - rad); |
| 549 | verts[4].set(rect.fRight - rad, rect.fBottom - rad); |
| 550 | verts[5].set(rect.fRight + rad, rect.fBottom + rad); |
| 551 | verts[6].set(rect.fLeft + rad, rect.fBottom - rad); |
| 552 | verts[7].set(rect.fLeft - rad, rect.fBottom + rad); |
| 553 | verts[8] = verts[0]; |
| 554 | verts[9] = verts[1]; |
| 555 | } |
| 556 | |
| 557 | |
| 558 | GrColor color() const { return fBatch.fColor; } |
| 559 | bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; } |
| 560 | bool colorIgnored() const { return fBatch.fColorIgnored; } |
| 561 | const SkMatrix& viewMatrix() const { return fGeoData[0].fViewMatrix; } |
| 562 | bool hairline() const { return fBatch.fHairline; } |
| 563 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 564 | bool onCombineIfPossible(GrBatch* t) override { |
joshualitt | 0823bfa | 2015-02-27 10:06:15 -0800 | [diff] [blame] | 565 | // StrokeRectBatch* that = t->cast<StrokeRectBatch>(); |
| 566 | |
| 567 | // NonAA stroke rects cannot batch right now |
| 568 | // TODO make these batchable |
| 569 | return false; |
| 570 | } |
| 571 | |
| 572 | struct BatchTracker { |
| 573 | GrColor fColor; |
| 574 | bool fUsesLocalCoords; |
| 575 | bool fColorIgnored; |
| 576 | bool fCoverageIgnored; |
| 577 | bool fHairline; |
| 578 | }; |
| 579 | |
| 580 | const static int kVertsPerHairlineRect = 5; |
| 581 | const static int kVertsPerStrokeRect = 10; |
| 582 | |
| 583 | BatchTracker fBatch; |
| 584 | SkSTArray<1, Geometry, true> fGeoData; |
| 585 | }; |
| 586 | |
joshualitt | 25d9c15 | 2015-02-18 12:29:52 -0800 | [diff] [blame] | 587 | void GrContext::drawRect(GrRenderTarget* rt, |
joshualitt | 570d2f8 | 2015-02-25 13:19:48 -0800 | [diff] [blame] | 588 | const GrClip& clip, |
joshualitt | 25d9c15 | 2015-02-18 12:29:52 -0800 | [diff] [blame] | 589 | const GrPaint& paint, |
joshualitt | 5531d51 | 2014-12-17 15:50:11 -0800 | [diff] [blame] | 590 | const SkMatrix& viewMatrix, |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 591 | const SkRect& rect, |
bsalomon | 01c8da1 | 2014-08-04 09:21:30 -0700 | [diff] [blame] | 592 | const GrStrokeInfo* strokeInfo) { |
joshualitt | 5f5a8d7 | 2015-02-25 14:09:45 -0800 | [diff] [blame] | 593 | RETURN_IF_ABANDONED |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 594 | if (strokeInfo && strokeInfo->isDashed()) { |
egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 595 | SkPath path; |
| 596 | path.addRect(rect); |
joshualitt | 570d2f8 | 2015-02-25 13:19:48 -0800 | [diff] [blame] | 597 | this->drawPath(rt, clip, paint, viewMatrix, path, *strokeInfo); |
egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 598 | return; |
| 599 | } |
| 600 | |
bsalomon | f21dab9 | 2014-11-13 13:33:28 -0800 | [diff] [blame] | 601 | AutoCheckFlush acf(this); |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 602 | GrPipelineBuilder pipelineBuilder; |
joshualitt | 570d2f8 | 2015-02-25 13:19:48 -0800 | [diff] [blame] | 603 | GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, clip, &paint, &acf); |
bsalomon | 41ebbdd | 2014-08-04 08:31:39 -0700 | [diff] [blame] | 604 | if (NULL == target) { |
| 605 | return; |
| 606 | } |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 607 | |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 608 | GR_CREATE_TRACE_MARKER("GrContext::drawRect", target); |
egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 609 | SkScalar width = NULL == strokeInfo ? -1 : strokeInfo->getStrokeRec().getWidth(); |
commit-bot@chromium.org | 24ab3b0 | 2013-08-14 21:56:37 +0000 | [diff] [blame] | 610 | |
| 611 | // Check if this is a full RT draw and can be replaced with a clear. We don't bother checking |
| 612 | // cases where the RT is fully inside a stroke. |
| 613 | if (width < 0) { |
| 614 | SkRect rtRect; |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 615 | pipelineBuilder.getRenderTarget()->getBoundsRect(&rtRect); |
commit-bot@chromium.org | 24ab3b0 | 2013-08-14 21:56:37 +0000 | [diff] [blame] | 616 | SkRect clipSpaceRTRect = rtRect; |
joshualitt | 570d2f8 | 2015-02-25 13:19:48 -0800 | [diff] [blame] | 617 | bool checkClip = GrClip::kWideOpen_ClipType != clip.clipType(); |
joshualitt | 44701df | 2015-02-23 14:44:57 -0800 | [diff] [blame] | 618 | if (checkClip) { |
joshualitt | 570d2f8 | 2015-02-25 13:19:48 -0800 | [diff] [blame] | 619 | clipSpaceRTRect.offset(SkIntToScalar(clip.origin().fX), |
| 620 | SkIntToScalar(clip.origin().fY)); |
commit-bot@chromium.org | 24ab3b0 | 2013-08-14 21:56:37 +0000 | [diff] [blame] | 621 | } |
| 622 | // Does the clip contain the entire RT? |
joshualitt | 570d2f8 | 2015-02-25 13:19:48 -0800 | [diff] [blame] | 623 | if (!checkClip || clip.quickContains(clipSpaceRTRect)) { |
commit-bot@chromium.org | 24ab3b0 | 2013-08-14 21:56:37 +0000 | [diff] [blame] | 624 | SkMatrix invM; |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 625 | if (!viewMatrix.invert(&invM)) { |
commit-bot@chromium.org | 24ab3b0 | 2013-08-14 21:56:37 +0000 | [diff] [blame] | 626 | return; |
| 627 | } |
| 628 | // Does the rect bound the RT? |
| 629 | SkPoint srcSpaceRTQuad[4]; |
| 630 | invM.mapRectToQuad(srcSpaceRTQuad, rtRect); |
| 631 | if (rect_contains_inclusive(rect, srcSpaceRTQuad[0]) && |
| 632 | rect_contains_inclusive(rect, srcSpaceRTQuad[1]) && |
| 633 | rect_contains_inclusive(rect, srcSpaceRTQuad[2]) && |
| 634 | rect_contains_inclusive(rect, srcSpaceRTQuad[3])) { |
| 635 | // Will it blend? |
| 636 | GrColor clearColor; |
| 637 | if (paint.isOpaqueAndConstantColor(&clearColor)) { |
joshualitt | 25d9c15 | 2015-02-18 12:29:52 -0800 | [diff] [blame] | 638 | target->clear(NULL, clearColor, true, rt); |
commit-bot@chromium.org | 24ab3b0 | 2013-08-14 21:56:37 +0000 | [diff] [blame] | 639 | return; |
| 640 | } |
| 641 | } |
| 642 | } |
| 643 | } |
| 644 | |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 645 | GrColor color = paint.getColor(); |
commit-bot@chromium.org | 24ab3b0 | 2013-08-14 21:56:37 +0000 | [diff] [blame] | 646 | SkRect devBoundRect; |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 647 | bool needAA = paint.isAntiAlias() && !pipelineBuilder.getRenderTarget()->isMultisampled(); |
| 648 | bool doAA = needAA && apply_aa_to_rect(target, &pipelineBuilder, &devBoundRect, rect, width, |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 649 | viewMatrix, color); |
egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 650 | |
bsalomon@google.com | 205d460 | 2011-04-25 12:43:45 +0000 | [diff] [blame] | 651 | if (doAA) { |
bsalomon@google.com | 205d460 | 2011-04-25 12:43:45 +0000 | [diff] [blame] | 652 | if (width >= 0) { |
bsalomon | 395ef05 | 2014-11-12 11:35:22 -0800 | [diff] [blame] | 653 | const SkStrokeRec& strokeRec = strokeInfo->getStrokeRec(); |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 654 | fAARectRenderer->strokeAARect(target, |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 655 | &pipelineBuilder, |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 656 | color, |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 657 | viewMatrix, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 658 | rect, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 659 | devBoundRect, |
| 660 | strokeRec); |
bsalomon@google.com | 205d460 | 2011-04-25 12:43:45 +0000 | [diff] [blame] | 661 | } else { |
robertphillips@google.com | df3695e | 2013-04-09 14:01:44 +0000 | [diff] [blame] | 662 | // filled AA rect |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 663 | fAARectRenderer->fillAARect(target, |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 664 | &pipelineBuilder, |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 665 | color, |
| 666 | viewMatrix, |
| 667 | rect, |
joshualitt | d27f73e | 2014-12-29 07:43:36 -0800 | [diff] [blame] | 668 | devBoundRect); |
bsalomon@google.com | 205d460 | 2011-04-25 12:43:45 +0000 | [diff] [blame] | 669 | } |
| 670 | return; |
| 671 | } |
| 672 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 673 | if (width >= 0) { |
joshualitt | 0823bfa | 2015-02-27 10:06:15 -0800 | [diff] [blame] | 674 | StrokeRectBatch::Geometry geometry; |
| 675 | geometry.fViewMatrix = viewMatrix; |
| 676 | geometry.fColor = color; |
| 677 | geometry.fRect = rect; |
| 678 | geometry.fStrokeWidth = width; |
bsalomon@google.com | 26c2d0a | 2011-05-17 20:15:30 +0000 | [diff] [blame] | 679 | |
joshualitt | 0823bfa | 2015-02-27 10:06:15 -0800 | [diff] [blame] | 680 | SkAutoTUnref<GrBatch> batch(StrokeRectBatch::Create(geometry)); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 681 | |
joshualitt | 0823bfa | 2015-02-27 10:06:15 -0800 | [diff] [blame] | 682 | SkRect bounds = rect; |
| 683 | SkScalar rad = SkScalarHalf(width); |
| 684 | bounds.outset(rad, rad); |
| 685 | viewMatrix.mapRect(&bounds); |
bsalomon | d79c549 | 2015-04-27 10:07:04 -0700 | [diff] [blame] | 686 | // Depending on sub-pixel coordinates and the particular GPU, we may lose a corner of |
| 687 | // hairline rects. We jam all the vertices to pixel centers to avoid this, but not when MSAA |
| 688 | // is enabled because it can cause ugly artifacts. |
| 689 | pipelineBuilder.setState(GrPipelineBuilder::kSnapVerticesToPixelCenters_Flag, |
| 690 | 0 == width && !rt->isMultisampled()); |
joshualitt | 0823bfa | 2015-02-27 10:06:15 -0800 | [diff] [blame] | 691 | target->drawBatch(&pipelineBuilder, batch, &bounds); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 692 | } else { |
robertphillips@google.com | df3695e | 2013-04-09 14:01:44 +0000 | [diff] [blame] | 693 | // filled BW rect |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 694 | target->drawSimpleRect(&pipelineBuilder, color, viewMatrix, rect); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 695 | } |
| 696 | } |
| 697 | |
joshualitt | 25d9c15 | 2015-02-18 12:29:52 -0800 | [diff] [blame] | 698 | void GrContext::drawNonAARectToRect(GrRenderTarget* rt, |
joshualitt | 570d2f8 | 2015-02-25 13:19:48 -0800 | [diff] [blame] | 699 | const GrClip& clip, |
joshualitt | 25d9c15 | 2015-02-18 12:29:52 -0800 | [diff] [blame] | 700 | const GrPaint& paint, |
joshualitt | 16b2789 | 2014-12-18 07:47:16 -0800 | [diff] [blame] | 701 | const SkMatrix& viewMatrix, |
| 702 | const SkRect& rectToDraw, |
| 703 | const SkRect& localRect, |
| 704 | const SkMatrix* localMatrix) { |
joshualitt | 5f5a8d7 | 2015-02-25 14:09:45 -0800 | [diff] [blame] | 705 | RETURN_IF_ABANDONED |
bsalomon | f21dab9 | 2014-11-13 13:33:28 -0800 | [diff] [blame] | 706 | AutoCheckFlush acf(this); |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 707 | GrPipelineBuilder pipelineBuilder; |
joshualitt | 570d2f8 | 2015-02-25 13:19:48 -0800 | [diff] [blame] | 708 | GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, clip, &paint, &acf); |
bsalomon | 41ebbdd | 2014-08-04 08:31:39 -0700 | [diff] [blame] | 709 | if (NULL == target) { |
| 710 | return; |
| 711 | } |
bsalomon@google.com | 6438695 | 2013-02-08 21:22:44 +0000 | [diff] [blame] | 712 | |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 713 | GR_CREATE_TRACE_MARKER("GrContext::drawRectToRect", target); |
| 714 | |
joshualitt | 44701df | 2015-02-23 14:44:57 -0800 | [diff] [blame] | 715 | target->drawRect(&pipelineBuilder, |
| 716 | paint.getColor(), |
| 717 | viewMatrix, |
| 718 | rectToDraw, |
| 719 | &localRect, |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 720 | localMatrix); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 721 | } |
| 722 | |
joshualitt | 0823bfa | 2015-02-27 10:06:15 -0800 | [diff] [blame] | 723 | static const GrGeometryProcessor* set_vertex_attributes(bool hasLocalCoords, |
| 724 | bool hasColors, |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 725 | int* colorOffset, |
| 726 | int* texOffset, |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 727 | GrColor color, |
| 728 | const SkMatrix& viewMatrix) { |
robertphillips@google.com | 4290330 | 2013-04-20 12:26:07 +0000 | [diff] [blame] | 729 | *texOffset = -1; |
| 730 | *colorOffset = -1; |
joshualitt | 5478d42 | 2014-11-14 16:00:38 -0800 | [diff] [blame] | 731 | uint32_t flags = GrDefaultGeoProcFactory::kPosition_GPType; |
joshualitt | 0823bfa | 2015-02-27 10:06:15 -0800 | [diff] [blame] | 732 | if (hasLocalCoords && hasColors) { |
joshualitt | 5478d42 | 2014-11-14 16:00:38 -0800 | [diff] [blame] | 733 | *colorOffset = sizeof(SkPoint); |
| 734 | *texOffset = sizeof(SkPoint) + sizeof(GrColor); |
| 735 | flags |= GrDefaultGeoProcFactory::kColor_GPType | |
| 736 | GrDefaultGeoProcFactory::kLocalCoord_GPType; |
joshualitt | 0823bfa | 2015-02-27 10:06:15 -0800 | [diff] [blame] | 737 | } else if (hasLocalCoords) { |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 738 | *texOffset = sizeof(SkPoint); |
joshualitt | 5478d42 | 2014-11-14 16:00:38 -0800 | [diff] [blame] | 739 | flags |= GrDefaultGeoProcFactory::kLocalCoord_GPType; |
joshualitt | 0823bfa | 2015-02-27 10:06:15 -0800 | [diff] [blame] | 740 | } else if (hasColors) { |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 741 | *colorOffset = sizeof(SkPoint); |
joshualitt | 5478d42 | 2014-11-14 16:00:38 -0800 | [diff] [blame] | 742 | flags |= GrDefaultGeoProcFactory::kColor_GPType; |
robertphillips@google.com | 4290330 | 2013-04-20 12:26:07 +0000 | [diff] [blame] | 743 | } |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 744 | return GrDefaultGeoProcFactory::Create(flags, color, viewMatrix, SkMatrix::I()); |
robertphillips@google.com | 4290330 | 2013-04-20 12:26:07 +0000 | [diff] [blame] | 745 | } |
| 746 | |
joshualitt | 0823bfa | 2015-02-27 10:06:15 -0800 | [diff] [blame] | 747 | class DrawVerticesBatch : public GrBatch { |
| 748 | public: |
| 749 | struct Geometry { |
| 750 | GrColor fColor; |
| 751 | SkTDArray<SkPoint> fPositions; |
| 752 | SkTDArray<uint16_t> fIndices; |
| 753 | SkTDArray<GrColor> fColors; |
| 754 | SkTDArray<SkPoint> fLocalCoords; |
| 755 | }; |
| 756 | |
| 757 | static GrBatch* Create(const Geometry& geometry, GrPrimitiveType primitiveType, |
| 758 | const SkMatrix& viewMatrix, |
| 759 | const SkPoint* positions, int vertexCount, |
| 760 | const uint16_t* indices, int indexCount, |
| 761 | const GrColor* colors, const SkPoint* localCoords) { |
| 762 | return SkNEW_ARGS(DrawVerticesBatch, (geometry, primitiveType, viewMatrix, positions, |
| 763 | vertexCount, indices, indexCount, colors, |
| 764 | localCoords)); |
| 765 | } |
| 766 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 767 | const char* name() const override { return "DrawVerticesBatch"; } |
joshualitt | 0823bfa | 2015-02-27 10:06:15 -0800 | [diff] [blame] | 768 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 769 | void getInvariantOutputColor(GrInitInvariantOutput* out) const override { |
joshualitt | 0823bfa | 2015-02-27 10:06:15 -0800 | [diff] [blame] | 770 | // When this is called on a batch, there is only one geometry bundle |
| 771 | if (this->hasColors()) { |
| 772 | out->setUnknownFourComponents(); |
| 773 | } else { |
| 774 | out->setKnownFourComponents(fGeoData[0].fColor); |
| 775 | } |
| 776 | } |
| 777 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 778 | void getInvariantOutputCoverage(GrInitInvariantOutput* out) const override { |
joshualitt | d4c7d55 | 2015-02-27 13:00:56 -0800 | [diff] [blame] | 779 | out->setKnownSingleComponent(0xff); |
joshualitt | 0823bfa | 2015-02-27 10:06:15 -0800 | [diff] [blame] | 780 | } |
| 781 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 782 | void initBatchTracker(const GrPipelineInfo& init) override { |
joshualitt | 0823bfa | 2015-02-27 10:06:15 -0800 | [diff] [blame] | 783 | // Handle any color overrides |
| 784 | if (init.fColorIgnored) { |
| 785 | fGeoData[0].fColor = GrColor_ILLEGAL; |
| 786 | } else if (GrColor_ILLEGAL != init.fOverrideColor) { |
| 787 | fGeoData[0].fColor = init.fOverrideColor; |
| 788 | } |
| 789 | |
| 790 | // setup batch properties |
| 791 | fBatch.fColorIgnored = init.fColorIgnored; |
| 792 | fBatch.fColor = fGeoData[0].fColor; |
| 793 | fBatch.fUsesLocalCoords = init.fUsesLocalCoords; |
| 794 | fBatch.fCoverageIgnored = init.fCoverageIgnored; |
| 795 | } |
| 796 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 797 | void generateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeline) override { |
joshualitt | 0823bfa | 2015-02-27 10:06:15 -0800 | [diff] [blame] | 798 | int colorOffset = -1, texOffset = -1; |
| 799 | SkAutoTUnref<const GrGeometryProcessor> gp( |
| 800 | set_vertex_attributes(this->hasLocalCoords(), this->hasColors(), &colorOffset, |
| 801 | &texOffset, this->color(), this->viewMatrix())); |
| 802 | |
| 803 | batchTarget->initDraw(gp, pipeline); |
| 804 | |
| 805 | // TODO this is hacky, but the only way we have to initialize the GP is to use the |
| 806 | // GrPipelineInfo struct so we can generate the correct shader. Once we have GrBatch |
| 807 | // everywhere we can remove this nastiness |
| 808 | GrPipelineInfo init; |
| 809 | init.fColorIgnored = fBatch.fColorIgnored; |
| 810 | init.fOverrideColor = GrColor_ILLEGAL; |
| 811 | init.fCoverageIgnored = fBatch.fCoverageIgnored; |
| 812 | init.fUsesLocalCoords = this->usesLocalCoords(); |
| 813 | gp->initBatchTracker(batchTarget->currentBatchTracker(), init); |
| 814 | |
| 815 | size_t vertexStride = gp->getVertexStride(); |
| 816 | |
| 817 | SkASSERT(vertexStride == sizeof(SkPoint) + (this->hasLocalCoords() ? sizeof(SkPoint) : 0) |
| 818 | + (this->hasColors() ? sizeof(GrColor) : 0)); |
| 819 | |
| 820 | int instanceCount = fGeoData.count(); |
| 821 | |
| 822 | const GrVertexBuffer* vertexBuffer; |
| 823 | int firstVertex; |
| 824 | |
| 825 | void* vertices = batchTarget->vertexPool()->makeSpace(vertexStride, |
| 826 | this->vertexCount(), |
| 827 | &vertexBuffer, |
| 828 | &firstVertex); |
| 829 | |
joshualitt | 4b31de8 | 2015-03-05 14:33:41 -0800 | [diff] [blame] | 830 | if (!vertices) { |
| 831 | SkDebugf("Could not allocate vertices\n"); |
| 832 | return; |
| 833 | } |
| 834 | |
joshualitt | 0823bfa | 2015-02-27 10:06:15 -0800 | [diff] [blame] | 835 | const GrIndexBuffer* indexBuffer; |
| 836 | int firstIndex; |
| 837 | |
| 838 | void* indices = NULL; |
| 839 | if (this->hasIndices()) { |
| 840 | indices = batchTarget->indexPool()->makeSpace(this->indexCount(), |
| 841 | &indexBuffer, |
| 842 | &firstIndex); |
joshualitt | 4b31de8 | 2015-03-05 14:33:41 -0800 | [diff] [blame] | 843 | |
| 844 | if (!indices) { |
| 845 | SkDebugf("Could not allocate indices\n"); |
| 846 | return; |
| 847 | } |
joshualitt | 0823bfa | 2015-02-27 10:06:15 -0800 | [diff] [blame] | 848 | } |
| 849 | |
| 850 | int indexOffset = 0; |
| 851 | int vertexOffset = 0; |
| 852 | for (int i = 0; i < instanceCount; i++) { |
| 853 | const Geometry& args = fGeoData[i]; |
| 854 | |
| 855 | // TODO we can actually cache this interleaved and then just memcopy |
| 856 | if (this->hasIndices()) { |
| 857 | for (int j = 0; j < args.fIndices.count(); ++j, ++indexOffset) { |
| 858 | *((uint16_t*)indices + indexOffset) = args.fIndices[j] + vertexOffset; |
| 859 | } |
| 860 | } |
| 861 | |
| 862 | for (int j = 0; j < args.fPositions.count(); ++j) { |
| 863 | *((SkPoint*)vertices) = args.fPositions[j]; |
| 864 | if (this->hasColors()) { |
| 865 | *(GrColor*)((intptr_t)vertices + colorOffset) = args.fColors[j]; |
| 866 | } |
| 867 | if (this->hasLocalCoords()) { |
| 868 | *(SkPoint*)((intptr_t)vertices + texOffset) = args.fLocalCoords[j]; |
| 869 | } |
| 870 | vertices = (void*)((intptr_t)vertices + vertexStride); |
| 871 | vertexOffset++; |
| 872 | } |
| 873 | } |
| 874 | |
| 875 | GrDrawTarget::DrawInfo drawInfo; |
| 876 | drawInfo.setPrimitiveType(this->primitiveType()); |
| 877 | drawInfo.setVertexBuffer(vertexBuffer); |
| 878 | drawInfo.setStartVertex(firstVertex); |
| 879 | drawInfo.setVertexCount(this->vertexCount()); |
| 880 | if (this->hasIndices()) { |
| 881 | drawInfo.setIndexBuffer(indexBuffer); |
| 882 | drawInfo.setStartIndex(firstIndex); |
| 883 | drawInfo.setIndexCount(this->indexCount()); |
| 884 | } else { |
| 885 | drawInfo.setStartIndex(0); |
| 886 | drawInfo.setIndexCount(0); |
| 887 | } |
| 888 | batchTarget->draw(drawInfo); |
| 889 | } |
| 890 | |
| 891 | SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } |
| 892 | |
| 893 | private: |
| 894 | DrawVerticesBatch(const Geometry& geometry, GrPrimitiveType primitiveType, |
| 895 | const SkMatrix& viewMatrix, |
| 896 | const SkPoint* positions, int vertexCount, |
| 897 | const uint16_t* indices, int indexCount, |
| 898 | const GrColor* colors, const SkPoint* localCoords) { |
| 899 | this->initClassID<DrawVerticesBatch>(); |
| 900 | SkASSERT(positions); |
| 901 | |
| 902 | fBatch.fViewMatrix = viewMatrix; |
| 903 | Geometry& installedGeo = fGeoData.push_back(geometry); |
| 904 | |
| 905 | installedGeo.fPositions.append(vertexCount, positions); |
| 906 | if (indices) { |
| 907 | installedGeo.fIndices.append(indexCount, indices); |
| 908 | fBatch.fHasIndices = true; |
| 909 | } else { |
| 910 | fBatch.fHasIndices = false; |
| 911 | } |
| 912 | |
| 913 | if (colors) { |
| 914 | installedGeo.fColors.append(vertexCount, colors); |
| 915 | fBatch.fHasColors = true; |
| 916 | } else { |
| 917 | fBatch.fHasColors = false; |
| 918 | } |
| 919 | |
| 920 | if (localCoords) { |
| 921 | installedGeo.fLocalCoords.append(vertexCount, localCoords); |
| 922 | fBatch.fHasLocalCoords = true; |
| 923 | } else { |
| 924 | fBatch.fHasLocalCoords = false; |
| 925 | } |
| 926 | fBatch.fVertexCount = vertexCount; |
| 927 | fBatch.fIndexCount = indexCount; |
| 928 | fBatch.fPrimitiveType = primitiveType; |
| 929 | } |
| 930 | |
| 931 | GrPrimitiveType primitiveType() const { return fBatch.fPrimitiveType; } |
| 932 | bool batchablePrimitiveType() const { |
| 933 | return kTriangles_GrPrimitiveType == fBatch.fPrimitiveType || |
| 934 | kLines_GrPrimitiveType == fBatch.fPrimitiveType || |
| 935 | kPoints_GrPrimitiveType == fBatch.fPrimitiveType; |
| 936 | } |
| 937 | GrColor color() const { return fBatch.fColor; } |
| 938 | bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; } |
| 939 | bool colorIgnored() const { return fBatch.fColorIgnored; } |
| 940 | const SkMatrix& viewMatrix() const { return fBatch.fViewMatrix; } |
| 941 | bool hasColors() const { return fBatch.fHasColors; } |
| 942 | bool hasIndices() const { return fBatch.fHasIndices; } |
| 943 | bool hasLocalCoords() const { return fBatch.fHasLocalCoords; } |
| 944 | int vertexCount() const { return fBatch.fVertexCount; } |
| 945 | int indexCount() const { return fBatch.fIndexCount; } |
| 946 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 947 | bool onCombineIfPossible(GrBatch* t) override { |
joshualitt | 0823bfa | 2015-02-27 10:06:15 -0800 | [diff] [blame] | 948 | DrawVerticesBatch* that = t->cast<DrawVerticesBatch>(); |
| 949 | |
| 950 | if (!this->batchablePrimitiveType() || this->primitiveType() != that->primitiveType()) { |
| 951 | return false; |
| 952 | } |
| 953 | |
| 954 | SkASSERT(this->usesLocalCoords() == that->usesLocalCoords()); |
| 955 | |
| 956 | // We currently use a uniform viewmatrix for this batch |
| 957 | if (!this->viewMatrix().cheapEqualTo(that->viewMatrix())) { |
| 958 | return false; |
| 959 | } |
| 960 | |
| 961 | if (this->hasColors() != that->hasColors()) { |
| 962 | return false; |
| 963 | } |
| 964 | |
| 965 | if (this->hasIndices() != that->hasIndices()) { |
| 966 | return false; |
| 967 | } |
| 968 | |
| 969 | if (this->hasLocalCoords() != that->hasLocalCoords()) { |
| 970 | return false; |
| 971 | } |
| 972 | |
| 973 | if (!this->hasColors() && this->color() != that->color()) { |
| 974 | return false; |
| 975 | } |
| 976 | |
| 977 | if (this->color() != that->color()) { |
| 978 | fBatch.fColor = GrColor_ILLEGAL; |
| 979 | } |
| 980 | fGeoData.push_back_n(that->geoData()->count(), that->geoData()->begin()); |
| 981 | fBatch.fVertexCount += that->vertexCount(); |
| 982 | fBatch.fIndexCount += that->indexCount(); |
| 983 | return true; |
| 984 | } |
| 985 | |
| 986 | struct BatchTracker { |
| 987 | GrPrimitiveType fPrimitiveType; |
| 988 | SkMatrix fViewMatrix; |
| 989 | GrColor fColor; |
| 990 | bool fUsesLocalCoords; |
| 991 | bool fColorIgnored; |
| 992 | bool fCoverageIgnored; |
| 993 | bool fHasColors; |
| 994 | bool fHasIndices; |
| 995 | bool fHasLocalCoords; |
| 996 | int fVertexCount; |
| 997 | int fIndexCount; |
| 998 | }; |
| 999 | |
| 1000 | BatchTracker fBatch; |
| 1001 | SkSTArray<1, Geometry, true> fGeoData; |
| 1002 | }; |
| 1003 | |
joshualitt | 25d9c15 | 2015-02-18 12:29:52 -0800 | [diff] [blame] | 1004 | void GrContext::drawVertices(GrRenderTarget* rt, |
joshualitt | 570d2f8 | 2015-02-25 13:19:48 -0800 | [diff] [blame] | 1005 | const GrClip& clip, |
joshualitt | 25d9c15 | 2015-02-18 12:29:52 -0800 | [diff] [blame] | 1006 | const GrPaint& paint, |
joshualitt | 5531d51 | 2014-12-17 15:50:11 -0800 | [diff] [blame] | 1007 | const SkMatrix& viewMatrix, |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 1008 | GrPrimitiveType primitiveType, |
| 1009 | int vertexCount, |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 1010 | const SkPoint positions[], |
| 1011 | const SkPoint texCoords[], |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 1012 | const GrColor colors[], |
| 1013 | const uint16_t indices[], |
| 1014 | int indexCount) { |
joshualitt | 5f5a8d7 | 2015-02-25 14:09:45 -0800 | [diff] [blame] | 1015 | RETURN_IF_ABANDONED |
bsalomon | f21dab9 | 2014-11-13 13:33:28 -0800 | [diff] [blame] | 1016 | AutoCheckFlush acf(this); |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 1017 | GrPipelineBuilder pipelineBuilder; |
commit-bot@chromium.org | 5a56793 | 2014-01-08 21:26:09 +0000 | [diff] [blame] | 1018 | |
joshualitt | 570d2f8 | 2015-02-25 13:19:48 -0800 | [diff] [blame] | 1019 | GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, clip, &paint, &acf); |
bsalomon | 41ebbdd | 2014-08-04 08:31:39 -0700 | [diff] [blame] | 1020 | if (NULL == target) { |
| 1021 | return; |
| 1022 | } |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 1023 | |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 1024 | GR_CREATE_TRACE_MARKER("GrContext::drawVertices", target); |
| 1025 | |
joshualitt | a09c046 | 2015-04-30 14:03:02 -0700 | [diff] [blame] | 1026 | // TODO clients should give us bounds |
| 1027 | SkRect bounds; |
| 1028 | if (!bounds.setBoundsCheck(positions, vertexCount)) { |
| 1029 | SkDebugf("drawVertices call empty bounds\n"); |
| 1030 | return; |
| 1031 | } |
| 1032 | |
joshualitt | 0823bfa | 2015-02-27 10:06:15 -0800 | [diff] [blame] | 1033 | DrawVerticesBatch::Geometry geometry; |
| 1034 | geometry.fColor = paint.getColor(); |
jvanverth@google.com | 9b855c7 | 2013-03-01 18:21:22 +0000 | [diff] [blame] | 1035 | |
joshualitt | 0823bfa | 2015-02-27 10:06:15 -0800 | [diff] [blame] | 1036 | SkAutoTUnref<GrBatch> batch(DrawVerticesBatch::Create(geometry, primitiveType, viewMatrix, |
| 1037 | positions, vertexCount, indices, |
| 1038 | indexCount,colors, texCoords)); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 1039 | |
joshualitt | 0823bfa | 2015-02-27 10:06:15 -0800 | [diff] [blame] | 1040 | // TODO figure out bounds |
joshualitt | a09c046 | 2015-04-30 14:03:02 -0700 | [diff] [blame] | 1041 | target->drawBatch(&pipelineBuilder, batch, &bounds); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 1042 | } |
| 1043 | |
bsalomon@google.com | 06afe7b | 2011-04-26 15:31:40 +0000 | [diff] [blame] | 1044 | /////////////////////////////////////////////////////////////////////////////// |
bsalomon@google.com | 93c9660 | 2012-04-27 13:05:21 +0000 | [diff] [blame] | 1045 | |
joshualitt | 25d9c15 | 2015-02-18 12:29:52 -0800 | [diff] [blame] | 1046 | void GrContext::drawRRect(GrRenderTarget*rt, |
joshualitt | 570d2f8 | 2015-02-25 13:19:48 -0800 | [diff] [blame] | 1047 | const GrClip& clip, |
joshualitt | 25d9c15 | 2015-02-18 12:29:52 -0800 | [diff] [blame] | 1048 | const GrPaint& paint, |
joshualitt | 5531d51 | 2014-12-17 15:50:11 -0800 | [diff] [blame] | 1049 | const SkMatrix& viewMatrix, |
commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 1050 | const SkRRect& rrect, |
egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 1051 | const GrStrokeInfo& strokeInfo) { |
joshualitt | 5f5a8d7 | 2015-02-25 14:09:45 -0800 | [diff] [blame] | 1052 | RETURN_IF_ABANDONED |
commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 1053 | if (rrect.isEmpty()) { |
commit-bot@chromium.org | 19dd017 | 2013-08-05 13:28:55 +0000 | [diff] [blame] | 1054 | return; |
| 1055 | } |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 1056 | |
egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 1057 | if (strokeInfo.isDashed()) { |
| 1058 | SkPath path; |
| 1059 | path.addRRect(rrect); |
joshualitt | 570d2f8 | 2015-02-25 13:19:48 -0800 | [diff] [blame] | 1060 | this->drawPath(rt, clip, paint, viewMatrix, path, strokeInfo); |
egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 1061 | return; |
| 1062 | } |
| 1063 | |
bsalomon | f21dab9 | 2014-11-13 13:33:28 -0800 | [diff] [blame] | 1064 | AutoCheckFlush acf(this); |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 1065 | GrPipelineBuilder pipelineBuilder; |
joshualitt | 570d2f8 | 2015-02-25 13:19:48 -0800 | [diff] [blame] | 1066 | GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, clip, &paint, &acf); |
bsalomon | 41ebbdd | 2014-08-04 08:31:39 -0700 | [diff] [blame] | 1067 | if (NULL == target) { |
| 1068 | return; |
| 1069 | } |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 1070 | |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 1071 | GR_CREATE_TRACE_MARKER("GrContext::drawRRect", target); |
| 1072 | |
egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 1073 | const SkStrokeRec& strokeRec = strokeInfo.getStrokeRec(); |
| 1074 | |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 1075 | GrColor color = paint.getColor(); |
joshualitt | 44701df | 2015-02-23 14:44:57 -0800 | [diff] [blame] | 1076 | if (!fOvalRenderer->drawRRect(target, |
| 1077 | &pipelineBuilder, |
| 1078 | color, |
| 1079 | viewMatrix, |
| 1080 | paint.isAntiAlias(), |
| 1081 | rrect, |
| 1082 | strokeRec)) { |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 1083 | SkPath path; |
commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 1084 | path.addRRect(rrect); |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 1085 | this->internalDrawPath(target, &pipelineBuilder, viewMatrix, color, paint.isAntiAlias(), |
| 1086 | path, strokeInfo); |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 1087 | } |
| 1088 | } |
| 1089 | |
| 1090 | /////////////////////////////////////////////////////////////////////////////// |
| 1091 | |
joshualitt | 25d9c15 | 2015-02-18 12:29:52 -0800 | [diff] [blame] | 1092 | void GrContext::drawDRRect(GrRenderTarget* rt, |
joshualitt | 570d2f8 | 2015-02-25 13:19:48 -0800 | [diff] [blame] | 1093 | const GrClip& clip, |
joshualitt | 25d9c15 | 2015-02-18 12:29:52 -0800 | [diff] [blame] | 1094 | const GrPaint& paint, |
joshualitt | 5531d51 | 2014-12-17 15:50:11 -0800 | [diff] [blame] | 1095 | const SkMatrix& viewMatrix, |
commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 1096 | const SkRRect& outer, |
| 1097 | const SkRRect& inner) { |
joshualitt | 5f5a8d7 | 2015-02-25 14:09:45 -0800 | [diff] [blame] | 1098 | RETURN_IF_ABANDONED |
commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 1099 | if (outer.isEmpty()) { |
| 1100 | return; |
| 1101 | } |
| 1102 | |
bsalomon | f21dab9 | 2014-11-13 13:33:28 -0800 | [diff] [blame] | 1103 | AutoCheckFlush acf(this); |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 1104 | GrPipelineBuilder pipelineBuilder; |
joshualitt | 570d2f8 | 2015-02-25 13:19:48 -0800 | [diff] [blame] | 1105 | GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, clip, &paint, &acf); |
commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 1106 | |
| 1107 | GR_CREATE_TRACE_MARKER("GrContext::drawDRRect", target); |
| 1108 | |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 1109 | GrColor color = paint.getColor(); |
joshualitt | 44701df | 2015-02-23 14:44:57 -0800 | [diff] [blame] | 1110 | if (!fOvalRenderer->drawDRRect(target, |
| 1111 | &pipelineBuilder, |
| 1112 | color, |
| 1113 | viewMatrix, |
| 1114 | paint.isAntiAlias(), |
| 1115 | outer, |
| 1116 | inner)) { |
commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 1117 | SkPath path; |
| 1118 | path.addRRect(inner); |
| 1119 | path.addRRect(outer); |
| 1120 | path.setFillType(SkPath::kEvenOdd_FillType); |
| 1121 | |
egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 1122 | GrStrokeInfo fillRec(SkStrokeRec::kFill_InitStyle); |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 1123 | this->internalDrawPath(target, &pipelineBuilder, viewMatrix, color, paint.isAntiAlias(), |
| 1124 | path, fillRec); |
commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 1125 | } |
| 1126 | } |
| 1127 | |
| 1128 | /////////////////////////////////////////////////////////////////////////////// |
| 1129 | |
joshualitt | 570d2f8 | 2015-02-25 13:19:48 -0800 | [diff] [blame] | 1130 | void GrContext::drawOval(GrRenderTarget* rt, |
| 1131 | const GrClip& clip, |
joshualitt | 25d9c15 | 2015-02-18 12:29:52 -0800 | [diff] [blame] | 1132 | const GrPaint& paint, |
joshualitt | 5531d51 | 2014-12-17 15:50:11 -0800 | [diff] [blame] | 1133 | const SkMatrix& viewMatrix, |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 1134 | const SkRect& oval, |
egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 1135 | const GrStrokeInfo& strokeInfo) { |
joshualitt | 5f5a8d7 | 2015-02-25 14:09:45 -0800 | [diff] [blame] | 1136 | RETURN_IF_ABANDONED |
commit-bot@chromium.org | 19dd017 | 2013-08-05 13:28:55 +0000 | [diff] [blame] | 1137 | if (oval.isEmpty()) { |
| 1138 | return; |
| 1139 | } |
jvanverth@google.com | 46d3d39 | 2013-01-22 13:34:01 +0000 | [diff] [blame] | 1140 | |
egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 1141 | if (strokeInfo.isDashed()) { |
| 1142 | SkPath path; |
| 1143 | path.addOval(oval); |
joshualitt | 570d2f8 | 2015-02-25 13:19:48 -0800 | [diff] [blame] | 1144 | this->drawPath(rt, clip, paint, viewMatrix, path, strokeInfo); |
egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 1145 | return; |
| 1146 | } |
| 1147 | |
bsalomon | f21dab9 | 2014-11-13 13:33:28 -0800 | [diff] [blame] | 1148 | AutoCheckFlush acf(this); |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 1149 | GrPipelineBuilder pipelineBuilder; |
joshualitt | 570d2f8 | 2015-02-25 13:19:48 -0800 | [diff] [blame] | 1150 | GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, clip, &paint, &acf); |
bsalomon | 41ebbdd | 2014-08-04 08:31:39 -0700 | [diff] [blame] | 1151 | if (NULL == target) { |
| 1152 | return; |
| 1153 | } |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 1154 | |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 1155 | GR_CREATE_TRACE_MARKER("GrContext::drawOval", target); |
| 1156 | |
egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 1157 | const SkStrokeRec& strokeRec = strokeInfo.getStrokeRec(); |
| 1158 | |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 1159 | GrColor color = paint.getColor(); |
joshualitt | 44701df | 2015-02-23 14:44:57 -0800 | [diff] [blame] | 1160 | if (!fOvalRenderer->drawOval(target, |
| 1161 | &pipelineBuilder, |
| 1162 | color, |
| 1163 | viewMatrix, |
| 1164 | paint.isAntiAlias(), |
| 1165 | oval, |
| 1166 | strokeRec)) { |
bsalomon@google.com | 93c9660 | 2012-04-27 13:05:21 +0000 | [diff] [blame] | 1167 | SkPath path; |
jvanverth@google.com | 46d3d39 | 2013-01-22 13:34:01 +0000 | [diff] [blame] | 1168 | path.addOval(oval); |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 1169 | this->internalDrawPath(target, &pipelineBuilder, viewMatrix, color, paint.isAntiAlias(), |
| 1170 | path, strokeInfo); |
skia.committer@gmail.com | 98ded84 | 2013-01-23 07:06:17 +0000 | [diff] [blame] | 1171 | } |
bsalomon@google.com | 150d284 | 2012-01-12 20:19:56 +0000 | [diff] [blame] | 1172 | } |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 1173 | |
robertphillips@google.com | 83d1a68 | 2013-05-17 12:50:27 +0000 | [diff] [blame] | 1174 | // Can 'path' be drawn as a pair of filled nested rectangles? |
| 1175 | static bool is_nested_rects(GrDrawTarget* target, |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 1176 | GrPipelineBuilder* pipelineBuilder, |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 1177 | GrColor color, |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 1178 | const SkMatrix& viewMatrix, |
robertphillips@google.com | 83d1a68 | 2013-05-17 12:50:27 +0000 | [diff] [blame] | 1179 | const SkPath& path, |
| 1180 | const SkStrokeRec& stroke, |
bsalomon | 9c0822a | 2014-08-11 11:07:48 -0700 | [diff] [blame] | 1181 | SkRect rects[2]) { |
robertphillips@google.com | 83d1a68 | 2013-05-17 12:50:27 +0000 | [diff] [blame] | 1182 | SkASSERT(stroke.isFillStyle()); |
| 1183 | |
| 1184 | if (path.isInverseFillType()) { |
| 1185 | return false; |
| 1186 | } |
| 1187 | |
robertphillips@google.com | 83d1a68 | 2013-05-17 12:50:27 +0000 | [diff] [blame] | 1188 | // TODO: this restriction could be lifted if we were willing to apply |
| 1189 | // the matrix to all the points individually rather than just to the rect |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 1190 | if (!viewMatrix.preservesAxisAlignment()) { |
robertphillips@google.com | 83d1a68 | 2013-05-17 12:50:27 +0000 | [diff] [blame] | 1191 | return false; |
| 1192 | } |
| 1193 | |
robertphillips@google.com | 83d1a68 | 2013-05-17 12:50:27 +0000 | [diff] [blame] | 1194 | SkPath::Direction dirs[2]; |
caryclark | 95bc5f3 | 2015-04-08 08:34:15 -0700 | [diff] [blame] | 1195 | if (!path.isNestedFillRects(rects, dirs)) { |
robertphillips@google.com | 83d1a68 | 2013-05-17 12:50:27 +0000 | [diff] [blame] | 1196 | return false; |
| 1197 | } |
| 1198 | |
robertphillips@google.com | 8d3c640 | 2013-08-20 12:11:31 +0000 | [diff] [blame] | 1199 | if (SkPath::kWinding_FillType == path.getFillType() && dirs[0] == dirs[1]) { |
robertphillips@google.com | 83d1a68 | 2013-05-17 12:50:27 +0000 | [diff] [blame] | 1200 | // The two rects need to be wound opposite to each other |
robertphillips@google.com | 8d3c640 | 2013-08-20 12:11:31 +0000 | [diff] [blame] | 1201 | return false; |
robertphillips@google.com | 83d1a68 | 2013-05-17 12:50:27 +0000 | [diff] [blame] | 1202 | } |
robertphillips@google.com | 83d1a68 | 2013-05-17 12:50:27 +0000 | [diff] [blame] | 1203 | |
robertphillips@google.com | 8d3c640 | 2013-08-20 12:11:31 +0000 | [diff] [blame] | 1204 | // Right now, nested rects where the margin is not the same width |
| 1205 | // all around do not render correctly |
| 1206 | const SkScalar* outer = rects[0].asScalars(); |
| 1207 | const SkScalar* inner = rects[1].asScalars(); |
| 1208 | |
robertphillips | 183e985 | 2014-10-21 11:25:37 -0700 | [diff] [blame] | 1209 | bool allEq = true; |
| 1210 | |
robertphillips@google.com | 8d3c640 | 2013-08-20 12:11:31 +0000 | [diff] [blame] | 1211 | SkScalar margin = SkScalarAbs(outer[0] - inner[0]); |
robertphillips | 183e985 | 2014-10-21 11:25:37 -0700 | [diff] [blame] | 1212 | bool allGoE1 = margin >= SK_Scalar1; |
| 1213 | |
robertphillips@google.com | 8d3c640 | 2013-08-20 12:11:31 +0000 | [diff] [blame] | 1214 | for (int i = 1; i < 4; ++i) { |
| 1215 | SkScalar temp = SkScalarAbs(outer[i] - inner[i]); |
robertphillips | 183e985 | 2014-10-21 11:25:37 -0700 | [diff] [blame] | 1216 | if (temp < SK_Scalar1) { |
| 1217 | allGoE1 = false; |
| 1218 | } |
robertphillips@google.com | 8d3c640 | 2013-08-20 12:11:31 +0000 | [diff] [blame] | 1219 | if (!SkScalarNearlyEqual(margin, temp)) { |
robertphillips | 183e985 | 2014-10-21 11:25:37 -0700 | [diff] [blame] | 1220 | allEq = false; |
robertphillips@google.com | 8d3c640 | 2013-08-20 12:11:31 +0000 | [diff] [blame] | 1221 | } |
| 1222 | } |
| 1223 | |
robertphillips | 183e985 | 2014-10-21 11:25:37 -0700 | [diff] [blame] | 1224 | return allEq || allGoE1; |
robertphillips@google.com | 8d3c640 | 2013-08-20 12:11:31 +0000 | [diff] [blame] | 1225 | } |
robertphillips@google.com | 83d1a68 | 2013-05-17 12:50:27 +0000 | [diff] [blame] | 1226 | |
joshualitt | 25d9c15 | 2015-02-18 12:29:52 -0800 | [diff] [blame] | 1227 | void GrContext::drawPath(GrRenderTarget* rt, |
joshualitt | 570d2f8 | 2015-02-25 13:19:48 -0800 | [diff] [blame] | 1228 | const GrClip& clip, |
joshualitt | 25d9c15 | 2015-02-18 12:29:52 -0800 | [diff] [blame] | 1229 | const GrPaint& paint, |
joshualitt | 5531d51 | 2014-12-17 15:50:11 -0800 | [diff] [blame] | 1230 | const SkMatrix& viewMatrix, |
| 1231 | const SkPath& path, |
| 1232 | const GrStrokeInfo& strokeInfo) { |
joshualitt | 5f5a8d7 | 2015-02-25 14:09:45 -0800 | [diff] [blame] | 1233 | RETURN_IF_ABANDONED |
bsalomon@google.com | fa6ac93 | 2011-10-05 19:57:55 +0000 | [diff] [blame] | 1234 | if (path.isEmpty()) { |
sugoi@google.com | 12b4e27 | 2012-12-06 20:13:11 +0000 | [diff] [blame] | 1235 | if (path.isInverseFillType()) { |
joshualitt | 570d2f8 | 2015-02-25 13:19:48 -0800 | [diff] [blame] | 1236 | this->drawPaint(rt, clip, paint, viewMatrix); |
bsalomon@google.com | fa6ac93 | 2011-10-05 19:57:55 +0000 | [diff] [blame] | 1237 | } |
| 1238 | return; |
| 1239 | } |
| 1240 | |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 1241 | GrColor color = paint.getColor(); |
egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 1242 | |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 1243 | // Note that internalDrawPath may sw-rasterize the path into a scratch texture. |
bsalomon@google.com | fb4ce6f | 2012-03-14 13:27:54 +0000 | [diff] [blame] | 1244 | // Scratch textures can be recycled after they are returned to the texture |
| 1245 | // cache. This presents a potential hazard for buffered drawing. However, |
| 1246 | // the writePixels that uploads to the scratch will perform a flush so we're |
| 1247 | // OK. |
bsalomon | f21dab9 | 2014-11-13 13:33:28 -0800 | [diff] [blame] | 1248 | AutoCheckFlush acf(this); |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 1249 | GrPipelineBuilder pipelineBuilder; |
joshualitt | 570d2f8 | 2015-02-25 13:19:48 -0800 | [diff] [blame] | 1250 | GrDrawTarget* target = this->prepareToDraw(&pipelineBuilder, rt, clip, &paint, &acf); |
bsalomon | 41ebbdd | 2014-08-04 08:31:39 -0700 | [diff] [blame] | 1251 | if (NULL == target) { |
| 1252 | return; |
| 1253 | } |
bsalomon@google.com | d46e242 | 2011-09-23 17:40:07 +0000 | [diff] [blame] | 1254 | |
egdaniel | 93a37bc | 2014-07-21 13:47:57 -0700 | [diff] [blame] | 1255 | GR_CREATE_TRACE_MARKER1("GrContext::drawPath", target, "Is Convex", path.isConvex()); |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 1256 | |
kkinnunen | 1899651 | 2015-04-26 23:18:49 -0700 | [diff] [blame] | 1257 | if (!strokeInfo.isDashed()) { |
| 1258 | const SkStrokeRec& strokeRec = strokeInfo.getStrokeRec(); |
| 1259 | bool useCoverageAA = paint.isAntiAlias() && |
| 1260 | !pipelineBuilder.getRenderTarget()->isMultisampled(); |
egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 1261 | |
kkinnunen | 1899651 | 2015-04-26 23:18:49 -0700 | [diff] [blame] | 1262 | if (useCoverageAA && strokeRec.getWidth() < 0 && !path.isConvex()) { |
| 1263 | // Concave AA paths are expensive - try to avoid them for special cases |
| 1264 | SkRect rects[2]; |
commit-bot@chromium.org | e0a868c | 2013-11-22 07:02:11 +0000 | [diff] [blame] | 1265 | |
kkinnunen | 1899651 | 2015-04-26 23:18:49 -0700 | [diff] [blame] | 1266 | if (is_nested_rects(target, &pipelineBuilder, color, viewMatrix, path, strokeRec, |
| 1267 | rects)) { |
| 1268 | fAARectRenderer->fillAANestedRects(target, &pipelineBuilder, color, viewMatrix, |
| 1269 | rects); |
| 1270 | return; |
| 1271 | } |
| 1272 | } |
| 1273 | SkRect ovalRect; |
| 1274 | bool isOval = path.isOval(&ovalRect); |
robertphillips@google.com | 83d1a68 | 2013-05-17 12:50:27 +0000 | [diff] [blame] | 1275 | |
kkinnunen | 1899651 | 2015-04-26 23:18:49 -0700 | [diff] [blame] | 1276 | if (isOval && !path.isInverseFillType()) { |
| 1277 | if (fOvalRenderer->drawOval(target, |
| 1278 | &pipelineBuilder, |
| 1279 | color, |
| 1280 | viewMatrix, |
| 1281 | paint.isAntiAlias(), |
| 1282 | ovalRect, |
| 1283 | strokeRec)) { |
| 1284 | return; |
| 1285 | } |
robertphillips@google.com | 83d1a68 | 2013-05-17 12:50:27 +0000 | [diff] [blame] | 1286 | } |
| 1287 | } |
kkinnunen | 1899651 | 2015-04-26 23:18:49 -0700 | [diff] [blame] | 1288 | this->internalDrawPath(target, &pipelineBuilder, viewMatrix, color, paint.isAntiAlias(), |
| 1289 | path, strokeInfo); |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 1290 | } |
| 1291 | |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 1292 | void GrContext::internalDrawPath(GrDrawTarget* target, |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 1293 | GrPipelineBuilder* pipelineBuilder, |
joshualitt | 5531d51 | 2014-12-17 15:50:11 -0800 | [diff] [blame] | 1294 | const SkMatrix& viewMatrix, |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 1295 | GrColor color, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 1296 | bool useAA, |
| 1297 | const SkPath& path, |
egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 1298 | const GrStrokeInfo& strokeInfo) { |
joshualitt | 5f5a8d7 | 2015-02-25 14:09:45 -0800 | [diff] [blame] | 1299 | RETURN_IF_ABANDONED |
commit-bot@chromium.org | 19dd017 | 2013-08-05 13:28:55 +0000 | [diff] [blame] | 1300 | SkASSERT(!path.isEmpty()); |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 1301 | |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 1302 | GR_CREATE_TRACE_MARKER("GrContext::internalDrawPath", target); |
| 1303 | |
| 1304 | |
bsalomon@google.com | d46e242 | 2011-09-23 17:40:07 +0000 | [diff] [blame] | 1305 | // An Assumption here is that path renderer would use some form of tweaking |
| 1306 | // the src color (either the input alpha or in the frag shader) to implement |
| 1307 | // aa. If we have some future driver-mojo path AA that can do the right |
| 1308 | // thing WRT to the blend then we'll need some query on the PR. |
commit-bot@chromium.org | e0a868c | 2013-11-22 07:02:11 +0000 | [diff] [blame] | 1309 | bool useCoverageAA = useAA && |
egdaniel | 0bdeec9 | 2015-02-23 12:12:54 -0800 | [diff] [blame] | 1310 | !pipelineBuilder->getRenderTarget()->isMultisampled(); |
bsalomon@google.com | 289533a | 2011-10-27 12:34:25 +0000 | [diff] [blame] | 1311 | |
commit-bot@chromium.org | e0a868c | 2013-11-22 07:02:11 +0000 | [diff] [blame] | 1312 | |
| 1313 | GrPathRendererChain::DrawType type = |
| 1314 | useCoverageAA ? GrPathRendererChain::kColorAntiAlias_DrawType : |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 1315 | GrPathRendererChain::kColor_DrawType; |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 1316 | |
robertphillips@google.com | eb928ea | 2013-01-08 13:45:09 +0000 | [diff] [blame] | 1317 | const SkPath* pathPtr = &path; |
commit-bot@chromium.org | f0c41e2 | 2014-01-14 18:42:34 +0000 | [diff] [blame] | 1318 | SkTLazy<SkPath> tmpPath; |
kkinnunen | 1899651 | 2015-04-26 23:18:49 -0700 | [diff] [blame] | 1319 | const GrStrokeInfo* strokeInfoPtr = &strokeInfo; |
robertphillips@google.com | eb928ea | 2013-01-08 13:45:09 +0000 | [diff] [blame] | 1320 | |
| 1321 | // Try a 1st time without stroking the path and without allowing the SW renderer |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 1322 | GrPathRenderer* pr = this->getPathRenderer(target, pipelineBuilder, viewMatrix, *pathPtr, |
kkinnunen | 1899651 | 2015-04-26 23:18:49 -0700 | [diff] [blame] | 1323 | *strokeInfoPtr, false, type); |
| 1324 | |
| 1325 | GrStrokeInfo dashlessStrokeInfo(strokeInfo, false); |
| 1326 | if (NULL == pr && strokeInfo.isDashed()) { |
| 1327 | // It didn't work above, so try again with dashed stroke converted to a dashless stroke. |
| 1328 | if (strokeInfo.applyDash(tmpPath.init(), &dashlessStrokeInfo, *pathPtr)) { |
| 1329 | pathPtr = tmpPath.get(); |
| 1330 | if (pathPtr->isEmpty()) { |
| 1331 | return; |
| 1332 | } |
| 1333 | strokeInfoPtr = &dashlessStrokeInfo; |
| 1334 | } |
| 1335 | pr = this->getPathRenderer(target, pipelineBuilder, viewMatrix, *pathPtr, *strokeInfoPtr, |
| 1336 | false, type); |
| 1337 | } |
robertphillips@google.com | eb928ea | 2013-01-08 13:45:09 +0000 | [diff] [blame] | 1338 | |
robertphillips@google.com | e79f320 | 2014-02-11 16:30:21 +0000 | [diff] [blame] | 1339 | if (NULL == pr) { |
kkinnunen | 1899651 | 2015-04-26 23:18:49 -0700 | [diff] [blame] | 1340 | if (!GrPathRenderer::IsStrokeHairlineOrEquivalent(*strokeInfoPtr, viewMatrix, NULL)) { |
| 1341 | // It didn't work above, so try again with stroke converted to a fill. |
| 1342 | if (!tmpPath.isValid()) { |
| 1343 | tmpPath.init(); |
| 1344 | } |
| 1345 | SkStrokeRec* strokeRec = dashlessStrokeInfo.getStrokeRecPtr(); |
| 1346 | strokeRec->setResScale(SkScalarAbs(viewMatrix.getMaxScale())); |
| 1347 | if (strokeRec->applyToPath(tmpPath.get(), *pathPtr)) { |
commit-bot@chromium.org | f0c41e2 | 2014-01-14 18:42:34 +0000 | [diff] [blame] | 1348 | pathPtr = tmpPath.get(); |
commit-bot@chromium.org | e0a868c | 2013-11-22 07:02:11 +0000 | [diff] [blame] | 1349 | if (pathPtr->isEmpty()) { |
| 1350 | return; |
| 1351 | } |
kkinnunen | 1899651 | 2015-04-26 23:18:49 -0700 | [diff] [blame] | 1352 | strokeRec->setFillStyle(); |
| 1353 | strokeInfoPtr = &dashlessStrokeInfo; |
robertphillips@google.com | eb928ea | 2013-01-08 13:45:09 +0000 | [diff] [blame] | 1354 | } |
| 1355 | } |
commit-bot@chromium.org | 19dd017 | 2013-08-05 13:28:55 +0000 | [diff] [blame] | 1356 | |
robertphillips@google.com | eb928ea | 2013-01-08 13:45:09 +0000 | [diff] [blame] | 1357 | // This time, allow SW renderer |
kkinnunen | 1899651 | 2015-04-26 23:18:49 -0700 | [diff] [blame] | 1358 | pr = this->getPathRenderer(target, pipelineBuilder, viewMatrix, *pathPtr, *strokeInfoPtr, |
| 1359 | true, type); |
robertphillips@google.com | eb928ea | 2013-01-08 13:45:09 +0000 | [diff] [blame] | 1360 | } |
| 1361 | |
robertphillips@google.com | e79f320 | 2014-02-11 16:30:21 +0000 | [diff] [blame] | 1362 | if (NULL == pr) { |
commit-bot@chromium.org | 515dcd3 | 2013-08-28 14:17:03 +0000 | [diff] [blame] | 1363 | #ifdef SK_DEBUG |
tfarina | 38406c8 | 2014-10-31 07:11:12 -0700 | [diff] [blame] | 1364 | SkDebugf("Unable to find path renderer compatible with path.\n"); |
bsalomon@google.com | 1983f39 | 2011-10-10 15:17:58 +0000 | [diff] [blame] | 1365 | #endif |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 1366 | return; |
| 1367 | } |
| 1368 | |
kkinnunen | 1899651 | 2015-04-26 23:18:49 -0700 | [diff] [blame] | 1369 | pr->drawPath(target, pipelineBuilder, color, viewMatrix, *pathPtr, *strokeInfoPtr, useCoverageAA); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 1370 | } |
bsalomon@google.com | 8295dc1 | 2011-05-02 12:53:34 +0000 | [diff] [blame] | 1371 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 1372 | //////////////////////////////////////////////////////////////////////////////// |
| 1373 | |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 1374 | void GrContext::flush(int flagsBitfield) { |
robertphillips@google.com | e7db8d6 | 2013-07-04 11:48:52 +0000 | [diff] [blame] | 1375 | if (NULL == fDrawBuffer) { |
| 1376 | return; |
| 1377 | } |
| 1378 | |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 1379 | if (kDiscard_FlushBit & flagsBitfield) { |
| 1380 | fDrawBuffer->reset(); |
| 1381 | } else { |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 1382 | fDrawBuffer->flush(); |
junov@google.com | 53a5584 | 2011-06-08 22:55:10 +0000 | [diff] [blame] | 1383 | } |
bsalomon | 3f32432 | 2015-04-08 11:01:54 -0700 | [diff] [blame] | 1384 | fResourceCache->notifyFlushOccurred(); |
bsalomon | f21dab9 | 2014-11-13 13:33:28 -0800 | [diff] [blame] | 1385 | fFlushToReduceCacheSize = false; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 1386 | } |
| 1387 | |
bsalomon | 81beccc | 2014-10-13 12:32:55 -0700 | [diff] [blame] | 1388 | bool sw_convert_to_premul(GrPixelConfig srcConfig, int width, int height, size_t inRowBytes, |
| 1389 | const void* inPixels, size_t outRowBytes, void* outPixels) { |
| 1390 | SkSrcPixelInfo srcPI; |
jvanverth | fa1e8a7 | 2014-12-22 08:31:49 -0800 | [diff] [blame] | 1391 | if (!GrPixelConfig2ColorAndProfileType(srcConfig, &srcPI.fColorType, NULL)) { |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 1392 | return false; |
| 1393 | } |
bsalomon | 81beccc | 2014-10-13 12:32:55 -0700 | [diff] [blame] | 1394 | srcPI.fAlphaType = kUnpremul_SkAlphaType; |
| 1395 | srcPI.fPixels = inPixels; |
| 1396 | srcPI.fRowBytes = inRowBytes; |
| 1397 | |
| 1398 | SkDstPixelInfo dstPI; |
| 1399 | dstPI.fColorType = srcPI.fColorType; |
| 1400 | dstPI.fAlphaType = kPremul_SkAlphaType; |
| 1401 | dstPI.fPixels = outPixels; |
| 1402 | dstPI.fRowBytes = outRowBytes; |
| 1403 | |
| 1404 | return srcPI.convertPixelsTo(&dstPI, width, height); |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 1405 | } |
| 1406 | |
bsalomon | 81beccc | 2014-10-13 12:32:55 -0700 | [diff] [blame] | 1407 | bool GrContext::writeSurfacePixels(GrSurface* surface, |
| 1408 | int left, int top, int width, int height, |
| 1409 | GrPixelConfig srcConfig, const void* buffer, size_t rowBytes, |
| 1410 | uint32_t pixelOpsFlags) { |
joshualitt | 5f5a8d7 | 2015-02-25 14:09:45 -0800 | [diff] [blame] | 1411 | RETURN_FALSE_IF_ABANDONED |
bsalomon | 81beccc | 2014-10-13 12:32:55 -0700 | [diff] [blame] | 1412 | { |
| 1413 | GrTexture* texture = NULL; |
| 1414 | if (!(kUnpremul_PixelOpsFlag & pixelOpsFlags) && (texture = surface->asTexture()) && |
| 1415 | fGpu->canWriteTexturePixels(texture, srcConfig)) { |
| 1416 | |
| 1417 | if (!(kDontFlush_PixelOpsFlag & pixelOpsFlags) && |
| 1418 | surface->surfacePriv().hasPendingIO()) { |
| 1419 | this->flush(); |
| 1420 | } |
| 1421 | return fGpu->writeTexturePixels(texture, left, top, width, height, |
| 1422 | srcConfig, buffer, rowBytes); |
| 1423 | // Don't need to check kFlushWrites_PixelOp here, we just did a direct write so the |
| 1424 | // upload is already flushed. |
| 1425 | } |
| 1426 | } |
| 1427 | |
| 1428 | // If we didn't do a direct texture write then we upload the pixels to a texture and draw. |
| 1429 | GrRenderTarget* renderTarget = surface->asRenderTarget(); |
| 1430 | if (NULL == renderTarget) { |
| 1431 | return false; |
| 1432 | } |
| 1433 | |
| 1434 | // We ignore the preferred config unless it is a R/B swap of the src config. In that case |
| 1435 | // we will upload the original src data to a scratch texture but we will spoof it as the swapped |
| 1436 | // config. This scratch will then have R and B swapped. We correct for this by swapping again |
| 1437 | // when drawing the scratch to the dst using a conversion effect. |
| 1438 | bool swapRAndB = false; |
| 1439 | GrPixelConfig writeConfig = srcConfig; |
| 1440 | if (GrPixelConfigSwapRAndB(srcConfig) == |
| 1441 | fGpu->preferredWritePixelsConfig(srcConfig, renderTarget->config())) { |
| 1442 | writeConfig = GrPixelConfigSwapRAndB(srcConfig); |
| 1443 | swapRAndB = true; |
| 1444 | } |
| 1445 | |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 1446 | GrSurfaceDesc desc; |
bsalomon | 81beccc | 2014-10-13 12:32:55 -0700 | [diff] [blame] | 1447 | desc.fWidth = width; |
| 1448 | desc.fHeight = height; |
| 1449 | desc.fConfig = writeConfig; |
bsalomon | d309e7a | 2015-04-30 14:18:54 -0700 | [diff] [blame^] | 1450 | SkAutoTUnref<GrTexture> texture(this->textureProvider()->refScratchTexture(desc, |
| 1451 | GrTextureProvider::kApprox_ScratchTexMatch)); |
bsalomon | e305973 | 2014-10-14 11:47:22 -0700 | [diff] [blame] | 1452 | if (!texture) { |
bsalomon | 81beccc | 2014-10-13 12:32:55 -0700 | [diff] [blame] | 1453 | return false; |
| 1454 | } |
| 1455 | |
| 1456 | SkAutoTUnref<const GrFragmentProcessor> fp; |
| 1457 | SkMatrix textureMatrix; |
| 1458 | textureMatrix.setIDiv(texture->width(), texture->height()); |
| 1459 | |
| 1460 | // allocate a tmp buffer and sw convert the pixels to premul |
| 1461 | SkAutoSTMalloc<128 * 128, uint32_t> tmpPixels(0); |
| 1462 | |
| 1463 | if (kUnpremul_PixelOpsFlag & pixelOpsFlags) { |
| 1464 | if (!GrPixelConfigIs8888(srcConfig)) { |
| 1465 | return false; |
| 1466 | } |
| 1467 | fp.reset(this->createUPMToPMEffect(texture, swapRAndB, textureMatrix)); |
| 1468 | // handle the unpremul step on the CPU if we couldn't create an effect to do it. |
| 1469 | if (NULL == fp) { |
| 1470 | size_t tmpRowBytes = 4 * width; |
| 1471 | tmpPixels.reset(width * height); |
| 1472 | if (!sw_convert_to_premul(srcConfig, width, height, rowBytes, buffer, tmpRowBytes, |
| 1473 | tmpPixels.get())) { |
| 1474 | return false; |
| 1475 | } |
| 1476 | rowBytes = tmpRowBytes; |
| 1477 | buffer = tmpPixels.get(); |
| 1478 | } |
| 1479 | } |
| 1480 | if (NULL == fp) { |
| 1481 | fp.reset(GrConfigConversionEffect::Create(texture, |
| 1482 | swapRAndB, |
| 1483 | GrConfigConversionEffect::kNone_PMConversion, |
| 1484 | textureMatrix)); |
| 1485 | } |
| 1486 | |
| 1487 | // Even if the client told us not to flush, we still flush here. The client may have known that |
| 1488 | // writes to the original surface caused no data hazards, but they can't know that the scratch |
| 1489 | // we just got is safe. |
| 1490 | if (texture->surfacePriv().hasPendingIO()) { |
| 1491 | this->flush(); |
| 1492 | } |
| 1493 | if (!fGpu->writeTexturePixels(texture, 0, 0, width, height, |
| 1494 | writeConfig, buffer, rowBytes)) { |
| 1495 | return false; |
| 1496 | } |
| 1497 | |
| 1498 | SkMatrix matrix; |
| 1499 | matrix.setTranslate(SkIntToScalar(left), SkIntToScalar(top)); |
| 1500 | |
| 1501 | // This function can be called in the midst of drawing another object (e.g., when uploading a |
| 1502 | // SW-rasterized clip while issuing a draw). So we push the current geometry state before |
| 1503 | // drawing a rect to the render target. |
| 1504 | // The bracket ensures we pop the stack if we wind up flushing below. |
| 1505 | { |
joshualitt | 570d2f8 | 2015-02-25 13:19:48 -0800 | [diff] [blame] | 1506 | GrDrawTarget* drawTarget = this->prepareToDraw(); |
| 1507 | if (!drawTarget) { |
| 1508 | return false; |
| 1509 | } |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 1510 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 1511 | GrPipelineBuilder pipelineBuilder; |
| 1512 | pipelineBuilder.addColorProcessor(fp); |
| 1513 | pipelineBuilder.setRenderTarget(renderTarget); |
joshualitt | 44701df | 2015-02-23 14:44:57 -0800 | [diff] [blame] | 1514 | drawTarget->drawSimpleRect(&pipelineBuilder, |
| 1515 | GrColor_WHITE, |
| 1516 | matrix, |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 1517 | SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(height))); |
bsalomon | 81beccc | 2014-10-13 12:32:55 -0700 | [diff] [blame] | 1518 | } |
| 1519 | |
| 1520 | if (kFlushWrites_PixelOp & pixelOpsFlags) { |
| 1521 | this->flushSurfaceWrites(surface); |
| 1522 | } |
| 1523 | |
| 1524 | return true; |
| 1525 | } |
bsalomon@google.com | a91e923 | 2012-02-23 15:39:54 +0000 | [diff] [blame] | 1526 | |
reed@google.com | 7111d46 | 2014-03-25 16:20:24 +0000 | [diff] [blame] | 1527 | // toggles between RGBA and BGRA |
| 1528 | static SkColorType toggle_colortype32(SkColorType ct) { |
| 1529 | if (kRGBA_8888_SkColorType == ct) { |
| 1530 | return kBGRA_8888_SkColorType; |
| 1531 | } else { |
| 1532 | SkASSERT(kBGRA_8888_SkColorType == ct); |
| 1533 | return kRGBA_8888_SkColorType; |
bsalomon@google.com | a91e923 | 2012-02-23 15:39:54 +0000 | [diff] [blame] | 1534 | } |
| 1535 | } |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 1536 | |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 1537 | bool GrContext::readRenderTargetPixels(GrRenderTarget* target, |
| 1538 | int left, int top, int width, int height, |
bsalomon@google.com | 9c68058 | 2013-02-06 18:17:50 +0000 | [diff] [blame] | 1539 | GrPixelConfig dstConfig, void* buffer, size_t rowBytes, |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 1540 | uint32_t flags) { |
joshualitt | 5f5a8d7 | 2015-02-25 14:09:45 -0800 | [diff] [blame] | 1541 | RETURN_FALSE_IF_ABANDONED |
bsalomon@google.com | bc4b654 | 2011-11-19 13:56:11 +0000 | [diff] [blame] | 1542 | ASSERT_OWNED_RESOURCE(target); |
bsalomon | 89c6298 | 2014-11-03 12:08:42 -0800 | [diff] [blame] | 1543 | SkASSERT(target); |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 1544 | |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame] | 1545 | if (!(kDontFlush_PixelOpsFlag & flags) && target->surfacePriv().hasPendingWrite()) { |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 1546 | this->flush(); |
| 1547 | } |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 1548 | |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 1549 | // Determine which conversions have to be applied: flipY, swapRAnd, and/or unpremul. |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 1550 | |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 1551 | // If fGpu->readPixels would incur a y-flip cost then we will read the pixels upside down. We'll |
| 1552 | // either do the flipY by drawing into a scratch with a matrix or on the cpu after the read. |
| 1553 | bool flipY = fGpu->readPixelsWillPayForYFlip(target, left, top, |
bsalomon@google.com | 9c68058 | 2013-02-06 18:17:50 +0000 | [diff] [blame] | 1554 | width, height, dstConfig, |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 1555 | rowBytes); |
bsalomon@google.com | 9c68058 | 2013-02-06 18:17:50 +0000 | [diff] [blame] | 1556 | // We ignore the preferred config if it is different than our config unless it is an R/B swap. |
| 1557 | // In that case we'll perform an R and B swap while drawing to a scratch texture of the swapped |
| 1558 | // config. Then we will call readPixels on the scratch with the swapped config. The swaps during |
| 1559 | // the draw cancels out the fact that we call readPixels with a config that is R/B swapped from |
| 1560 | // dstConfig. |
| 1561 | GrPixelConfig readConfig = dstConfig; |
| 1562 | bool swapRAndB = false; |
commit-bot@chromium.org | 5d1d79a | 2013-05-24 18:52:52 +0000 | [diff] [blame] | 1563 | if (GrPixelConfigSwapRAndB(dstConfig) == |
| 1564 | fGpu->preferredReadPixelsConfig(dstConfig, target->config())) { |
bsalomon@google.com | 9c68058 | 2013-02-06 18:17:50 +0000 | [diff] [blame] | 1565 | readConfig = GrPixelConfigSwapRAndB(readConfig); |
| 1566 | swapRAndB = true; |
| 1567 | } |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 1568 | |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 1569 | bool unpremul = SkToBool(kUnpremul_PixelOpsFlag & flags); |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 1570 | |
bsalomon@google.com | 9c68058 | 2013-02-06 18:17:50 +0000 | [diff] [blame] | 1571 | if (unpremul && !GrPixelConfigIs8888(dstConfig)) { |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 1572 | // The unpremul flag is only allowed for these two configs. |
bsalomon@google.com | 0a97be2 | 2011-11-08 19:20:57 +0000 | [diff] [blame] | 1573 | return false; |
| 1574 | } |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 1575 | |
bsalomon | 191bcc0 | 2014-11-14 11:31:13 -0800 | [diff] [blame] | 1576 | SkAutoTUnref<GrTexture> tempTexture; |
| 1577 | |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 1578 | // If the src is a texture and we would have to do conversions after read pixels, we instead |
| 1579 | // do the conversions by drawing the src to a scratch texture. If we handle any of the |
| 1580 | // conversions in the draw we set the corresponding bool to false so that we don't reapply it |
| 1581 | // on the read back pixels. |
| 1582 | GrTexture* src = target->asTexture(); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 1583 | if (src && (swapRAndB || unpremul || flipY)) { |
bsalomon | 81beccc | 2014-10-13 12:32:55 -0700 | [diff] [blame] | 1584 | // Make the scratch a render so we can read its pixels. |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 1585 | GrSurfaceDesc desc; |
| 1586 | desc.fFlags = kRenderTarget_GrSurfaceFlag; |
robertphillips@google.com | 75b3c96 | 2012-06-07 12:08:45 +0000 | [diff] [blame] | 1587 | desc.fWidth = width; |
| 1588 | desc.fHeight = height; |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 1589 | desc.fConfig = readConfig; |
senorblanco@chromium.org | 3cb406b | 2013-02-05 19:50:46 +0000 | [diff] [blame] | 1590 | desc.fOrigin = kTopLeft_GrSurfaceOrigin; |
bsalomon@google.com | c4ff22a | 2011-11-10 21:56:21 +0000 | [diff] [blame] | 1591 | |
bsalomon@google.com | 9c68058 | 2013-02-06 18:17:50 +0000 | [diff] [blame] | 1592 | // When a full read back is faster than a partial we could always make the scratch exactly |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 1593 | // match the passed rect. However, if we see many different size rectangles we will trash |
| 1594 | // our texture cache and pay the cost of creating and destroying many textures. So, we only |
| 1595 | // request an exact match when the caller is reading an entire RT. |
bsalomon | d309e7a | 2015-04-30 14:18:54 -0700 | [diff] [blame^] | 1596 | GrTextureProvider::ScratchTexMatch match = GrTextureProvider::kApprox_ScratchTexMatch; |
bsalomon@google.com | 56d11e0 | 2011-11-30 19:59:08 +0000 | [diff] [blame] | 1597 | if (0 == left && |
| 1598 | 0 == top && |
| 1599 | target->width() == width && |
| 1600 | target->height() == height && |
| 1601 | fGpu->fullReadPixelsIsFasterThanPartial()) { |
bsalomon | d309e7a | 2015-04-30 14:18:54 -0700 | [diff] [blame^] | 1602 | match = GrTextureProvider::kExact_ScratchTexMatch; |
bsalomon@google.com | 56d11e0 | 2011-11-30 19:59:08 +0000 | [diff] [blame] | 1603 | } |
bsalomon | d309e7a | 2015-04-30 14:18:54 -0700 | [diff] [blame^] | 1604 | tempTexture.reset(this->textureProvider()->refScratchTexture(desc, match)); |
bsalomon | 191bcc0 | 2014-11-14 11:31:13 -0800 | [diff] [blame] | 1605 | if (tempTexture) { |
bsalomon@google.com | d8b5fac | 2012-11-01 17:02:46 +0000 | [diff] [blame] | 1606 | // compute a matrix to perform the draw |
bsalomon@google.com | b9086a0 | 2012-11-01 18:02:54 +0000 | [diff] [blame] | 1607 | SkMatrix textureMatrix; |
senorblanco@chromium.org | 3cb406b | 2013-02-05 19:50:46 +0000 | [diff] [blame] | 1608 | textureMatrix.setTranslate(SK_Scalar1 *left, SK_Scalar1 *top); |
bsalomon@google.com | d8b5fac | 2012-11-01 17:02:46 +0000 | [diff] [blame] | 1609 | textureMatrix.postIDiv(src->width(), src->height()); |
| 1610 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 1611 | SkAutoTUnref<const GrFragmentProcessor> fp; |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 1612 | if (unpremul) { |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 1613 | fp.reset(this->createPMToUPMEffect(src, swapRAndB, textureMatrix)); |
| 1614 | if (fp) { |
bsalomon@google.com | 9c68058 | 2013-02-06 18:17:50 +0000 | [diff] [blame] | 1615 | unpremul = false; // we no longer need to do this on CPU after the read back. |
bsalomon@google.com | d8b5fac | 2012-11-01 17:02:46 +0000 | [diff] [blame] | 1616 | } |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 1617 | } |
| 1618 | // If we failed to create a PM->UPM effect and have no other conversions to perform then |
| 1619 | // there is no longer any point to using the scratch. |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 1620 | if (fp || flipY || swapRAndB) { |
| 1621 | if (!fp) { |
| 1622 | fp.reset(GrConfigConversionEffect::Create( |
| 1623 | src, swapRAndB, GrConfigConversionEffect::kNone_PMConversion, |
| 1624 | textureMatrix)); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 1625 | } |
| 1626 | swapRAndB = false; // we will handle the swap in the draw. |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 1627 | |
robertphillips@google.com | 13f181f | 2013-03-02 12:02:08 +0000 | [diff] [blame] | 1628 | // We protect the existing geometry here since it may not be |
| 1629 | // clear to the caller that a draw operation (i.e., drawSimpleRect) |
| 1630 | // can be invoked in this method |
joshualitt | 5c55fef | 2014-10-31 14:04:35 -0700 | [diff] [blame] | 1631 | { |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 1632 | GrPipelineBuilder pipelineBuilder; |
joshualitt | 5c55fef | 2014-10-31 14:04:35 -0700 | [diff] [blame] | 1633 | SkASSERT(fp); |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 1634 | pipelineBuilder.addColorProcessor(fp); |
bsalomon@google.com | d8b5fac | 2012-11-01 17:02:46 +0000 | [diff] [blame] | 1635 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 1636 | pipelineBuilder.setRenderTarget(tempTexture->asRenderTarget()); |
joshualitt | 5c55fef | 2014-10-31 14:04:35 -0700 | [diff] [blame] | 1637 | SkRect rect = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(height)); |
joshualitt | 44701df | 2015-02-23 14:44:57 -0800 | [diff] [blame] | 1638 | fDrawBuffer->drawSimpleRect(&pipelineBuilder, |
| 1639 | GrColor_WHITE, |
| 1640 | SkMatrix::I(), |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 1641 | rect); |
joshualitt | 5c55fef | 2014-10-31 14:04:35 -0700 | [diff] [blame] | 1642 | // we want to read back from the scratch's origin |
| 1643 | left = 0; |
| 1644 | top = 0; |
bsalomon | 191bcc0 | 2014-11-14 11:31:13 -0800 | [diff] [blame] | 1645 | target = tempTexture->asRenderTarget(); |
joshualitt | 5c55fef | 2014-10-31 14:04:35 -0700 | [diff] [blame] | 1646 | } |
| 1647 | this->flushSurfaceWrites(target); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 1648 | } |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 1649 | } |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 1650 | } |
joshualitt | 5c55fef | 2014-10-31 14:04:35 -0700 | [diff] [blame] | 1651 | |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 1652 | if (!fGpu->readPixels(target, |
| 1653 | left, top, width, height, |
senorblanco@chromium.org | 3cb406b | 2013-02-05 19:50:46 +0000 | [diff] [blame] | 1654 | readConfig, buffer, rowBytes)) { |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 1655 | return false; |
| 1656 | } |
bsalomon@google.com | d8b5fac | 2012-11-01 17:02:46 +0000 | [diff] [blame] | 1657 | // Perform any conversions we weren't able to perform using a scratch texture. |
senorblanco@chromium.org | 3cb406b | 2013-02-05 19:50:46 +0000 | [diff] [blame] | 1658 | if (unpremul || swapRAndB) { |
reed@google.com | 7111d46 | 2014-03-25 16:20:24 +0000 | [diff] [blame] | 1659 | SkDstPixelInfo dstPI; |
jvanverth | fa1e8a7 | 2014-12-22 08:31:49 -0800 | [diff] [blame] | 1660 | if (!GrPixelConfig2ColorAndProfileType(dstConfig, &dstPI.fColorType, NULL)) { |
reed@google.com | 7111d46 | 2014-03-25 16:20:24 +0000 | [diff] [blame] | 1661 | return false; |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 1662 | } |
reed@google.com | 7111d46 | 2014-03-25 16:20:24 +0000 | [diff] [blame] | 1663 | dstPI.fAlphaType = kUnpremul_SkAlphaType; |
| 1664 | dstPI.fPixels = buffer; |
| 1665 | dstPI.fRowBytes = rowBytes; |
| 1666 | |
| 1667 | SkSrcPixelInfo srcPI; |
| 1668 | srcPI.fColorType = swapRAndB ? toggle_colortype32(dstPI.fColorType) : dstPI.fColorType; |
| 1669 | srcPI.fAlphaType = kPremul_SkAlphaType; |
| 1670 | srcPI.fPixels = buffer; |
| 1671 | srcPI.fRowBytes = rowBytes; |
| 1672 | |
| 1673 | return srcPI.convertPixelsTo(&dstPI, width, height); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 1674 | } |
| 1675 | return true; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 1676 | } |
| 1677 | |
bsalomon | 87a94eb | 2014-11-03 14:28:32 -0800 | [diff] [blame] | 1678 | void GrContext::prepareSurfaceForExternalRead(GrSurface* surface) { |
joshualitt | 5f5a8d7 | 2015-02-25 14:09:45 -0800 | [diff] [blame] | 1679 | RETURN_IF_ABANDONED |
bsalomon | 87a94eb | 2014-11-03 14:28:32 -0800 | [diff] [blame] | 1680 | SkASSERT(surface); |
| 1681 | ASSERT_OWNED_RESOURCE(surface); |
| 1682 | if (surface->surfacePriv().hasPendingIO()) { |
| 1683 | this->flush(); |
| 1684 | } |
| 1685 | GrRenderTarget* rt = surface->asRenderTarget(); |
| 1686 | if (fGpu && rt) { |
| 1687 | fGpu->resolveRenderTarget(rt); |
bsalomon | 41ebbdd | 2014-08-04 08:31:39 -0700 | [diff] [blame] | 1688 | } |
bsalomon@google.com | 75f9f25 | 2012-01-31 13:35:56 +0000 | [diff] [blame] | 1689 | } |
| 1690 | |
bsalomon | 41ebbdd | 2014-08-04 08:31:39 -0700 | [diff] [blame] | 1691 | void GrContext::discardRenderTarget(GrRenderTarget* renderTarget) { |
joshualitt | 5f5a8d7 | 2015-02-25 14:09:45 -0800 | [diff] [blame] | 1692 | RETURN_IF_ABANDONED |
bsalomon | 41ebbdd | 2014-08-04 08:31:39 -0700 | [diff] [blame] | 1693 | SkASSERT(renderTarget); |
| 1694 | ASSERT_OWNED_RESOURCE(renderTarget); |
bsalomon | f21dab9 | 2014-11-13 13:33:28 -0800 | [diff] [blame] | 1695 | AutoCheckFlush acf(this); |
joshualitt | 570d2f8 | 2015-02-25 13:19:48 -0800 | [diff] [blame] | 1696 | GrDrawTarget* target = this->prepareToDraw(); |
bsalomon | 41ebbdd | 2014-08-04 08:31:39 -0700 | [diff] [blame] | 1697 | if (NULL == target) { |
| 1698 | return; |
| 1699 | } |
| 1700 | target->discard(renderTarget); |
commit-bot@chromium.org | 28361fa | 2014-03-28 16:08:05 +0000 | [diff] [blame] | 1701 | } |
| 1702 | |
bsalomon | f80bfed | 2014-10-07 05:56:02 -0700 | [diff] [blame] | 1703 | void GrContext::copySurface(GrSurface* dst, GrSurface* src, const SkIRect& srcRect, |
| 1704 | const SkIPoint& dstPoint, uint32_t pixelOpsFlags) { |
joshualitt | 5f5a8d7 | 2015-02-25 14:09:45 -0800 | [diff] [blame] | 1705 | RETURN_IF_ABANDONED |
senorblanco@chromium.org | ef843cd | 2011-12-02 19:11:17 +0000 | [diff] [blame] | 1706 | if (NULL == src || NULL == dst) { |
| 1707 | return; |
| 1708 | } |
bsalomon | e3d4bf2 | 2014-09-23 09:15:03 -0700 | [diff] [blame] | 1709 | ASSERT_OWNED_RESOURCE(src); |
junov | 2bb5210 | 2014-09-29 10:18:59 -0700 | [diff] [blame] | 1710 | ASSERT_OWNED_RESOURCE(dst); |
Brian Salomon | 34a9895 | 2014-09-24 11:41:24 -0400 | [diff] [blame] | 1711 | |
bsalomon | f80bfed | 2014-10-07 05:56:02 -0700 | [diff] [blame] | 1712 | // Since we're going to the draw target and not GPU, no need to check kNoFlush |
| 1713 | // here. |
junov | 96c118e | 2014-09-26 13:09:47 -0700 | [diff] [blame] | 1714 | |
joshualitt | 570d2f8 | 2015-02-25 13:19:48 -0800 | [diff] [blame] | 1715 | GrDrawTarget* target = this->prepareToDraw(); |
junov | 96c118e | 2014-09-26 13:09:47 -0700 | [diff] [blame] | 1716 | if (NULL == target) { |
| 1717 | return; |
| 1718 | } |
junov | 96c118e | 2014-09-26 13:09:47 -0700 | [diff] [blame] | 1719 | target->copySurface(dst, src, srcRect, dstPoint); |
bsalomon | f80bfed | 2014-10-07 05:56:02 -0700 | [diff] [blame] | 1720 | |
| 1721 | if (kFlushWrites_PixelOp & pixelOpsFlags) { |
| 1722 | this->flush(); |
| 1723 | } |
senorblanco@chromium.org | ef843cd | 2011-12-02 19:11:17 +0000 | [diff] [blame] | 1724 | } |
| 1725 | |
bsalomon | f80bfed | 2014-10-07 05:56:02 -0700 | [diff] [blame] | 1726 | void GrContext::flushSurfaceWrites(GrSurface* surface) { |
joshualitt | 5f5a8d7 | 2015-02-25 14:09:45 -0800 | [diff] [blame] | 1727 | RETURN_IF_ABANDONED |
bsalomon | f80bfed | 2014-10-07 05:56:02 -0700 | [diff] [blame] | 1728 | if (surface->surfacePriv().hasPendingWrite()) { |
| 1729 | this->flush(); |
| 1730 | } |
| 1731 | } |
| 1732 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 1733 | GrDrawTarget* GrContext::prepareToDraw(GrPipelineBuilder* pipelineBuilder, |
joshualitt | 25d9c15 | 2015-02-18 12:29:52 -0800 | [diff] [blame] | 1734 | GrRenderTarget* rt, |
joshualitt | 570d2f8 | 2015-02-25 13:19:48 -0800 | [diff] [blame] | 1735 | const GrClip& clip, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 1736 | const GrPaint* paint, |
| 1737 | const AutoCheckFlush* acf) { |
joshualitt | 5f5a8d7 | 2015-02-25 14:09:45 -0800 | [diff] [blame] | 1738 | if (NULL == fGpu || NULL == fDrawBuffer) { |
bsalomon | 41ebbdd | 2014-08-04 08:31:39 -0700 | [diff] [blame] | 1739 | return NULL; |
| 1740 | } |
| 1741 | |
joshualitt | 570d2f8 | 2015-02-25 13:19:48 -0800 | [diff] [blame] | 1742 | ASSERT_OWNED_RESOURCE(rt); |
| 1743 | SkASSERT(rt && paint && acf); |
| 1744 | pipelineBuilder->setFromPaint(*paint, rt, clip); |
| 1745 | return fDrawBuffer; |
| 1746 | } |
| 1747 | |
| 1748 | GrDrawTarget* GrContext::prepareToDraw() { |
| 1749 | if (NULL == fGpu) { |
| 1750 | return NULL; |
bsalomon@google.com | 07ea2db | 2012-08-17 14:06:49 +0000 | [diff] [blame] | 1751 | } |
joshualitt | 5c55fef | 2014-10-31 14:04:35 -0700 | [diff] [blame] | 1752 | return fDrawBuffer; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 1753 | } |
| 1754 | |
robertphillips@google.com | 72176b2 | 2012-05-23 13:19:12 +0000 | [diff] [blame] | 1755 | /* |
| 1756 | * This method finds a path renderer that can draw the specified path on |
| 1757 | * the provided target. |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 1758 | * Due to its expense, the software path renderer has split out so it can |
robertphillips@google.com | 72176b2 | 2012-05-23 13:19:12 +0000 | [diff] [blame] | 1759 | * can be individually allowed/disallowed via the "allowSW" boolean. |
| 1760 | */ |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 1761 | GrPathRenderer* GrContext::getPathRenderer(const GrDrawTarget* target, |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 1762 | const GrPipelineBuilder* pipelineBuilder, |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 1763 | const SkMatrix& viewMatrix, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 1764 | const SkPath& path, |
kkinnunen | 1899651 | 2015-04-26 23:18:49 -0700 | [diff] [blame] | 1765 | const GrStrokeInfo& stroke, |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 1766 | bool allowSW, |
| 1767 | GrPathRendererChain::DrawType drawType, |
| 1768 | GrPathRendererChain::StencilSupport* stencilSupport) { |
| 1769 | |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 1770 | if (NULL == fPathRendererChain) { |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 1771 | fPathRendererChain = SkNEW_ARGS(GrPathRendererChain, (this)); |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 1772 | } |
robertphillips@google.com | 72176b2 | 2012-05-23 13:19:12 +0000 | [diff] [blame] | 1773 | |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 1774 | GrPathRenderer* pr = fPathRendererChain->getPathRenderer(target, |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 1775 | pipelineBuilder, |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 1776 | viewMatrix, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 1777 | path, |
sugoi@google.com | 12b4e27 | 2012-12-06 20:13:11 +0000 | [diff] [blame] | 1778 | stroke, |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 1779 | drawType, |
| 1780 | stencilSupport); |
robertphillips@google.com | 72176b2 | 2012-05-23 13:19:12 +0000 | [diff] [blame] | 1781 | |
| 1782 | if (NULL == pr && allowSW) { |
| 1783 | if (NULL == fSoftwarePathRenderer) { |
tomhudson@google.com | c377baf | 2012-07-09 20:17:56 +0000 | [diff] [blame] | 1784 | fSoftwarePathRenderer = SkNEW_ARGS(GrSoftwarePathRenderer, (this)); |
robertphillips@google.com | 72176b2 | 2012-05-23 13:19:12 +0000 | [diff] [blame] | 1785 | } |
robertphillips@google.com | 72176b2 | 2012-05-23 13:19:12 +0000 | [diff] [blame] | 1786 | pr = fSoftwarePathRenderer; |
| 1787 | } |
| 1788 | |
| 1789 | return pr; |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 1790 | } |
| 1791 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 1792 | //////////////////////////////////////////////////////////////////////////////// |
commit-bot@chromium.org | 6b7938f | 2013-10-15 14:18:16 +0000 | [diff] [blame] | 1793 | bool GrContext::isConfigRenderable(GrPixelConfig config, bool withMSAA) const { |
| 1794 | return fGpu->caps()->isConfigRenderable(config, withMSAA); |
robertphillips@google.com | 99a5ac0 | 2012-04-10 19:26:38 +0000 | [diff] [blame] | 1795 | } |
| 1796 | |
commit-bot@chromium.org | b471a32 | 2014-03-10 07:40:03 +0000 | [diff] [blame] | 1797 | int GrContext::getRecommendedSampleCount(GrPixelConfig config, |
| 1798 | SkScalar dpi) const { |
| 1799 | if (!this->isConfigRenderable(config, true)) { |
| 1800 | return 0; |
| 1801 | } |
| 1802 | int chosenSampleCount = 0; |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 1803 | if (fGpu->caps()->shaderCaps()->pathRenderingSupport()) { |
commit-bot@chromium.org | b471a32 | 2014-03-10 07:40:03 +0000 | [diff] [blame] | 1804 | if (dpi >= 250.0f) { |
| 1805 | chosenSampleCount = 4; |
| 1806 | } else { |
| 1807 | chosenSampleCount = 16; |
| 1808 | } |
| 1809 | } |
| 1810 | return chosenSampleCount <= fGpu->caps()->maxSampleCount() ? |
| 1811 | chosenSampleCount : 0; |
| 1812 | } |
| 1813 | |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 1814 | void GrContext::setupDrawBuffer() { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 1815 | SkASSERT(NULL == fDrawBuffer); |
| 1816 | SkASSERT(NULL == fDrawBufferVBAllocPool); |
| 1817 | SkASSERT(NULL == fDrawBufferIBAllocPool); |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 1818 | |
bsalomon@google.com | de6ac2d | 2011-02-25 21:50:42 +0000 | [diff] [blame] | 1819 | fDrawBufferVBAllocPool = |
bsalomon | ecb8e3e | 2015-04-29 04:33:52 -0700 | [diff] [blame] | 1820 | SkNEW_ARGS(GrVertexBufferAllocPool, (fGpu, |
| 1821 | DRAW_BUFFER_VBPOOL_BUFFER_SIZE, |
| 1822 | DRAW_BUFFER_VBPOOL_PREALLOC_BUFFERS)); |
bsalomon@google.com | de6ac2d | 2011-02-25 21:50:42 +0000 | [diff] [blame] | 1823 | fDrawBufferIBAllocPool = |
bsalomon | ecb8e3e | 2015-04-29 04:33:52 -0700 | [diff] [blame] | 1824 | SkNEW_ARGS(GrIndexBufferAllocPool, (fGpu, |
| 1825 | DRAW_BUFFER_IBPOOL_BUFFER_SIZE, |
| 1826 | DRAW_BUFFER_IBPOOL_PREALLOC_BUFFERS)); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 1827 | |
bsalomon | a73239a | 2015-04-28 13:35:17 -0700 | [diff] [blame] | 1828 | fDrawBuffer = SkNEW_ARGS(GrInOrderDrawBuffer, (this, |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 1829 | fDrawBufferVBAllocPool, |
| 1830 | fDrawBufferIBAllocPool)); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 1831 | } |
| 1832 | |
bsalomon@google.com | 21c10c5 | 2013-06-13 17:44:07 +0000 | [diff] [blame] | 1833 | GrDrawTarget* GrContext::getTextTarget() { |
joshualitt | 570d2f8 | 2015-02-25 13:19:48 -0800 | [diff] [blame] | 1834 | return this->prepareToDraw(); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 1835 | } |
| 1836 | |
| 1837 | const GrIndexBuffer* GrContext::getQuadIndexBuffer() const { |
| 1838 | return fGpu->getQuadIndexBuffer(); |
| 1839 | } |
bsalomon@google.com | dfe75bc | 2011-03-25 12:31:16 +0000 | [diff] [blame] | 1840 | |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 1841 | namespace { |
| 1842 | void test_pm_conversions(GrContext* ctx, int* pmToUPMValue, int* upmToPMValue) { |
| 1843 | GrConfigConversionEffect::PMConversion pmToUPM; |
| 1844 | GrConfigConversionEffect::PMConversion upmToPM; |
| 1845 | GrConfigConversionEffect::TestForPreservingPMConversions(ctx, &pmToUPM, &upmToPM); |
| 1846 | *pmToUPMValue = pmToUPM; |
| 1847 | *upmToPMValue = upmToPM; |
| 1848 | } |
| 1849 | } |
| 1850 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 1851 | const GrFragmentProcessor* GrContext::createPMToUPMEffect(GrTexture* texture, |
| 1852 | bool swapRAndB, |
| 1853 | const SkMatrix& matrix) { |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 1854 | if (!fDidTestPMConversions) { |
| 1855 | test_pm_conversions(this, &fPMToUPMConversion, &fUPMToPMConversion); |
bsalomon@google.com | d0f3f68 | 2012-08-28 13:08:14 +0000 | [diff] [blame] | 1856 | fDidTestPMConversions = true; |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 1857 | } |
| 1858 | GrConfigConversionEffect::PMConversion pmToUPM = |
| 1859 | static_cast<GrConfigConversionEffect::PMConversion>(fPMToUPMConversion); |
| 1860 | if (GrConfigConversionEffect::kNone_PMConversion != pmToUPM) { |
bsalomon@google.com | adc6536 | 2013-01-28 14:26:09 +0000 | [diff] [blame] | 1861 | return GrConfigConversionEffect::Create(texture, swapRAndB, pmToUPM, matrix); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 1862 | } else { |
bsalomon@google.com | adc6536 | 2013-01-28 14:26:09 +0000 | [diff] [blame] | 1863 | return NULL; |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 1864 | } |
| 1865 | } |
| 1866 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 1867 | const GrFragmentProcessor* GrContext::createUPMToPMEffect(GrTexture* texture, |
| 1868 | bool swapRAndB, |
| 1869 | const SkMatrix& matrix) { |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 1870 | if (!fDidTestPMConversions) { |
| 1871 | test_pm_conversions(this, &fPMToUPMConversion, &fUPMToPMConversion); |
bsalomon@google.com | d0f3f68 | 2012-08-28 13:08:14 +0000 | [diff] [blame] | 1872 | fDidTestPMConversions = true; |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 1873 | } |
| 1874 | GrConfigConversionEffect::PMConversion upmToPM = |
| 1875 | static_cast<GrConfigConversionEffect::PMConversion>(fUPMToPMConversion); |
| 1876 | if (GrConfigConversionEffect::kNone_PMConversion != upmToPM) { |
bsalomon@google.com | adc6536 | 2013-01-28 14:26:09 +0000 | [diff] [blame] | 1877 | return GrConfigConversionEffect::Create(texture, swapRAndB, upmToPM, matrix); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 1878 | } else { |
bsalomon@google.com | adc6536 | 2013-01-28 14:26:09 +0000 | [diff] [blame] | 1879 | return NULL; |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 1880 | } |
| 1881 | } |
| 1882 | |
bsalomon | 37f9a26 | 2015-02-02 13:00:10 -0800 | [diff] [blame] | 1883 | ////////////////////////////////////////////////////////////////////////////// |
| 1884 | |
| 1885 | void GrContext::getResourceCacheLimits(int* maxTextures, size_t* maxTextureBytes) const { |
| 1886 | if (maxTextures) { |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 1887 | *maxTextures = fResourceCache->getMaxResourceCount(); |
bsalomon | 37f9a26 | 2015-02-02 13:00:10 -0800 | [diff] [blame] | 1888 | } |
| 1889 | if (maxTextureBytes) { |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 1890 | *maxTextureBytes = fResourceCache->getMaxResourceBytes(); |
bsalomon | 37f9a26 | 2015-02-02 13:00:10 -0800 | [diff] [blame] | 1891 | } |
| 1892 | } |
| 1893 | |
| 1894 | void GrContext::setResourceCacheLimits(int maxTextures, size_t maxTextureBytes) { |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 1895 | fResourceCache->setLimits(maxTextures, maxTextureBytes); |
bsalomon | 37f9a26 | 2015-02-02 13:00:10 -0800 | [diff] [blame] | 1896 | } |
| 1897 | |
bsalomon | 37f9a26 | 2015-02-02 13:00:10 -0800 | [diff] [blame] | 1898 | ////////////////////////////////////////////////////////////////////////////// |
| 1899 | |
egdaniel | bbcb38d | 2014-06-19 10:19:29 -0700 | [diff] [blame] | 1900 | void GrContext::addGpuTraceMarker(const GrGpuTraceMarker* marker) { |
| 1901 | fGpu->addGpuTraceMarker(marker); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 1902 | if (fDrawBuffer) { |
egdaniel | bbcb38d | 2014-06-19 10:19:29 -0700 | [diff] [blame] | 1903 | fDrawBuffer->addGpuTraceMarker(marker); |
| 1904 | } |
| 1905 | } |
| 1906 | |
| 1907 | void GrContext::removeGpuTraceMarker(const GrGpuTraceMarker* marker) { |
| 1908 | fGpu->removeGpuTraceMarker(marker); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 1909 | if (fDrawBuffer) { |
egdaniel | bbcb38d | 2014-06-19 10:19:29 -0700 | [diff] [blame] | 1910 | fDrawBuffer->removeGpuTraceMarker(marker); |
| 1911 | } |
| 1912 | } |