bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 1 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 2 | * Copyright 2011 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 8 | #include "GrBackendSemaphore.h" |
bsalomon@google.com | 1fadb20 | 2011-12-12 16:10:08 +0000 | [diff] [blame] | 9 | #include "GrContext.h" |
Brian Salomon | c65aec9 | 2017-03-09 09:03:58 -0500 | [diff] [blame] | 10 | #include "GrClip.h" |
bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 11 | #include "GrContextOptions.h" |
Brian Salomon | c65aec9 | 2017-03-09 09:03:58 -0500 | [diff] [blame] | 12 | #include "GrContextPriv.h" |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 13 | #include "GrDrawingManager.h" |
Robert Phillips | 646e429 | 2017-06-13 12:44:56 -0400 | [diff] [blame] | 14 | #include "GrGpu.h" |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 15 | #include "GrRenderTargetContext.h" |
Brian Salomon | c65aec9 | 2017-03-09 09:03:58 -0500 | [diff] [blame] | 16 | #include "GrRenderTargetProxy.h" |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 17 | #include "GrResourceCache.h" |
bsalomon | d309e7a | 2015-04-30 14:18:54 -0700 | [diff] [blame] | 18 | #include "GrResourceProvider.h" |
Greg Daniel | d85f97d | 2017-03-07 13:37:21 -0500 | [diff] [blame] | 19 | #include "GrSemaphore.h" |
robertphillips@google.com | 72176b2 | 2012-05-23 13:19:12 +0000 | [diff] [blame] | 20 | #include "GrSoftwarePathRenderer.h" |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 21 | #include "GrSurfaceContext.h" |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame] | 22 | #include "GrSurfacePriv.h" |
Robert Phillips | 757914d | 2017-01-25 15:48:30 -0500 | [diff] [blame] | 23 | #include "GrSurfaceProxyPriv.h" |
Robert Phillips | 646e429 | 2017-06-13 12:44:56 -0400 | [diff] [blame] | 24 | #include "GrTexture.h" |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 25 | #include "GrTextureContext.h" |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 26 | #include "GrTracing.h" |
Matt Sarett | 485c499 | 2017-02-14 14:18:27 -0500 | [diff] [blame] | 27 | #include "SkConvertPixels.h" |
Brian Osman | 3b65598 | 2017-03-07 16:58:08 -0500 | [diff] [blame] | 28 | #include "SkGr.h" |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 29 | #include "SkJSONWriter.h" |
Brian Osman | 5127998 | 2017-08-23 10:12:00 -0400 | [diff] [blame] | 30 | #include "SkMakeUnique.h" |
| 31 | #include "SkTaskGroup.h" |
Matt Sarett | c7b2908 | 2017-02-09 16:22:39 -0500 | [diff] [blame] | 32 | #include "SkUnPreMultiplyPriv.h" |
joshualitt | 5478d42 | 2014-11-14 16:00:38 -0800 | [diff] [blame] | 33 | #include "effects/GrConfigConversionEffect.h" |
joshualitt | e804292 | 2015-12-11 06:11:21 -0800 | [diff] [blame] | 34 | #include "text/GrTextBlobCache.h" |
joshualitt | 5478d42 | 2014-11-14 16:00:38 -0800 | [diff] [blame] | 35 | |
Greg Daniel | 02611d9 | 2017-07-25 10:05:01 -0400 | [diff] [blame] | 36 | #include "gl/GrGLGpu.h" |
| 37 | #include "mock/GrMockGpu.h" |
Greg Daniel | b76a72a | 2017-07-13 15:07:54 -0400 | [diff] [blame] | 38 | #ifdef SK_METAL |
| 39 | #include "mtl/GrMtlTrampoline.h" |
| 40 | #endif |
Greg Daniel | 02611d9 | 2017-07-25 10:05:01 -0400 | [diff] [blame] | 41 | #ifdef SK_VULKAN |
| 42 | #include "vk/GrVkGpu.h" |
| 43 | #endif |
Greg Daniel | b76a72a | 2017-07-13 15:07:54 -0400 | [diff] [blame] | 44 | |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 45 | #define ASSERT_OWNED_PROXY(P) \ |
| 46 | SkASSERT(!(P) || !((P)->priv().peekTexture()) || (P)->priv().peekTexture()->getContext() == this) |
Robert Phillips | 7ee385e | 2017-03-30 08:02:11 -0400 | [diff] [blame] | 47 | #define ASSERT_OWNED_PROXY_PRIV(P) \ |
| 48 | SkASSERT(!(P) || !((P)->priv().peekTexture()) || (P)->priv().peekTexture()->getContext() == fContext) |
| 49 | |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 50 | #define ASSERT_OWNED_RESOURCE(R) SkASSERT(!(R) || (R)->getContext() == this) |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 51 | #define ASSERT_SINGLE_OWNER \ |
| 52 | SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(&fSingleOwner);) |
robertphillips | 4fd74ae | 2016-08-03 14:26:53 -0700 | [diff] [blame] | 53 | #define ASSERT_SINGLE_OWNER_PRIV \ |
| 54 | SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(&fContext->fSingleOwner);) |
robertphillips | 7761d61 | 2016-05-16 09:14:53 -0700 | [diff] [blame] | 55 | #define RETURN_IF_ABANDONED if (fDrawingManager->wasAbandoned()) { return; } |
Robert Phillips | 7ee385e | 2017-03-30 08:02:11 -0400 | [diff] [blame] | 56 | #define RETURN_IF_ABANDONED_PRIV if (fContext->fDrawingManager->wasAbandoned()) { return; } |
robertphillips | 7761d61 | 2016-05-16 09:14:53 -0700 | [diff] [blame] | 57 | #define RETURN_FALSE_IF_ABANDONED if (fDrawingManager->wasAbandoned()) { return false; } |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 58 | #define RETURN_FALSE_IF_ABANDONED_PRIV if (fContext->fDrawingManager->wasAbandoned()) { return false; } |
robertphillips | 7761d61 | 2016-05-16 09:14:53 -0700 | [diff] [blame] | 59 | #define RETURN_NULL_IF_ABANDONED if (fDrawingManager->wasAbandoned()) { return nullptr; } |
bsalomon@google.com | bc4b654 | 2011-11-19 13:56:11 +0000 | [diff] [blame] | 60 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 61 | //////////////////////////////////////////////////////////////////////////////// |
| 62 | |
bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 63 | GrContext* GrContext::Create(GrBackend backend, GrBackendContext backendContext) { |
| 64 | GrContextOptions defaultOptions; |
| 65 | return Create(backend, backendContext, defaultOptions); |
| 66 | } |
bsalomon | f28cff7 | 2015-05-22 12:25:41 -0700 | [diff] [blame] | 67 | |
bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 68 | GrContext* GrContext::Create(GrBackend backend, GrBackendContext backendContext, |
| 69 | const GrContextOptions& options) { |
Brian Salomon | 91a3e52 | 2017-06-23 10:58:19 -0400 | [diff] [blame] | 70 | sk_sp<GrContext> context(new GrContext); |
bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 71 | |
Brian Salomon | 91a3e52 | 2017-06-23 10:58:19 -0400 | [diff] [blame] | 72 | if (!context->init(backend, backendContext, options)) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 73 | return nullptr; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 74 | } |
Brian Salomon | 91a3e52 | 2017-06-23 10:58:19 -0400 | [diff] [blame] | 75 | return context.release(); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 76 | } |
| 77 | |
Greg Daniel | 02611d9 | 2017-07-25 10:05:01 -0400 | [diff] [blame] | 78 | sk_sp<GrContext> GrContext::MakeGL(const GrGLInterface* interface) { |
| 79 | GrContextOptions defaultOptions; |
| 80 | return MakeGL(interface, defaultOptions); |
| 81 | } |
| 82 | |
| 83 | sk_sp<GrContext> GrContext::MakeGL(const GrGLInterface* interface, |
| 84 | const GrContextOptions& options) { |
| 85 | sk_sp<GrContext> context(new GrContext); |
| 86 | context->fGpu = GrGLGpu::Create(interface, options, context.get()); |
| 87 | if (!context->fGpu) { |
| 88 | return nullptr; |
| 89 | } |
| 90 | context->fBackend = kOpenGL_GrBackend; |
| 91 | if (!context->init(options)) { |
| 92 | return nullptr; |
| 93 | } |
| 94 | return context; |
| 95 | } |
| 96 | |
| 97 | sk_sp<GrContext> GrContext::MakeMock(const GrMockOptions* mockOptions) { |
| 98 | GrContextOptions defaultOptions; |
| 99 | return MakeMock(mockOptions, defaultOptions); |
| 100 | } |
| 101 | |
| 102 | sk_sp<GrContext> GrContext::MakeMock(const GrMockOptions* mockOptions, |
| 103 | const GrContextOptions& options) { |
| 104 | sk_sp<GrContext> context(new GrContext); |
| 105 | context->fGpu = GrMockGpu::Create(mockOptions, options, context.get()); |
| 106 | if (!context->fGpu) { |
| 107 | return nullptr; |
| 108 | } |
| 109 | context->fBackend = kMock_GrBackend; |
| 110 | if (!context->init(options)) { |
| 111 | return nullptr; |
| 112 | } |
| 113 | return context; |
| 114 | } |
| 115 | |
| 116 | #ifdef SK_VULKAN |
| 117 | sk_sp<GrContext> GrContext::MakeVulkan(const GrVkBackendContext* backendContext) { |
| 118 | GrContextOptions defaultOptions; |
| 119 | return MakeVulkan(backendContext, defaultOptions); |
| 120 | } |
| 121 | |
| 122 | sk_sp<GrContext> GrContext::MakeVulkan(const GrVkBackendContext* backendContext, |
| 123 | const GrContextOptions& options) { |
| 124 | sk_sp<GrContext> context(new GrContext); |
| 125 | context->fGpu = GrVkGpu::Create(backendContext, options, context.get()); |
| 126 | if (!context->fGpu) { |
| 127 | return nullptr; |
| 128 | } |
| 129 | context->fBackend = kVulkan_GrBackend; |
| 130 | if (!context->init(options)) { |
| 131 | return nullptr; |
| 132 | } |
| 133 | return context; |
| 134 | } |
| 135 | #endif |
| 136 | |
Greg Daniel | b76a72a | 2017-07-13 15:07:54 -0400 | [diff] [blame] | 137 | #ifdef SK_METAL |
Greg Daniel | 02611d9 | 2017-07-25 10:05:01 -0400 | [diff] [blame] | 138 | sk_sp<GrContext> GrContext::MakeMetal(void* device, void* queue) { |
| 139 | GrContextOptions defaultOptions; |
| 140 | return MakeMetal(device, queue, defaultOptions); |
| 141 | } |
| 142 | |
Greg Daniel | b76a72a | 2017-07-13 15:07:54 -0400 | [diff] [blame] | 143 | sk_sp<GrContext> GrContext::MakeMetal(void* device, void* queue, const GrContextOptions& options) { |
| 144 | sk_sp<GrContext> context(new GrContext); |
| 145 | context->fGpu = GrMtlTrampoline::CreateGpu(context.get(), options, device, queue); |
| 146 | if (!context->fGpu) { |
| 147 | return nullptr; |
| 148 | } |
| 149 | context->fBackend = kMetal_GrBackend; |
| 150 | if (!context->init(options)) { |
| 151 | return nullptr; |
| 152 | } |
| 153 | return context; |
| 154 | } |
| 155 | #endif |
| 156 | |
joshualitt | 0acd0d3 | 2015-05-07 08:23:19 -0700 | [diff] [blame] | 157 | static int32_t gNextID = 1; |
| 158 | static int32_t next_id() { |
| 159 | int32_t id; |
| 160 | do { |
| 161 | id = sk_atomic_inc(&gNextID); |
| 162 | } while (id == SK_InvalidGenID); |
| 163 | return id; |
| 164 | } |
| 165 | |
bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 166 | GrContext::GrContext() : fUniqueID(next_id()) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 167 | fGpu = nullptr; |
| 168 | fCaps = nullptr; |
| 169 | fResourceCache = nullptr; |
| 170 | fResourceProvider = nullptr; |
Brian Salomon | f856fd1 | 2016-12-16 14:24:34 -0500 | [diff] [blame] | 171 | fAtlasGlyphCache = nullptr; |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 172 | } |
| 173 | |
bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 174 | bool GrContext::init(GrBackend backend, GrBackendContext backendContext, |
| 175 | const GrContextOptions& options) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 176 | ASSERT_SINGLE_OWNER |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 177 | SkASSERT(!fGpu); |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 178 | |
Greg Daniel | fc978fd | 2017-04-13 09:54:12 -0400 | [diff] [blame] | 179 | fBackend = backend; |
| 180 | |
bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 181 | fGpu = GrGpu::Create(backend, backendContext, options, this); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 182 | if (!fGpu) { |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 183 | return false; |
| 184 | } |
Greg Daniel | b76a72a | 2017-07-13 15:07:54 -0400 | [diff] [blame] | 185 | return this->init(options); |
| 186 | } |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 187 | |
Greg Daniel | b76a72a | 2017-07-13 15:07:54 -0400 | [diff] [blame] | 188 | bool GrContext::init(const GrContextOptions& options) { |
| 189 | ASSERT_SINGLE_OWNER |
bsalomon | 7622863 | 2015-05-29 08:02:10 -0700 | [diff] [blame] | 190 | fCaps = SkRef(fGpu->caps()); |
Brian Osman | 13dddce | 2017-05-09 13:19:50 -0400 | [diff] [blame] | 191 | fResourceCache = new GrResourceCache(fCaps, fUniqueID); |
joshualitt | 6d0872d | 2016-01-11 08:27:48 -0800 | [diff] [blame] | 192 | fResourceProvider = new GrResourceProvider(fGpu, fResourceCache, &fSingleOwner); |
commit-bot@chromium.org | 1836d33 | 2013-07-16 22:55:03 +0000 | [diff] [blame] | 193 | |
Brian Osman | 46da1cc | 2017-02-14 14:15:48 -0500 | [diff] [blame] | 194 | fDisableGpuYUVConversion = options.fDisableGpuYUVConversion; |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 195 | fDidTestPMConversions = false; |
| 196 | |
bsalomon | 6b2552f | 2016-09-15 13:50:26 -0700 | [diff] [blame] | 197 | GrPathRendererChain::Options prcOptions; |
bsalomon | 39ef7fb | 2016-09-21 11:16:05 -0700 | [diff] [blame] | 198 | prcOptions.fAllowPathMaskCaching = options.fAllowPathMaskCaching; |
Brian Osman | 195c05b | 2017-08-30 15:14:04 -0400 | [diff] [blame] | 199 | #if GR_TEST_UTILS |
csmartdalton | 008b9d8 | 2017-02-22 12:00:42 -0700 | [diff] [blame] | 200 | prcOptions.fGpuPathRenderers = options.fGpuPathRenderers; |
Brian Osman | 195c05b | 2017-08-30 15:14:04 -0400 | [diff] [blame] | 201 | #endif |
Brian Osman | b350ae2 | 2017-08-29 16:15:39 -0400 | [diff] [blame] | 202 | if (options.fDisableDistanceFieldPaths) { |
Brian Osman | 195c05b | 2017-08-30 15:14:04 -0400 | [diff] [blame] | 203 | prcOptions.fGpuPathRenderers &= ~GpuPathRenderers::kSmall; |
Brian Osman | b350ae2 | 2017-08-29 16:15:39 -0400 | [diff] [blame] | 204 | } |
Robert Phillips | 3ea1798 | 2017-06-02 12:43:04 -0400 | [diff] [blame] | 205 | fDrawingManager.reset(new GrDrawingManager(this, prcOptions, &fSingleOwner)); |
joshualitt | 7c3a2f8 | 2015-03-31 13:32:05 -0700 | [diff] [blame] | 206 | |
Eric Karl | 6d34228 | 2017-05-03 17:08:42 -0700 | [diff] [blame] | 207 | fAtlasGlyphCache = new GrAtlasGlyphCache(this, options.fGlyphCacheTextureMaximumBytes); |
Jim Van Verth | 106b5c4 | 2017-09-26 12:45:29 -0400 | [diff] [blame^] | 208 | this->contextPriv().addOnFlushCallbackObject(fAtlasGlyphCache); |
joshualitt | b7133be | 2015-04-08 09:08:31 -0700 | [diff] [blame] | 209 | |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 210 | fTextBlobCache.reset(new GrTextBlobCache(TextBlobCacheOverBudgetCB, this)); |
Brian Salomon | 91a3e52 | 2017-06-23 10:58:19 -0400 | [diff] [blame] | 211 | |
Brian Osman | 5127998 | 2017-08-23 10:12:00 -0400 | [diff] [blame] | 212 | if (options.fExecutor) { |
| 213 | fTaskGroup = skstd::make_unique<SkTaskGroup>(*options.fExecutor); |
| 214 | } |
| 215 | |
Brian Salomon | 91a3e52 | 2017-06-23 10:58:19 -0400 | [diff] [blame] | 216 | return true; |
bsalomon@google.com | c0af317 | 2012-06-15 14:10:09 +0000 | [diff] [blame] | 217 | } |
| 218 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 219 | GrContext::~GrContext() { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 220 | ASSERT_SINGLE_OWNER |
| 221 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 222 | if (!fGpu) { |
bsalomon | 7622863 | 2015-05-29 08:02:10 -0700 | [diff] [blame] | 223 | SkASSERT(!fCaps); |
bsalomon@google.com | 733c062 | 2013-04-24 17:59:32 +0000 | [diff] [blame] | 224 | return; |
| 225 | } |
| 226 | |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 227 | this->flush(); |
robertphillips@google.com | 5acc0e3 | 2012-05-17 12:01:02 +0000 | [diff] [blame] | 228 | |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 229 | fDrawingManager->cleanup(); |
robertphillips | 2334fb6 | 2015-06-17 05:43:33 -0700 | [diff] [blame] | 230 | |
robertphillips@google.com | 950b1b0 | 2013-10-21 17:37:28 +0000 | [diff] [blame] | 231 | for (int i = 0; i < fCleanUpData.count(); ++i) { |
| 232 | (*fCleanUpData[i].fFunc)(this, fCleanUpData[i].fInfo); |
| 233 | } |
| 234 | |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 235 | delete fResourceProvider; |
| 236 | delete fResourceCache; |
Brian Salomon | f856fd1 | 2016-12-16 14:24:34 -0500 | [diff] [blame] | 237 | delete fAtlasGlyphCache; |
robertphillips@google.com | f6747b0 | 2012-06-12 00:32:28 +0000 | [diff] [blame] | 238 | |
bsalomon@google.com | 205d460 | 2011-04-25 12:43:45 +0000 | [diff] [blame] | 239 | fGpu->unref(); |
bsalomon | 7622863 | 2015-05-29 08:02:10 -0700 | [diff] [blame] | 240 | fCaps->unref(); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 241 | } |
| 242 | |
bungeman | 6bd5284 | 2016-10-27 09:30:08 -0700 | [diff] [blame] | 243 | sk_sp<GrContextThreadSafeProxy> GrContext::threadSafeProxy() { |
bsalomon | 41b952c | 2016-03-11 06:46:33 -0800 | [diff] [blame] | 244 | if (!fThreadSafeProxy) { |
bungeman | 6bd5284 | 2016-10-27 09:30:08 -0700 | [diff] [blame] | 245 | fThreadSafeProxy.reset(new GrContextThreadSafeProxy(sk_ref_sp(fCaps), this->uniqueID())); |
bsalomon | 41b952c | 2016-03-11 06:46:33 -0800 | [diff] [blame] | 246 | } |
bungeman | 6bd5284 | 2016-10-27 09:30:08 -0700 | [diff] [blame] | 247 | return fThreadSafeProxy; |
bsalomon | 41b952c | 2016-03-11 06:46:33 -0800 | [diff] [blame] | 248 | } |
| 249 | |
bsalomon | 2354f84 | 2014-07-28 13:48:36 -0700 | [diff] [blame] | 250 | void GrContext::abandonContext() { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 251 | ASSERT_SINGLE_OWNER |
| 252 | |
bsalomon | d309e7a | 2015-04-30 14:18:54 -0700 | [diff] [blame] | 253 | fResourceProvider->abandon(); |
robertphillips | 0dfa62c | 2015-11-16 06:23:31 -0800 | [diff] [blame] | 254 | |
| 255 | // Need to abandon the drawing manager first so all the render targets |
| 256 | // will be released/forgotten before they too are abandoned. |
| 257 | fDrawingManager->abandon(); |
| 258 | |
bsalomon@google.com | 205d460 | 2011-04-25 12:43:45 +0000 | [diff] [blame] | 259 | // abandon first to so destructors |
| 260 | // don't try to free the resources in the API. |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 261 | fResourceCache->abandonAll(); |
bsalomon | c8dc1f7 | 2014-08-21 13:02:13 -0700 | [diff] [blame] | 262 | |
bsalomon | 6e2aad4 | 2016-04-01 11:54:31 -0700 | [diff] [blame] | 263 | fGpu->disconnect(GrGpu::DisconnectType::kAbandon); |
| 264 | |
Brian Salomon | f856fd1 | 2016-12-16 14:24:34 -0500 | [diff] [blame] | 265 | fAtlasGlyphCache->freeAll(); |
bsalomon | 6e2aad4 | 2016-04-01 11:54:31 -0700 | [diff] [blame] | 266 | fTextBlobCache->freeAll(); |
| 267 | } |
| 268 | |
| 269 | void GrContext::releaseResourcesAndAbandonContext() { |
| 270 | ASSERT_SINGLE_OWNER |
| 271 | |
| 272 | fResourceProvider->abandon(); |
| 273 | |
| 274 | // Need to abandon the drawing manager first so all the render targets |
| 275 | // will be released/forgotten before they too are abandoned. |
| 276 | fDrawingManager->abandon(); |
| 277 | |
| 278 | // Release all resources in the backend 3D API. |
| 279 | fResourceCache->releaseAll(); |
| 280 | |
| 281 | fGpu->disconnect(GrGpu::DisconnectType::kCleanup); |
bsalomon@google.com | 205d460 | 2011-04-25 12:43:45 +0000 | [diff] [blame] | 282 | |
Brian Salomon | f856fd1 | 2016-12-16 14:24:34 -0500 | [diff] [blame] | 283 | fAtlasGlyphCache->freeAll(); |
joshualitt | 26ffc00 | 2015-04-16 11:24:04 -0700 | [diff] [blame] | 284 | fTextBlobCache->freeAll(); |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 285 | } |
| 286 | |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 287 | void GrContext::resetContext(uint32_t state) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 288 | ASSERT_SINGLE_OWNER |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 289 | fGpu->markContextDirty(state); |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | void GrContext::freeGpuResources() { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 293 | ASSERT_SINGLE_OWNER |
| 294 | |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 295 | this->flush(); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 296 | |
Brian Salomon | f856fd1 | 2016-12-16 14:24:34 -0500 | [diff] [blame] | 297 | fAtlasGlyphCache->freeAll(); |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 298 | |
| 299 | fDrawingManager->freeGpuResources(); |
bsalomon | 3033b9f | 2015-04-13 11:09:56 -0700 | [diff] [blame] | 300 | |
| 301 | fResourceCache->purgeAllUnlocked(); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 302 | } |
| 303 | |
Brian Salomon | 5e15085 | 2017-03-22 14:53:13 -0400 | [diff] [blame] | 304 | void GrContext::purgeResourcesNotUsedInMs(std::chrono::milliseconds ms) { |
| 305 | ASSERT_SINGLE_OWNER |
| 306 | fResourceCache->purgeResourcesNotUsedSince(GrStdSteadyClock::now() - ms); |
| 307 | } |
| 308 | |
Derek Sollenberger | 5480a18 | 2017-05-25 16:43:59 -0400 | [diff] [blame] | 309 | void GrContext::purgeUnlockedResources(size_t bytesToPurge, bool preferScratchResources) { |
| 310 | ASSERT_SINGLE_OWNER |
| 311 | fResourceCache->purgeUnlockedResources(bytesToPurge, preferScratchResources); |
| 312 | } |
| 313 | |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 314 | void GrContext::getResourceCacheUsage(int* resourceCount, size_t* resourceBytes) const { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 315 | ASSERT_SINGLE_OWNER |
| 316 | |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 317 | if (resourceCount) { |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 318 | *resourceCount = fResourceCache->getBudgetedResourceCount(); |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 319 | } |
| 320 | if (resourceBytes) { |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 321 | *resourceBytes = fResourceCache->getBudgetedResourceBytes(); |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 322 | } |
commit-bot@chromium.org | d8a57af | 2014-03-19 21:19:16 +0000 | [diff] [blame] | 323 | } |
| 324 | |
Derek Sollenberger | ee47914 | 2017-05-24 11:41:33 -0400 | [diff] [blame] | 325 | size_t GrContext::getResourceCachePurgeableBytes() const { |
| 326 | ASSERT_SINGLE_OWNER |
| 327 | return fResourceCache->getPurgeableBytes(); |
| 328 | } |
| 329 | |
bsalomon@google.com | fea37b5 | 2011-04-25 15:51:06 +0000 | [diff] [blame] | 330 | //////////////////////////////////////////////////////////////////////////////// |
| 331 | |
joshualitt | 0db6dfa | 2015-04-10 07:01:30 -0700 | [diff] [blame] | 332 | void GrContext::TextBlobCacheOverBudgetCB(void* data) { |
| 333 | SkASSERT(data); |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 334 | // TextBlobs are drawn at the SkGpuDevice level, therefore they cannot rely on |
| 335 | // GrRenderTargetContext to perform a necessary flush. The solution is to move drawText calls |
| 336 | // to below the GrContext level, but this is not trivial because they call drawPath on |
| 337 | // SkGpuDevice. |
joshualitt | 0db6dfa | 2015-04-10 07:01:30 -0700 | [diff] [blame] | 338 | GrContext* context = reinterpret_cast<GrContext*>(data); |
| 339 | context->flush(); |
| 340 | } |
| 341 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 342 | //////////////////////////////////////////////////////////////////////////////// |
| 343 | |
bsalomon | b77a907 | 2016-09-07 10:02:04 -0700 | [diff] [blame] | 344 | void GrContext::flush() { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 345 | ASSERT_SINGLE_OWNER |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 346 | RETURN_IF_ABANDONED |
Robert Phillips | 7ee385e | 2017-03-30 08:02:11 -0400 | [diff] [blame] | 347 | |
| 348 | fDrawingManager->flush(nullptr); |
| 349 | } |
| 350 | |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 351 | GrSemaphoresSubmitted GrContext::flushAndSignalSemaphores(int numSemaphores, |
| 352 | GrBackendSemaphore signalSemaphores[]) { |
| 353 | ASSERT_SINGLE_OWNER |
| 354 | if (fDrawingManager->wasAbandoned()) { return GrSemaphoresSubmitted::kNo; } |
| 355 | |
| 356 | return fDrawingManager->flush(nullptr, numSemaphores, signalSemaphores); |
| 357 | } |
| 358 | |
Robert Phillips | 7ee385e | 2017-03-30 08:02:11 -0400 | [diff] [blame] | 359 | void GrContextPriv::flush(GrSurfaceProxy* proxy) { |
| 360 | ASSERT_SINGLE_OWNER_PRIV |
| 361 | RETURN_IF_ABANDONED_PRIV |
| 362 | ASSERT_OWNED_PROXY_PRIV(proxy); |
| 363 | |
| 364 | fContext->fDrawingManager->flush(proxy); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 365 | } |
| 366 | |
bsalomon | 81beccc | 2014-10-13 12:32:55 -0700 | [diff] [blame] | 367 | bool sw_convert_to_premul(GrPixelConfig srcConfig, int width, int height, size_t inRowBytes, |
| 368 | const void* inPixels, size_t outRowBytes, void* outPixels) { |
Matt Sarett | c7b2908 | 2017-02-09 16:22:39 -0500 | [diff] [blame] | 369 | SkColorType colorType; |
| 370 | if (!GrPixelConfigToColorType(srcConfig, &colorType) || |
| 371 | 4 != SkColorTypeBytesPerPixel(colorType)) |
| 372 | { |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 373 | return false; |
| 374 | } |
bsalomon | 81beccc | 2014-10-13 12:32:55 -0700 | [diff] [blame] | 375 | |
Matt Sarett | c7b2908 | 2017-02-09 16:22:39 -0500 | [diff] [blame] | 376 | for (int y = 0; y < height; y++) { |
| 377 | SkOpts::RGBA_to_rgbA((uint32_t*) outPixels, inPixels, width); |
| 378 | outPixels = SkTAddOffset<void>(outPixels, outRowBytes); |
| 379 | inPixels = SkTAddOffset<const void>(inPixels, inRowBytes); |
| 380 | } |
bsalomon | 81beccc | 2014-10-13 12:32:55 -0700 | [diff] [blame] | 381 | |
Matt Sarett | c7b2908 | 2017-02-09 16:22:39 -0500 | [diff] [blame] | 382 | return true; |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 383 | } |
| 384 | |
Brian Osman | d2ca59a | 2017-04-13 14:03:57 -0400 | [diff] [blame] | 385 | static bool valid_premul_config(GrPixelConfig config) { |
Brian Osman | ce42551 | 2017-03-22 14:37:50 -0400 | [diff] [blame] | 386 | return GrPixelConfigIs8888Unorm(config) || kRGBA_half_GrPixelConfig == config; |
| 387 | } |
| 388 | |
Brian Osman | d2ca59a | 2017-04-13 14:03:57 -0400 | [diff] [blame] | 389 | static bool valid_pixel_conversion(GrPixelConfig srcConfig, GrPixelConfig dstConfig, |
| 390 | bool premulConversion) { |
| 391 | // We don't allow conversion between integer configs and float/fixed configs. |
| 392 | if (GrPixelConfigIsSint(srcConfig) != GrPixelConfigIsSint(dstConfig)) { |
| 393 | return false; |
| 394 | } |
| 395 | |
| 396 | // We only allow premul <-> unpremul conversions for some formats |
| 397 | if (premulConversion && (!valid_premul_config(srcConfig) || !valid_premul_config(dstConfig))) { |
| 398 | return false; |
| 399 | } |
| 400 | |
| 401 | return true; |
| 402 | } |
| 403 | |
Brian Osman | 409e74f | 2017-04-17 11:48:28 -0400 | [diff] [blame] | 404 | static bool pm_upm_must_round_trip(GrPixelConfig config, SkColorSpace* colorSpace) { |
| 405 | return !colorSpace && |
| 406 | (kRGBA_8888_GrPixelConfig == config || kBGRA_8888_GrPixelConfig == config); |
| 407 | } |
| 408 | |
Robert Phillips | f41c22f | 2017-04-18 07:48:58 -0400 | [diff] [blame] | 409 | bool GrContextPriv::writeSurfacePixels(GrSurfaceContext* dst, |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 410 | int left, int top, int width, int height, |
| 411 | GrPixelConfig srcConfig, SkColorSpace* srcColorSpace, |
| 412 | const void* buffer, size_t rowBytes, |
| 413 | uint32_t pixelOpsFlags) { |
Brian Osman | b62ea22 | 2016-12-22 11:12:16 -0500 | [diff] [blame] | 414 | // TODO: Color space conversion |
| 415 | |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 416 | ASSERT_SINGLE_OWNER_PRIV |
| 417 | RETURN_FALSE_IF_ABANDONED_PRIV |
Robert Phillips | f41c22f | 2017-04-18 07:48:58 -0400 | [diff] [blame] | 418 | SkASSERT(dst); |
| 419 | ASSERT_OWNED_PROXY_PRIV(dst->asSurfaceProxy()); |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 420 | GR_CREATE_TRACE_MARKER_CONTEXT("GrContextPriv", "writeSurfacePixels", fContext); |
bsalomon | 6c6f658 | 2015-09-10 08:12:46 -0700 | [diff] [blame] | 421 | |
Robert Phillips | eee4d6e | 2017-06-05 09:26:07 -0400 | [diff] [blame] | 422 | if (!dst->asSurfaceProxy()->instantiate(fContext->resourceProvider())) { |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 423 | return false; |
| 424 | } |
| 425 | |
Robert Phillips | 16d8ec6 | 2017-07-27 16:16:25 -0400 | [diff] [blame] | 426 | GrSurfaceProxy* dstProxy = dst->asSurfaceProxy(); |
| 427 | GrSurface* dstSurface = dstProxy->priv().peekSurface(); |
Robert Phillips | eee4d6e | 2017-06-05 09:26:07 -0400 | [diff] [blame] | 428 | |
Brian Osman | d2ca59a | 2017-04-13 14:03:57 -0400 | [diff] [blame] | 429 | // The src is unpremul but the dst is premul -> premul the src before or as part of the write |
Brian Osman | 409e74f | 2017-04-17 11:48:28 -0400 | [diff] [blame] | 430 | const bool premul = SkToBool(kUnpremul_PixelOpsFlag & pixelOpsFlags); |
Robert Phillips | 16d8ec6 | 2017-07-27 16:16:25 -0400 | [diff] [blame] | 431 | if (!valid_pixel_conversion(srcConfig, dstProxy->config(), premul)) { |
Brian Osman | d2ca59a | 2017-04-13 14:03:57 -0400 | [diff] [blame] | 432 | return false; |
| 433 | } |
| 434 | |
Brian Osman | 409e74f | 2017-04-17 11:48:28 -0400 | [diff] [blame] | 435 | // We need to guarantee round-trip conversion if we are reading and writing 8888 non-sRGB data, |
| 436 | // without any color spaces attached, and the caller wants us to premul. |
Robert Phillips | f41c22f | 2017-04-18 07:48:58 -0400 | [diff] [blame] | 437 | bool useConfigConversionEffect = |
| 438 | premul && |
| 439 | pm_upm_must_round_trip(srcConfig, srcColorSpace) && |
Robert Phillips | 16d8ec6 | 2017-07-27 16:16:25 -0400 | [diff] [blame] | 440 | pm_upm_must_round_trip(dstProxy->config(), dst->getColorSpace()); |
Brian Osman | 409e74f | 2017-04-17 11:48:28 -0400 | [diff] [blame] | 441 | |
| 442 | // Are we going to try to premul as part of a draw? For the non-legacy case, we always allow |
| 443 | // this. GrConfigConversionEffect fails on some GPUs, so only allow this if it works perfectly. |
| 444 | bool premulOnGpu = premul && |
| 445 | (!useConfigConversionEffect || fContext->validPMUPMConversionExists()); |
bsalomon | 81beccc | 2014-10-13 12:32:55 -0700 | [diff] [blame] | 446 | |
bsalomon | e8d21e8 | 2015-07-16 08:23:13 -0700 | [diff] [blame] | 447 | // Trim the params here so that if we wind up making a temporary surface it can be as small as |
bsalomon | f067451 | 2015-07-28 13:26:15 -0700 | [diff] [blame] | 448 | // necessary and because GrGpu::getWritePixelsInfo requires it. |
Robert Phillips | f41c22f | 2017-04-18 07:48:58 -0400 | [diff] [blame] | 449 | if (!GrSurfacePriv::AdjustWritePixelParams(dstSurface->width(), dstSurface->height(), |
bsalomon | e8d21e8 | 2015-07-16 08:23:13 -0700 | [diff] [blame] | 450 | GrBytesPerPixel(srcConfig), &left, &top, &width, |
| 451 | &height, &buffer, &rowBytes)) { |
| 452 | return false; |
| 453 | } |
| 454 | |
Brian Osman | 409e74f | 2017-04-17 11:48:28 -0400 | [diff] [blame] | 455 | GrGpu::DrawPreference drawPreference = premulOnGpu ? GrGpu::kCallerPrefersDraw_DrawPreference |
| 456 | : GrGpu::kNoDraw_DrawPreference; |
bsalomon | f067451 | 2015-07-28 13:26:15 -0700 | [diff] [blame] | 457 | GrGpu::WritePixelTempDrawInfo tempDrawInfo; |
Robert Phillips | b0e93a2 | 2017-08-29 08:26:54 -0400 | [diff] [blame] | 458 | if (!fContext->fGpu->getWritePixelsInfo(dstSurface, dstProxy->origin(), width, height, |
Robert Phillips | 16d8ec6 | 2017-07-27 16:16:25 -0400 | [diff] [blame] | 459 | srcConfig, &drawPreference, &tempDrawInfo)) { |
bsalomon | f067451 | 2015-07-28 13:26:15 -0700 | [diff] [blame] | 460 | return false; |
| 461 | } |
| 462 | |
Robert Phillips | f41c22f | 2017-04-18 07:48:58 -0400 | [diff] [blame] | 463 | if (!(kDontFlush_PixelOpsFlag & pixelOpsFlags) && dstSurface->surfacePriv().hasPendingIO()) { |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 464 | this->flush(nullptr); // MDB TODO: tighten this |
bsalomon | f067451 | 2015-07-28 13:26:15 -0700 | [diff] [blame] | 465 | } |
| 466 | |
Robert Phillips | 2f49314 | 2017-03-02 18:18:38 -0500 | [diff] [blame] | 467 | sk_sp<GrTextureProxy> tempProxy; |
bsalomon | f067451 | 2015-07-28 13:26:15 -0700 | [diff] [blame] | 468 | if (GrGpu::kNoDraw_DrawPreference != drawPreference) { |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 469 | tempProxy = GrSurfaceProxy::MakeDeferred(fContext->resourceProvider(), |
Robert Phillips | 2f49314 | 2017-03-02 18:18:38 -0500 | [diff] [blame] | 470 | tempDrawInfo.fTempSurfaceDesc, |
| 471 | SkBackingFit::kApprox, |
| 472 | SkBudgeted::kYes); |
| 473 | if (!tempProxy && GrGpu::kRequireDraw_DrawPreference == drawPreference) { |
bsalomon | f067451 | 2015-07-28 13:26:15 -0700 | [diff] [blame] | 474 | return false; |
| 475 | } |
| 476 | } |
| 477 | |
| 478 | // temp buffer for doing sw premul conversion, if needed. |
| 479 | SkAutoSTMalloc<128 * 128, uint32_t> tmpPixels(0); |
Brian Osman | 409e74f | 2017-04-17 11:48:28 -0400 | [diff] [blame] | 480 | // We need to do sw premul if we were unable to create a RT for drawing, or if we can't do the |
| 481 | // premul on the GPU |
| 482 | if (premul && (!tempProxy || !premulOnGpu)) { |
| 483 | size_t tmpRowBytes = 4 * width; |
| 484 | tmpPixels.reset(width * height); |
| 485 | if (!sw_convert_to_premul(srcConfig, width, height, rowBytes, buffer, tmpRowBytes, |
| 486 | tmpPixels.get())) { |
| 487 | return false; |
bsalomon | f067451 | 2015-07-28 13:26:15 -0700 | [diff] [blame] | 488 | } |
Brian Osman | 409e74f | 2017-04-17 11:48:28 -0400 | [diff] [blame] | 489 | rowBytes = tmpRowBytes; |
| 490 | buffer = tmpPixels.get(); |
bsalomon | f067451 | 2015-07-28 13:26:15 -0700 | [diff] [blame] | 491 | } |
Brian Osman | 409e74f | 2017-04-17 11:48:28 -0400 | [diff] [blame] | 492 | |
| 493 | if (tempProxy) { |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 494 | auto fp = GrSimpleTextureEffect::Make(tempProxy, nullptr, SkMatrix::I()); |
Brian Osman | 409e74f | 2017-04-17 11:48:28 -0400 | [diff] [blame] | 495 | if (premulOnGpu) { |
| 496 | fp = fContext->createUPMToPMEffect(std::move(fp), useConfigConversionEffect); |
bsalomon | 81beccc | 2014-10-13 12:32:55 -0700 | [diff] [blame] | 497 | } |
Brian Osman | 409e74f | 2017-04-17 11:48:28 -0400 | [diff] [blame] | 498 | fp = GrFragmentProcessor::SwizzleOutput(std::move(fp), tempDrawInfo.fSwizzle); |
Robert Phillips | 1c9686b | 2017-06-30 08:40:28 -0400 | [diff] [blame] | 499 | if (!fp) { |
| 500 | return false; |
| 501 | } |
Brian Osman | 409e74f | 2017-04-17 11:48:28 -0400 | [diff] [blame] | 502 | |
| 503 | if (tempProxy->priv().hasPendingIO()) { |
| 504 | this->flush(tempProxy.get()); |
| 505 | } |
Robert Phillips | eee4d6e | 2017-06-05 09:26:07 -0400 | [diff] [blame] | 506 | if (!tempProxy->instantiate(fContext->resourceProvider())) { |
Brian Osman | 409e74f | 2017-04-17 11:48:28 -0400 | [diff] [blame] | 507 | return false; |
| 508 | } |
Robert Phillips | eee4d6e | 2017-06-05 09:26:07 -0400 | [diff] [blame] | 509 | GrTexture* texture = tempProxy->priv().peekTexture(); |
Robert Phillips | b0e93a2 | 2017-08-29 08:26:54 -0400 | [diff] [blame] | 510 | if (!fContext->fGpu->writePixels(texture, tempProxy->origin(), 0, 0, width, height, |
| 511 | tempDrawInfo.fWriteConfig, buffer, rowBytes)) { |
Brian Osman | 409e74f | 2017-04-17 11:48:28 -0400 | [diff] [blame] | 512 | return false; |
| 513 | } |
| 514 | SkMatrix matrix; |
| 515 | matrix.setTranslate(SkIntToScalar(left), SkIntToScalar(top)); |
Robert Phillips | f41c22f | 2017-04-18 07:48:58 -0400 | [diff] [blame] | 516 | GrRenderTargetContext* renderTargetContext = dst->asRenderTargetContext(); |
Brian Osman | 409e74f | 2017-04-17 11:48:28 -0400 | [diff] [blame] | 517 | if (!renderTargetContext) { |
| 518 | return false; |
| 519 | } |
| 520 | GrPaint paint; |
| 521 | paint.addColorFragmentProcessor(std::move(fp)); |
| 522 | paint.setPorterDuffXPFactory(SkBlendMode::kSrc); |
Brian Osman | 7ab6a7f | 2017-04-25 15:01:46 -0400 | [diff] [blame] | 523 | paint.setAllowSRGBInputs(SkToBool(dst->getColorSpace()) || |
| 524 | GrPixelConfigIsSRGB(renderTargetContext->config())); |
Brian Osman | 409e74f | 2017-04-17 11:48:28 -0400 | [diff] [blame] | 525 | SkRect rect = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(height)); |
| 526 | renderTargetContext->drawRect(GrNoClip(), std::move(paint), GrAA::kNo, matrix, rect, |
| 527 | nullptr); |
| 528 | |
| 529 | if (kFlushWrites_PixelOp & pixelOpsFlags) { |
| 530 | this->flushSurfaceWrites(renderTargetContext->asRenderTargetProxy()); |
| 531 | } |
| 532 | } else { |
Robert Phillips | b0e93a2 | 2017-08-29 08:26:54 -0400 | [diff] [blame] | 533 | return fContext->fGpu->writePixels(dstSurface, dstProxy->origin(), left, top, width, |
| 534 | height, srcConfig, buffer, rowBytes); |
bsalomon | 81beccc | 2014-10-13 12:32:55 -0700 | [diff] [blame] | 535 | } |
bsalomon | 81beccc | 2014-10-13 12:32:55 -0700 | [diff] [blame] | 536 | return true; |
| 537 | } |
bsalomon@google.com | a91e923 | 2012-02-23 15:39:54 +0000 | [diff] [blame] | 538 | |
Robert Phillips | f41c22f | 2017-04-18 07:48:58 -0400 | [diff] [blame] | 539 | bool GrContextPriv::readSurfacePixels(GrSurfaceContext* src, |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 540 | int left, int top, int width, int height, |
| 541 | GrPixelConfig dstConfig, SkColorSpace* dstColorSpace, |
| 542 | void* buffer, size_t rowBytes, uint32_t flags) { |
Brian Osman | b62ea22 | 2016-12-22 11:12:16 -0500 | [diff] [blame] | 543 | // TODO: Color space conversion |
| 544 | |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 545 | ASSERT_SINGLE_OWNER_PRIV |
| 546 | RETURN_FALSE_IF_ABANDONED_PRIV |
Robert Phillips | f41c22f | 2017-04-18 07:48:58 -0400 | [diff] [blame] | 547 | SkASSERT(src); |
| 548 | ASSERT_OWNED_PROXY_PRIV(src->asSurfaceProxy()); |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 549 | GR_CREATE_TRACE_MARKER_CONTEXT("GrContextPriv", "readSurfacePixels", fContext); |
bsalomon | 32ab260 | 2015-09-09 18:57:49 -0700 | [diff] [blame] | 550 | |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 551 | // MDB TODO: delay this instantiation until later in the method |
Robert Phillips | eee4d6e | 2017-06-05 09:26:07 -0400 | [diff] [blame] | 552 | if (!src->asSurfaceProxy()->instantiate(fContext->resourceProvider())) { |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 553 | return false; |
| 554 | } |
| 555 | |
Robert Phillips | 16d8ec6 | 2017-07-27 16:16:25 -0400 | [diff] [blame] | 556 | GrSurfaceProxy* srcProxy = src->asSurfaceProxy(); |
| 557 | GrSurface* srcSurface = srcProxy->priv().peekSurface(); |
Robert Phillips | eee4d6e | 2017-06-05 09:26:07 -0400 | [diff] [blame] | 558 | |
Brian Osman | d2ca59a | 2017-04-13 14:03:57 -0400 | [diff] [blame] | 559 | // The src is premul but the dst is unpremul -> unpremul the src after or as part of the read |
| 560 | bool unpremul = SkToBool(kUnpremul_PixelOpsFlag & flags); |
Robert Phillips | 16d8ec6 | 2017-07-27 16:16:25 -0400 | [diff] [blame] | 561 | if (!valid_pixel_conversion(srcProxy->config(), dstConfig, unpremul)) { |
Brian Osman | d2ca59a | 2017-04-13 14:03:57 -0400 | [diff] [blame] | 562 | return false; |
| 563 | } |
| 564 | |
Brian Osman | 409e74f | 2017-04-17 11:48:28 -0400 | [diff] [blame] | 565 | // We need to guarantee round-trip conversion if we are reading and writing 8888 non-sRGB data, |
| 566 | // without any color spaces attached, and the caller wants us to unpremul. |
Robert Phillips | f41c22f | 2017-04-18 07:48:58 -0400 | [diff] [blame] | 567 | bool useConfigConversionEffect = |
| 568 | unpremul && |
Robert Phillips | 16d8ec6 | 2017-07-27 16:16:25 -0400 | [diff] [blame] | 569 | pm_upm_must_round_trip(srcProxy->config(), src->getColorSpace()) && |
Robert Phillips | f41c22f | 2017-04-18 07:48:58 -0400 | [diff] [blame] | 570 | pm_upm_must_round_trip(dstConfig, dstColorSpace); |
Brian Osman | 409e74f | 2017-04-17 11:48:28 -0400 | [diff] [blame] | 571 | |
| 572 | // Are we going to try to unpremul as part of a draw? For the non-legacy case, we always allow |
| 573 | // this. GrConfigConversionEffect fails on some GPUs, so only allow this if it works perfectly. |
| 574 | bool unpremulOnGpu = unpremul && |
| 575 | (!useConfigConversionEffect || fContext->validPMUPMConversionExists()); |
bsalomon | 6c6f658 | 2015-09-10 08:12:46 -0700 | [diff] [blame] | 576 | |
bsalomon | e8d21e8 | 2015-07-16 08:23:13 -0700 | [diff] [blame] | 577 | // Adjust the params so that if we wind up using an intermediate surface we've already done |
| 578 | // all the trimming and the temporary can be the min size required. |
Robert Phillips | f41c22f | 2017-04-18 07:48:58 -0400 | [diff] [blame] | 579 | if (!GrSurfacePriv::AdjustReadPixelParams(srcSurface->width(), srcSurface->height(), |
bsalomon | e8d21e8 | 2015-07-16 08:23:13 -0700 | [diff] [blame] | 580 | GrBytesPerPixel(dstConfig), &left, |
| 581 | &top, &width, &height, &buffer, &rowBytes)) { |
| 582 | return false; |
| 583 | } |
| 584 | |
Brian Osman | 409e74f | 2017-04-17 11:48:28 -0400 | [diff] [blame] | 585 | GrGpu::DrawPreference drawPreference = unpremulOnGpu ? GrGpu::kCallerPrefersDraw_DrawPreference |
| 586 | : GrGpu::kNoDraw_DrawPreference; |
bsalomon | 3982602 | 2015-07-23 08:07:21 -0700 | [diff] [blame] | 587 | GrGpu::ReadPixelTempDrawInfo tempDrawInfo; |
Robert Phillips | b0e93a2 | 2017-08-29 08:26:54 -0400 | [diff] [blame] | 588 | if (!fContext->fGpu->getReadPixelsInfo(srcSurface, srcProxy->origin(), width, height, rowBytes, |
Robert Phillips | 16d8ec6 | 2017-07-27 16:16:25 -0400 | [diff] [blame] | 589 | dstConfig, &drawPreference, &tempDrawInfo)) { |
bsalomon | 3982602 | 2015-07-23 08:07:21 -0700 | [diff] [blame] | 590 | return false; |
| 591 | } |
bsalomon | 191bcc0 | 2014-11-14 11:31:13 -0800 | [diff] [blame] | 592 | |
Robert Phillips | f41c22f | 2017-04-18 07:48:58 -0400 | [diff] [blame] | 593 | if (!(kDontFlush_PixelOpsFlag & flags) && srcSurface->surfacePriv().hasPendingWrite()) { |
Brian Osman | d2ca59a | 2017-04-13 14:03:57 -0400 | [diff] [blame] | 594 | this->flush(nullptr); // MDB TODO: tighten this |
| 595 | } |
| 596 | |
Robert Phillips | f41c22f | 2017-04-18 07:48:58 -0400 | [diff] [blame] | 597 | sk_sp<GrSurfaceProxy> proxyToRead = src->asSurfaceProxyRef(); |
bsalomon | 3982602 | 2015-07-23 08:07:21 -0700 | [diff] [blame] | 598 | bool didTempDraw = false; |
| 599 | if (GrGpu::kNoDraw_DrawPreference != drawPreference) { |
bsalomon | b117ff1 | 2016-07-19 07:24:40 -0700 | [diff] [blame] | 600 | if (SkBackingFit::kExact == tempDrawInfo.fTempSurfaceFit) { |
bsalomon | 3982602 | 2015-07-23 08:07:21 -0700 | [diff] [blame] | 601 | // We only respect this when the entire src is being read. Otherwise we can trigger too |
| 602 | // many odd ball texture sizes and trash the cache. |
Robert Phillips | f41c22f | 2017-04-18 07:48:58 -0400 | [diff] [blame] | 603 | if (width != srcSurface->width() || height != srcSurface->height()) { |
bsalomon | b117ff1 | 2016-07-19 07:24:40 -0700 | [diff] [blame] | 604 | tempDrawInfo.fTempSurfaceFit= SkBackingFit::kApprox; |
bsalomon | 3982602 | 2015-07-23 08:07:21 -0700 | [diff] [blame] | 605 | } |
bsalomon@google.com | 56d11e0 | 2011-11-30 19:59:08 +0000 | [diff] [blame] | 606 | } |
brianosman | dfe4f2e | 2016-07-21 13:28:36 -0700 | [diff] [blame] | 607 | // TODO: Need to decide the semantics of this function for color spaces. Do we support |
| 608 | // conversion to a passed-in color space? For now, specifying nullptr means that this |
| 609 | // path will do no conversion, so it will match the behavior of the non-draw path. |
Robert Phillips | dd3b3f4 | 2017-04-24 10:57:28 -0400 | [diff] [blame] | 610 | sk_sp<GrRenderTargetContext> tempRTC = fContext->makeDeferredRenderTargetContext( |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 611 | tempDrawInfo.fTempSurfaceFit, |
bsalomon | b117ff1 | 2016-07-19 07:24:40 -0700 | [diff] [blame] | 612 | tempDrawInfo.fTempSurfaceDesc.fWidth, |
| 613 | tempDrawInfo.fTempSurfaceDesc.fHeight, |
| 614 | tempDrawInfo.fTempSurfaceDesc.fConfig, |
brianosman | dfe4f2e | 2016-07-21 13:28:36 -0700 | [diff] [blame] | 615 | nullptr, |
bsalomon | b117ff1 | 2016-07-19 07:24:40 -0700 | [diff] [blame] | 616 | tempDrawInfo.fTempSurfaceDesc.fSampleCnt, |
| 617 | tempDrawInfo.fTempSurfaceDesc.fOrigin); |
Brian Osman | 693a540 | 2016-10-27 15:13:22 -0400 | [diff] [blame] | 618 | if (tempRTC) { |
Robert Phillips | 67c18d6 | 2017-01-20 12:44:06 -0500 | [diff] [blame] | 619 | SkMatrix textureMatrix = SkMatrix::MakeTrans(SkIntToScalar(left), SkIntToScalar(top)); |
Robert Phillips | f41c22f | 2017-04-18 07:48:58 -0400 | [diff] [blame] | 620 | sk_sp<GrTextureProxy> proxy = src->asTextureProxyRef(); |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 621 | auto fp = GrSimpleTextureEffect::Make(std::move(proxy), nullptr, textureMatrix); |
Brian Osman | 409e74f | 2017-04-17 11:48:28 -0400 | [diff] [blame] | 622 | if (unpremulOnGpu) { |
| 623 | fp = fContext->createPMToUPMEffect(std::move(fp), useConfigConversionEffect); |
| 624 | // We no longer need to do this on CPU after the read back. |
| 625 | unpremul = false; |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 626 | } |
Brian Osman | 409e74f | 2017-04-17 11:48:28 -0400 | [diff] [blame] | 627 | fp = GrFragmentProcessor::SwizzleOutput(std::move(fp), tempDrawInfo.fSwizzle); |
Robert Phillips | 1c9686b | 2017-06-30 08:40:28 -0400 | [diff] [blame] | 628 | if (!fp) { |
| 629 | return false; |
| 630 | } |
Brian Osman | 60cd57e | 2017-04-06 10:19:06 -0400 | [diff] [blame] | 631 | |
Brian Osman | 409e74f | 2017-04-17 11:48:28 -0400 | [diff] [blame] | 632 | GrPaint paint; |
| 633 | paint.addColorFragmentProcessor(std::move(fp)); |
| 634 | paint.setPorterDuffXPFactory(SkBlendMode::kSrc); |
| 635 | paint.setAllowSRGBInputs(true); |
| 636 | SkRect rect = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(height)); |
| 637 | tempRTC->drawRect(GrNoClip(), std::move(paint), GrAA::kNo, SkMatrix::I(), rect, |
| 638 | nullptr); |
| 639 | proxyToRead = tempRTC->asTextureProxyRef(); |
| 640 | left = 0; |
| 641 | top = 0; |
| 642 | didTempDraw = true; |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 643 | } |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 644 | } |
joshualitt | 5c55fef | 2014-10-31 14:04:35 -0700 | [diff] [blame] | 645 | |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 646 | if (!proxyToRead) { |
| 647 | return false; |
| 648 | } |
| 649 | |
bsalomon | 3982602 | 2015-07-23 08:07:21 -0700 | [diff] [blame] | 650 | if (GrGpu::kRequireDraw_DrawPreference == drawPreference && !didTempDraw) { |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 651 | return false; |
| 652 | } |
bsalomon | 3982602 | 2015-07-23 08:07:21 -0700 | [diff] [blame] | 653 | GrPixelConfig configToRead = dstConfig; |
| 654 | if (didTempDraw) { |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 655 | this->flushSurfaceWrites(proxyToRead.get()); |
bsalomon | 6c9cd55 | 2016-01-22 07:17:34 -0800 | [diff] [blame] | 656 | configToRead = tempDrawInfo.fReadConfig; |
bsalomon | 3982602 | 2015-07-23 08:07:21 -0700 | [diff] [blame] | 657 | } |
Robert Phillips | 09dfc47 | 2017-09-13 15:25:47 -0400 | [diff] [blame] | 658 | |
| 659 | if (!proxyToRead->instantiate(fContext->resourceProvider())) { |
| 660 | return false; |
| 661 | } |
| 662 | |
| 663 | GrSurface* surfaceToRead = proxyToRead->priv().peekSurface(); |
| 664 | |
Robert Phillips | b0e93a2 | 2017-08-29 08:26:54 -0400 | [diff] [blame] | 665 | if (!fContext->fGpu->readPixels(surfaceToRead, proxyToRead->origin(), |
Robert Phillips | 16d8ec6 | 2017-07-27 16:16:25 -0400 | [diff] [blame] | 666 | left, top, width, height, configToRead, buffer, rowBytes)) { |
bsalomon | 3982602 | 2015-07-23 08:07:21 -0700 | [diff] [blame] | 667 | return false; |
| 668 | } |
| 669 | |
| 670 | // Perform umpremul conversion if we weren't able to perform it as a draw. |
| 671 | if (unpremul) { |
Matt Sarett | c7b2908 | 2017-02-09 16:22:39 -0500 | [diff] [blame] | 672 | SkColorType colorType; |
| 673 | if (!GrPixelConfigToColorType(dstConfig, &colorType) || |
| 674 | 4 != SkColorTypeBytesPerPixel(colorType)) |
| 675 | { |
reed@google.com | 7111d46 | 2014-03-25 16:20:24 +0000 | [diff] [blame] | 676 | return false; |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 677 | } |
reed@google.com | 7111d46 | 2014-03-25 16:20:24 +0000 | [diff] [blame] | 678 | |
Matt Sarett | c7b2908 | 2017-02-09 16:22:39 -0500 | [diff] [blame] | 679 | for (int y = 0; y < height; y++) { |
| 680 | SkUnpremultiplyRow<false>((uint32_t*) buffer, (const uint32_t*) buffer, width); |
| 681 | buffer = SkTAddOffset<void>(buffer, rowBytes); |
| 682 | } |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 683 | } |
| 684 | return true; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 685 | } |
| 686 | |
Robert Phillips | 7ee385e | 2017-03-30 08:02:11 -0400 | [diff] [blame] | 687 | void GrContextPriv::prepareSurfaceForExternalIO(GrSurfaceProxy* proxy) { |
| 688 | ASSERT_SINGLE_OWNER_PRIV |
| 689 | RETURN_IF_ABANDONED_PRIV |
| 690 | SkASSERT(proxy); |
| 691 | ASSERT_OWNED_PROXY_PRIV(proxy); |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 692 | fContext->fDrawingManager->prepareSurfaceForExternalIO(proxy, 0, nullptr); |
bsalomon@google.com | 75f9f25 | 2012-01-31 13:35:56 +0000 | [diff] [blame] | 693 | } |
| 694 | |
Robert Phillips | 7ee385e | 2017-03-30 08:02:11 -0400 | [diff] [blame] | 695 | void GrContextPriv::flushSurfaceWrites(GrSurfaceProxy* proxy) { |
| 696 | ASSERT_SINGLE_OWNER_PRIV |
| 697 | RETURN_IF_ABANDONED_PRIV |
| 698 | SkASSERT(proxy); |
| 699 | ASSERT_OWNED_PROXY_PRIV(proxy); |
| 700 | if (proxy->priv().hasPendingWrite()) { |
| 701 | this->flush(proxy); |
bsalomon | f80bfed | 2014-10-07 05:56:02 -0700 | [diff] [blame] | 702 | } |
| 703 | } |
| 704 | |
Robert Phillips | 7ee385e | 2017-03-30 08:02:11 -0400 | [diff] [blame] | 705 | void GrContextPriv::flushSurfaceIO(GrSurfaceProxy* proxy) { |
| 706 | ASSERT_SINGLE_OWNER_PRIV |
| 707 | RETURN_IF_ABANDONED_PRIV |
| 708 | SkASSERT(proxy); |
| 709 | ASSERT_OWNED_PROXY_PRIV(proxy); |
| 710 | if (proxy->priv().hasPendingIO()) { |
| 711 | this->flush(proxy); |
ajuma | 95243eb | 2016-08-24 08:19:02 -0700 | [diff] [blame] | 712 | } |
| 713 | } |
| 714 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 715 | //////////////////////////////////////////////////////////////////////////////// |
commit-bot@chromium.org | b471a32 | 2014-03-10 07:40:03 +0000 | [diff] [blame] | 716 | int GrContext::getRecommendedSampleCount(GrPixelConfig config, |
| 717 | SkScalar dpi) const { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 718 | ASSERT_SINGLE_OWNER |
| 719 | |
bsalomon | 7622863 | 2015-05-29 08:02:10 -0700 | [diff] [blame] | 720 | if (!this->caps()->isConfigRenderable(config, true)) { |
commit-bot@chromium.org | b471a32 | 2014-03-10 07:40:03 +0000 | [diff] [blame] | 721 | return 0; |
| 722 | } |
| 723 | int chosenSampleCount = 0; |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 724 | if (fGpu->caps()->shaderCaps()->pathRenderingSupport()) { |
commit-bot@chromium.org | b471a32 | 2014-03-10 07:40:03 +0000 | [diff] [blame] | 725 | if (dpi >= 250.0f) { |
| 726 | chosenSampleCount = 4; |
| 727 | } else { |
| 728 | chosenSampleCount = 16; |
| 729 | } |
| 730 | } |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 731 | int supportedSampleCount = fGpu->caps()->getSampleCount(chosenSampleCount, config); |
| 732 | return chosenSampleCount <= supportedSampleCount ? supportedSampleCount : 0; |
commit-bot@chromium.org | b471a32 | 2014-03-10 07:40:03 +0000 | [diff] [blame] | 733 | } |
| 734 | |
Robert Phillips | 2c86249 | 2017-01-18 10:08:39 -0500 | [diff] [blame] | 735 | sk_sp<GrSurfaceContext> GrContextPriv::makeWrappedSurfaceContext(sk_sp<GrSurfaceProxy> proxy, |
| 736 | sk_sp<SkColorSpace> colorSpace) { |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 737 | ASSERT_SINGLE_OWNER_PRIV |
| 738 | |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 739 | if (proxy->asRenderTargetProxy()) { |
Robert Phillips | 2c86249 | 2017-01-18 10:08:39 -0500 | [diff] [blame] | 740 | return this->drawingManager()->makeRenderTargetContext(std::move(proxy), |
| 741 | std::move(colorSpace), nullptr); |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 742 | } else { |
| 743 | SkASSERT(proxy->asTextureProxy()); |
Robert Phillips | 2c86249 | 2017-01-18 10:08:39 -0500 | [diff] [blame] | 744 | return this->drawingManager()->makeTextureContext(std::move(proxy), std::move(colorSpace)); |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 745 | } |
| 746 | } |
| 747 | |
Robert Phillips | e2f7d18 | 2016-12-15 09:23:05 -0500 | [diff] [blame] | 748 | sk_sp<GrSurfaceContext> GrContextPriv::makeDeferredSurfaceContext(const GrSurfaceDesc& dstDesc, |
| 749 | SkBackingFit fit, |
| 750 | SkBudgeted isDstBudgeted) { |
| 751 | |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 752 | sk_sp<GrTextureProxy> proxy = GrSurfaceProxy::MakeDeferred(fContext->resourceProvider(), |
Robert Phillips | 26c90e0 | 2017-03-14 14:39:29 -0400 | [diff] [blame] | 753 | dstDesc, fit, isDstBudgeted); |
Robert Phillips | 77b3f32 | 2017-01-31 18:24:12 -0500 | [diff] [blame] | 754 | if (!proxy) { |
| 755 | return nullptr; |
| 756 | } |
Robert Phillips | e2f7d18 | 2016-12-15 09:23:05 -0500 | [diff] [blame] | 757 | |
Robert Phillips | 2c86249 | 2017-01-18 10:08:39 -0500 | [diff] [blame] | 758 | return this->makeWrappedSurfaceContext(std::move(proxy), nullptr); |
Robert Phillips | e2f7d18 | 2016-12-15 09:23:05 -0500 | [diff] [blame] | 759 | } |
| 760 | |
Brian Salomon | d17f658 | 2017-07-19 18:28:58 -0400 | [diff] [blame] | 761 | sk_sp<GrTextureContext> GrContextPriv::makeBackendTextureContext(const GrBackendTexture& tex, |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 762 | GrSurfaceOrigin origin, |
Brian Osman | c1e3705 | 2017-03-09 14:19:20 -0500 | [diff] [blame] | 763 | sk_sp<SkColorSpace> colorSpace) { |
Robert Phillips | 26caf89 | 2017-01-27 10:58:31 -0500 | [diff] [blame] | 764 | ASSERT_SINGLE_OWNER_PRIV |
| 765 | |
Robert Phillips | b0e93a2 | 2017-08-29 08:26:54 -0400 | [diff] [blame] | 766 | sk_sp<GrSurface> surface(fContext->resourceProvider()->wrapBackendTexture(tex)); |
Robert Phillips | 26caf89 | 2017-01-27 10:58:31 -0500 | [diff] [blame] | 767 | if (!surface) { |
| 768 | return nullptr; |
| 769 | } |
| 770 | |
Robert Phillips | 066f020 | 2017-07-25 10:16:35 -0400 | [diff] [blame] | 771 | sk_sp<GrSurfaceProxy> proxy(GrSurfaceProxy::MakeWrapped(std::move(surface), origin)); |
Robert Phillips | 77b3f32 | 2017-01-31 18:24:12 -0500 | [diff] [blame] | 772 | if (!proxy) { |
| 773 | return nullptr; |
| 774 | } |
Robert Phillips | 26caf89 | 2017-01-27 10:58:31 -0500 | [diff] [blame] | 775 | |
Brian Salomon | d17f658 | 2017-07-19 18:28:58 -0400 | [diff] [blame] | 776 | return this->drawingManager()->makeTextureContext(std::move(proxy), std::move(colorSpace)); |
Robert Phillips | 26caf89 | 2017-01-27 10:58:31 -0500 | [diff] [blame] | 777 | } |
| 778 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 779 | sk_sp<GrRenderTargetContext> GrContextPriv::makeBackendTextureRenderTargetContext( |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 780 | const GrBackendTexture& tex, |
| 781 | GrSurfaceOrigin origin, |
| 782 | int sampleCnt, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 783 | sk_sp<SkColorSpace> colorSpace, |
Brian Osman | c1e3705 | 2017-03-09 14:19:20 -0500 | [diff] [blame] | 784 | const SkSurfaceProps* props) { |
robertphillips | 4fd74ae | 2016-08-03 14:26:53 -0700 | [diff] [blame] | 785 | ASSERT_SINGLE_OWNER_PRIV |
robertphillips | 4fd74ae | 2016-08-03 14:26:53 -0700 | [diff] [blame] | 786 | |
Brian Salomon | d17f658 | 2017-07-19 18:28:58 -0400 | [diff] [blame] | 787 | sk_sp<GrSurface> surface( |
Robert Phillips | b0e93a2 | 2017-08-29 08:26:54 -0400 | [diff] [blame] | 788 | fContext->resourceProvider()->wrapRenderableBackendTexture(tex, sampleCnt)); |
robertphillips | 4fd74ae | 2016-08-03 14:26:53 -0700 | [diff] [blame] | 789 | if (!surface) { |
| 790 | return nullptr; |
| 791 | } |
| 792 | |
Robert Phillips | 066f020 | 2017-07-25 10:16:35 -0400 | [diff] [blame] | 793 | sk_sp<GrSurfaceProxy> proxy(GrSurfaceProxy::MakeWrapped(std::move(surface), origin)); |
Robert Phillips | 77b3f32 | 2017-01-31 18:24:12 -0500 | [diff] [blame] | 794 | if (!proxy) { |
| 795 | return nullptr; |
| 796 | } |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 797 | |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 798 | return this->drawingManager()->makeRenderTargetContext(std::move(proxy), |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 799 | std::move(colorSpace), props); |
robertphillips | 4fd74ae | 2016-08-03 14:26:53 -0700 | [diff] [blame] | 800 | } |
| 801 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 802 | sk_sp<GrRenderTargetContext> GrContextPriv::makeBackendRenderTargetRenderTargetContext( |
Greg Daniel | bcf612b | 2017-05-01 13:50:58 +0000 | [diff] [blame] | 803 | const GrBackendRenderTarget& backendRT, |
| 804 | GrSurfaceOrigin origin, |
robertphillips | 4fd74ae | 2016-08-03 14:26:53 -0700 | [diff] [blame] | 805 | sk_sp<SkColorSpace> colorSpace, |
| 806 | const SkSurfaceProps* surfaceProps) { |
| 807 | ASSERT_SINGLE_OWNER_PRIV |
| 808 | |
Robert Phillips | b0e93a2 | 2017-08-29 08:26:54 -0400 | [diff] [blame] | 809 | sk_sp<GrRenderTarget> rt(fContext->resourceProvider()->wrapBackendRenderTarget(backendRT)); |
robertphillips | 4fd74ae | 2016-08-03 14:26:53 -0700 | [diff] [blame] | 810 | if (!rt) { |
| 811 | return nullptr; |
| 812 | } |
| 813 | |
Robert Phillips | 066f020 | 2017-07-25 10:16:35 -0400 | [diff] [blame] | 814 | sk_sp<GrSurfaceProxy> proxy(GrSurfaceProxy::MakeWrapped(std::move(rt), origin)); |
Robert Phillips | 77b3f32 | 2017-01-31 18:24:12 -0500 | [diff] [blame] | 815 | if (!proxy) { |
| 816 | return nullptr; |
| 817 | } |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 818 | |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 819 | return this->drawingManager()->makeRenderTargetContext(std::move(proxy), |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 820 | std::move(colorSpace), |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 821 | surfaceProps); |
robertphillips | 4fd74ae | 2016-08-03 14:26:53 -0700 | [diff] [blame] | 822 | } |
| 823 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 824 | sk_sp<GrRenderTargetContext> GrContextPriv::makeBackendTextureAsRenderTargetRenderTargetContext( |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 825 | const GrBackendTexture& tex, |
| 826 | GrSurfaceOrigin origin, |
| 827 | int sampleCnt, |
robertphillips | 4fd74ae | 2016-08-03 14:26:53 -0700 | [diff] [blame] | 828 | sk_sp<SkColorSpace> colorSpace, |
| 829 | const SkSurfaceProps* surfaceProps) { |
| 830 | ASSERT_SINGLE_OWNER_PRIV |
robertphillips | 4fd74ae | 2016-08-03 14:26:53 -0700 | [diff] [blame] | 831 | |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 832 | sk_sp<GrSurface> surface(fContext->resourceProvider()->wrapBackendTextureAsRenderTarget( |
| 833 | tex, |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 834 | sampleCnt)); |
robertphillips | 4fd74ae | 2016-08-03 14:26:53 -0700 | [diff] [blame] | 835 | if (!surface) { |
| 836 | return nullptr; |
| 837 | } |
| 838 | |
Robert Phillips | 066f020 | 2017-07-25 10:16:35 -0400 | [diff] [blame] | 839 | sk_sp<GrSurfaceProxy> proxy(GrSurfaceProxy::MakeWrapped(std::move(surface), origin)); |
Robert Phillips | 77b3f32 | 2017-01-31 18:24:12 -0500 | [diff] [blame] | 840 | if (!proxy) { |
| 841 | return nullptr; |
| 842 | } |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 843 | |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 844 | return this->drawingManager()->makeRenderTargetContext(std::move(proxy), |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 845 | std::move(colorSpace), |
| 846 | surfaceProps); |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 847 | } |
| 848 | |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 849 | void GrContextPriv::addOnFlushCallbackObject(GrOnFlushCallbackObject* onFlushCBObject) { |
| 850 | fContext->fDrawingManager->addOnFlushCallbackObject(onFlushCBObject); |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 851 | } |
| 852 | |
| 853 | |
robertphillips | 48fde9c | 2016-09-06 05:20:20 -0700 | [diff] [blame] | 854 | static inline GrPixelConfig GrPixelConfigFallback(GrPixelConfig config) { |
Brian Osman | 78f20e0 | 2017-01-12 10:28:01 -0500 | [diff] [blame] | 855 | switch (config) { |
| 856 | case kAlpha_8_GrPixelConfig: |
| 857 | case kRGB_565_GrPixelConfig: |
| 858 | case kRGBA_4444_GrPixelConfig: |
| 859 | case kBGRA_8888_GrPixelConfig: |
| 860 | return kRGBA_8888_GrPixelConfig; |
| 861 | case kSBGRA_8888_GrPixelConfig: |
| 862 | return kSRGBA_8888_GrPixelConfig; |
| 863 | case kAlpha_half_GrPixelConfig: |
| 864 | return kRGBA_half_GrPixelConfig; |
| 865 | default: |
| 866 | return kUnknown_GrPixelConfig; |
| 867 | } |
robertphillips | 48fde9c | 2016-09-06 05:20:20 -0700 | [diff] [blame] | 868 | } |
| 869 | |
robertphillips | d728f0c | 2016-11-21 11:05:03 -0800 | [diff] [blame] | 870 | sk_sp<GrRenderTargetContext> GrContext::makeDeferredRenderTargetContextWithFallback( |
| 871 | SkBackingFit fit, |
| 872 | int width, int height, |
| 873 | GrPixelConfig config, |
| 874 | sk_sp<SkColorSpace> colorSpace, |
| 875 | int sampleCnt, |
| 876 | GrSurfaceOrigin origin, |
| 877 | const SkSurfaceProps* surfaceProps, |
| 878 | SkBudgeted budgeted) { |
| 879 | if (!this->caps()->isConfigRenderable(config, sampleCnt > 0)) { |
| 880 | config = GrPixelConfigFallback(config); |
| 881 | } |
| 882 | |
| 883 | return this->makeDeferredRenderTargetContext(fit, width, height, config, std::move(colorSpace), |
| 884 | sampleCnt, origin, surfaceProps, budgeted); |
| 885 | } |
| 886 | |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 887 | sk_sp<GrRenderTargetContext> GrContext::makeDeferredRenderTargetContext( |
| 888 | SkBackingFit fit, |
| 889 | int width, int height, |
| 890 | GrPixelConfig config, |
| 891 | sk_sp<SkColorSpace> colorSpace, |
| 892 | int sampleCnt, |
| 893 | GrSurfaceOrigin origin, |
| 894 | const SkSurfaceProps* surfaceProps, |
| 895 | SkBudgeted budgeted) { |
Brian Salomon | 79e4d1b | 2017-07-13 11:17:11 -0400 | [diff] [blame] | 896 | if (this->abandoned()) { |
| 897 | return nullptr; |
| 898 | } |
| 899 | |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 900 | GrSurfaceDesc desc; |
| 901 | desc.fFlags = kRenderTarget_GrSurfaceFlag; |
| 902 | desc.fOrigin = origin; |
| 903 | desc.fWidth = width; |
| 904 | desc.fHeight = height; |
| 905 | desc.fConfig = config; |
| 906 | desc.fSampleCnt = sampleCnt; |
| 907 | |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 908 | sk_sp<GrTextureProxy> rtp = GrSurfaceProxy::MakeDeferred(this->resourceProvider(), |
Robert Phillips | 26c90e0 | 2017-03-14 14:39:29 -0400 | [diff] [blame] | 909 | desc, fit, budgeted); |
Robert Phillips | 08c5ec7 | 2017-01-30 12:26:47 -0500 | [diff] [blame] | 910 | if (!rtp) { |
| 911 | return nullptr; |
| 912 | } |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 913 | |
Robert Phillips | 1119dc3 | 2017-04-11 12:54:57 -0400 | [diff] [blame] | 914 | sk_sp<GrRenderTargetContext> renderTargetContext( |
| 915 | fDrawingManager->makeRenderTargetContext(std::move(rtp), |
| 916 | std::move(colorSpace), |
| 917 | surfaceProps)); |
Robert Phillips | 1119dc3 | 2017-04-11 12:54:57 -0400 | [diff] [blame] | 918 | if (!renderTargetContext) { |
| 919 | return nullptr; |
| 920 | } |
| 921 | |
| 922 | renderTargetContext->discard(); |
| 923 | |
| 924 | return renderTargetContext; |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 925 | } |
| 926 | |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 927 | bool GrContext::abandoned() const { |
| 928 | ASSERT_SINGLE_OWNER |
robertphillips | 7761d61 | 2016-05-16 09:14:53 -0700 | [diff] [blame] | 929 | return fDrawingManager->wasAbandoned(); |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 930 | } |
| 931 | |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 932 | std::unique_ptr<GrFragmentProcessor> GrContext::createPMToUPMEffect( |
| 933 | std::unique_ptr<GrFragmentProcessor> fp, bool useConfigConversionEffect) { |
Robert Phillips | 757914d | 2017-01-25 15:48:30 -0500 | [diff] [blame] | 934 | ASSERT_SINGLE_OWNER |
Brian Osman | 409e74f | 2017-04-17 11:48:28 -0400 | [diff] [blame] | 935 | // We have specialized effects that guarantee round-trip conversion for some formats |
| 936 | if (useConfigConversionEffect) { |
| 937 | // We should have already called this->validPMUPMConversionExists() in this case |
| 938 | SkASSERT(fDidTestPMConversions); |
| 939 | // ...and it should have succeeded |
| 940 | SkASSERT(this->validPMUPMConversionExists()); |
| 941 | |
Brian Osman | 28804f3 | 2017-04-20 10:24:36 -0400 | [diff] [blame] | 942 | return GrConfigConversionEffect::Make(std::move(fp), |
| 943 | GrConfigConversionEffect::kToUnpremul_PMConversion); |
Brian Osman | 2d2da4f | 2017-04-12 17:07:22 -0400 | [diff] [blame] | 944 | } else { |
| 945 | // For everything else (sRGB, half-float, etc...), it doesn't make sense to try and |
| 946 | // explicitly round the results. Just do the obvious, naive thing in the shader. |
| 947 | return GrFragmentProcessor::UnpremulOutput(std::move(fp)); |
Robert Phillips | 757914d | 2017-01-25 15:48:30 -0500 | [diff] [blame] | 948 | } |
| 949 | } |
| 950 | |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 951 | std::unique_ptr<GrFragmentProcessor> GrContext::createUPMToPMEffect( |
| 952 | std::unique_ptr<GrFragmentProcessor> fp, bool useConfigConversionEffect) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 953 | ASSERT_SINGLE_OWNER |
Brian Osman | 2d2da4f | 2017-04-12 17:07:22 -0400 | [diff] [blame] | 954 | // We have specialized effects that guarantee round-trip conversion for these formats |
Brian Osman | 409e74f | 2017-04-17 11:48:28 -0400 | [diff] [blame] | 955 | if (useConfigConversionEffect) { |
| 956 | // We should have already called this->validPMUPMConversionExists() in this case |
| 957 | SkASSERT(fDidTestPMConversions); |
| 958 | // ...and it should have succeeded |
| 959 | SkASSERT(this->validPMUPMConversionExists()); |
| 960 | |
Brian Osman | 28804f3 | 2017-04-20 10:24:36 -0400 | [diff] [blame] | 961 | return GrConfigConversionEffect::Make(std::move(fp), |
| 962 | GrConfigConversionEffect::kToPremul_PMConversion); |
Brian Osman | 2d2da4f | 2017-04-12 17:07:22 -0400 | [diff] [blame] | 963 | } else { |
| 964 | // For everything else (sRGB, half-float, etc...), it doesn't make sense to try and |
| 965 | // explicitly round the results. Just do the obvious, naive thing in the shader. |
| 966 | return GrFragmentProcessor::PremulOutput(std::move(fp)); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 967 | } |
| 968 | } |
| 969 | |
Brian Osman | 409e74f | 2017-04-17 11:48:28 -0400 | [diff] [blame] | 970 | bool GrContext::validPMUPMConversionExists() { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 971 | ASSERT_SINGLE_OWNER |
Brian Osman | 409e74f | 2017-04-17 11:48:28 -0400 | [diff] [blame] | 972 | if (!fDidTestPMConversions) { |
Brian Osman | 28804f3 | 2017-04-20 10:24:36 -0400 | [diff] [blame] | 973 | fPMUPMConversionsRoundTrip = GrConfigConversionEffect::TestForPreservingPMConversions(this); |
Brian Osman | 409e74f | 2017-04-17 11:48:28 -0400 | [diff] [blame] | 974 | fDidTestPMConversions = true; |
| 975 | } |
| 976 | |
bsalomon | 636e802 | 2015-07-29 06:08:46 -0700 | [diff] [blame] | 977 | // The PM<->UPM tests fail or succeed together so we only need to check one. |
Brian Osman | 28804f3 | 2017-04-20 10:24:36 -0400 | [diff] [blame] | 978 | return fPMUPMConversionsRoundTrip; |
bsalomon | 636e802 | 2015-07-29 06:08:46 -0700 | [diff] [blame] | 979 | } |
| 980 | |
bsalomon | 37f9a26 | 2015-02-02 13:00:10 -0800 | [diff] [blame] | 981 | ////////////////////////////////////////////////////////////////////////////// |
| 982 | |
| 983 | void GrContext::getResourceCacheLimits(int* maxTextures, size_t* maxTextureBytes) const { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 984 | ASSERT_SINGLE_OWNER |
bsalomon | 37f9a26 | 2015-02-02 13:00:10 -0800 | [diff] [blame] | 985 | if (maxTextures) { |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 986 | *maxTextures = fResourceCache->getMaxResourceCount(); |
bsalomon | 37f9a26 | 2015-02-02 13:00:10 -0800 | [diff] [blame] | 987 | } |
| 988 | if (maxTextureBytes) { |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 989 | *maxTextureBytes = fResourceCache->getMaxResourceBytes(); |
bsalomon | 37f9a26 | 2015-02-02 13:00:10 -0800 | [diff] [blame] | 990 | } |
| 991 | } |
| 992 | |
| 993 | void GrContext::setResourceCacheLimits(int maxTextures, size_t maxTextureBytes) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 994 | ASSERT_SINGLE_OWNER |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 995 | fResourceCache->setLimits(maxTextures, maxTextureBytes); |
bsalomon | 37f9a26 | 2015-02-02 13:00:10 -0800 | [diff] [blame] | 996 | } |
| 997 | |
ericrk | 0a5fa48 | 2015-09-15 14:16:10 -0700 | [diff] [blame] | 998 | ////////////////////////////////////////////////////////////////////////////// |
| 999 | |
| 1000 | void GrContext::dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 1001 | ASSERT_SINGLE_OWNER |
ericrk | 0a5fa48 | 2015-09-15 14:16:10 -0700 | [diff] [blame] | 1002 | fResourceCache->dumpMemoryStatistics(traceMemoryDump); |
| 1003 | } |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 1004 | |
| 1005 | ////////////////////////////////////////////////////////////////////////////// |
| 1006 | |
| 1007 | SkString GrContext::dump() const { |
| 1008 | SkDynamicMemoryWStream stream; |
| 1009 | SkJSONWriter writer(&stream, SkJSONWriter::Mode::kPretty); |
| 1010 | writer.beginObject(); |
| 1011 | |
| 1012 | static const char* kBackendStr[] = { |
| 1013 | "Metal", |
| 1014 | "OpenGL", |
| 1015 | "Vulkan", |
| 1016 | "Mock", |
| 1017 | }; |
| 1018 | GR_STATIC_ASSERT(0 == kMetal_GrBackend); |
| 1019 | GR_STATIC_ASSERT(1 == kOpenGL_GrBackend); |
| 1020 | GR_STATIC_ASSERT(2 == kVulkan_GrBackend); |
| 1021 | GR_STATIC_ASSERT(3 == kMock_GrBackend); |
| 1022 | writer.appendString("backend", kBackendStr[fBackend]); |
| 1023 | |
| 1024 | writer.appendName("caps"); |
| 1025 | fCaps->dumpJSON(&writer); |
| 1026 | |
| 1027 | writer.appendName("gpu"); |
| 1028 | fGpu->dumpJSON(&writer); |
| 1029 | |
| 1030 | // Flush JSON to the memory stream |
| 1031 | writer.endObject(); |
| 1032 | writer.flush(); |
| 1033 | |
| 1034 | // Null terminate the JSON data in the memory stream |
| 1035 | stream.write8(0); |
| 1036 | |
| 1037 | // Allocate a string big enough to hold all the data, then copy out of the stream |
| 1038 | SkString result(stream.bytesWritten()); |
| 1039 | stream.copyToAndReset(result.writable_str()); |
| 1040 | return result; |
| 1041 | } |