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" |
tomhudson@google.com | 278cbb4 | 2011-06-30 19:37:01 +0000 | [diff] [blame] | 12 | #include "GrBufferAllocPool.h" |
joshualitt | 5478d42 | 2014-11-14 16:00:38 -0800 | [diff] [blame] | 13 | #include "GrDefaultGeoProcFactory.h" |
jvanverth | 787cdf9 | 2014-12-04 10:46:50 -0800 | [diff] [blame] | 14 | #include "GrFontCache.h" |
bsalomon | 453cf40 | 2014-11-11 14:15:57 -0800 | [diff] [blame] | 15 | #include "GrGpuResource.h" |
| 16 | #include "GrGpuResourceCacheAccess.h" |
kkinnunen | c6cb56f | 2014-06-24 00:12:27 -0700 | [diff] [blame] | 17 | #include "GrDistanceFieldTextContext.h" |
commit-bot@chromium.org | 4784182 | 2014-03-27 14:19:17 +0000 | [diff] [blame] | 18 | #include "GrDrawTargetCaps.h" |
joshualitt | 5478d42 | 2014-11-14 16:00:38 -0800 | [diff] [blame] | 19 | #include "GrGpu.h" |
commit-bot@chromium.org | dcb8ef9 | 2014-03-27 11:26:10 +0000 | [diff] [blame] | 20 | #include "GrIndexBuffer.h" |
commit-bot@chromium.org | 4784182 | 2014-03-27 14:19:17 +0000 | [diff] [blame] | 21 | #include "GrInOrderDrawBuffer.h" |
robertphillips@google.com | e930a07 | 2014-04-03 00:34:27 +0000 | [diff] [blame] | 22 | #include "GrLayerCache.h" |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 23 | #include "GrOvalRenderer.h" |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 24 | #include "GrPathRenderer.h" |
tomhudson@google.com | d22b6e4 | 2011-06-24 15:53:40 +0000 | [diff] [blame] | 25 | #include "GrPathUtils.h" |
bsalomon | c8dc1f7 | 2014-08-21 13:02:13 -0700 | [diff] [blame] | 26 | #include "GrResourceCache2.h" |
robertphillips@google.com | 72176b2 | 2012-05-23 13:19:12 +0000 | [diff] [blame] | 27 | #include "GrSoftwarePathRenderer.h" |
kkinnunen | c6cb56f | 2014-06-24 00:12:27 -0700 | [diff] [blame] | 28 | #include "GrStencilAndCoverTextContext.h" |
egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 29 | #include "GrStrokeInfo.h" |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame] | 30 | #include "GrSurfacePriv.h" |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame] | 31 | #include "GrTexturePriv.h" |
egdaniel | bbcb38d | 2014-06-19 10:19:29 -0700 | [diff] [blame] | 32 | #include "GrTraceMarker.h" |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 33 | #include "GrTracing.h" |
egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 34 | #include "SkDashPathPriv.h" |
bsalomon | 81beccc | 2014-10-13 12:32:55 -0700 | [diff] [blame] | 35 | #include "SkConfig8888.h" |
reed@google.com | 7111d46 | 2014-03-25 16:20:24 +0000 | [diff] [blame] | 36 | #include "SkGr.h" |
commit-bot@chromium.org | 4784182 | 2014-03-27 14:19:17 +0000 | [diff] [blame] | 37 | #include "SkRRect.h" |
sugoi@google.com | 5f74cf8 | 2012-12-17 21:16:45 +0000 | [diff] [blame] | 38 | #include "SkStrokeRec.h" |
commit-bot@chromium.org | dcb8ef9 | 2014-03-27 11:26:10 +0000 | [diff] [blame] | 39 | #include "SkTLazy.h" |
commit-bot@chromium.org | 4784182 | 2014-03-27 14:19:17 +0000 | [diff] [blame] | 40 | #include "SkTLS.h" |
commit-bot@chromium.org | 933e65d | 2014-03-20 20:00:24 +0000 | [diff] [blame] | 41 | #include "SkTraceEvent.h" |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 42 | |
joshualitt | 5478d42 | 2014-11-14 16:00:38 -0800 | [diff] [blame] | 43 | #include "effects/GrConfigConversionEffect.h" |
| 44 | #include "effects/GrDashingEffect.h" |
| 45 | #include "effects/GrSingleTextureEffect.h" |
| 46 | |
commit-bot@chromium.org | 515dcd3 | 2013-08-28 14:17:03 +0000 | [diff] [blame] | 47 | #ifdef SK_DEBUG |
reed@google.com | 4b2d3f3 | 2012-05-15 18:05:50 +0000 | [diff] [blame] | 48 | // change this to a 1 to see notifications when partial coverage fails |
| 49 | #define GR_DEBUG_PARTIAL_COVERAGE_CHECK 0 |
| 50 | #else |
| 51 | #define GR_DEBUG_PARTIAL_COVERAGE_CHECK 0 |
| 52 | #endif |
| 53 | |
bsalomon@google.com | 6036149 | 2012-03-15 17:47:06 +0000 | [diff] [blame] | 54 | static const size_t DRAW_BUFFER_VBPOOL_BUFFER_SIZE = 1 << 15; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 55 | static const int DRAW_BUFFER_VBPOOL_PREALLOC_BUFFERS = 4; |
| 56 | |
bsalomon@google.com | 1d4edd3 | 2012-08-16 18:36:06 +0000 | [diff] [blame] | 57 | static const size_t DRAW_BUFFER_IBPOOL_BUFFER_SIZE = 1 << 11; |
| 58 | static const int DRAW_BUFFER_IBPOOL_PREALLOC_BUFFERS = 4; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 59 | |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 60 | #define ASSERT_OWNED_RESOURCE(R) SkASSERT(!(R) || (R)->getContext() == this) |
bsalomon@google.com | bc4b654 | 2011-11-19 13:56:11 +0000 | [diff] [blame] | 61 | |
bsalomon | f21dab9 | 2014-11-13 13:33:28 -0800 | [diff] [blame] | 62 | class GrContext::AutoCheckFlush { |
| 63 | public: |
| 64 | AutoCheckFlush(GrContext* context) : fContext(context) { SkASSERT(context); } |
| 65 | |
| 66 | ~AutoCheckFlush() { |
| 67 | if (fContext->fFlushToReduceCacheSize) { |
| 68 | fContext->flush(); |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | private: |
| 73 | GrContext* fContext; |
| 74 | }; |
| 75 | |
krajcevski | 9c6d4d7 | 2014-08-12 07:26:25 -0700 | [diff] [blame] | 76 | GrContext* GrContext::Create(GrBackend backend, GrBackendContext backendContext, |
| 77 | const Options* opts) { |
| 78 | GrContext* context; |
| 79 | if (NULL == opts) { |
| 80 | context = SkNEW_ARGS(GrContext, (Options())); |
| 81 | } else { |
| 82 | context = SkNEW_ARGS(GrContext, (*opts)); |
| 83 | } |
| 84 | |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 85 | if (context->init(backend, backendContext)) { |
| 86 | return context; |
| 87 | } else { |
| 88 | context->unref(); |
| 89 | return NULL; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 90 | } |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 91 | } |
| 92 | |
krajcevski | 9c6d4d7 | 2014-08-12 07:26:25 -0700 | [diff] [blame] | 93 | GrContext::GrContext(const Options& opts) : fOptions(opts) { |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 94 | fGpu = NULL; |
commit-bot@chromium.org | bb6a317 | 2013-05-28 17:25:49 +0000 | [diff] [blame] | 95 | fClip = NULL; |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 96 | fPathRendererChain = NULL; |
| 97 | fSoftwarePathRenderer = NULL; |
bsalomon | c8dc1f7 | 2014-08-21 13:02:13 -0700 | [diff] [blame] | 98 | fResourceCache2 = NULL; |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 99 | fFontCache = NULL; |
| 100 | fDrawBuffer = NULL; |
| 101 | fDrawBufferVBAllocPool = NULL; |
| 102 | fDrawBufferIBAllocPool = NULL; |
bsalomon | f21dab9 | 2014-11-13 13:33:28 -0800 | [diff] [blame] | 103 | fFlushToReduceCacheSize = false; |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 104 | fAARectRenderer = NULL; |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 105 | fOvalRenderer = NULL; |
commit-bot@chromium.org | bb6a317 | 2013-05-28 17:25:49 +0000 | [diff] [blame] | 106 | fViewMatrix.reset(); |
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 | c8dc1f7 | 2014-08-21 13:02:13 -0700 | [diff] [blame] | 122 | fResourceCache2 = SkNEW(GrResourceCache2); |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 123 | fResourceCache2->setOverBudgetCallback(OverBudgetCB, this); |
commit-bot@chromium.org | 1836d33 | 2013-07-16 22:55:03 +0000 | [diff] [blame] | 124 | |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 125 | fFontCache = SkNEW_ARGS(GrFontCache, (fGpu)); |
| 126 | |
robertphillips | 4ec84da | 2014-06-24 13:10:43 -0700 | [diff] [blame] | 127 | fLayerCache.reset(SkNEW_ARGS(GrLayerCache, (this))); |
robertphillips@google.com | e930a07 | 2014-04-03 00:34:27 +0000 | [diff] [blame] | 128 | |
joshualitt | b44293e | 2014-10-28 08:12:18 -0700 | [diff] [blame] | 129 | fAARectRenderer = SkNEW_ARGS(GrAARectRenderer, (fGpu)); |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 130 | fOvalRenderer = SkNEW(GrOvalRenderer); |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 131 | |
| 132 | fDidTestPMConversions = false; |
| 133 | |
| 134 | this->setupDrawBuffer(); |
bsalomon@google.com | c0af317 | 2012-06-15 14:10:09 +0000 | [diff] [blame] | 135 | } |
| 136 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 137 | GrContext::~GrContext() { |
bsalomon@google.com | 733c062 | 2013-04-24 17:59:32 +0000 | [diff] [blame] | 138 | if (NULL == fGpu) { |
| 139 | return; |
| 140 | } |
| 141 | |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 142 | this->flush(); |
robertphillips@google.com | 5acc0e3 | 2012-05-17 12:01:02 +0000 | [diff] [blame] | 143 | |
robertphillips@google.com | 950b1b0 | 2013-10-21 17:37:28 +0000 | [diff] [blame] | 144 | for (int i = 0; i < fCleanUpData.count(); ++i) { |
| 145 | (*fCleanUpData[i].fFunc)(this, fCleanUpData[i].fInfo); |
| 146 | } |
| 147 | |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 148 | SkDELETE(fResourceCache2); |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 149 | SkDELETE(fFontCache); |
| 150 | SkDELETE(fDrawBuffer); |
| 151 | SkDELETE(fDrawBufferVBAllocPool); |
| 152 | SkDELETE(fDrawBufferIBAllocPool); |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 153 | |
robertphillips@google.com | f6747b0 | 2012-06-12 00:32:28 +0000 | [diff] [blame] | 154 | fAARectRenderer->unref(); |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 155 | fOvalRenderer->unref(); |
robertphillips@google.com | f6747b0 | 2012-06-12 00:32:28 +0000 | [diff] [blame] | 156 | |
bsalomon@google.com | 205d460 | 2011-04-25 12:43:45 +0000 | [diff] [blame] | 157 | fGpu->unref(); |
commit-bot@chromium.org | a4de8c2 | 2013-09-09 13:38:37 +0000 | [diff] [blame] | 158 | SkSafeUnref(fPathRendererChain); |
| 159 | SkSafeUnref(fSoftwarePathRenderer); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 160 | } |
| 161 | |
bsalomon | 2354f84 | 2014-07-28 13:48:36 -0700 | [diff] [blame] | 162 | void GrContext::abandonContext() { |
bsalomon@google.com | 205d460 | 2011-04-25 12:43:45 +0000 | [diff] [blame] | 163 | // abandon first to so destructors |
| 164 | // don't try to free the resources in the API. |
bsalomon | c8dc1f7 | 2014-08-21 13:02:13 -0700 | [diff] [blame] | 165 | fResourceCache2->abandonAll(); |
| 166 | |
robertphillips | e337130 | 2014-09-17 06:01:06 -0700 | [diff] [blame] | 167 | fGpu->contextAbandoned(); |
bsalomon@google.com | 205d460 | 2011-04-25 12:43:45 +0000 | [diff] [blame] | 168 | |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 169 | // a path renderer may be holding onto resources that |
| 170 | // are now unusable |
commit-bot@chromium.org | a4de8c2 | 2013-09-09 13:38:37 +0000 | [diff] [blame] | 171 | SkSafeSetNull(fPathRendererChain); |
| 172 | SkSafeSetNull(fSoftwarePathRenderer); |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 173 | |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 174 | delete fDrawBuffer; |
| 175 | fDrawBuffer = NULL; |
bsalomon@google.com | 205d460 | 2011-04-25 12:43:45 +0000 | [diff] [blame] | 176 | |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 177 | delete fDrawBufferVBAllocPool; |
| 178 | fDrawBufferVBAllocPool = NULL; |
bsalomon@google.com | 205d460 | 2011-04-25 12:43:45 +0000 | [diff] [blame] | 179 | |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 180 | delete fDrawBufferIBAllocPool; |
| 181 | fDrawBufferIBAllocPool = NULL; |
| 182 | |
robertphillips@google.com | f6747b0 | 2012-06-12 00:32:28 +0000 | [diff] [blame] | 183 | fAARectRenderer->reset(); |
commit-bot@chromium.org | ef284a8 | 2013-07-11 22:29:29 +0000 | [diff] [blame] | 184 | fOvalRenderer->reset(); |
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 | fFontCache->freeAll(); |
robertphillips@google.com | e930a07 | 2014-04-03 00:34:27 +0000 | [diff] [blame] | 187 | fLayerCache->freeAll(); |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 188 | } |
| 189 | |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 190 | void GrContext::resetContext(uint32_t state) { |
| 191 | fGpu->markContextDirty(state); |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | void GrContext::freeGpuResources() { |
| 195 | this->flush(); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 196 | |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 197 | if (fDrawBuffer) { |
bsalomon | c8dc1f7 | 2014-08-21 13:02:13 -0700 | [diff] [blame] | 198 | fDrawBuffer->purgeResources(); |
| 199 | } |
robertphillips@google.com | ff17584 | 2012-05-14 19:31:39 +0000 | [diff] [blame] | 200 | |
robertphillips@google.com | f6747b0 | 2012-06-12 00:32:28 +0000 | [diff] [blame] | 201 | fAARectRenderer->reset(); |
commit-bot@chromium.org | ef284a8 | 2013-07-11 22:29:29 +0000 | [diff] [blame] | 202 | fOvalRenderer->reset(); |
robertphillips@google.com | f6747b0 | 2012-06-12 00:32:28 +0000 | [diff] [blame] | 203 | |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 204 | fFontCache->freeAll(); |
robertphillips@google.com | e930a07 | 2014-04-03 00:34:27 +0000 | [diff] [blame] | 205 | fLayerCache->freeAll(); |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 206 | // a path renderer may be holding onto resources |
commit-bot@chromium.org | a4de8c2 | 2013-09-09 13:38:37 +0000 | [diff] [blame] | 207 | SkSafeSetNull(fPathRendererChain); |
| 208 | SkSafeSetNull(fSoftwarePathRenderer); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 209 | } |
| 210 | |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 211 | void GrContext::getResourceCacheUsage(int* resourceCount, size_t* resourceBytes) const { |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 212 | if (resourceCount) { |
bsalomon | dace19e | 2014-11-17 07:34:06 -0800 | [diff] [blame] | 213 | *resourceCount = fResourceCache2->getBudgetedResourceCount(); |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 214 | } |
| 215 | if (resourceBytes) { |
bsalomon | dace19e | 2014-11-17 07:34:06 -0800 | [diff] [blame] | 216 | *resourceBytes = fResourceCache2->getBudgetedResourceBytes(); |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 217 | } |
commit-bot@chromium.org | d8a57af | 2014-03-19 21:19:16 +0000 | [diff] [blame] | 218 | } |
| 219 | |
kkinnunen | c6cb56f | 2014-06-24 00:12:27 -0700 | [diff] [blame] | 220 | GrTextContext* GrContext::createTextContext(GrRenderTarget* renderTarget, |
| 221 | const SkDeviceProperties& |
| 222 | leakyProperties, |
| 223 | bool enableDistanceFieldFonts) { |
jvanverth | 8c27a18 | 2014-10-14 08:45:50 -0700 | [diff] [blame] | 224 | if (fGpu->caps()->pathRenderingSupport() && renderTarget->getStencilBuffer() && |
| 225 | renderTarget->isMultisampled()) { |
| 226 | return GrStencilAndCoverTextContext::Create(this, leakyProperties); |
| 227 | } |
| 228 | |
| 229 | return GrDistanceFieldTextContext::Create(this, leakyProperties, enableDistanceFieldFonts); |
kkinnunen | c6cb56f | 2014-06-24 00:12:27 -0700 | [diff] [blame] | 230 | } |
| 231 | |
bsalomon@google.com | fea37b5 | 2011-04-25 15:51:06 +0000 | [diff] [blame] | 232 | //////////////////////////////////////////////////////////////////////////////// |
| 233 | |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 234 | GrTexture* GrContext::findAndRefTexture(const GrSurfaceDesc& desc, |
bsalomon@google.com | 95ed55a | 2013-01-24 14:46:47 +0000 | [diff] [blame] | 235 | const GrCacheID& cacheID, |
| 236 | const GrTextureParams* params) { |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame] | 237 | GrResourceKey resourceKey = GrTexturePriv::ComputeKey(fGpu, params, desc, cacheID); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 238 | |
| 239 | GrGpuResource* resource = this->findAndRefCachedResource(resourceKey); |
bsalomon | 37dd331 | 2014-11-03 08:47:23 -0800 | [diff] [blame] | 240 | if (resource) { |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 241 | SkASSERT(static_cast<GrSurface*>(resource)->asTexture()); |
bsalomon | 37dd331 | 2014-11-03 08:47:23 -0800 | [diff] [blame] | 242 | return static_cast<GrSurface*>(resource)->asTexture(); |
bsalomon | 37dd331 | 2014-11-03 08:47:23 -0800 | [diff] [blame] | 243 | } |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 244 | return NULL; |
bsalomon@google.com | 558a75b | 2011-08-08 17:01:14 +0000 | [diff] [blame] | 245 | } |
| 246 | |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 247 | bool GrContext::isTextureInCache(const GrSurfaceDesc& desc, |
bsalomon@google.com | 0797c2c | 2012-12-20 15:13:01 +0000 | [diff] [blame] | 248 | const GrCacheID& cacheID, |
bsalomon@google.com | b867099 | 2012-07-25 21:27:09 +0000 | [diff] [blame] | 249 | const GrTextureParams* params) const { |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame] | 250 | GrResourceKey resourceKey = GrTexturePriv::ComputeKey(fGpu, params, desc, cacheID); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 251 | return fResourceCache2->hasContentKey(resourceKey); |
bsalomon@google.com | fb30951 | 2011-11-30 14:13:48 +0000 | [diff] [blame] | 252 | } |
| 253 | |
commit-bot@chromium.org | b0ce4b6 | 2014-05-16 17:22:51 +0000 | [diff] [blame] | 254 | static void stretch_image(void* dst, |
| 255 | int dstW, |
| 256 | int dstH, |
commit-bot@chromium.org | f9bd04f | 2014-05-29 19:26:48 +0000 | [diff] [blame] | 257 | const void* src, |
commit-bot@chromium.org | b0ce4b6 | 2014-05-16 17:22:51 +0000 | [diff] [blame] | 258 | int srcW, |
| 259 | int srcH, |
| 260 | size_t bpp) { |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 261 | SkFixed dx = (srcW << 16) / dstW; |
| 262 | SkFixed dy = (srcH << 16) / dstH; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 263 | |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 264 | SkFixed y = dy >> 1; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 265 | |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 266 | size_t dstXLimit = dstW*bpp; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 267 | for (int j = 0; j < dstH; ++j) { |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 268 | SkFixed x = dx >> 1; |
commit-bot@chromium.org | f9bd04f | 2014-05-29 19:26:48 +0000 | [diff] [blame] | 269 | const uint8_t* srcRow = reinterpret_cast<const uint8_t *>(src) + (y>>16)*srcW*bpp; |
| 270 | uint8_t* dstRow = reinterpret_cast<uint8_t *>(dst) + j*dstW*bpp; |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 271 | for (size_t i = 0; i < dstXLimit; i += bpp) { |
commit-bot@chromium.org | f9bd04f | 2014-05-29 19:26:48 +0000 | [diff] [blame] | 272 | memcpy(dstRow + i, srcRow + (x>>16)*bpp, bpp); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 273 | x += dx; |
| 274 | } |
| 275 | y += dy; |
| 276 | } |
| 277 | } |
| 278 | |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 279 | // The desired texture is NPOT and tiled but that isn't supported by |
robertphillips@google.com | 3319f33 | 2012-08-13 18:00:36 +0000 | [diff] [blame] | 280 | // the current hardware. Resize the texture to be a POT |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 281 | GrTexture* GrContext::createResizedTexture(const GrSurfaceDesc& desc, |
bsalomon@google.com | 0797c2c | 2012-12-20 15:13:01 +0000 | [diff] [blame] | 282 | const GrCacheID& cacheID, |
commit-bot@chromium.org | f9bd04f | 2014-05-29 19:26:48 +0000 | [diff] [blame] | 283 | const void* srcData, |
robertphillips@google.com | 3319f33 | 2012-08-13 18:00:36 +0000 | [diff] [blame] | 284 | size_t rowBytes, |
humper@google.com | b86add1 | 2013-07-25 18:49:07 +0000 | [diff] [blame] | 285 | bool filter) { |
bsalomon@google.com | 95ed55a | 2013-01-24 14:46:47 +0000 | [diff] [blame] | 286 | SkAutoTUnref<GrTexture> clampedTexture(this->findAndRefTexture(desc, cacheID, NULL)); |
robertphillips@google.com | 1f47f4f | 2012-08-16 14:49:16 +0000 | [diff] [blame] | 287 | if (NULL == clampedTexture) { |
bsalomon@google.com | 95ed55a | 2013-01-24 14:46:47 +0000 | [diff] [blame] | 288 | clampedTexture.reset(this->createTexture(NULL, desc, cacheID, srcData, rowBytes)); |
robertphillips@google.com | 9fbcad0 | 2012-09-09 14:44:15 +0000 | [diff] [blame] | 289 | |
robertphillips@google.com | 1f47f4f | 2012-08-16 14:49:16 +0000 | [diff] [blame] | 290 | if (NULL == clampedTexture) { |
robertphillips@google.com | 3319f33 | 2012-08-13 18:00:36 +0000 | [diff] [blame] | 291 | return NULL; |
| 292 | } |
| 293 | } |
robertphillips@google.com | 0d25eef | 2012-09-11 21:25:51 +0000 | [diff] [blame] | 294 | |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 295 | GrSurfaceDesc rtDesc = desc; |
robertphillips@google.com | 3319f33 | 2012-08-13 18:00:36 +0000 | [diff] [blame] | 296 | rtDesc.fFlags = rtDesc.fFlags | |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 297 | kRenderTarget_GrSurfaceFlag | |
| 298 | kNoStencil_GrSurfaceFlag; |
commit-bot@chromium.org | 5898dce | 2013-09-18 18:52:16 +0000 | [diff] [blame] | 299 | rtDesc.fWidth = GrNextPow2(desc.fWidth); |
| 300 | rtDesc.fHeight = GrNextPow2(desc.fHeight); |
robertphillips@google.com | 3319f33 | 2012-08-13 18:00:36 +0000 | [diff] [blame] | 301 | |
| 302 | GrTexture* texture = fGpu->createTexture(rtDesc, NULL, 0); |
| 303 | |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 304 | if (texture) { |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 305 | GrDrawState drawState; |
| 306 | drawState.setRenderTarget(texture->asRenderTarget()); |
robertphillips@google.com | 3319f33 | 2012-08-13 18:00:36 +0000 | [diff] [blame] | 307 | |
| 308 | // if filtering is not desired then we want to ensure all |
| 309 | // texels in the resampled image are copies of texels from |
| 310 | // the original. |
joshualitt | 5c55fef | 2014-10-31 14:04:35 -0700 | [diff] [blame] | 311 | GrTextureParams params(SkShader::kClamp_TileMode, |
| 312 | filter ? GrTextureParams::kBilerp_FilterMode : |
| 313 | GrTextureParams::kNone_FilterMode); |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 314 | drawState.addColorTextureProcessor(clampedTexture, SkMatrix::I(), params); |
robertphillips@google.com | 3319f33 | 2012-08-13 18:00:36 +0000 | [diff] [blame] | 315 | |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 316 | uint32_t flags = GrDefaultGeoProcFactory::kPosition_GPType | |
| 317 | GrDefaultGeoProcFactory::kLocalCoord_GPType; |
| 318 | const GrGeometryProcessor* gp = GrDefaultGeoProcFactory::Create(flags); |
| 319 | drawState.setGeometryProcessor(gp)->unref(); |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 320 | |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 321 | GrDrawTarget::AutoReleaseGeometry arg(fDrawBuffer, 4, gp->getVertexStride(), 0); |
| 322 | SkASSERT(gp->getVertexStride() == 2 * sizeof(SkPoint)); |
robertphillips@google.com | 3319f33 | 2012-08-13 18:00:36 +0000 | [diff] [blame] | 323 | |
| 324 | if (arg.succeeded()) { |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 325 | SkPoint* verts = (SkPoint*) arg.vertices(); |
| 326 | verts[0].setIRectFan(0, 0, texture->width(), texture->height(), 2 * sizeof(SkPoint)); |
| 327 | verts[1].setIRectFan(0, 0, 1, 1, 2 * sizeof(SkPoint)); |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 328 | fDrawBuffer->drawNonIndexed(&drawState, kTriangleFan_GrPrimitiveType, 0, 4); |
robertphillips@google.com | 3319f33 | 2012-08-13 18:00:36 +0000 | [diff] [blame] | 329 | } |
robertphillips@google.com | 3319f33 | 2012-08-13 18:00:36 +0000 | [diff] [blame] | 330 | } else { |
| 331 | // TODO: Our CPU stretch doesn't filter. But we create separate |
bsalomon@google.com | 08283af | 2012-10-26 13:01:20 +0000 | [diff] [blame] | 332 | // stretched textures when the texture params is either filtered or |
robertphillips@google.com | 3319f33 | 2012-08-13 18:00:36 +0000 | [diff] [blame] | 333 | // not. Either implement filtered stretch blit on CPU or just create |
| 334 | // one when FBO case fails. |
| 335 | |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 336 | rtDesc.fFlags = kNone_GrSurfaceFlags; |
robertphillips@google.com | 3319f33 | 2012-08-13 18:00:36 +0000 | [diff] [blame] | 337 | // no longer need to clamp at min RT size. |
| 338 | rtDesc.fWidth = GrNextPow2(desc.fWidth); |
| 339 | rtDesc.fHeight = GrNextPow2(desc.fHeight); |
commit-bot@chromium.org | 6e7ddaa | 2014-05-30 13:55:58 +0000 | [diff] [blame] | 340 | |
| 341 | // We shouldn't be resizing a compressed texture. |
| 342 | SkASSERT(!GrPixelConfigIsCompressed(desc.fConfig)); |
| 343 | |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 344 | size_t bpp = GrBytesPerPixel(desc.fConfig); |
george | b62508b | 2014-08-12 18:00:47 -0700 | [diff] [blame] | 345 | GrAutoMalloc<128*128*4> stretchedPixels(bpp * rtDesc.fWidth * rtDesc.fHeight); |
commit-bot@chromium.org | b0ce4b6 | 2014-05-16 17:22:51 +0000 | [diff] [blame] | 346 | stretch_image(stretchedPixels.get(), rtDesc.fWidth, rtDesc.fHeight, |
| 347 | srcData, desc.fWidth, desc.fHeight, bpp); |
robertphillips@google.com | 3319f33 | 2012-08-13 18:00:36 +0000 | [diff] [blame] | 348 | |
| 349 | size_t stretchedRowBytes = rtDesc.fWidth * bpp; |
| 350 | |
commit-bot@chromium.org | b0ce4b6 | 2014-05-16 17:22:51 +0000 | [diff] [blame] | 351 | texture = fGpu->createTexture(rtDesc, stretchedPixels.get(), stretchedRowBytes); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 352 | SkASSERT(texture); |
robertphillips@google.com | 3319f33 | 2012-08-13 18:00:36 +0000 | [diff] [blame] | 353 | } |
robertphillips@google.com | 3319f33 | 2012-08-13 18:00:36 +0000 | [diff] [blame] | 354 | |
| 355 | return texture; |
| 356 | } |
| 357 | |
bsalomon@google.com | 95ed55a | 2013-01-24 14:46:47 +0000 | [diff] [blame] | 358 | GrTexture* GrContext::createTexture(const GrTextureParams* params, |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 359 | const GrSurfaceDesc& desc, |
bsalomon@google.com | 95ed55a | 2013-01-24 14:46:47 +0000 | [diff] [blame] | 360 | const GrCacheID& cacheID, |
commit-bot@chromium.org | f9bd04f | 2014-05-29 19:26:48 +0000 | [diff] [blame] | 361 | const void* srcData, |
commit-bot@chromium.org | 50a3043 | 2013-10-24 17:44:27 +0000 | [diff] [blame] | 362 | size_t rowBytes, |
| 363 | GrResourceKey* cacheKey) { |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame] | 364 | GrResourceKey resourceKey = GrTexturePriv::ComputeKey(fGpu, params, desc, cacheID); |
robertphillips@google.com | a1e5795 | 2012-06-04 20:05:28 +0000 | [diff] [blame] | 365 | |
bsalomon@google.com | 95ed55a | 2013-01-24 14:46:47 +0000 | [diff] [blame] | 366 | GrTexture* texture; |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame] | 367 | if (GrTexturePriv::NeedsResizing(resourceKey)) { |
krajcevski | 9c0e629 | 2014-06-02 07:38:14 -0700 | [diff] [blame] | 368 | // We do not know how to resize compressed textures. |
| 369 | SkASSERT(!GrPixelConfigIsCompressed(desc.fConfig)); |
| 370 | |
bsalomon@google.com | 95ed55a | 2013-01-24 14:46:47 +0000 | [diff] [blame] | 371 | texture = this->createResizedTexture(desc, cacheID, |
| 372 | srcData, rowBytes, |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame] | 373 | GrTexturePriv::NeedsBilerp(resourceKey)); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 374 | } else { |
krajcevski | 9c0e629 | 2014-06-02 07:38:14 -0700 | [diff] [blame] | 375 | texture = fGpu->createTexture(desc, srcData, rowBytes); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 376 | } |
robertphillips@google.com | 3319f33 | 2012-08-13 18:00:36 +0000 | [diff] [blame] | 377 | |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 378 | if (texture) { |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 379 | if (texture->cacheAccess().setContentKey(resourceKey)) { |
| 380 | if (cacheKey) { |
| 381 | *cacheKey = resourceKey; |
| 382 | } |
| 383 | } else { |
| 384 | texture->unref(); |
| 385 | texture = NULL; |
commit-bot@chromium.org | 50a3043 | 2013-10-24 17:44:27 +0000 | [diff] [blame] | 386 | } |
robertphillips@google.com | 3319f33 | 2012-08-13 18:00:36 +0000 | [diff] [blame] | 387 | } |
| 388 | |
robertphillips@google.com | 1f47f4f | 2012-08-16 14:49:16 +0000 | [diff] [blame] | 389 | return texture; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 390 | } |
| 391 | |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 392 | GrTexture* GrContext::refScratchTexture(const GrSurfaceDesc& inDesc, ScratchTexMatch match, |
bsalomon | e305973 | 2014-10-14 11:47:22 -0700 | [diff] [blame] | 393 | bool calledDuringFlush) { |
bsalomon | bcf0a52 | 2014-10-08 08:40:09 -0700 | [diff] [blame] | 394 | // kNoStencil has no meaning if kRT isn't set. |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 395 | SkASSERT((inDesc.fFlags & kRenderTarget_GrSurfaceFlag) || |
| 396 | !(inDesc.fFlags & kNoStencil_GrSurfaceFlag)); |
robertphillips@google.com | e4eaea2 | 2013-07-19 16:51:46 +0000 | [diff] [blame] | 397 | |
bsalomon | bcf0a52 | 2014-10-08 08:40:09 -0700 | [diff] [blame] | 398 | // Make sure caller has checked for renderability if kRT is set. |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 399 | SkASSERT(!(inDesc.fFlags & kRenderTarget_GrSurfaceFlag) || |
bsalomon | bcf0a52 | 2014-10-08 08:40:09 -0700 | [diff] [blame] | 400 | this->isConfigRenderable(inDesc.fConfig, inDesc.fSampleCnt > 0)); |
robertphillips@google.com | e4eaea2 | 2013-07-19 16:51:46 +0000 | [diff] [blame] | 401 | |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 402 | SkTCopyOnFirstWrite<GrSurfaceDesc> desc(inDesc); |
robertphillips@google.com | e4eaea2 | 2013-07-19 16:51:46 +0000 | [diff] [blame] | 403 | |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 404 | if (fGpu->caps()->reuseScratchTextures() || (desc->fFlags & kRenderTarget_GrSurfaceFlag)) { |
| 405 | GrSurfaceFlags origFlags = desc->fFlags; |
bsalomon | bcf0a52 | 2014-10-08 08:40:09 -0700 | [diff] [blame] | 406 | if (kApprox_ScratchTexMatch == match) { |
| 407 | // bin by pow2 with a reasonable min |
| 408 | static const int MIN_SIZE = 16; |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 409 | GrSurfaceDesc* wdesc = desc.writable(); |
bsalomon | bcf0a52 | 2014-10-08 08:40:09 -0700 | [diff] [blame] | 410 | wdesc->fWidth = SkTMax(MIN_SIZE, GrNextPow2(desc->fWidth)); |
| 411 | wdesc->fHeight = SkTMax(MIN_SIZE, GrNextPow2(desc->fHeight)); |
bsalomon@google.com | b5b3168 | 2011-06-16 18:05:35 +0000 | [diff] [blame] | 412 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 413 | |
bsalomon | bcf0a52 | 2014-10-08 08:40:09 -0700 | [diff] [blame] | 414 | do { |
| 415 | GrResourceKey key = GrTexturePriv::ComputeScratchKey(*desc); |
bsalomon | 000f829 | 2014-10-15 19:04:14 -0700 | [diff] [blame] | 416 | uint32_t scratchFlags = 0; |
| 417 | if (calledDuringFlush) { |
| 418 | scratchFlags = GrResourceCache2::kRequireNoPendingIO_ScratchFlag; |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 419 | } else if (!(desc->fFlags & kRenderTarget_GrSurfaceFlag)) { |
bsalomon | 000f829 | 2014-10-15 19:04:14 -0700 | [diff] [blame] | 420 | // If it is not a render target then it will most likely be populated by |
| 421 | // writePixels() which will trigger a flush if the texture has pending IO. |
| 422 | scratchFlags = GrResourceCache2::kPreferNoPendingIO_ScratchFlag; |
| 423 | } |
| 424 | GrGpuResource* resource = fResourceCache2->findAndRefScratchResource(key, scratchFlags); |
bsalomon | bcf0a52 | 2014-10-08 08:40:09 -0700 | [diff] [blame] | 425 | if (resource) { |
bsalomon | 37dd331 | 2014-11-03 08:47:23 -0800 | [diff] [blame] | 426 | return static_cast<GrSurface*>(resource)->asTexture(); |
bsalomon | bcf0a52 | 2014-10-08 08:40:09 -0700 | [diff] [blame] | 427 | } |
bsalomon@google.com | b5b3168 | 2011-06-16 18:05:35 +0000 | [diff] [blame] | 428 | |
bsalomon | bcf0a52 | 2014-10-08 08:40:09 -0700 | [diff] [blame] | 429 | if (kExact_ScratchTexMatch == match) { |
| 430 | break; |
| 431 | } |
| 432 | // We had a cache miss and we are in approx mode, relax the fit of the flags. |
| 433 | |
| 434 | // We no longer try to reuse textures that were previously used as render targets in |
| 435 | // situations where no RT is needed; doing otherwise can confuse the video driver and |
| 436 | // cause significant performance problems in some cases. |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 437 | if (desc->fFlags & kNoStencil_GrSurfaceFlag) { |
| 438 | desc.writable()->fFlags = desc->fFlags & ~kNoStencil_GrSurfaceFlag; |
bsalomon | bcf0a52 | 2014-10-08 08:40:09 -0700 | [diff] [blame] | 439 | } else { |
| 440 | break; |
| 441 | } |
| 442 | |
| 443 | } while (true); |
| 444 | |
| 445 | desc.writable()->fFlags = origFlags; |
bsalomon@google.com | b5b3168 | 2011-06-16 18:05:35 +0000 | [diff] [blame] | 446 | } |
| 447 | |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 448 | GrTexture* texture = fGpu->createTexture(*desc, NULL, 0); |
bsalomon | bcf0a52 | 2014-10-08 08:40:09 -0700 | [diff] [blame] | 449 | SkASSERT(NULL == texture || |
bsalomon | 453cf40 | 2014-11-11 14:15:57 -0800 | [diff] [blame] | 450 | texture->cacheAccess().getScratchKey() == GrTexturePriv::ComputeScratchKey(*desc)); |
bsalomon | bcf0a52 | 2014-10-08 08:40:09 -0700 | [diff] [blame] | 451 | return texture; |
Brian Salomon | 9323b8b | 2014-10-07 15:07:38 -0400 | [diff] [blame] | 452 | } |
| 453 | |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 454 | void GrContext::OverBudgetCB(void* data) { |
bsalomon | 66a450f | 2014-11-13 13:19:10 -0800 | [diff] [blame] | 455 | SkASSERT(data); |
bsalomon | f21dab9 | 2014-11-13 13:33:28 -0800 | [diff] [blame] | 456 | |
bsalomon | 66a450f | 2014-11-13 13:19:10 -0800 | [diff] [blame] | 457 | GrContext* context = reinterpret_cast<GrContext*>(data); |
bsalomon | f21dab9 | 2014-11-13 13:33:28 -0800 | [diff] [blame] | 458 | |
| 459 | // Flush the InOrderDrawBuffer to possibly free up some textures |
| 460 | context->fFlushToReduceCacheSize = true; |
commit-bot@chromium.org | cae27fe | 2013-07-10 10:14:35 +0000 | [diff] [blame] | 461 | } |
| 462 | |
| 463 | |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 464 | GrTexture* GrContext::createUncachedTexture(const GrSurfaceDesc& descIn, |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 465 | void* srcData, |
| 466 | size_t rowBytes) { |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 467 | GrSurfaceDesc descCopy = descIn; |
bsalomon | 84c8e62 | 2014-11-17 09:33:27 -0800 | [diff] [blame] | 468 | GrTexture* texture = fGpu->createTexture(descCopy, srcData, rowBytes); |
| 469 | if (texture) { |
| 470 | // TODO: It'd be nice to be able to do this before creation so we don't boot something |
| 471 | // out of the cache. We could temporarily boost the cache budget. |
| 472 | texture->cacheAccess().setBudgeted(false); |
| 473 | } |
| 474 | return texture; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 475 | } |
| 476 | |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 477 | void GrContext::getResourceCacheLimits(int* maxTextures, size_t* maxTextureBytes) const { |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 478 | if (maxTextures) { |
| 479 | *maxTextures = fResourceCache2->getMaxResourceCount(); |
| 480 | } |
| 481 | if (maxTextureBytes) { |
| 482 | *maxTextureBytes = fResourceCache2->getMaxResourceBytes(); |
| 483 | } |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 484 | } |
| 485 | |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 486 | void GrContext::setResourceCacheLimits(int maxTextures, size_t maxTextureBytes) { |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 487 | fResourceCache2->setLimits(maxTextures, maxTextureBytes); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 488 | } |
| 489 | |
bsalomon@google.com | 9195836 | 2011-06-13 17:58:13 +0000 | [diff] [blame] | 490 | int GrContext::getMaxTextureSize() const { |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 491 | return SkTMin(fGpu->caps()->maxTextureSize(), fMaxTextureSizeOverride); |
bsalomon@google.com | 9195836 | 2011-06-13 17:58:13 +0000 | [diff] [blame] | 492 | } |
| 493 | |
| 494 | int GrContext::getMaxRenderTargetSize() const { |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 495 | return fGpu->caps()->maxRenderTargetSize(); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 496 | } |
| 497 | |
bsalomon@google.com | 8a70eef | 2013-03-19 13:58:55 +0000 | [diff] [blame] | 498 | int GrContext::getMaxSampleCount() const { |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 499 | return fGpu->caps()->maxSampleCount(); |
bsalomon@google.com | 8a70eef | 2013-03-19 13:58:55 +0000 | [diff] [blame] | 500 | } |
| 501 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 502 | /////////////////////////////////////////////////////////////////////////////// |
| 503 | |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame] | 504 | GrTexture* GrContext::wrapBackendTexture(const GrBackendTextureDesc& desc) { |
| 505 | return fGpu->wrapBackendTexture(desc); |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 506 | } |
| 507 | |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame] | 508 | GrRenderTarget* GrContext::wrapBackendRenderTarget(const GrBackendRenderTargetDesc& desc) { |
| 509 | return fGpu->wrapBackendRenderTarget(desc); |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 510 | } |
| 511 | |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 512 | /////////////////////////////////////////////////////////////////////////////// |
| 513 | |
bsalomon@google.com | b867099 | 2012-07-25 21:27:09 +0000 | [diff] [blame] | 514 | bool GrContext::supportsIndex8PixelConfig(const GrTextureParams* params, |
bsalomon@google.com | 1f221a7 | 2011-08-23 20:54:07 +0000 | [diff] [blame] | 515 | int width, int height) const { |
bsalomon@google.com | c26d94f | 2013-03-25 18:19:00 +0000 | [diff] [blame] | 516 | const GrDrawTargetCaps* caps = fGpu->caps(); |
commit-bot@chromium.org | 6e7ddaa | 2014-05-30 13:55:58 +0000 | [diff] [blame] | 517 | if (!caps->isConfigTexturable(kIndex_8_GrPixelConfig)) { |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 518 | return false; |
| 519 | } |
| 520 | |
tfarina | f9dae78 | 2014-06-06 06:35:28 -0700 | [diff] [blame] | 521 | bool isPow2 = SkIsPow2(width) && SkIsPow2(height); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 522 | |
| 523 | if (!isPow2) { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 524 | bool tiled = params && params->isTiled(); |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 525 | if (tiled && !caps->npotTextureTileSupport()) { |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 526 | return false; |
| 527 | } |
| 528 | } |
| 529 | return true; |
| 530 | } |
| 531 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 532 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 533 | //////////////////////////////////////////////////////////////////////////////// |
| 534 | |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 535 | void GrContext::clear(const SkIRect* rect, |
bsalomon@google.com | 07ea2db | 2012-08-17 14:06:49 +0000 | [diff] [blame] | 536 | const GrColor color, |
robertphillips@google.com | 56ce48a | 2013-10-31 21:44:25 +0000 | [diff] [blame] | 537 | bool canIgnoreRect, |
bsalomon | 41ebbdd | 2014-08-04 08:31:39 -0700 | [diff] [blame] | 538 | GrRenderTarget* renderTarget) { |
| 539 | ASSERT_OWNED_RESOURCE(renderTarget); |
bsalomon | 89c6298 | 2014-11-03 12:08:42 -0800 | [diff] [blame] | 540 | SkASSERT(renderTarget); |
| 541 | |
bsalomon | f21dab9 | 2014-11-13 13:33:28 -0800 | [diff] [blame] | 542 | AutoCheckFlush acf(this); |
egdaniel | d78a168 | 2014-07-09 10:41:26 -0700 | [diff] [blame] | 543 | GR_CREATE_TRACE_MARKER_CONTEXT("GrContext::clear", this); |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 544 | GrDrawTarget* target = this->prepareToDraw(NULL, NULL, &acf); |
bsalomon | 41ebbdd | 2014-08-04 08:31:39 -0700 | [diff] [blame] | 545 | if (NULL == target) { |
| 546 | return; |
| 547 | } |
| 548 | target->clear(rect, color, canIgnoreRect, renderTarget); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 549 | } |
| 550 | |
bsalomon@google.com | 5dc26b9 | 2012-10-11 19:32:32 +0000 | [diff] [blame] | 551 | void GrContext::drawPaint(const GrPaint& origPaint) { |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 552 | // set rect to be big enough to fill the space, but not super-huge, so we |
| 553 | // don't overflow fixed-point implementations |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 554 | SkRect r; |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 555 | r.setLTRB(0, 0, |
bsalomon@google.com | 8171288 | 2012-11-01 17:12:34 +0000 | [diff] [blame] | 556 | SkIntToScalar(getRenderTarget()->width()), |
| 557 | SkIntToScalar(getRenderTarget()->height())); |
bsalomon@google.com | b9086a0 | 2012-11-01 18:02:54 +0000 | [diff] [blame] | 558 | SkMatrix inverse; |
bsalomon@google.com | 5dc26b9 | 2012-10-11 19:32:32 +0000 | [diff] [blame] | 559 | SkTCopyOnFirstWrite<GrPaint> paint(origPaint); |
robertphillips@google.com | fea85ac | 2012-07-11 18:53:23 +0000 | [diff] [blame] | 560 | AutoMatrix am; |
egdaniel | d78a168 | 2014-07-09 10:41:26 -0700 | [diff] [blame] | 561 | GR_CREATE_TRACE_MARKER_CONTEXT("GrContext::drawPaint", this); |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 562 | |
bsalomon@google.com | 4f83be8 | 2011-09-12 13:52:51 +0000 | [diff] [blame] | 563 | // We attempt to map r by the inverse matrix and draw that. mapRect will |
| 564 | // map the four corners and bound them with a new rect. This will not |
| 565 | // produce a correct result for some perspective matrices. |
bsalomon@google.com | 8c2fe99 | 2011-09-13 15:27:18 +0000 | [diff] [blame] | 566 | if (!this->getMatrix().hasPerspective()) { |
commit-bot@chromium.org | bb6a317 | 2013-05-28 17:25:49 +0000 | [diff] [blame] | 567 | if (!fViewMatrix.invert(&inverse)) { |
tfarina | 38406c8 | 2014-10-31 07:11:12 -0700 | [diff] [blame] | 568 | SkDebugf("Could not invert matrix\n"); |
bsalomon@google.com | 8c2fe99 | 2011-09-13 15:27:18 +0000 | [diff] [blame] | 569 | return; |
| 570 | } |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 571 | inverse.mapRect(&r); |
| 572 | } else { |
bsalomon@google.com | 3cbaa2d | 2012-10-12 14:51:52 +0000 | [diff] [blame] | 573 | if (!am.setIdentity(this, paint.writable())) { |
tfarina | 38406c8 | 2014-10-31 07:11:12 -0700 | [diff] [blame] | 574 | SkDebugf("Could not invert matrix\n"); |
bsalomon@google.com | 3cbaa2d | 2012-10-12 14:51:52 +0000 | [diff] [blame] | 575 | return; |
bsalomon@google.com | 8c2fe99 | 2011-09-13 15:27:18 +0000 | [diff] [blame] | 576 | } |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 577 | } |
bsalomon@google.com | 4f83be8 | 2011-09-12 13:52:51 +0000 | [diff] [blame] | 578 | // by definition this fills the entire clip, no need for AA |
bsalomon@google.com | 5dc26b9 | 2012-10-11 19:32:32 +0000 | [diff] [blame] | 579 | if (paint->isAntiAlias()) { |
| 580 | paint.writable()->setAntiAlias(false); |
bsalomon@google.com | 4f83be8 | 2011-09-12 13:52:51 +0000 | [diff] [blame] | 581 | } |
bsalomon@google.com | 5dc26b9 | 2012-10-11 19:32:32 +0000 | [diff] [blame] | 582 | this->drawRect(*paint, r); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 583 | } |
| 584 | |
commit-bot@chromium.org | 03e3e89 | 2013-10-02 18:19:17 +0000 | [diff] [blame] | 585 | #ifdef SK_DEVELOPER |
| 586 | void GrContext::dumpFontCache() const { |
| 587 | fFontCache->dump(); |
| 588 | } |
| 589 | #endif |
| 590 | |
bsalomon@google.com | 205d460 | 2011-04-25 12:43:45 +0000 | [diff] [blame] | 591 | //////////////////////////////////////////////////////////////////////////////// |
| 592 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 593 | /* create a triangle strip that strokes the specified triangle. There are 8 |
| 594 | unique vertices, but we repreat the last 2 to close up. Alternatively we |
| 595 | could use an indices array, and then only send 8 verts, but not sure that |
| 596 | would be faster. |
| 597 | */ |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 598 | static void setStrokeRectStrip(SkPoint verts[10], SkRect rect, |
bsalomon@google.com | 8171288 | 2012-11-01 17:12:34 +0000 | [diff] [blame] | 599 | SkScalar width) { |
| 600 | const SkScalar rad = SkScalarHalf(width); |
bsalomon@google.com | 205d460 | 2011-04-25 12:43:45 +0000 | [diff] [blame] | 601 | rect.sort(); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 602 | |
| 603 | verts[0].set(rect.fLeft + rad, rect.fTop + rad); |
| 604 | verts[1].set(rect.fLeft - rad, rect.fTop - rad); |
| 605 | verts[2].set(rect.fRight - rad, rect.fTop + rad); |
| 606 | verts[3].set(rect.fRight + rad, rect.fTop - rad); |
| 607 | verts[4].set(rect.fRight - rad, rect.fBottom - rad); |
| 608 | verts[5].set(rect.fRight + rad, rect.fBottom + rad); |
| 609 | verts[6].set(rect.fLeft + rad, rect.fBottom - rad); |
| 610 | verts[7].set(rect.fLeft - rad, rect.fBottom + rad); |
| 611 | verts[8] = verts[0]; |
| 612 | verts[9] = verts[1]; |
| 613 | } |
| 614 | |
bsalomon | c30aaa0 | 2014-08-13 07:15:29 -0700 | [diff] [blame] | 615 | static inline bool is_irect(const SkRect& r) { |
tfarina | 38406c8 | 2014-10-31 07:11:12 -0700 | [diff] [blame] | 616 | return SkScalarIsInt(r.fLeft) && SkScalarIsInt(r.fTop) && |
| 617 | SkScalarIsInt(r.fRight) && SkScalarIsInt(r.fBottom); |
bsalomon | c30aaa0 | 2014-08-13 07:15:29 -0700 | [diff] [blame] | 618 | } |
| 619 | |
bsalomon@google.com | 205d460 | 2011-04-25 12:43:45 +0000 | [diff] [blame] | 620 | static bool apply_aa_to_rect(GrDrawTarget* target, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 621 | GrDrawState* ds, |
| 622 | SkRect* devBoundRect, |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 623 | const SkRect& rect, |
robertphillips@google.com | df3695e | 2013-04-09 14:01:44 +0000 | [diff] [blame] | 624 | SkScalar strokeWidth, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 625 | const SkMatrix& combinedMatrix) { |
| 626 | if (!ds->canTweakAlphaForCoverage() && !ds->couldApplyCoverage(*target->caps())) { |
commit-bot@chromium.org | 515dcd3 | 2013-08-28 14:17:03 +0000 | [diff] [blame] | 627 | #ifdef SK_DEBUG |
tfarina | 38406c8 | 2014-10-31 07:11:12 -0700 | [diff] [blame] | 628 | //SkDebugf("Turning off AA to correctly apply blend.\n"); |
bsalomon@google.com | 1983f39 | 2011-10-10 15:17:58 +0000 | [diff] [blame] | 629 | #endif |
bsalomon | 9c0822a | 2014-08-11 11:07:48 -0700 | [diff] [blame] | 630 | return false; |
bsalomon@google.com | 205d460 | 2011-04-25 12:43:45 +0000 | [diff] [blame] | 631 | } |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 632 | |
| 633 | if (ds->getRenderTarget()->isMultisampled()) { |
bsalomon@google.com | 205d460 | 2011-04-25 12:43:45 +0000 | [diff] [blame] | 634 | return false; |
| 635 | } |
| 636 | |
robertphillips@google.com | 4b140b5 | 2013-05-02 17:13:13 +0000 | [diff] [blame] | 637 | #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] | 638 | if (strokeWidth >= 0) { |
| 639 | #endif |
commit-bot@chromium.org | 24ab3b0 | 2013-08-14 21:56:37 +0000 | [diff] [blame] | 640 | if (!combinedMatrix.preservesAxisAlignment()) { |
robertphillips@google.com | df3695e | 2013-04-09 14:01:44 +0000 | [diff] [blame] | 641 | return false; |
| 642 | } |
bsalomon@google.com | 205d460 | 2011-04-25 12:43:45 +0000 | [diff] [blame] | 643 | |
robertphillips@google.com | 4b140b5 | 2013-05-02 17:13:13 +0000 | [diff] [blame] | 644 | #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] | 645 | } else { |
commit-bot@chromium.org | 24ab3b0 | 2013-08-14 21:56:37 +0000 | [diff] [blame] | 646 | if (!combinedMatrix.preservesRightAngles()) { |
robertphillips@google.com | df3695e | 2013-04-09 14:01:44 +0000 | [diff] [blame] | 647 | return false; |
| 648 | } |
bsalomon@google.com | 205d460 | 2011-04-25 12:43:45 +0000 | [diff] [blame] | 649 | } |
robertphillips@google.com | df3695e | 2013-04-09 14:01:44 +0000 | [diff] [blame] | 650 | #endif |
bsalomon@google.com | 205d460 | 2011-04-25 12:43:45 +0000 | [diff] [blame] | 651 | |
commit-bot@chromium.org | 24ab3b0 | 2013-08-14 21:56:37 +0000 | [diff] [blame] | 652 | combinedMatrix.mapRect(devBoundRect, rect); |
derekf | e638d1c | 2014-12-02 13:51:29 -0800 | [diff] [blame] | 653 | if (!combinedMatrix.rectStaysRect()) { |
| 654 | return true; |
| 655 | } |
| 656 | |
bsalomon | c30aaa0 | 2014-08-13 07:15:29 -0700 | [diff] [blame] | 657 | if (strokeWidth < 0) { |
| 658 | return !is_irect(*devBoundRect); |
| 659 | } |
robertphillips@google.com | 28ac96e | 2013-05-13 13:38:35 +0000 | [diff] [blame] | 660 | |
bsalomon | 9c0822a | 2014-08-11 11:07:48 -0700 | [diff] [blame] | 661 | return true; |
bsalomon@google.com | 205d460 | 2011-04-25 12:43:45 +0000 | [diff] [blame] | 662 | } |
| 663 | |
commit-bot@chromium.org | 24ab3b0 | 2013-08-14 21:56:37 +0000 | [diff] [blame] | 664 | static inline bool rect_contains_inclusive(const SkRect& rect, const SkPoint& point) { |
| 665 | return point.fX >= rect.fLeft && point.fX <= rect.fRight && |
| 666 | point.fY >= rect.fTop && point.fY <= rect.fBottom; |
| 667 | } |
| 668 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 669 | void GrContext::drawRect(const GrPaint& paint, |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 670 | const SkRect& rect, |
bsalomon | 01c8da1 | 2014-08-04 09:21:30 -0700 | [diff] [blame] | 671 | const GrStrokeInfo* strokeInfo) { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 672 | if (strokeInfo && strokeInfo->isDashed()) { |
egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 673 | SkPath path; |
| 674 | path.addRect(rect); |
| 675 | this->drawPath(paint, path, *strokeInfo); |
| 676 | return; |
| 677 | } |
| 678 | |
bsalomon | f21dab9 | 2014-11-13 13:33:28 -0800 | [diff] [blame] | 679 | AutoCheckFlush acf(this); |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 680 | GrDrawState drawState; |
| 681 | GrDrawTarget* target = this->prepareToDraw(&drawState, &paint, &acf); |
bsalomon | 41ebbdd | 2014-08-04 08:31:39 -0700 | [diff] [blame] | 682 | if (NULL == target) { |
| 683 | return; |
| 684 | } |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 685 | |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 686 | GR_CREATE_TRACE_MARKER("GrContext::drawRect", target); |
egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 687 | SkScalar width = NULL == strokeInfo ? -1 : strokeInfo->getStrokeRec().getWidth(); |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 688 | SkMatrix matrix = drawState.getViewMatrix(); |
commit-bot@chromium.org | 24ab3b0 | 2013-08-14 21:56:37 +0000 | [diff] [blame] | 689 | |
| 690 | // Check if this is a full RT draw and can be replaced with a clear. We don't bother checking |
| 691 | // cases where the RT is fully inside a stroke. |
| 692 | if (width < 0) { |
| 693 | SkRect rtRect; |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 694 | drawState.getRenderTarget()->getBoundsRect(&rtRect); |
commit-bot@chromium.org | 24ab3b0 | 2013-08-14 21:56:37 +0000 | [diff] [blame] | 695 | SkRect clipSpaceRTRect = rtRect; |
| 696 | bool checkClip = false; |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 697 | if (this->getClip()) { |
commit-bot@chromium.org | 24ab3b0 | 2013-08-14 21:56:37 +0000 | [diff] [blame] | 698 | checkClip = true; |
| 699 | clipSpaceRTRect.offset(SkIntToScalar(this->getClip()->fOrigin.fX), |
| 700 | SkIntToScalar(this->getClip()->fOrigin.fY)); |
| 701 | } |
| 702 | // Does the clip contain the entire RT? |
| 703 | if (!checkClip || target->getClip()->fClipStack->quickContains(clipSpaceRTRect)) { |
| 704 | SkMatrix invM; |
bsalomon | 01c8da1 | 2014-08-04 09:21:30 -0700 | [diff] [blame] | 705 | if (!matrix.invert(&invM)) { |
commit-bot@chromium.org | 24ab3b0 | 2013-08-14 21:56:37 +0000 | [diff] [blame] | 706 | return; |
| 707 | } |
| 708 | // Does the rect bound the RT? |
| 709 | SkPoint srcSpaceRTQuad[4]; |
| 710 | invM.mapRectToQuad(srcSpaceRTQuad, rtRect); |
| 711 | if (rect_contains_inclusive(rect, srcSpaceRTQuad[0]) && |
| 712 | rect_contains_inclusive(rect, srcSpaceRTQuad[1]) && |
| 713 | rect_contains_inclusive(rect, srcSpaceRTQuad[2]) && |
| 714 | rect_contains_inclusive(rect, srcSpaceRTQuad[3])) { |
| 715 | // Will it blend? |
| 716 | GrColor clearColor; |
| 717 | if (paint.isOpaqueAndConstantColor(&clearColor)) { |
bsalomon | 89c6298 | 2014-11-03 12:08:42 -0800 | [diff] [blame] | 718 | target->clear(NULL, clearColor, true, fRenderTarget); |
commit-bot@chromium.org | 24ab3b0 | 2013-08-14 21:56:37 +0000 | [diff] [blame] | 719 | return; |
| 720 | } |
| 721 | } |
| 722 | } |
| 723 | } |
| 724 | |
| 725 | SkRect devBoundRect; |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 726 | bool needAA = paint.isAntiAlias() && !drawState.getRenderTarget()->isMultisampled(); |
| 727 | bool doAA = needAA && apply_aa_to_rect(target, &drawState, &devBoundRect, rect, width, matrix); |
egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 728 | |
bsalomon@google.com | 205d460 | 2011-04-25 12:43:45 +0000 | [diff] [blame] | 729 | if (doAA) { |
bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 730 | GrDrawState::AutoViewMatrixRestore avmr; |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 731 | if (!avmr.setIdentity(&drawState)) { |
bsalomon@google.com | e3d3216 | 2012-07-20 13:37:06 +0000 | [diff] [blame] | 732 | return; |
| 733 | } |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 734 | |
bsalomon@google.com | 205d460 | 2011-04-25 12:43:45 +0000 | [diff] [blame] | 735 | if (width >= 0) { |
bsalomon | 395ef05 | 2014-11-12 11:35:22 -0800 | [diff] [blame] | 736 | const SkStrokeRec& strokeRec = strokeInfo->getStrokeRec(); |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 737 | fAARectRenderer->strokeAARect(target, |
| 738 | &drawState, |
| 739 | rect, |
| 740 | matrix, |
| 741 | devBoundRect, |
| 742 | strokeRec); |
bsalomon@google.com | 205d460 | 2011-04-25 12:43:45 +0000 | [diff] [blame] | 743 | } else { |
robertphillips@google.com | df3695e | 2013-04-09 14:01:44 +0000 | [diff] [blame] | 744 | // filled AA rect |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 745 | fAARectRenderer->fillAARect(target, &drawState, rect, matrix, devBoundRect); |
bsalomon@google.com | 205d460 | 2011-04-25 12:43:45 +0000 | [diff] [blame] | 746 | } |
| 747 | return; |
| 748 | } |
| 749 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 750 | if (width >= 0) { |
| 751 | // TODO: consider making static vertex buffers for these cases. |
bsalomon@google.com | 6438695 | 2013-02-08 21:22:44 +0000 | [diff] [blame] | 752 | // Hairline could be done by just adding closing vertex to |
| 753 | // unitSquareVertexBuffer() |
bsalomon@google.com | 26c2d0a | 2011-05-17 20:15:30 +0000 | [diff] [blame] | 754 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 755 | static const int worstCaseVertCount = 10; |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 756 | const GrGeometryProcessor* gp = GrDefaultGeoProcFactory::Create(); |
| 757 | drawState.setGeometryProcessor(gp)->unref(); |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 758 | GrDrawTarget::AutoReleaseGeometry geo(target, |
| 759 | worstCaseVertCount, |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 760 | gp->getVertexStride(), |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 761 | 0); |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 762 | SkASSERT(gp->getVertexStride() == sizeof(SkPoint)); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 763 | |
| 764 | if (!geo.succeeded()) { |
tfarina | 38406c8 | 2014-10-31 07:11:12 -0700 | [diff] [blame] | 765 | SkDebugf("Failed to get space for vertices!\n"); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 766 | return; |
| 767 | } |
| 768 | |
| 769 | GrPrimitiveType primType; |
| 770 | int vertCount; |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 771 | SkPoint* vertex = geo.positions(); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 772 | |
| 773 | if (width > 0) { |
| 774 | vertCount = 10; |
bsalomon@google.com | 4705954 | 2012-06-06 20:51:20 +0000 | [diff] [blame] | 775 | primType = kTriangleStrip_GrPrimitiveType; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 776 | setStrokeRectStrip(vertex, rect, width); |
| 777 | } else { |
| 778 | // hairline |
| 779 | vertCount = 5; |
bsalomon@google.com | 4705954 | 2012-06-06 20:51:20 +0000 | [diff] [blame] | 780 | primType = kLineStrip_GrPrimitiveType; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 781 | vertex[0].set(rect.fLeft, rect.fTop); |
| 782 | vertex[1].set(rect.fRight, rect.fTop); |
| 783 | vertex[2].set(rect.fRight, rect.fBottom); |
| 784 | vertex[3].set(rect.fLeft, rect.fBottom); |
| 785 | vertex[4].set(rect.fLeft, rect.fTop); |
| 786 | } |
| 787 | |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 788 | target->drawNonIndexed(&drawState, primType, 0, vertCount); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 789 | } else { |
robertphillips@google.com | df3695e | 2013-04-09 14:01:44 +0000 | [diff] [blame] | 790 | // filled BW rect |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 791 | target->drawSimpleRect(&drawState, rect); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 792 | } |
| 793 | } |
| 794 | |
| 795 | void GrContext::drawRectToRect(const GrPaint& paint, |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 796 | const SkRect& dstRect, |
| 797 | const SkRect& localRect, |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 798 | const SkMatrix* localMatrix) { |
bsalomon | f21dab9 | 2014-11-13 13:33:28 -0800 | [diff] [blame] | 799 | AutoCheckFlush acf(this); |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 800 | GrDrawState drawState; |
| 801 | GrDrawTarget* target = this->prepareToDraw(&drawState, &paint, &acf); |
bsalomon | 41ebbdd | 2014-08-04 08:31:39 -0700 | [diff] [blame] | 802 | if (NULL == target) { |
| 803 | return; |
| 804 | } |
bsalomon@google.com | 6438695 | 2013-02-08 21:22:44 +0000 | [diff] [blame] | 805 | |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 806 | GR_CREATE_TRACE_MARKER("GrContext::drawRectToRect", target); |
| 807 | |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 808 | target->drawRect(&drawState, dstRect, &localRect, localMatrix); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 809 | } |
| 810 | |
robertphillips@google.com | 4290330 | 2013-04-20 12:26:07 +0000 | [diff] [blame] | 811 | static void set_vertex_attributes(GrDrawState* drawState, |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 812 | const SkPoint* texCoords, |
robertphillips@google.com | 4290330 | 2013-04-20 12:26:07 +0000 | [diff] [blame] | 813 | const GrColor* colors, |
| 814 | int* colorOffset, |
| 815 | int* texOffset) { |
| 816 | *texOffset = -1; |
| 817 | *colorOffset = -1; |
| 818 | |
joshualitt | 5478d42 | 2014-11-14 16:00:38 -0800 | [diff] [blame] | 819 | uint32_t flags = GrDefaultGeoProcFactory::kPosition_GPType; |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 820 | if (texCoords && colors) { |
joshualitt | 5478d42 | 2014-11-14 16:00:38 -0800 | [diff] [blame] | 821 | *colorOffset = sizeof(SkPoint); |
| 822 | *texOffset = sizeof(SkPoint) + sizeof(GrColor); |
| 823 | flags |= GrDefaultGeoProcFactory::kColor_GPType | |
| 824 | GrDefaultGeoProcFactory::kLocalCoord_GPType; |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 825 | } else if (texCoords) { |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 826 | *texOffset = sizeof(SkPoint); |
joshualitt | 5478d42 | 2014-11-14 16:00:38 -0800 | [diff] [blame] | 827 | flags |= GrDefaultGeoProcFactory::kLocalCoord_GPType; |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 828 | } else if (colors) { |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 829 | *colorOffset = sizeof(SkPoint); |
joshualitt | 5478d42 | 2014-11-14 16:00:38 -0800 | [diff] [blame] | 830 | flags |= GrDefaultGeoProcFactory::kColor_GPType; |
robertphillips@google.com | 4290330 | 2013-04-20 12:26:07 +0000 | [diff] [blame] | 831 | } |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 832 | drawState->setGeometryProcessor(GrDefaultGeoProcFactory::Create(flags))->unref(); |
robertphillips@google.com | 4290330 | 2013-04-20 12:26:07 +0000 | [diff] [blame] | 833 | } |
| 834 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 835 | void GrContext::drawVertices(const GrPaint& paint, |
| 836 | GrPrimitiveType primitiveType, |
| 837 | int vertexCount, |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 838 | const SkPoint positions[], |
| 839 | const SkPoint texCoords[], |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 840 | const GrColor colors[], |
| 841 | const uint16_t indices[], |
| 842 | int indexCount) { |
bsalomon | f21dab9 | 2014-11-13 13:33:28 -0800 | [diff] [blame] | 843 | AutoCheckFlush acf(this); |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 844 | GrDrawState drawState; |
bsalomon | f21dab9 | 2014-11-13 13:33:28 -0800 | [diff] [blame] | 845 | GrDrawTarget::AutoReleaseGeometry geo; // must be inside AutoCheckFlush scope |
commit-bot@chromium.org | 5a56793 | 2014-01-08 21:26:09 +0000 | [diff] [blame] | 846 | |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 847 | GrDrawTarget* target = this->prepareToDraw(&drawState, &paint, &acf); |
bsalomon | 41ebbdd | 2014-08-04 08:31:39 -0700 | [diff] [blame] | 848 | if (NULL == target) { |
| 849 | return; |
| 850 | } |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 851 | |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 852 | GR_CREATE_TRACE_MARKER("GrContext::drawVertices", target); |
| 853 | |
jvanverth@google.com | 9b855c7 | 2013-03-01 18:21:22 +0000 | [diff] [blame] | 854 | int colorOffset = -1, texOffset = -1; |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 855 | set_vertex_attributes(&drawState, texCoords, colors, &colorOffset, &texOffset); |
jvanverth@google.com | 9b855c7 | 2013-03-01 18:21:22 +0000 | [diff] [blame] | 856 | |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 857 | size_t vertexStride = drawState.getGeometryProcessor()->getVertexStride(); |
| 858 | SkASSERT(vertexStride == sizeof(SkPoint) + (SkToBool(texCoords) ? sizeof(SkPoint) : 0) |
| 859 | + (SkToBool(colors) ? sizeof(GrColor) : 0)); |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 860 | if (!geo.set(target, vertexCount, vertexStride, indexCount)) { |
joshualitt | d1aa8ff | 2014-11-04 07:47:55 -0800 | [diff] [blame] | 861 | SkDebugf("Failed to get space for vertices!\n"); |
| 862 | return; |
| 863 | } |
| 864 | void* curVertex = geo.vertices(); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 865 | |
joshualitt | d1aa8ff | 2014-11-04 07:47:55 -0800 | [diff] [blame] | 866 | for (int i = 0; i < vertexCount; ++i) { |
| 867 | *((SkPoint*)curVertex) = positions[i]; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 868 | |
joshualitt | d1aa8ff | 2014-11-04 07:47:55 -0800 | [diff] [blame] | 869 | if (texOffset >= 0) { |
| 870 | *(SkPoint*)((intptr_t)curVertex + texOffset) = texCoords[i]; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 871 | } |
joshualitt | d1aa8ff | 2014-11-04 07:47:55 -0800 | [diff] [blame] | 872 | if (colorOffset >= 0) { |
| 873 | *(GrColor*)((intptr_t)curVertex + colorOffset) = colors[i]; |
| 874 | } |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 875 | curVertex = (void*)((intptr_t)curVertex + vertexStride); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 876 | } |
| 877 | |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 878 | // we don't currently apply offscreen AA to this path. Need improved |
bsalomon@google.com | 9195836 | 2011-06-13 17:58:13 +0000 | [diff] [blame] | 879 | // management of GrDrawTarget's geometry to avoid copying points per-tile. |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 880 | if (indices) { |
joshualitt | d1aa8ff | 2014-11-04 07:47:55 -0800 | [diff] [blame] | 881 | uint16_t* curIndex = (uint16_t*)geo.indices(); |
| 882 | for (int i = 0; i < indexCount; ++i) { |
| 883 | curIndex[i] = indices[i]; |
| 884 | } |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 885 | target->drawIndexed(&drawState, primitiveType, 0, 0, vertexCount, indexCount); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 886 | } else { |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 887 | target->drawNonIndexed(&drawState, primitiveType, 0, vertexCount); |
bsalomon@google.com | 8295dc1 | 2011-05-02 12:53:34 +0000 | [diff] [blame] | 888 | } |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 889 | } |
| 890 | |
bsalomon@google.com | 06afe7b | 2011-04-26 15:31:40 +0000 | [diff] [blame] | 891 | /////////////////////////////////////////////////////////////////////////////// |
bsalomon@google.com | 93c9660 | 2012-04-27 13:05:21 +0000 | [diff] [blame] | 892 | |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 893 | void GrContext::drawRRect(const GrPaint& paint, |
commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 894 | const SkRRect& rrect, |
egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 895 | const GrStrokeInfo& strokeInfo) { |
commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 896 | if (rrect.isEmpty()) { |
commit-bot@chromium.org | 19dd017 | 2013-08-05 13:28:55 +0000 | [diff] [blame] | 897 | return; |
| 898 | } |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 899 | |
egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 900 | if (strokeInfo.isDashed()) { |
| 901 | SkPath path; |
| 902 | path.addRRect(rrect); |
| 903 | this->drawPath(paint, path, strokeInfo); |
| 904 | return; |
| 905 | } |
| 906 | |
bsalomon | f21dab9 | 2014-11-13 13:33:28 -0800 | [diff] [blame] | 907 | AutoCheckFlush acf(this); |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 908 | GrDrawState drawState; |
| 909 | GrDrawTarget* target = this->prepareToDraw(&drawState, &paint, &acf); |
bsalomon | 41ebbdd | 2014-08-04 08:31:39 -0700 | [diff] [blame] | 910 | if (NULL == target) { |
| 911 | return; |
| 912 | } |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 913 | |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 914 | GR_CREATE_TRACE_MARKER("GrContext::drawRRect", target); |
| 915 | |
egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 916 | const SkStrokeRec& strokeRec = strokeInfo.getStrokeRec(); |
| 917 | |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 918 | if (!fOvalRenderer->drawRRect(target, &drawState, this, paint.isAntiAlias(), rrect, |
| 919 | strokeRec)) { |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 920 | SkPath path; |
commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 921 | path.addRRect(rrect); |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 922 | this->internalDrawPath(target, &drawState, paint.isAntiAlias(), path, strokeInfo); |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 923 | } |
| 924 | } |
| 925 | |
| 926 | /////////////////////////////////////////////////////////////////////////////// |
| 927 | |
commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 928 | void GrContext::drawDRRect(const GrPaint& paint, |
| 929 | const SkRRect& outer, |
| 930 | const SkRRect& inner) { |
| 931 | if (outer.isEmpty()) { |
| 932 | return; |
| 933 | } |
| 934 | |
bsalomon | f21dab9 | 2014-11-13 13:33:28 -0800 | [diff] [blame] | 935 | AutoCheckFlush acf(this); |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 936 | GrDrawState drawState; |
| 937 | GrDrawTarget* target = this->prepareToDraw(&drawState, &paint, &acf); |
commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 938 | |
| 939 | GR_CREATE_TRACE_MARKER("GrContext::drawDRRect", target); |
| 940 | |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 941 | if (!fOvalRenderer->drawDRRect(target, &drawState, this, paint.isAntiAlias(), outer, inner)) { |
commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 942 | SkPath path; |
| 943 | path.addRRect(inner); |
| 944 | path.addRRect(outer); |
| 945 | path.setFillType(SkPath::kEvenOdd_FillType); |
| 946 | |
egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 947 | GrStrokeInfo fillRec(SkStrokeRec::kFill_InitStyle); |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 948 | this->internalDrawPath(target, &drawState, paint.isAntiAlias(), path, fillRec); |
commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 949 | } |
| 950 | } |
| 951 | |
| 952 | /////////////////////////////////////////////////////////////////////////////// |
| 953 | |
bsalomon@google.com | 93c9660 | 2012-04-27 13:05:21 +0000 | [diff] [blame] | 954 | void GrContext::drawOval(const GrPaint& paint, |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 955 | const SkRect& oval, |
egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 956 | const GrStrokeInfo& strokeInfo) { |
commit-bot@chromium.org | 19dd017 | 2013-08-05 13:28:55 +0000 | [diff] [blame] | 957 | if (oval.isEmpty()) { |
| 958 | return; |
| 959 | } |
jvanverth@google.com | 46d3d39 | 2013-01-22 13:34:01 +0000 | [diff] [blame] | 960 | |
egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 961 | if (strokeInfo.isDashed()) { |
| 962 | SkPath path; |
| 963 | path.addOval(oval); |
| 964 | this->drawPath(paint, path, strokeInfo); |
| 965 | return; |
| 966 | } |
| 967 | |
bsalomon | f21dab9 | 2014-11-13 13:33:28 -0800 | [diff] [blame] | 968 | AutoCheckFlush acf(this); |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 969 | GrDrawState drawState; |
| 970 | GrDrawTarget* target = this->prepareToDraw(&drawState, &paint, &acf); |
bsalomon | 41ebbdd | 2014-08-04 08:31:39 -0700 | [diff] [blame] | 971 | if (NULL == target) { |
| 972 | return; |
| 973 | } |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 974 | |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 975 | GR_CREATE_TRACE_MARKER("GrContext::drawOval", target); |
| 976 | |
egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 977 | const SkStrokeRec& strokeRec = strokeInfo.getStrokeRec(); |
| 978 | |
| 979 | |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 980 | if (!fOvalRenderer->drawOval(target, &drawState, this, paint.isAntiAlias(), oval, strokeRec)) { |
bsalomon@google.com | 93c9660 | 2012-04-27 13:05:21 +0000 | [diff] [blame] | 981 | SkPath path; |
jvanverth@google.com | 46d3d39 | 2013-01-22 13:34:01 +0000 | [diff] [blame] | 982 | path.addOval(oval); |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 983 | this->internalDrawPath(target, &drawState, paint.isAntiAlias(), path, strokeInfo); |
skia.committer@gmail.com | 98ded84 | 2013-01-23 07:06:17 +0000 | [diff] [blame] | 984 | } |
bsalomon@google.com | 150d284 | 2012-01-12 20:19:56 +0000 | [diff] [blame] | 985 | } |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 986 | |
robertphillips@google.com | 83d1a68 | 2013-05-17 12:50:27 +0000 | [diff] [blame] | 987 | // Can 'path' be drawn as a pair of filled nested rectangles? |
| 988 | static bool is_nested_rects(GrDrawTarget* target, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 989 | GrDrawState* drawState, |
robertphillips@google.com | 83d1a68 | 2013-05-17 12:50:27 +0000 | [diff] [blame] | 990 | const SkPath& path, |
| 991 | const SkStrokeRec& stroke, |
bsalomon | 9c0822a | 2014-08-11 11:07:48 -0700 | [diff] [blame] | 992 | SkRect rects[2]) { |
robertphillips@google.com | 83d1a68 | 2013-05-17 12:50:27 +0000 | [diff] [blame] | 993 | SkASSERT(stroke.isFillStyle()); |
| 994 | |
| 995 | if (path.isInverseFillType()) { |
| 996 | return false; |
| 997 | } |
| 998 | |
robertphillips@google.com | 83d1a68 | 2013-05-17 12:50:27 +0000 | [diff] [blame] | 999 | // TODO: this restriction could be lifted if we were willing to apply |
| 1000 | // the matrix to all the points individually rather than just to the rect |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 1001 | if (!drawState->getViewMatrix().preservesAxisAlignment()) { |
robertphillips@google.com | 83d1a68 | 2013-05-17 12:50:27 +0000 | [diff] [blame] | 1002 | return false; |
| 1003 | } |
| 1004 | |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 1005 | if (!drawState->canTweakAlphaForCoverage() && !drawState->couldApplyCoverage(*target->caps())) { |
bsalomon | 9c0822a | 2014-08-11 11:07:48 -0700 | [diff] [blame] | 1006 | return false; |
robertphillips@google.com | 83d1a68 | 2013-05-17 12:50:27 +0000 | [diff] [blame] | 1007 | } |
| 1008 | |
| 1009 | SkPath::Direction dirs[2]; |
| 1010 | if (!path.isNestedRects(rects, dirs)) { |
| 1011 | return false; |
| 1012 | } |
| 1013 | |
robertphillips@google.com | 8d3c640 | 2013-08-20 12:11:31 +0000 | [diff] [blame] | 1014 | if (SkPath::kWinding_FillType == path.getFillType() && dirs[0] == dirs[1]) { |
robertphillips@google.com | 83d1a68 | 2013-05-17 12:50:27 +0000 | [diff] [blame] | 1015 | // The two rects need to be wound opposite to each other |
robertphillips@google.com | 8d3c640 | 2013-08-20 12:11:31 +0000 | [diff] [blame] | 1016 | return false; |
robertphillips@google.com | 83d1a68 | 2013-05-17 12:50:27 +0000 | [diff] [blame] | 1017 | } |
robertphillips@google.com | 83d1a68 | 2013-05-17 12:50:27 +0000 | [diff] [blame] | 1018 | |
robertphillips@google.com | 8d3c640 | 2013-08-20 12:11:31 +0000 | [diff] [blame] | 1019 | // Right now, nested rects where the margin is not the same width |
| 1020 | // all around do not render correctly |
| 1021 | const SkScalar* outer = rects[0].asScalars(); |
| 1022 | const SkScalar* inner = rects[1].asScalars(); |
| 1023 | |
robertphillips | 183e985 | 2014-10-21 11:25:37 -0700 | [diff] [blame] | 1024 | bool allEq = true; |
| 1025 | |
robertphillips@google.com | 8d3c640 | 2013-08-20 12:11:31 +0000 | [diff] [blame] | 1026 | SkScalar margin = SkScalarAbs(outer[0] - inner[0]); |
robertphillips | 183e985 | 2014-10-21 11:25:37 -0700 | [diff] [blame] | 1027 | bool allGoE1 = margin >= SK_Scalar1; |
| 1028 | |
robertphillips@google.com | 8d3c640 | 2013-08-20 12:11:31 +0000 | [diff] [blame] | 1029 | for (int i = 1; i < 4; ++i) { |
| 1030 | SkScalar temp = SkScalarAbs(outer[i] - inner[i]); |
robertphillips | 183e985 | 2014-10-21 11:25:37 -0700 | [diff] [blame] | 1031 | if (temp < SK_Scalar1) { |
| 1032 | allGoE1 = false; |
| 1033 | } |
robertphillips@google.com | 8d3c640 | 2013-08-20 12:11:31 +0000 | [diff] [blame] | 1034 | if (!SkScalarNearlyEqual(margin, temp)) { |
robertphillips | 183e985 | 2014-10-21 11:25:37 -0700 | [diff] [blame] | 1035 | allEq = false; |
robertphillips@google.com | 8d3c640 | 2013-08-20 12:11:31 +0000 | [diff] [blame] | 1036 | } |
| 1037 | } |
| 1038 | |
robertphillips | 183e985 | 2014-10-21 11:25:37 -0700 | [diff] [blame] | 1039 | return allEq || allGoE1; |
robertphillips@google.com | 8d3c640 | 2013-08-20 12:11:31 +0000 | [diff] [blame] | 1040 | } |
robertphillips@google.com | 83d1a68 | 2013-05-17 12:50:27 +0000 | [diff] [blame] | 1041 | |
egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 1042 | void GrContext::drawPath(const GrPaint& paint, const SkPath& path, const GrStrokeInfo& strokeInfo) { |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 1043 | |
bsalomon@google.com | fa6ac93 | 2011-10-05 19:57:55 +0000 | [diff] [blame] | 1044 | if (path.isEmpty()) { |
sugoi@google.com | 12b4e27 | 2012-12-06 20:13:11 +0000 | [diff] [blame] | 1045 | if (path.isInverseFillType()) { |
bsalomon@google.com | fa6ac93 | 2011-10-05 19:57:55 +0000 | [diff] [blame] | 1046 | this->drawPaint(paint); |
| 1047 | } |
| 1048 | return; |
| 1049 | } |
| 1050 | |
egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 1051 | if (strokeInfo.isDashed()) { |
egdaniel | e61c411 | 2014-06-12 10:24:21 -0700 | [diff] [blame] | 1052 | SkPoint pts[2]; |
| 1053 | if (path.isLine(pts)) { |
bsalomon | f21dab9 | 2014-11-13 13:33:28 -0800 | [diff] [blame] | 1054 | AutoCheckFlush acf(this); |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 1055 | GrDrawState drawState; |
| 1056 | GrDrawTarget* target = this->prepareToDraw(&drawState, &paint, &acf); |
bsalomon | 41ebbdd | 2014-08-04 08:31:39 -0700 | [diff] [blame] | 1057 | if (NULL == target) { |
| 1058 | return; |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 1059 | }; |
egdaniel | e61c411 | 2014-06-12 10:24:21 -0700 | [diff] [blame] | 1060 | |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 1061 | SkMatrix origViewMatrix = drawState.getViewMatrix(); |
egdaniel | e61c411 | 2014-06-12 10:24:21 -0700 | [diff] [blame] | 1062 | GrDrawState::AutoViewMatrixRestore avmr; |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 1063 | if (avmr.setIdentity(&drawState)) { |
| 1064 | if (GrDashingEffect::DrawDashLine(fGpu, target, &drawState, pts, paint, |
| 1065 | strokeInfo, origViewMatrix)) { |
egdaniel | e61c411 | 2014-06-12 10:24:21 -0700 | [diff] [blame] | 1066 | return; |
| 1067 | } |
| 1068 | } |
| 1069 | } |
| 1070 | |
| 1071 | // Filter dashed path into new path with the dashing applied |
egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 1072 | const SkPathEffect::DashInfo& info = strokeInfo.getDashInfo(); |
| 1073 | SkTLazy<SkPath> effectPath; |
| 1074 | GrStrokeInfo newStrokeInfo(strokeInfo, false); |
| 1075 | SkStrokeRec* stroke = newStrokeInfo.getStrokeRecPtr(); |
| 1076 | if (SkDashPath::FilterDashPath(effectPath.init(), path, stroke, NULL, info)) { |
| 1077 | this->drawPath(paint, *effectPath.get(), newStrokeInfo); |
| 1078 | return; |
| 1079 | } |
| 1080 | |
| 1081 | this->drawPath(paint, path, newStrokeInfo); |
| 1082 | return; |
| 1083 | } |
| 1084 | |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 1085 | // 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] | 1086 | // Scratch textures can be recycled after they are returned to the texture |
| 1087 | // cache. This presents a potential hazard for buffered drawing. However, |
| 1088 | // the writePixels that uploads to the scratch will perform a flush so we're |
| 1089 | // OK. |
bsalomon | f21dab9 | 2014-11-13 13:33:28 -0800 | [diff] [blame] | 1090 | AutoCheckFlush acf(this); |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 1091 | GrDrawState drawState; |
| 1092 | GrDrawTarget* target = this->prepareToDraw(&drawState, &paint, &acf); |
bsalomon | 41ebbdd | 2014-08-04 08:31:39 -0700 | [diff] [blame] | 1093 | if (NULL == target) { |
| 1094 | return; |
| 1095 | } |
bsalomon@google.com | d46e242 | 2011-09-23 17:40:07 +0000 | [diff] [blame] | 1096 | |
egdaniel | 93a37bc | 2014-07-21 13:47:57 -0700 | [diff] [blame] | 1097 | 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] | 1098 | |
egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 1099 | const SkStrokeRec& strokeRec = strokeInfo.getStrokeRec(); |
| 1100 | |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 1101 | bool useCoverageAA = paint.isAntiAlias() && !drawState.getRenderTarget()->isMultisampled(); |
commit-bot@chromium.org | e0a868c | 2013-11-22 07:02:11 +0000 | [diff] [blame] | 1102 | |
egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 1103 | if (useCoverageAA && strokeRec.getWidth() < 0 && !path.isConvex()) { |
robertphillips@google.com | 83d1a68 | 2013-05-17 12:50:27 +0000 | [diff] [blame] | 1104 | // Concave AA paths are expensive - try to avoid them for special cases |
robertphillips@google.com | 83d1a68 | 2013-05-17 12:50:27 +0000 | [diff] [blame] | 1105 | SkRect rects[2]; |
| 1106 | |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 1107 | if (is_nested_rects(target, &drawState, path, strokeRec, rects)) { |
| 1108 | SkMatrix origViewMatrix = drawState.getViewMatrix(); |
bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 1109 | GrDrawState::AutoViewMatrixRestore avmr; |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 1110 | if (!avmr.setIdentity(&drawState)) { |
robertphillips@google.com | 83d1a68 | 2013-05-17 12:50:27 +0000 | [diff] [blame] | 1111 | return; |
| 1112 | } |
| 1113 | |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 1114 | fAARectRenderer->fillAANestedRects(target, &drawState, rects, origViewMatrix); |
robertphillips@google.com | 83d1a68 | 2013-05-17 12:50:27 +0000 | [diff] [blame] | 1115 | return; |
| 1116 | } |
| 1117 | } |
| 1118 | |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 1119 | SkRect ovalRect; |
| 1120 | bool isOval = path.isOval(&ovalRect); |
| 1121 | |
skia.committer@gmail.com | 7e32851 | 2013-03-23 07:01:28 +0000 | [diff] [blame] | 1122 | if (!isOval || path.isInverseFillType() |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 1123 | || !fOvalRenderer->drawOval(target, &drawState, this, paint.isAntiAlias(), ovalRect, |
| 1124 | strokeRec)) { |
| 1125 | this->internalDrawPath(target, &drawState, paint.isAntiAlias(), path, strokeInfo); |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 1126 | } |
| 1127 | } |
| 1128 | |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 1129 | void GrContext::internalDrawPath(GrDrawTarget* target, |
| 1130 | GrDrawState* drawState, |
| 1131 | bool useAA, |
| 1132 | const SkPath& path, |
egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 1133 | const GrStrokeInfo& strokeInfo) { |
commit-bot@chromium.org | 19dd017 | 2013-08-05 13:28:55 +0000 | [diff] [blame] | 1134 | SkASSERT(!path.isEmpty()); |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 1135 | |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 1136 | GR_CREATE_TRACE_MARKER("GrContext::internalDrawPath", target); |
| 1137 | |
| 1138 | |
bsalomon@google.com | d46e242 | 2011-09-23 17:40:07 +0000 | [diff] [blame] | 1139 | // An Assumption here is that path renderer would use some form of tweaking |
| 1140 | // the src color (either the input alpha or in the frag shader) to implement |
| 1141 | // aa. If we have some future driver-mojo path AA that can do the right |
| 1142 | // 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] | 1143 | bool useCoverageAA = useAA && |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 1144 | !drawState->getRenderTarget()->isMultisampled() && |
| 1145 | drawState->couldApplyCoverage(*target->caps()); |
bsalomon@google.com | 289533a | 2011-10-27 12:34:25 +0000 | [diff] [blame] | 1146 | |
commit-bot@chromium.org | e0a868c | 2013-11-22 07:02:11 +0000 | [diff] [blame] | 1147 | |
| 1148 | GrPathRendererChain::DrawType type = |
| 1149 | useCoverageAA ? GrPathRendererChain::kColorAntiAlias_DrawType : |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 1150 | GrPathRendererChain::kColor_DrawType; |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 1151 | |
robertphillips@google.com | eb928ea | 2013-01-08 13:45:09 +0000 | [diff] [blame] | 1152 | const SkPath* pathPtr = &path; |
commit-bot@chromium.org | f0c41e2 | 2014-01-14 18:42:34 +0000 | [diff] [blame] | 1153 | SkTLazy<SkPath> tmpPath; |
egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 1154 | SkTCopyOnFirstWrite<SkStrokeRec> stroke(strokeInfo.getStrokeRec()); |
robertphillips@google.com | eb928ea | 2013-01-08 13:45:09 +0000 | [diff] [blame] | 1155 | |
| 1156 | // Try a 1st time without stroking the path and without allowing the SW renderer |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 1157 | GrPathRenderer* pr = this->getPathRenderer(target, drawState, *pathPtr, *stroke, false, type); |
robertphillips@google.com | eb928ea | 2013-01-08 13:45:09 +0000 | [diff] [blame] | 1158 | |
robertphillips@google.com | e79f320 | 2014-02-11 16:30:21 +0000 | [diff] [blame] | 1159 | if (NULL == pr) { |
commit-bot@chromium.org | f0c41e2 | 2014-01-14 18:42:34 +0000 | [diff] [blame] | 1160 | if (!GrPathRenderer::IsStrokeHairlineOrEquivalent(*stroke, this->getMatrix(), NULL)) { |
robertphillips@google.com | eb928ea | 2013-01-08 13:45:09 +0000 | [diff] [blame] | 1161 | // It didn't work the 1st time, so try again with the stroked path |
commit-bot@chromium.org | f0c41e2 | 2014-01-14 18:42:34 +0000 | [diff] [blame] | 1162 | if (stroke->applyToPath(tmpPath.init(), *pathPtr)) { |
| 1163 | pathPtr = tmpPath.get(); |
| 1164 | stroke.writable()->setFillStyle(); |
commit-bot@chromium.org | e0a868c | 2013-11-22 07:02:11 +0000 | [diff] [blame] | 1165 | if (pathPtr->isEmpty()) { |
| 1166 | return; |
| 1167 | } |
robertphillips@google.com | eb928ea | 2013-01-08 13:45:09 +0000 | [diff] [blame] | 1168 | } |
| 1169 | } |
commit-bot@chromium.org | 19dd017 | 2013-08-05 13:28:55 +0000 | [diff] [blame] | 1170 | |
robertphillips@google.com | eb928ea | 2013-01-08 13:45:09 +0000 | [diff] [blame] | 1171 | // This time, allow SW renderer |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 1172 | pr = this->getPathRenderer(target, drawState, *pathPtr, *stroke, true, type); |
robertphillips@google.com | eb928ea | 2013-01-08 13:45:09 +0000 | [diff] [blame] | 1173 | } |
| 1174 | |
robertphillips@google.com | e79f320 | 2014-02-11 16:30:21 +0000 | [diff] [blame] | 1175 | if (NULL == pr) { |
commit-bot@chromium.org | 515dcd3 | 2013-08-28 14:17:03 +0000 | [diff] [blame] | 1176 | #ifdef SK_DEBUG |
tfarina | 38406c8 | 2014-10-31 07:11:12 -0700 | [diff] [blame] | 1177 | SkDebugf("Unable to find path renderer compatible with path.\n"); |
bsalomon@google.com | 1983f39 | 2011-10-10 15:17:58 +0000 | [diff] [blame] | 1178 | #endif |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 1179 | return; |
| 1180 | } |
| 1181 | |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 1182 | pr->drawPath(target, drawState, *pathPtr, *stroke, useCoverageAA); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 1183 | } |
bsalomon@google.com | 8295dc1 | 2011-05-02 12:53:34 +0000 | [diff] [blame] | 1184 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 1185 | //////////////////////////////////////////////////////////////////////////////// |
| 1186 | |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 1187 | void GrContext::flush(int flagsBitfield) { |
robertphillips@google.com | e7db8d6 | 2013-07-04 11:48:52 +0000 | [diff] [blame] | 1188 | if (NULL == fDrawBuffer) { |
| 1189 | return; |
| 1190 | } |
| 1191 | |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 1192 | if (kDiscard_FlushBit & flagsBitfield) { |
| 1193 | fDrawBuffer->reset(); |
| 1194 | } else { |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 1195 | fDrawBuffer->flush(); |
junov@google.com | 53a5584 | 2011-06-08 22:55:10 +0000 | [diff] [blame] | 1196 | } |
bsalomon | f21dab9 | 2014-11-13 13:33:28 -0800 | [diff] [blame] | 1197 | fFlushToReduceCacheSize = false; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 1198 | } |
| 1199 | |
bsalomon | 81beccc | 2014-10-13 12:32:55 -0700 | [diff] [blame] | 1200 | bool sw_convert_to_premul(GrPixelConfig srcConfig, int width, int height, size_t inRowBytes, |
| 1201 | const void* inPixels, size_t outRowBytes, void* outPixels) { |
| 1202 | SkSrcPixelInfo srcPI; |
| 1203 | if (!GrPixelConfig2ColorType(srcConfig, &srcPI.fColorType)) { |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 1204 | return false; |
| 1205 | } |
bsalomon | 81beccc | 2014-10-13 12:32:55 -0700 | [diff] [blame] | 1206 | srcPI.fAlphaType = kUnpremul_SkAlphaType; |
| 1207 | srcPI.fPixels = inPixels; |
| 1208 | srcPI.fRowBytes = inRowBytes; |
| 1209 | |
| 1210 | SkDstPixelInfo dstPI; |
| 1211 | dstPI.fColorType = srcPI.fColorType; |
| 1212 | dstPI.fAlphaType = kPremul_SkAlphaType; |
| 1213 | dstPI.fPixels = outPixels; |
| 1214 | dstPI.fRowBytes = outRowBytes; |
| 1215 | |
| 1216 | return srcPI.convertPixelsTo(&dstPI, width, height); |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 1217 | } |
| 1218 | |
bsalomon | 81beccc | 2014-10-13 12:32:55 -0700 | [diff] [blame] | 1219 | bool GrContext::writeSurfacePixels(GrSurface* surface, |
| 1220 | int left, int top, int width, int height, |
| 1221 | GrPixelConfig srcConfig, const void* buffer, size_t rowBytes, |
| 1222 | uint32_t pixelOpsFlags) { |
| 1223 | |
| 1224 | { |
| 1225 | GrTexture* texture = NULL; |
| 1226 | if (!(kUnpremul_PixelOpsFlag & pixelOpsFlags) && (texture = surface->asTexture()) && |
| 1227 | fGpu->canWriteTexturePixels(texture, srcConfig)) { |
| 1228 | |
| 1229 | if (!(kDontFlush_PixelOpsFlag & pixelOpsFlags) && |
| 1230 | surface->surfacePriv().hasPendingIO()) { |
| 1231 | this->flush(); |
| 1232 | } |
| 1233 | return fGpu->writeTexturePixels(texture, left, top, width, height, |
| 1234 | srcConfig, buffer, rowBytes); |
| 1235 | // Don't need to check kFlushWrites_PixelOp here, we just did a direct write so the |
| 1236 | // upload is already flushed. |
| 1237 | } |
| 1238 | } |
| 1239 | |
| 1240 | // If we didn't do a direct texture write then we upload the pixels to a texture and draw. |
| 1241 | GrRenderTarget* renderTarget = surface->asRenderTarget(); |
| 1242 | if (NULL == renderTarget) { |
| 1243 | return false; |
| 1244 | } |
| 1245 | |
| 1246 | // We ignore the preferred config unless it is a R/B swap of the src config. In that case |
| 1247 | // we will upload the original src data to a scratch texture but we will spoof it as the swapped |
| 1248 | // config. This scratch will then have R and B swapped. We correct for this by swapping again |
| 1249 | // when drawing the scratch to the dst using a conversion effect. |
| 1250 | bool swapRAndB = false; |
| 1251 | GrPixelConfig writeConfig = srcConfig; |
| 1252 | if (GrPixelConfigSwapRAndB(srcConfig) == |
| 1253 | fGpu->preferredWritePixelsConfig(srcConfig, renderTarget->config())) { |
| 1254 | writeConfig = GrPixelConfigSwapRAndB(srcConfig); |
| 1255 | swapRAndB = true; |
| 1256 | } |
| 1257 | |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 1258 | GrSurfaceDesc desc; |
bsalomon | 81beccc | 2014-10-13 12:32:55 -0700 | [diff] [blame] | 1259 | desc.fWidth = width; |
| 1260 | desc.fHeight = height; |
| 1261 | desc.fConfig = writeConfig; |
bsalomon | e305973 | 2014-10-14 11:47:22 -0700 | [diff] [blame] | 1262 | SkAutoTUnref<GrTexture> texture(this->refScratchTexture(desc, kApprox_ScratchTexMatch)); |
| 1263 | if (!texture) { |
bsalomon | 81beccc | 2014-10-13 12:32:55 -0700 | [diff] [blame] | 1264 | return false; |
| 1265 | } |
| 1266 | |
| 1267 | SkAutoTUnref<const GrFragmentProcessor> fp; |
| 1268 | SkMatrix textureMatrix; |
| 1269 | textureMatrix.setIDiv(texture->width(), texture->height()); |
| 1270 | |
| 1271 | // allocate a tmp buffer and sw convert the pixels to premul |
| 1272 | SkAutoSTMalloc<128 * 128, uint32_t> tmpPixels(0); |
| 1273 | |
| 1274 | if (kUnpremul_PixelOpsFlag & pixelOpsFlags) { |
| 1275 | if (!GrPixelConfigIs8888(srcConfig)) { |
| 1276 | return false; |
| 1277 | } |
| 1278 | fp.reset(this->createUPMToPMEffect(texture, swapRAndB, textureMatrix)); |
| 1279 | // handle the unpremul step on the CPU if we couldn't create an effect to do it. |
| 1280 | if (NULL == fp) { |
| 1281 | size_t tmpRowBytes = 4 * width; |
| 1282 | tmpPixels.reset(width * height); |
| 1283 | if (!sw_convert_to_premul(srcConfig, width, height, rowBytes, buffer, tmpRowBytes, |
| 1284 | tmpPixels.get())) { |
| 1285 | return false; |
| 1286 | } |
| 1287 | rowBytes = tmpRowBytes; |
| 1288 | buffer = tmpPixels.get(); |
| 1289 | } |
| 1290 | } |
| 1291 | if (NULL == fp) { |
| 1292 | fp.reset(GrConfigConversionEffect::Create(texture, |
| 1293 | swapRAndB, |
| 1294 | GrConfigConversionEffect::kNone_PMConversion, |
| 1295 | textureMatrix)); |
| 1296 | } |
| 1297 | |
| 1298 | // Even if the client told us not to flush, we still flush here. The client may have known that |
| 1299 | // writes to the original surface caused no data hazards, but they can't know that the scratch |
| 1300 | // we just got is safe. |
| 1301 | if (texture->surfacePriv().hasPendingIO()) { |
| 1302 | this->flush(); |
| 1303 | } |
| 1304 | if (!fGpu->writeTexturePixels(texture, 0, 0, width, height, |
| 1305 | writeConfig, buffer, rowBytes)) { |
| 1306 | return false; |
| 1307 | } |
| 1308 | |
| 1309 | SkMatrix matrix; |
| 1310 | matrix.setTranslate(SkIntToScalar(left), SkIntToScalar(top)); |
| 1311 | |
| 1312 | // This function can be called in the midst of drawing another object (e.g., when uploading a |
| 1313 | // SW-rasterized clip while issuing a draw). So we push the current geometry state before |
| 1314 | // drawing a rect to the render target. |
| 1315 | // The bracket ensures we pop the stack if we wind up flushing below. |
| 1316 | { |
bsalomon | f21dab9 | 2014-11-13 13:33:28 -0800 | [diff] [blame] | 1317 | GrDrawTarget* drawTarget = this->prepareToDraw(NULL, NULL, NULL); |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 1318 | GrDrawTarget::AutoGeometryPush agp(drawTarget); |
| 1319 | |
| 1320 | GrDrawState drawState(matrix); |
| 1321 | drawState.addColorProcessor(fp); |
| 1322 | drawState.setRenderTarget(renderTarget); |
| 1323 | drawTarget->drawSimpleRect(&drawState, SkRect::MakeWH(SkIntToScalar(width), |
| 1324 | SkIntToScalar(height))); |
bsalomon | 81beccc | 2014-10-13 12:32:55 -0700 | [diff] [blame] | 1325 | } |
| 1326 | |
| 1327 | if (kFlushWrites_PixelOp & pixelOpsFlags) { |
| 1328 | this->flushSurfaceWrites(surface); |
| 1329 | } |
| 1330 | |
| 1331 | return true; |
| 1332 | } |
bsalomon@google.com | a91e923 | 2012-02-23 15:39:54 +0000 | [diff] [blame] | 1333 | |
reed@google.com | 7111d46 | 2014-03-25 16:20:24 +0000 | [diff] [blame] | 1334 | // toggles between RGBA and BGRA |
| 1335 | static SkColorType toggle_colortype32(SkColorType ct) { |
| 1336 | if (kRGBA_8888_SkColorType == ct) { |
| 1337 | return kBGRA_8888_SkColorType; |
| 1338 | } else { |
| 1339 | SkASSERT(kBGRA_8888_SkColorType == ct); |
| 1340 | return kRGBA_8888_SkColorType; |
bsalomon@google.com | a91e923 | 2012-02-23 15:39:54 +0000 | [diff] [blame] | 1341 | } |
| 1342 | } |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 1343 | |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 1344 | bool GrContext::readRenderTargetPixels(GrRenderTarget* target, |
| 1345 | int left, int top, int width, int height, |
bsalomon@google.com | 9c68058 | 2013-02-06 18:17:50 +0000 | [diff] [blame] | 1346 | GrPixelConfig dstConfig, void* buffer, size_t rowBytes, |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 1347 | uint32_t flags) { |
bsalomon@google.com | bc4b654 | 2011-11-19 13:56:11 +0000 | [diff] [blame] | 1348 | ASSERT_OWNED_RESOURCE(target); |
bsalomon | 89c6298 | 2014-11-03 12:08:42 -0800 | [diff] [blame] | 1349 | SkASSERT(target); |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 1350 | |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame] | 1351 | if (!(kDontFlush_PixelOpsFlag & flags) && target->surfacePriv().hasPendingWrite()) { |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 1352 | this->flush(); |
| 1353 | } |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 1354 | |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 1355 | // 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] | 1356 | |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 1357 | // If fGpu->readPixels would incur a y-flip cost then we will read the pixels upside down. We'll |
| 1358 | // either do the flipY by drawing into a scratch with a matrix or on the cpu after the read. |
| 1359 | bool flipY = fGpu->readPixelsWillPayForYFlip(target, left, top, |
bsalomon@google.com | 9c68058 | 2013-02-06 18:17:50 +0000 | [diff] [blame] | 1360 | width, height, dstConfig, |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 1361 | rowBytes); |
bsalomon@google.com | 9c68058 | 2013-02-06 18:17:50 +0000 | [diff] [blame] | 1362 | // We ignore the preferred config if it is different than our config unless it is an R/B swap. |
| 1363 | // In that case we'll perform an R and B swap while drawing to a scratch texture of the swapped |
| 1364 | // config. Then we will call readPixels on the scratch with the swapped config. The swaps during |
| 1365 | // the draw cancels out the fact that we call readPixels with a config that is R/B swapped from |
| 1366 | // dstConfig. |
| 1367 | GrPixelConfig readConfig = dstConfig; |
| 1368 | bool swapRAndB = false; |
commit-bot@chromium.org | 5d1d79a | 2013-05-24 18:52:52 +0000 | [diff] [blame] | 1369 | if (GrPixelConfigSwapRAndB(dstConfig) == |
| 1370 | fGpu->preferredReadPixelsConfig(dstConfig, target->config())) { |
bsalomon@google.com | 9c68058 | 2013-02-06 18:17:50 +0000 | [diff] [blame] | 1371 | readConfig = GrPixelConfigSwapRAndB(readConfig); |
| 1372 | swapRAndB = true; |
| 1373 | } |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 1374 | |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 1375 | bool unpremul = SkToBool(kUnpremul_PixelOpsFlag & flags); |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 1376 | |
bsalomon@google.com | 9c68058 | 2013-02-06 18:17:50 +0000 | [diff] [blame] | 1377 | if (unpremul && !GrPixelConfigIs8888(dstConfig)) { |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 1378 | // The unpremul flag is only allowed for these two configs. |
bsalomon@google.com | 0a97be2 | 2011-11-08 19:20:57 +0000 | [diff] [blame] | 1379 | return false; |
| 1380 | } |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 1381 | |
bsalomon | 191bcc0 | 2014-11-14 11:31:13 -0800 | [diff] [blame] | 1382 | SkAutoTUnref<GrTexture> tempTexture; |
| 1383 | |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 1384 | // If the src is a texture and we would have to do conversions after read pixels, we instead |
| 1385 | // do the conversions by drawing the src to a scratch texture. If we handle any of the |
| 1386 | // conversions in the draw we set the corresponding bool to false so that we don't reapply it |
| 1387 | // on the read back pixels. |
| 1388 | GrTexture* src = target->asTexture(); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 1389 | if (src && (swapRAndB || unpremul || flipY)) { |
bsalomon | 81beccc | 2014-10-13 12:32:55 -0700 | [diff] [blame] | 1390 | // Make the scratch a render so we can read its pixels. |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 1391 | GrSurfaceDesc desc; |
| 1392 | desc.fFlags = kRenderTarget_GrSurfaceFlag; |
robertphillips@google.com | 75b3c96 | 2012-06-07 12:08:45 +0000 | [diff] [blame] | 1393 | desc.fWidth = width; |
| 1394 | desc.fHeight = height; |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 1395 | desc.fConfig = readConfig; |
senorblanco@chromium.org | 3cb406b | 2013-02-05 19:50:46 +0000 | [diff] [blame] | 1396 | desc.fOrigin = kTopLeft_GrSurfaceOrigin; |
bsalomon@google.com | c4ff22a | 2011-11-10 21:56:21 +0000 | [diff] [blame] | 1397 | |
bsalomon@google.com | 9c68058 | 2013-02-06 18:17:50 +0000 | [diff] [blame] | 1398 | // 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] | 1399 | // match the passed rect. However, if we see many different size rectangles we will trash |
| 1400 | // our texture cache and pay the cost of creating and destroying many textures. So, we only |
| 1401 | // request an exact match when the caller is reading an entire RT. |
bsalomon@google.com | 56d11e0 | 2011-11-30 19:59:08 +0000 | [diff] [blame] | 1402 | ScratchTexMatch match = kApprox_ScratchTexMatch; |
| 1403 | if (0 == left && |
| 1404 | 0 == top && |
| 1405 | target->width() == width && |
| 1406 | target->height() == height && |
| 1407 | fGpu->fullReadPixelsIsFasterThanPartial()) { |
| 1408 | match = kExact_ScratchTexMatch; |
| 1409 | } |
bsalomon | 191bcc0 | 2014-11-14 11:31:13 -0800 | [diff] [blame] | 1410 | tempTexture.reset(this->refScratchTexture(desc, match)); |
| 1411 | if (tempTexture) { |
bsalomon@google.com | d8b5fac | 2012-11-01 17:02:46 +0000 | [diff] [blame] | 1412 | // compute a matrix to perform the draw |
bsalomon@google.com | b9086a0 | 2012-11-01 18:02:54 +0000 | [diff] [blame] | 1413 | SkMatrix textureMatrix; |
senorblanco@chromium.org | 3cb406b | 2013-02-05 19:50:46 +0000 | [diff] [blame] | 1414 | textureMatrix.setTranslate(SK_Scalar1 *left, SK_Scalar1 *top); |
bsalomon@google.com | d8b5fac | 2012-11-01 17:02:46 +0000 | [diff] [blame] | 1415 | textureMatrix.postIDiv(src->width(), src->height()); |
| 1416 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 1417 | SkAutoTUnref<const GrFragmentProcessor> fp; |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 1418 | if (unpremul) { |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 1419 | fp.reset(this->createPMToUPMEffect(src, swapRAndB, textureMatrix)); |
| 1420 | if (fp) { |
bsalomon@google.com | 9c68058 | 2013-02-06 18:17:50 +0000 | [diff] [blame] | 1421 | 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] | 1422 | } |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 1423 | } |
| 1424 | // If we failed to create a PM->UPM effect and have no other conversions to perform then |
| 1425 | // there is no longer any point to using the scratch. |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 1426 | if (fp || flipY || swapRAndB) { |
| 1427 | if (!fp) { |
| 1428 | fp.reset(GrConfigConversionEffect::Create( |
| 1429 | src, swapRAndB, GrConfigConversionEffect::kNone_PMConversion, |
| 1430 | textureMatrix)); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 1431 | } |
| 1432 | swapRAndB = false; // we will handle the swap in the draw. |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 1433 | |
robertphillips@google.com | 13f181f | 2013-03-02 12:02:08 +0000 | [diff] [blame] | 1434 | // We protect the existing geometry here since it may not be |
| 1435 | // clear to the caller that a draw operation (i.e., drawSimpleRect) |
| 1436 | // can be invoked in this method |
joshualitt | 5c55fef | 2014-10-31 14:04:35 -0700 | [diff] [blame] | 1437 | { |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 1438 | GrDrawTarget::AutoGeometryPush agp(fDrawBuffer); |
| 1439 | GrDrawState drawState; |
joshualitt | 5c55fef | 2014-10-31 14:04:35 -0700 | [diff] [blame] | 1440 | SkASSERT(fp); |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 1441 | drawState.addColorProcessor(fp); |
bsalomon@google.com | d8b5fac | 2012-11-01 17:02:46 +0000 | [diff] [blame] | 1442 | |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 1443 | drawState.setRenderTarget(tempTexture->asRenderTarget()); |
joshualitt | 5c55fef | 2014-10-31 14:04:35 -0700 | [diff] [blame] | 1444 | SkRect rect = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(height)); |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 1445 | fDrawBuffer->drawSimpleRect(&drawState, rect); |
joshualitt | 5c55fef | 2014-10-31 14:04:35 -0700 | [diff] [blame] | 1446 | // we want to read back from the scratch's origin |
| 1447 | left = 0; |
| 1448 | top = 0; |
bsalomon | 191bcc0 | 2014-11-14 11:31:13 -0800 | [diff] [blame] | 1449 | target = tempTexture->asRenderTarget(); |
joshualitt | 5c55fef | 2014-10-31 14:04:35 -0700 | [diff] [blame] | 1450 | } |
| 1451 | this->flushSurfaceWrites(target); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 1452 | } |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 1453 | } |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 1454 | } |
joshualitt | 5c55fef | 2014-10-31 14:04:35 -0700 | [diff] [blame] | 1455 | |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 1456 | if (!fGpu->readPixels(target, |
| 1457 | left, top, width, height, |
senorblanco@chromium.org | 3cb406b | 2013-02-05 19:50:46 +0000 | [diff] [blame] | 1458 | readConfig, buffer, rowBytes)) { |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 1459 | return false; |
| 1460 | } |
bsalomon@google.com | d8b5fac | 2012-11-01 17:02:46 +0000 | [diff] [blame] | 1461 | // 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] | 1462 | if (unpremul || swapRAndB) { |
reed@google.com | 7111d46 | 2014-03-25 16:20:24 +0000 | [diff] [blame] | 1463 | SkDstPixelInfo dstPI; |
| 1464 | if (!GrPixelConfig2ColorType(dstConfig, &dstPI.fColorType)) { |
| 1465 | return false; |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 1466 | } |
reed@google.com | 7111d46 | 2014-03-25 16:20:24 +0000 | [diff] [blame] | 1467 | dstPI.fAlphaType = kUnpremul_SkAlphaType; |
| 1468 | dstPI.fPixels = buffer; |
| 1469 | dstPI.fRowBytes = rowBytes; |
| 1470 | |
| 1471 | SkSrcPixelInfo srcPI; |
| 1472 | srcPI.fColorType = swapRAndB ? toggle_colortype32(dstPI.fColorType) : dstPI.fColorType; |
| 1473 | srcPI.fAlphaType = kPremul_SkAlphaType; |
| 1474 | srcPI.fPixels = buffer; |
| 1475 | srcPI.fRowBytes = rowBytes; |
| 1476 | |
| 1477 | return srcPI.convertPixelsTo(&dstPI, width, height); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 1478 | } |
| 1479 | return true; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 1480 | } |
| 1481 | |
bsalomon | 87a94eb | 2014-11-03 14:28:32 -0800 | [diff] [blame] | 1482 | void GrContext::prepareSurfaceForExternalRead(GrSurface* surface) { |
| 1483 | SkASSERT(surface); |
| 1484 | ASSERT_OWNED_RESOURCE(surface); |
| 1485 | if (surface->surfacePriv().hasPendingIO()) { |
| 1486 | this->flush(); |
| 1487 | } |
| 1488 | GrRenderTarget* rt = surface->asRenderTarget(); |
| 1489 | if (fGpu && rt) { |
| 1490 | fGpu->resolveRenderTarget(rt); |
bsalomon | 41ebbdd | 2014-08-04 08:31:39 -0700 | [diff] [blame] | 1491 | } |
bsalomon@google.com | 75f9f25 | 2012-01-31 13:35:56 +0000 | [diff] [blame] | 1492 | } |
| 1493 | |
bsalomon | 41ebbdd | 2014-08-04 08:31:39 -0700 | [diff] [blame] | 1494 | void GrContext::discardRenderTarget(GrRenderTarget* renderTarget) { |
| 1495 | SkASSERT(renderTarget); |
| 1496 | ASSERT_OWNED_RESOURCE(renderTarget); |
bsalomon | f21dab9 | 2014-11-13 13:33:28 -0800 | [diff] [blame] | 1497 | AutoCheckFlush acf(this); |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 1498 | GrDrawTarget* target = this->prepareToDraw(NULL, NULL, &acf); |
bsalomon | 41ebbdd | 2014-08-04 08:31:39 -0700 | [diff] [blame] | 1499 | if (NULL == target) { |
| 1500 | return; |
| 1501 | } |
| 1502 | target->discard(renderTarget); |
commit-bot@chromium.org | 28361fa | 2014-03-28 16:08:05 +0000 | [diff] [blame] | 1503 | } |
| 1504 | |
bsalomon | f80bfed | 2014-10-07 05:56:02 -0700 | [diff] [blame] | 1505 | void GrContext::copySurface(GrSurface* dst, GrSurface* src, const SkIRect& srcRect, |
| 1506 | const SkIPoint& dstPoint, uint32_t pixelOpsFlags) { |
senorblanco@chromium.org | ef843cd | 2011-12-02 19:11:17 +0000 | [diff] [blame] | 1507 | if (NULL == src || NULL == dst) { |
| 1508 | return; |
| 1509 | } |
bsalomon | e3d4bf2 | 2014-09-23 09:15:03 -0700 | [diff] [blame] | 1510 | ASSERT_OWNED_RESOURCE(src); |
junov | 2bb5210 | 2014-09-29 10:18:59 -0700 | [diff] [blame] | 1511 | ASSERT_OWNED_RESOURCE(dst); |
Brian Salomon | 34a9895 | 2014-09-24 11:41:24 -0400 | [diff] [blame] | 1512 | |
bsalomon | f80bfed | 2014-10-07 05:56:02 -0700 | [diff] [blame] | 1513 | // Since we're going to the draw target and not GPU, no need to check kNoFlush |
| 1514 | // here. |
junov | 96c118e | 2014-09-26 13:09:47 -0700 | [diff] [blame] | 1515 | |
bsalomon | f21dab9 | 2014-11-13 13:33:28 -0800 | [diff] [blame] | 1516 | GrDrawTarget* target = this->prepareToDraw(NULL, NULL, NULL); |
junov | 96c118e | 2014-09-26 13:09:47 -0700 | [diff] [blame] | 1517 | if (NULL == target) { |
| 1518 | return; |
| 1519 | } |
junov | 96c118e | 2014-09-26 13:09:47 -0700 | [diff] [blame] | 1520 | target->copySurface(dst, src, srcRect, dstPoint); |
bsalomon | f80bfed | 2014-10-07 05:56:02 -0700 | [diff] [blame] | 1521 | |
| 1522 | if (kFlushWrites_PixelOp & pixelOpsFlags) { |
| 1523 | this->flush(); |
| 1524 | } |
senorblanco@chromium.org | ef843cd | 2011-12-02 19:11:17 +0000 | [diff] [blame] | 1525 | } |
| 1526 | |
bsalomon | f80bfed | 2014-10-07 05:56:02 -0700 | [diff] [blame] | 1527 | void GrContext::flushSurfaceWrites(GrSurface* surface) { |
| 1528 | if (surface->surfacePriv().hasPendingWrite()) { |
| 1529 | this->flush(); |
| 1530 | } |
| 1531 | } |
| 1532 | |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 1533 | GrDrawTarget* GrContext::prepareToDraw(GrDrawState* ds, |
| 1534 | const GrPaint* paint, |
| 1535 | const AutoCheckFlush* acf) { |
bsalomon | 41ebbdd | 2014-08-04 08:31:39 -0700 | [diff] [blame] | 1536 | if (NULL == fGpu) { |
| 1537 | return NULL; |
| 1538 | } |
| 1539 | |
commit-bot@chromium.org | bb6a317 | 2013-05-28 17:25:49 +0000 | [diff] [blame] | 1540 | ASSERT_OWNED_RESOURCE(fRenderTarget.get()); |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 1541 | if (ds) { |
| 1542 | if (paint) { |
| 1543 | SkASSERT(acf); |
| 1544 | ds->setFromPaint(*paint, fViewMatrix, fRenderTarget.get()); |
bsalomon@google.com | af84e74 | 2012-10-05 13:23:24 +0000 | [diff] [blame] | 1545 | #if GR_DEBUG_PARTIAL_COVERAGE_CHECK |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 1546 | if ((paint->hasMask() || 0xff != paint->fCoverage) && |
| 1547 | !fDrawState->couldApplyCoverage(fGpu->caps())) { |
| 1548 | SkDebugf("Partial pixel coverage will be incorrectly blended.\n"); |
| 1549 | } |
bsalomon@google.com | af84e74 | 2012-10-05 13:23:24 +0000 | [diff] [blame] | 1550 | #endif |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 1551 | } else { |
| 1552 | ds->reset(fViewMatrix); |
| 1553 | ds->setRenderTarget(fRenderTarget.get()); |
| 1554 | } |
| 1555 | ds->setState(GrDrawState::kClip_StateBit, fClip && !fClip->fClipStack->isWideOpen()); |
bsalomon@google.com | 07ea2db | 2012-08-17 14:06:49 +0000 | [diff] [blame] | 1556 | } |
joshualitt | 5c55fef | 2014-10-31 14:04:35 -0700 | [diff] [blame] | 1557 | fDrawBuffer->setClip(fClip); |
joshualitt | 5c55fef | 2014-10-31 14:04:35 -0700 | [diff] [blame] | 1558 | return fDrawBuffer; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 1559 | } |
| 1560 | |
robertphillips@google.com | 72176b2 | 2012-05-23 13:19:12 +0000 | [diff] [blame] | 1561 | /* |
| 1562 | * This method finds a path renderer that can draw the specified path on |
| 1563 | * the provided target. |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 1564 | * 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] | 1565 | * can be individually allowed/disallowed via the "allowSW" boolean. |
| 1566 | */ |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 1567 | GrPathRenderer* GrContext::getPathRenderer(const GrDrawTarget* target, |
| 1568 | const GrDrawState* drawState, |
| 1569 | const SkPath& path, |
sugoi@google.com | 5f74cf8 | 2012-12-17 21:16:45 +0000 | [diff] [blame] | 1570 | const SkStrokeRec& stroke, |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 1571 | bool allowSW, |
| 1572 | GrPathRendererChain::DrawType drawType, |
| 1573 | GrPathRendererChain::StencilSupport* stencilSupport) { |
| 1574 | |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 1575 | if (NULL == fPathRendererChain) { |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 1576 | fPathRendererChain = SkNEW_ARGS(GrPathRendererChain, (this)); |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 1577 | } |
robertphillips@google.com | 72176b2 | 2012-05-23 13:19:12 +0000 | [diff] [blame] | 1578 | |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 1579 | GrPathRenderer* pr = fPathRendererChain->getPathRenderer(target, |
| 1580 | drawState, |
| 1581 | path, |
sugoi@google.com | 12b4e27 | 2012-12-06 20:13:11 +0000 | [diff] [blame] | 1582 | stroke, |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 1583 | drawType, |
| 1584 | stencilSupport); |
robertphillips@google.com | 72176b2 | 2012-05-23 13:19:12 +0000 | [diff] [blame] | 1585 | |
| 1586 | if (NULL == pr && allowSW) { |
| 1587 | if (NULL == fSoftwarePathRenderer) { |
tomhudson@google.com | c377baf | 2012-07-09 20:17:56 +0000 | [diff] [blame] | 1588 | fSoftwarePathRenderer = SkNEW_ARGS(GrSoftwarePathRenderer, (this)); |
robertphillips@google.com | 72176b2 | 2012-05-23 13:19:12 +0000 | [diff] [blame] | 1589 | } |
robertphillips@google.com | 72176b2 | 2012-05-23 13:19:12 +0000 | [diff] [blame] | 1590 | pr = fSoftwarePathRenderer; |
| 1591 | } |
| 1592 | |
| 1593 | return pr; |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 1594 | } |
| 1595 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 1596 | //////////////////////////////////////////////////////////////////////////////// |
commit-bot@chromium.org | 6b7938f | 2013-10-15 14:18:16 +0000 | [diff] [blame] | 1597 | bool GrContext::isConfigRenderable(GrPixelConfig config, bool withMSAA) const { |
| 1598 | return fGpu->caps()->isConfigRenderable(config, withMSAA); |
robertphillips@google.com | 99a5ac0 | 2012-04-10 19:26:38 +0000 | [diff] [blame] | 1599 | } |
| 1600 | |
commit-bot@chromium.org | b471a32 | 2014-03-10 07:40:03 +0000 | [diff] [blame] | 1601 | int GrContext::getRecommendedSampleCount(GrPixelConfig config, |
| 1602 | SkScalar dpi) const { |
| 1603 | if (!this->isConfigRenderable(config, true)) { |
| 1604 | return 0; |
| 1605 | } |
| 1606 | int chosenSampleCount = 0; |
| 1607 | if (fGpu->caps()->pathRenderingSupport()) { |
| 1608 | if (dpi >= 250.0f) { |
| 1609 | chosenSampleCount = 4; |
| 1610 | } else { |
| 1611 | chosenSampleCount = 16; |
| 1612 | } |
| 1613 | } |
| 1614 | return chosenSampleCount <= fGpu->caps()->maxSampleCount() ? |
| 1615 | chosenSampleCount : 0; |
| 1616 | } |
| 1617 | |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 1618 | void GrContext::setupDrawBuffer() { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 1619 | SkASSERT(NULL == fDrawBuffer); |
| 1620 | SkASSERT(NULL == fDrawBufferVBAllocPool); |
| 1621 | SkASSERT(NULL == fDrawBufferIBAllocPool); |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 1622 | |
bsalomon@google.com | de6ac2d | 2011-02-25 21:50:42 +0000 | [diff] [blame] | 1623 | fDrawBufferVBAllocPool = |
tomhudson@google.com | c377baf | 2012-07-09 20:17:56 +0000 | [diff] [blame] | 1624 | SkNEW_ARGS(GrVertexBufferAllocPool, (fGpu, false, |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 1625 | DRAW_BUFFER_VBPOOL_BUFFER_SIZE, |
tomhudson@google.com | c377baf | 2012-07-09 20:17:56 +0000 | [diff] [blame] | 1626 | DRAW_BUFFER_VBPOOL_PREALLOC_BUFFERS)); |
bsalomon@google.com | de6ac2d | 2011-02-25 21:50:42 +0000 | [diff] [blame] | 1627 | fDrawBufferIBAllocPool = |
tomhudson@google.com | c377baf | 2012-07-09 20:17:56 +0000 | [diff] [blame] | 1628 | SkNEW_ARGS(GrIndexBufferAllocPool, (fGpu, false, |
bsalomon@google.com | de6ac2d | 2011-02-25 21:50:42 +0000 | [diff] [blame] | 1629 | DRAW_BUFFER_IBPOOL_BUFFER_SIZE, |
tomhudson@google.com | c377baf | 2012-07-09 20:17:56 +0000 | [diff] [blame] | 1630 | DRAW_BUFFER_IBPOOL_PREALLOC_BUFFERS)); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 1631 | |
tomhudson@google.com | c377baf | 2012-07-09 20:17:56 +0000 | [diff] [blame] | 1632 | fDrawBuffer = SkNEW_ARGS(GrInOrderDrawBuffer, (fGpu, |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 1633 | fDrawBufferVBAllocPool, |
| 1634 | fDrawBufferIBAllocPool)); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 1635 | } |
| 1636 | |
bsalomon@google.com | 21c10c5 | 2013-06-13 17:44:07 +0000 | [diff] [blame] | 1637 | GrDrawTarget* GrContext::getTextTarget() { |
bsalomon | f21dab9 | 2014-11-13 13:33:28 -0800 | [diff] [blame] | 1638 | return this->prepareToDraw(NULL, NULL, NULL); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 1639 | } |
| 1640 | |
| 1641 | const GrIndexBuffer* GrContext::getQuadIndexBuffer() const { |
| 1642 | return fGpu->getQuadIndexBuffer(); |
| 1643 | } |
bsalomon@google.com | dfe75bc | 2011-03-25 12:31:16 +0000 | [diff] [blame] | 1644 | |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 1645 | namespace { |
| 1646 | void test_pm_conversions(GrContext* ctx, int* pmToUPMValue, int* upmToPMValue) { |
| 1647 | GrConfigConversionEffect::PMConversion pmToUPM; |
| 1648 | GrConfigConversionEffect::PMConversion upmToPM; |
| 1649 | GrConfigConversionEffect::TestForPreservingPMConversions(ctx, &pmToUPM, &upmToPM); |
| 1650 | *pmToUPMValue = pmToUPM; |
| 1651 | *upmToPMValue = upmToPM; |
| 1652 | } |
| 1653 | } |
| 1654 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 1655 | const GrFragmentProcessor* GrContext::createPMToUPMEffect(GrTexture* texture, |
| 1656 | bool swapRAndB, |
| 1657 | const SkMatrix& matrix) { |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 1658 | if (!fDidTestPMConversions) { |
| 1659 | test_pm_conversions(this, &fPMToUPMConversion, &fUPMToPMConversion); |
bsalomon@google.com | d0f3f68 | 2012-08-28 13:08:14 +0000 | [diff] [blame] | 1660 | fDidTestPMConversions = true; |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 1661 | } |
| 1662 | GrConfigConversionEffect::PMConversion pmToUPM = |
| 1663 | static_cast<GrConfigConversionEffect::PMConversion>(fPMToUPMConversion); |
| 1664 | if (GrConfigConversionEffect::kNone_PMConversion != pmToUPM) { |
bsalomon@google.com | adc6536 | 2013-01-28 14:26:09 +0000 | [diff] [blame] | 1665 | return GrConfigConversionEffect::Create(texture, swapRAndB, pmToUPM, matrix); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 1666 | } else { |
bsalomon@google.com | adc6536 | 2013-01-28 14:26:09 +0000 | [diff] [blame] | 1667 | return NULL; |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 1668 | } |
| 1669 | } |
| 1670 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 1671 | const GrFragmentProcessor* GrContext::createUPMToPMEffect(GrTexture* texture, |
| 1672 | bool swapRAndB, |
| 1673 | const SkMatrix& matrix) { |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 1674 | if (!fDidTestPMConversions) { |
| 1675 | test_pm_conversions(this, &fPMToUPMConversion, &fUPMToPMConversion); |
bsalomon@google.com | d0f3f68 | 2012-08-28 13:08:14 +0000 | [diff] [blame] | 1676 | fDidTestPMConversions = true; |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 1677 | } |
| 1678 | GrConfigConversionEffect::PMConversion upmToPM = |
| 1679 | static_cast<GrConfigConversionEffect::PMConversion>(fUPMToPMConversion); |
| 1680 | if (GrConfigConversionEffect::kNone_PMConversion != upmToPM) { |
bsalomon@google.com | adc6536 | 2013-01-28 14:26:09 +0000 | [diff] [blame] | 1681 | return GrConfigConversionEffect::Create(texture, swapRAndB, upmToPM, matrix); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 1682 | } else { |
bsalomon@google.com | adc6536 | 2013-01-28 14:26:09 +0000 | [diff] [blame] | 1683 | return NULL; |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 1684 | } |
| 1685 | } |
| 1686 | |
bsalomon | 6d3fe02 | 2014-07-25 08:35:45 -0700 | [diff] [blame] | 1687 | void GrContext::addResourceToCache(const GrResourceKey& resourceKey, GrGpuResource* resource) { |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 1688 | resource->cacheAccess().setContentKey(resourceKey); |
commit-bot@chromium.org | 95a2b0e | 2014-05-05 19:21:16 +0000 | [diff] [blame] | 1689 | } |
| 1690 | |
bsalomon | 6d3fe02 | 2014-07-25 08:35:45 -0700 | [diff] [blame] | 1691 | GrGpuResource* GrContext::findAndRefCachedResource(const GrResourceKey& resourceKey) { |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 1692 | return fResourceCache2->findAndRefContentResource(resourceKey); |
commit-bot@chromium.org | 95a2b0e | 2014-05-05 19:21:16 +0000 | [diff] [blame] | 1693 | } |
| 1694 | |
egdaniel | bbcb38d | 2014-06-19 10:19:29 -0700 | [diff] [blame] | 1695 | void GrContext::addGpuTraceMarker(const GrGpuTraceMarker* marker) { |
| 1696 | fGpu->addGpuTraceMarker(marker); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 1697 | if (fDrawBuffer) { |
egdaniel | bbcb38d | 2014-06-19 10:19:29 -0700 | [diff] [blame] | 1698 | fDrawBuffer->addGpuTraceMarker(marker); |
| 1699 | } |
| 1700 | } |
| 1701 | |
| 1702 | void GrContext::removeGpuTraceMarker(const GrGpuTraceMarker* marker) { |
| 1703 | fGpu->removeGpuTraceMarker(marker); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 1704 | if (fDrawBuffer) { |
egdaniel | bbcb38d | 2014-06-19 10:19:29 -0700 | [diff] [blame] | 1705 | fDrawBuffer->removeGpuTraceMarker(marker); |
| 1706 | } |
| 1707 | } |
| 1708 | |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 1709 | /////////////////////////////////////////////////////////////////////////////// |
robertphillips@google.com | 5955202 | 2012-08-31 13:07:37 +0000 | [diff] [blame] | 1710 | #if GR_CACHE_STATS |
robertphillips@google.com | 5f9f2f5 | 2012-08-22 10:57:05 +0000 | [diff] [blame] | 1711 | void GrContext::printCacheStats() const { |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 1712 | fResourceCache2->printStats(); |
robertphillips@google.com | 5f9f2f5 | 2012-08-22 10:57:05 +0000 | [diff] [blame] | 1713 | } |
| 1714 | #endif |
robertphillips | 754f4e9 | 2014-09-18 13:52:08 -0700 | [diff] [blame] | 1715 | |
| 1716 | #if GR_GPU_STATS |
| 1717 | const GrContext::GPUStats* GrContext::gpuStats() const { |
| 1718 | return fGpu->gpuStats(); |
| 1719 | } |
| 1720 | #endif |
| 1721 | |