reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 2 | * Copyright 2010 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. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 8 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 9 | #include "GrGpu.h" |
bsalomon@google.com | 558a75b | 2011-08-08 17:01:14 +0000 | [diff] [blame] | 10 | |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 11 | #include "GrBackendSemaphore.h" |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 12 | #include "GrBackendSurface.h" |
cdalton | 397536c | 2016-03-25 12:15:03 -0700 | [diff] [blame] | 13 | #include "GrBuffer.h" |
bsalomon | eb1cb5c | 2015-05-22 08:01:09 -0700 | [diff] [blame] | 14 | #include "GrCaps.h" |
bsalomon@google.com | 558a75b | 2011-08-08 17:01:14 +0000 | [diff] [blame] | 15 | #include "GrContext.h" |
bsalomon | 3582d3e | 2015-02-13 14:20:05 -0800 | [diff] [blame] | 16 | #include "GrGpuResourcePriv.h" |
egdaniel | 0e1853c | 2016-03-17 11:35:45 -0700 | [diff] [blame] | 17 | #include "GrMesh.h" |
kkinnunen | cabe20c | 2015-06-01 01:37:26 -0700 | [diff] [blame] | 18 | #include "GrPathRendering.h" |
bsalomon | cb02b38 | 2015-08-12 11:14:50 -0700 | [diff] [blame] | 19 | #include "GrPipeline.h" |
Robert Phillips | fbcef6e | 2017-06-15 12:07:18 -0400 | [diff] [blame] | 20 | #include "GrRenderTargetPriv.h" |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 21 | #include "GrResourceCache.h" |
egdaniel | ec00d94 | 2015-09-14 12:56:10 -0700 | [diff] [blame] | 22 | #include "GrResourceProvider.h" |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 23 | #include "GrSemaphore.h" |
egdaniel | 8dc7c3a | 2015-04-16 11:22:42 -0700 | [diff] [blame] | 24 | #include "GrStencilAttachment.h" |
csmartdalton | c633abb | 2016-11-01 08:55:55 -0700 | [diff] [blame] | 25 | #include "GrStencilSettings.h" |
egdaniel | 6d901da | 2015-07-30 12:02:15 -0700 | [diff] [blame] | 26 | #include "GrSurfacePriv.h" |
jvanverth | 900bd4a | 2016-04-29 13:53:12 -0700 | [diff] [blame] | 27 | #include "GrTexturePriv.h" |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 28 | #include "GrTracing.h" |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 29 | #include "SkJSONWriter.h" |
halcanary | 4dbbd04 | 2016-06-07 17:21:10 -0700 | [diff] [blame] | 30 | #include "SkMathPriv.h" |
bsalomon | cb8979d | 2015-05-05 09:51:38 -0700 | [diff] [blame] | 31 | |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 32 | //////////////////////////////////////////////////////////////////////////////// |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 33 | |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 34 | GrGpu::GrGpu(GrContext* context) |
joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame] | 35 | : fResetTimestamp(kExpiredTimestamp+1) |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 36 | , fResetBits(kAll_GrBackendState) |
joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame] | 37 | , fContext(context) { |
csmartdalton | 0d28e57 | 2016-07-06 09:59:43 -0700 | [diff] [blame] | 38 | fMultisampleSpecs.emplace_back(0, 0, nullptr); // Index 0 is an invalid unique id. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 39 | } |
| 40 | |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 41 | GrGpu::~GrGpu() {} |
bsalomon | 1d89ddc | 2014-08-19 14:20:58 -0700 | [diff] [blame] | 42 | |
bsalomon | 6e2aad4 | 2016-04-01 11:54:31 -0700 | [diff] [blame] | 43 | void GrGpu::disconnect(DisconnectType) {} |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 44 | |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 45 | //////////////////////////////////////////////////////////////////////////////// |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 46 | |
Robert Phillips | 81444fb | 2017-03-21 09:14:35 -0400 | [diff] [blame] | 47 | bool GrGpu::isACopyNeededForTextureParams(int width, int height, |
| 48 | const GrSamplerParams& textureParams, |
| 49 | GrTextureProducer::CopyParams* copyParams, |
| 50 | SkScalar scaleAdjust[2]) const { |
bsalomon | 045802d | 2015-10-20 07:58:01 -0700 | [diff] [blame] | 51 | const GrCaps& caps = *this->caps(); |
| 52 | if (textureParams.isTiled() && !caps.npotTextureTileSupport() && |
| 53 | (!SkIsPow2(width) || !SkIsPow2(height))) { |
Robert Phillips | 67c18d6 | 2017-01-20 12:44:06 -0500 | [diff] [blame] | 54 | SkASSERT(scaleAdjust); |
bsalomon | 100b8f8 | 2015-10-28 08:37:44 -0700 | [diff] [blame] | 55 | copyParams->fWidth = GrNextPow2(width); |
| 56 | copyParams->fHeight = GrNextPow2(height); |
Robert Phillips | 67c18d6 | 2017-01-20 12:44:06 -0500 | [diff] [blame] | 57 | scaleAdjust[0] = ((SkScalar) copyParams->fWidth) / width; |
| 58 | scaleAdjust[1] = ((SkScalar) copyParams->fHeight) / height; |
bsalomon | 045802d | 2015-10-20 07:58:01 -0700 | [diff] [blame] | 59 | switch (textureParams.filterMode()) { |
Brian Salomon | 514baff | 2016-11-17 15:17:07 -0500 | [diff] [blame] | 60 | case GrSamplerParams::kNone_FilterMode: |
| 61 | copyParams->fFilter = GrSamplerParams::kNone_FilterMode; |
bsalomon | 045802d | 2015-10-20 07:58:01 -0700 | [diff] [blame] | 62 | break; |
Brian Salomon | 514baff | 2016-11-17 15:17:07 -0500 | [diff] [blame] | 63 | case GrSamplerParams::kBilerp_FilterMode: |
| 64 | case GrSamplerParams::kMipMap_FilterMode: |
bsalomon | 045802d | 2015-10-20 07:58:01 -0700 | [diff] [blame] | 65 | // We are only ever scaling up so no reason to ever indicate kMipMap. |
Brian Salomon | 514baff | 2016-11-17 15:17:07 -0500 | [diff] [blame] | 66 | copyParams->fFilter = GrSamplerParams::kBilerp_FilterMode; |
bsalomon | 045802d | 2015-10-20 07:58:01 -0700 | [diff] [blame] | 67 | break; |
| 68 | } |
bsalomon | 100b8f8 | 2015-10-28 08:37:44 -0700 | [diff] [blame] | 69 | return true; |
bsalomon | 045802d | 2015-10-20 07:58:01 -0700 | [diff] [blame] | 70 | } |
bsalomon | 100b8f8 | 2015-10-28 08:37:44 -0700 | [diff] [blame] | 71 | return false; |
bsalomon | 045802d | 2015-10-20 07:58:01 -0700 | [diff] [blame] | 72 | } |
| 73 | |
cblume | 55f2d2d | 2016-02-26 13:20:48 -0800 | [diff] [blame] | 74 | /** |
| 75 | * Prior to creating a texture, make sure the type of texture being created is |
| 76 | * supported by calling check_texture_creation_params. |
| 77 | * |
Robert Phillips | 590533f | 2017-07-11 14:22:35 -0400 | [diff] [blame] | 78 | * @param caps The capabilities of the GL device. |
| 79 | * @param desc The descriptor of the texture to create. |
| 80 | * @param isRT Indicates if the texture can be a render target. |
| 81 | * @param texels The texel data for the mipmap levels |
| 82 | * @param mipLevelCount The number of GrMipLevels in 'texels' |
cblume | 55f2d2d | 2016-02-26 13:20:48 -0800 | [diff] [blame] | 83 | */ |
| 84 | static bool check_texture_creation_params(const GrCaps& caps, const GrSurfaceDesc& desc, |
Robert Phillips | 590533f | 2017-07-11 14:22:35 -0400 | [diff] [blame] | 85 | bool* isRT, |
| 86 | const GrMipLevel texels[], int mipLevelCount) { |
cblume | 55f2d2d | 2016-02-26 13:20:48 -0800 | [diff] [blame] | 87 | if (!caps.isConfigTexturable(desc.fConfig)) { |
| 88 | return false; |
robertphillips@google.com | d3eb336 | 2012-10-31 13:56:35 +0000 | [diff] [blame] | 89 | } |
krajcevski | 9c0e629 | 2014-06-02 07:38:14 -0700 | [diff] [blame] | 90 | |
Robert Phillips | 590533f | 2017-07-11 14:22:35 -0400 | [diff] [blame] | 91 | if (GrPixelConfigIsSint(desc.fConfig) && mipLevelCount > 1) { |
Brian Salomon | bf7b620 | 2016-11-11 16:08:03 -0500 | [diff] [blame] | 92 | return false; |
| 93 | } |
| 94 | |
cblume | 55f2d2d | 2016-02-26 13:20:48 -0800 | [diff] [blame] | 95 | *isRT = SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag); |
| 96 | if (*isRT && !caps.isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) { |
| 97 | return false; |
commit-bot@chromium.org | 6b7938f | 2013-10-15 14:18:16 +0000 | [diff] [blame] | 98 | } |
robertphillips@google.com | d3eb336 | 2012-10-31 13:56:35 +0000 | [diff] [blame] | 99 | |
robertphillips | 6e83ac7 | 2015-08-13 05:19:14 -0700 | [diff] [blame] | 100 | // We currently do not support multisampled textures |
cblume | 55f2d2d | 2016-02-26 13:20:48 -0800 | [diff] [blame] | 101 | if (!*isRT && desc.fSampleCnt > 0) { |
| 102 | return false; |
| 103 | } |
| 104 | |
| 105 | if (*isRT) { |
| 106 | int maxRTSize = caps.maxRenderTargetSize(); |
| 107 | if (desc.fWidth > maxRTSize || desc.fHeight > maxRTSize) { |
| 108 | return false; |
| 109 | } |
| 110 | } else { |
| 111 | int maxSize = caps.maxTextureSize(); |
| 112 | if (desc.fWidth > maxSize || desc.fHeight > maxSize) { |
| 113 | return false; |
| 114 | } |
| 115 | } |
bsalomon | e699d0c | 2016-03-09 06:25:15 -0800 | [diff] [blame] | 116 | |
Robert Phillips | 590533f | 2017-07-11 14:22:35 -0400 | [diff] [blame] | 117 | for (int i = 0; i < mipLevelCount; ++i) { |
bsalomon | e699d0c | 2016-03-09 06:25:15 -0800 | [diff] [blame] | 118 | if (!texels[i].fPixels) { |
| 119 | return false; |
| 120 | } |
| 121 | } |
cblume | 55f2d2d | 2016-02-26 13:20:48 -0800 | [diff] [blame] | 122 | return true; |
| 123 | } |
| 124 | |
Robert Phillips | 67d52cf | 2017-06-05 13:38:13 -0400 | [diff] [blame] | 125 | sk_sp<GrTexture> GrGpu::createTexture(const GrSurfaceDesc& origDesc, SkBudgeted budgeted, |
Robert Phillips | 590533f | 2017-07-11 14:22:35 -0400 | [diff] [blame] | 126 | const GrMipLevel texels[], int mipLevelCount) { |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 127 | GR_CREATE_TRACE_MARKER_CONTEXT("GrGpu", "createTexture", fContext); |
cblume | 55f2d2d | 2016-02-26 13:20:48 -0800 | [diff] [blame] | 128 | GrSurfaceDesc desc = origDesc; |
| 129 | |
| 130 | const GrCaps* caps = this->caps(); |
| 131 | bool isRT = false; |
Robert Phillips | 590533f | 2017-07-11 14:22:35 -0400 | [diff] [blame] | 132 | bool textureCreationParamsValid = check_texture_creation_params(*caps, desc, &isRT, |
| 133 | texels, mipLevelCount); |
cblume | 55f2d2d | 2016-02-26 13:20:48 -0800 | [diff] [blame] | 134 | if (!textureCreationParamsValid) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 135 | return nullptr; |
egdaniel | 8c9b6f1 | 2015-05-12 13:36:30 -0700 | [diff] [blame] | 136 | } |
| 137 | |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 138 | desc.fSampleCnt = caps->getSampleCount(desc.fSampleCnt, desc.fConfig); |
Brian Salomon | d17b4a6 | 2017-05-23 16:53:47 -0400 | [diff] [blame] | 139 | // Attempt to catch un- or wrongly initialized sample counts. |
egdaniel | b0e1be2 | 2015-04-22 13:27:39 -0700 | [diff] [blame] | 140 | SkASSERT(desc.fSampleCnt >= 0 && desc.fSampleCnt <= 64); |
egdaniel | b0e1be2 | 2015-04-22 13:27:39 -0700 | [diff] [blame] | 141 | |
Robert Phillips | 590533f | 2017-07-11 14:22:35 -0400 | [diff] [blame] | 142 | if (mipLevelCount && (desc.fFlags & kPerformInitialClear_GrSurfaceFlag)) { |
Brian Salomon | d17b4a6 | 2017-05-23 16:53:47 -0400 | [diff] [blame] | 143 | return nullptr; |
| 144 | } |
| 145 | |
Robert Phillips | 92de631 | 2017-05-23 07:43:48 -0400 | [diff] [blame] | 146 | this->handleDirtyContext(); |
Robert Phillips | 590533f | 2017-07-11 14:22:35 -0400 | [diff] [blame] | 147 | sk_sp<GrTexture> tex = this->onCreateTexture(desc, budgeted, texels, mipLevelCount); |
bsalomon | b12ea41 | 2015-02-02 21:19:50 -0800 | [diff] [blame] | 148 | if (tex) { |
cblume | 55f2d2d | 2016-02-26 13:20:48 -0800 | [diff] [blame] | 149 | if (!caps->reuseScratchTextures() && !isRT) { |
| 150 | tex->resourcePriv().removeScratchKey(); |
| 151 | } |
bsalomon | b12ea41 | 2015-02-02 21:19:50 -0800 | [diff] [blame] | 152 | fStats.incTextureCreates(); |
Robert Phillips | 590533f | 2017-07-11 14:22:35 -0400 | [diff] [blame] | 153 | if (mipLevelCount) { |
cblume | 55f2d2d | 2016-02-26 13:20:48 -0800 | [diff] [blame] | 154 | if (texels[0].fPixels) { |
| 155 | fStats.incTextureUploads(); |
| 156 | } |
bsalomon | b12ea41 | 2015-02-02 21:19:50 -0800 | [diff] [blame] | 157 | } |
| 158 | } |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 159 | return tex; |
| 160 | } |
| 161 | |
Robert Phillips | 646e429 | 2017-06-13 12:44:56 -0400 | [diff] [blame] | 162 | sk_sp<GrTexture> GrGpu::createTexture(const GrSurfaceDesc& desc, SkBudgeted budgeted) { |
Robert Phillips | 590533f | 2017-07-11 14:22:35 -0400 | [diff] [blame] | 163 | return this->createTexture(desc, budgeted, nullptr, 0); |
Robert Phillips | 646e429 | 2017-06-13 12:44:56 -0400 | [diff] [blame] | 164 | } |
| 165 | |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 166 | sk_sp<GrTexture> GrGpu::wrapBackendTexture(const GrBackendTexture& backendTex, |
bungeman | 6bd5284 | 2016-10-27 09:30:08 -0700 | [diff] [blame] | 167 | GrWrapOwnership ownership) { |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 168 | this->handleDirtyContext(); |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 169 | if (!this->caps()->isConfigTexturable(backendTex.config())) { |
bsalomon | 5b30c6f | 2015-12-17 14:17:34 -0800 | [diff] [blame] | 170 | return nullptr; |
| 171 | } |
Brian Salomon | d17f658 | 2017-07-19 18:28:58 -0400 | [diff] [blame] | 172 | if (backendTex.width() > this->caps()->maxTextureSize() || |
| 173 | backendTex.height() > this->caps()->maxTextureSize()) { |
bsalomon | 5b30c6f | 2015-12-17 14:17:34 -0800 | [diff] [blame] | 174 | return nullptr; |
| 175 | } |
Robert Phillips | b0e93a2 | 2017-08-29 08:26:54 -0400 | [diff] [blame] | 176 | sk_sp<GrTexture> tex = this->onWrapBackendTexture(backendTex, ownership); |
bungeman | 6bd5284 | 2016-10-27 09:30:08 -0700 | [diff] [blame] | 177 | if (!tex) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 178 | return nullptr; |
bsalomon@google.com | a14dd6d | 2012-01-03 21:08:12 +0000 | [diff] [blame] | 179 | } |
Brian Salomon | d17f658 | 2017-07-19 18:28:58 -0400 | [diff] [blame] | 180 | return tex; |
| 181 | } |
Eric Karl | 5c77975 | 2017-05-08 12:02:07 -0700 | [diff] [blame] | 182 | |
Brian Salomon | d17f658 | 2017-07-19 18:28:58 -0400 | [diff] [blame] | 183 | sk_sp<GrTexture> GrGpu::wrapRenderableBackendTexture(const GrBackendTexture& backendTex, |
Robert Phillips | b0e93a2 | 2017-08-29 08:26:54 -0400 | [diff] [blame] | 184 | int sampleCnt, GrWrapOwnership ownership) { |
Brian Salomon | d17f658 | 2017-07-19 18:28:58 -0400 | [diff] [blame] | 185 | this->handleDirtyContext(); |
| 186 | if (!this->caps()->isConfigTexturable(backendTex.config()) || |
| 187 | !this->caps()->isConfigRenderable(backendTex.config(), sampleCnt > 0)) { |
| 188 | return nullptr; |
| 189 | } |
| 190 | |
| 191 | if (backendTex.width() > this->caps()->maxRenderTargetSize() || |
| 192 | backendTex.height() > this->caps()->maxRenderTargetSize()) { |
| 193 | return nullptr; |
| 194 | } |
| 195 | sk_sp<GrTexture> tex = |
Robert Phillips | b0e93a2 | 2017-08-29 08:26:54 -0400 | [diff] [blame] | 196 | this->onWrapRenderableBackendTexture(backendTex, sampleCnt, ownership); |
Brian Salomon | d17f658 | 2017-07-19 18:28:58 -0400 | [diff] [blame] | 197 | if (!tex) { |
| 198 | return nullptr; |
| 199 | } |
| 200 | SkASSERT(tex->asRenderTarget()); |
Eric Karl | 5c77975 | 2017-05-08 12:02:07 -0700 | [diff] [blame] | 201 | if (!this->caps()->avoidStencilBuffers()) { |
| 202 | // TODO: defer this and attach dynamically |
Brian Salomon | d17f658 | 2017-07-19 18:28:58 -0400 | [diff] [blame] | 203 | if (!fContext->resourceProvider()->attachStencilAttachment(tex->asRenderTarget())) { |
Eric Karl | 5c77975 | 2017-05-08 12:02:07 -0700 | [diff] [blame] | 204 | return nullptr; |
| 205 | } |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 206 | } |
bungeman | 6bd5284 | 2016-10-27 09:30:08 -0700 | [diff] [blame] | 207 | return tex; |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 208 | } |
| 209 | |
Robert Phillips | b0e93a2 | 2017-08-29 08:26:54 -0400 | [diff] [blame] | 210 | sk_sp<GrRenderTarget> GrGpu::wrapBackendRenderTarget(const GrBackendRenderTarget& backendRT) { |
Greg Daniel | bcf612b | 2017-05-01 13:50:58 +0000 | [diff] [blame] | 211 | if (!this->caps()->isConfigRenderable(backendRT.config(), backendRT.sampleCnt() > 0)) { |
bsalomon | 5b30c6f | 2015-12-17 14:17:34 -0800 | [diff] [blame] | 212 | return nullptr; |
| 213 | } |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 214 | this->handleDirtyContext(); |
Robert Phillips | b0e93a2 | 2017-08-29 08:26:54 -0400 | [diff] [blame] | 215 | return this->onWrapBackendRenderTarget(backendRT); |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 216 | } |
| 217 | |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 218 | sk_sp<GrRenderTarget> GrGpu::wrapBackendTextureAsRenderTarget(const GrBackendTexture& tex, |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 219 | int sampleCnt) { |
ericrk | f7b8b8a | 2016-02-24 14:49:51 -0800 | [diff] [blame] | 220 | this->handleDirtyContext(); |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 221 | if (!this->caps()->isConfigRenderable(tex.config(), sampleCnt > 0)) { |
ericrk | f7b8b8a | 2016-02-24 14:49:51 -0800 | [diff] [blame] | 222 | return nullptr; |
| 223 | } |
| 224 | int maxSize = this->caps()->maxTextureSize(); |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 225 | if (tex.width() > maxSize || tex.height() > maxSize) { |
ericrk | f7b8b8a | 2016-02-24 14:49:51 -0800 | [diff] [blame] | 226 | return nullptr; |
| 227 | } |
Robert Phillips | b0e93a2 | 2017-08-29 08:26:54 -0400 | [diff] [blame] | 228 | return this->onWrapBackendTextureAsRenderTarget(tex, sampleCnt); |
ericrk | f7b8b8a | 2016-02-24 14:49:51 -0800 | [diff] [blame] | 229 | } |
| 230 | |
cdalton | e2e71c2 | 2016-04-07 18:13:29 -0700 | [diff] [blame] | 231 | GrBuffer* GrGpu::createBuffer(size_t size, GrBufferType intendedType, |
cdalton | 1bf3e71 | 2016-04-19 10:00:02 -0700 | [diff] [blame] | 232 | GrAccessPattern accessPattern, const void* data) { |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 233 | this->handleDirtyContext(); |
cdalton | 1bf3e71 | 2016-04-19 10:00:02 -0700 | [diff] [blame] | 234 | GrBuffer* buffer = this->onCreateBuffer(size, intendedType, accessPattern, data); |
robertphillips | 1b8e1b5 | 2015-06-24 06:54:10 -0700 | [diff] [blame] | 235 | if (!this->caps()->reuseScratchBuffers()) { |
cdalton | 397536c | 2016-03-25 12:15:03 -0700 | [diff] [blame] | 236 | buffer->resourcePriv().removeScratchKey(); |
robertphillips | 1b8e1b5 | 2015-06-24 06:54:10 -0700 | [diff] [blame] | 237 | } |
cdalton | 397536c | 2016-03-25 12:15:03 -0700 | [diff] [blame] | 238 | return buffer; |
jvanverth | 73063dc | 2015-12-03 09:15:47 -0800 | [diff] [blame] | 239 | } |
| 240 | |
Robert Phillips | e3302df | 2017-04-24 07:31:02 -0400 | [diff] [blame] | 241 | std::unique_ptr<gr_instanced::OpAllocator> GrGpu::createInstancedRenderingAllocator() { |
| 242 | SkASSERT(GrCaps::InstancedSupport::kNone != this->caps()->instancedSupport()); |
| 243 | return this->onCreateInstancedRenderingAllocator(); |
| 244 | } |
| 245 | |
csmartdalton | e0d3629 | 2016-07-29 08:14:20 -0700 | [diff] [blame] | 246 | gr_instanced::InstancedRendering* GrGpu::createInstancedRendering() { |
| 247 | SkASSERT(GrCaps::InstancedSupport::kNone != this->caps()->instancedSupport()); |
| 248 | return this->onCreateInstancedRendering(); |
| 249 | } |
| 250 | |
Robert Phillips | b0e93a2 | 2017-08-29 08:26:54 -0400 | [diff] [blame] | 251 | bool GrGpu::copySurface(GrSurface* dst, GrSurfaceOrigin dstOrigin, |
| 252 | GrSurface* src, GrSurfaceOrigin srcOrigin, |
| 253 | const SkIRect& srcRect, const SkIPoint& dstPoint) { |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 254 | GR_CREATE_TRACE_MARKER_CONTEXT("GrGpu", "copySurface", fContext); |
joshualitt | 1cbdcde | 2015-08-21 11:53:29 -0700 | [diff] [blame] | 255 | SkASSERT(dst && src); |
| 256 | this->handleDirtyContext(); |
Brian Salomon | bf7b620 | 2016-11-11 16:08:03 -0500 | [diff] [blame] | 257 | // We don't allow conversion between integer configs and float/fixed configs. |
| 258 | if (GrPixelConfigIsSint(dst->config()) != GrPixelConfigIsSint(src->config())) { |
| 259 | return false; |
| 260 | } |
Robert Phillips | b0e93a2 | 2017-08-29 08:26:54 -0400 | [diff] [blame] | 261 | return this->onCopySurface(dst, dstOrigin, src, srcOrigin, srcRect, dstPoint); |
joshualitt | 1cbdcde | 2015-08-21 11:53:29 -0700 | [diff] [blame] | 262 | } |
| 263 | |
Robert Phillips | b0e93a2 | 2017-08-29 08:26:54 -0400 | [diff] [blame] | 264 | bool GrGpu::getReadPixelsInfo(GrSurface* srcSurface, GrSurfaceOrigin srcOrigin, |
| 265 | int width, int height, size_t rowBytes, |
bsalomon | f067451 | 2015-07-28 13:26:15 -0700 | [diff] [blame] | 266 | GrPixelConfig readConfig, DrawPreference* drawPreference, |
| 267 | ReadPixelTempDrawInfo* tempDrawInfo) { |
| 268 | SkASSERT(drawPreference); |
| 269 | SkASSERT(tempDrawInfo); |
Brian Salomon | bf7b620 | 2016-11-11 16:08:03 -0500 | [diff] [blame] | 270 | SkASSERT(srcSurface); |
bsalomon | f067451 | 2015-07-28 13:26:15 -0700 | [diff] [blame] | 271 | SkASSERT(kGpuPrefersDraw_DrawPreference != *drawPreference); |
| 272 | |
egdaniel | 3fe0327 | 2016-08-15 10:59:17 -0700 | [diff] [blame] | 273 | // We currently do not support reading into the packed formats 565 or 4444 as they are not |
| 274 | // required to have read back support on all devices and backends. |
| 275 | if (kRGB_565_GrPixelConfig == readConfig || kRGBA_4444_GrPixelConfig == readConfig) { |
| 276 | return false; |
| 277 | } |
| 278 | |
Robert Phillips | b0e93a2 | 2017-08-29 08:26:54 -0400 | [diff] [blame] | 279 | if (!this->onGetReadPixelsInfo(srcSurface, srcOrigin, width, height, rowBytes, readConfig, |
| 280 | drawPreference, tempDrawInfo)) { |
bsalomon | f067451 | 2015-07-28 13:26:15 -0700 | [diff] [blame] | 281 | return false; |
| 282 | } |
| 283 | |
| 284 | // Check to see if we're going to request that the caller draw when drawing is not possible. |
| 285 | if (!srcSurface->asTexture() || |
| 286 | !this->caps()->isConfigRenderable(tempDrawInfo->fTempSurfaceDesc.fConfig, false)) { |
| 287 | // If we don't have a fallback to a straight read then fail. |
| 288 | if (kRequireDraw_DrawPreference == *drawPreference) { |
| 289 | return false; |
| 290 | } |
| 291 | *drawPreference = kNoDraw_DrawPreference; |
| 292 | } |
| 293 | |
| 294 | return true; |
| 295 | } |
Robert Phillips | b0e93a2 | 2017-08-29 08:26:54 -0400 | [diff] [blame] | 296 | bool GrGpu::getWritePixelsInfo(GrSurface* dstSurface, GrSurfaceOrigin dstOrigin, |
| 297 | int width, int height, |
bsalomon | f067451 | 2015-07-28 13:26:15 -0700 | [diff] [blame] | 298 | GrPixelConfig srcConfig, DrawPreference* drawPreference, |
| 299 | WritePixelTempDrawInfo* tempDrawInfo) { |
| 300 | SkASSERT(drawPreference); |
| 301 | SkASSERT(tempDrawInfo); |
Brian Salomon | bf7b620 | 2016-11-11 16:08:03 -0500 | [diff] [blame] | 302 | SkASSERT(dstSurface); |
bsalomon | f067451 | 2015-07-28 13:26:15 -0700 | [diff] [blame] | 303 | SkASSERT(kGpuPrefersDraw_DrawPreference != *drawPreference); |
| 304 | |
Robert Phillips | b0e93a2 | 2017-08-29 08:26:54 -0400 | [diff] [blame] | 305 | if (!this->onGetWritePixelsInfo(dstSurface, dstOrigin, width, height, srcConfig, drawPreference, |
bsalomon | f067451 | 2015-07-28 13:26:15 -0700 | [diff] [blame] | 306 | tempDrawInfo)) { |
| 307 | return false; |
| 308 | } |
| 309 | |
| 310 | // Check to see if we're going to request that the caller draw when drawing is not possible. |
| 311 | if (!dstSurface->asRenderTarget() || |
| 312 | !this->caps()->isConfigTexturable(tempDrawInfo->fTempSurfaceDesc.fConfig)) { |
| 313 | // If we don't have a fallback to a straight upload then fail. |
| 314 | if (kRequireDraw_DrawPreference == *drawPreference || |
| 315 | !this->caps()->isConfigTexturable(srcConfig)) { |
| 316 | return false; |
| 317 | } |
| 318 | *drawPreference = kNoDraw_DrawPreference; |
| 319 | } |
| 320 | return true; |
| 321 | } |
| 322 | |
Robert Phillips | b0e93a2 | 2017-08-29 08:26:54 -0400 | [diff] [blame] | 323 | bool GrGpu::readPixels(GrSurface* surface, GrSurfaceOrigin origin, |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 324 | int left, int top, int width, int height, |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 325 | GrPixelConfig config, void* buffer, |
senorblanco@chromium.org | 3cb406b | 2013-02-05 19:50:46 +0000 | [diff] [blame] | 326 | size_t rowBytes) { |
Brian Salomon | bf7b620 | 2016-11-11 16:08:03 -0500 | [diff] [blame] | 327 | SkASSERT(surface); |
| 328 | |
| 329 | // We don't allow conversion between integer configs and float/fixed configs. |
| 330 | if (GrPixelConfigIsSint(surface->config()) != GrPixelConfigIsSint(config)) { |
| 331 | return false; |
| 332 | } |
egdaniel | 6d901da | 2015-07-30 12:02:15 -0700 | [diff] [blame] | 333 | |
egdaniel | 6d901da | 2015-07-30 12:02:15 -0700 | [diff] [blame] | 334 | size_t bpp = GrBytesPerPixel(config); |
| 335 | if (!GrSurfacePriv::AdjustReadPixelParams(surface->width(), surface->height(), bpp, |
| 336 | &left, &top, &width, &height, |
| 337 | &buffer, |
| 338 | &rowBytes)) { |
| 339 | return false; |
| 340 | } |
| 341 | |
Brian Salomon | bf7b620 | 2016-11-11 16:08:03 -0500 | [diff] [blame] | 342 | this->handleDirtyContext(); |
| 343 | |
Robert Phillips | b0e93a2 | 2017-08-29 08:26:54 -0400 | [diff] [blame] | 344 | return this->onReadPixels(surface, origin, |
egdaniel | 6d901da | 2015-07-30 12:02:15 -0700 | [diff] [blame] | 345 | left, top, width, height, |
| 346 | config, buffer, |
| 347 | rowBytes); |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 348 | } |
| 349 | |
Robert Phillips | b0e93a2 | 2017-08-29 08:26:54 -0400 | [diff] [blame] | 350 | bool GrGpu::writePixels(GrSurface* surface, GrSurfaceOrigin origin, |
bsalomon | 6cb3cbe | 2015-07-30 07:34:27 -0700 | [diff] [blame] | 351 | int left, int top, int width, int height, |
Robert Phillips | 590533f | 2017-07-11 14:22:35 -0400 | [diff] [blame] | 352 | GrPixelConfig config, const GrMipLevel texels[], int mipLevelCount) { |
Brian Salomon | bf7b620 | 2016-11-11 16:08:03 -0500 | [diff] [blame] | 353 | SkASSERT(surface); |
Robert Phillips | 590533f | 2017-07-11 14:22:35 -0400 | [diff] [blame] | 354 | if (1 == mipLevelCount) { |
Greg Daniel | 660cc99 | 2017-06-26 14:55:05 -0400 | [diff] [blame] | 355 | // We require that if we are not mipped, then the write region is contained in the surface |
| 356 | SkIRect subRect = SkIRect::MakeXYWH(left, top, width, height); |
| 357 | SkIRect bounds = SkIRect::MakeWH(surface->width(), surface->height()); |
| 358 | if (!bounds.contains(subRect)) { |
| 359 | return false; |
| 360 | } |
| 361 | } else if (0 != left || 0 != top || width != surface->width() || height != surface->height()) { |
| 362 | // We require that if the texels are mipped, than the write region is the entire surface |
| 363 | return false; |
| 364 | } |
Robert Phillips | b7b7e5f | 2017-05-22 13:23:19 -0400 | [diff] [blame] | 365 | |
Robert Phillips | 590533f | 2017-07-11 14:22:35 -0400 | [diff] [blame] | 366 | for (int currentMipLevel = 0; currentMipLevel < mipLevelCount; currentMipLevel++) { |
bsalomon | e699d0c | 2016-03-09 06:25:15 -0800 | [diff] [blame] | 367 | if (!texels[currentMipLevel].fPixels ) { |
| 368 | return false; |
cblume | 55f2d2d | 2016-02-26 13:20:48 -0800 | [diff] [blame] | 369 | } |
| 370 | } |
jvanverth | 2dc2994 | 2015-09-01 07:16:46 -0700 | [diff] [blame] | 371 | |
Brian Salomon | bf7b620 | 2016-11-11 16:08:03 -0500 | [diff] [blame] | 372 | // We don't allow conversion between integer configs and float/fixed configs. |
| 373 | if (GrPixelConfigIsSint(surface->config()) != GrPixelConfigIsSint(config)) { |
| 374 | return false; |
| 375 | } |
| 376 | |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 377 | this->handleDirtyContext(); |
Robert Phillips | b0e93a2 | 2017-08-29 08:26:54 -0400 | [diff] [blame] | 378 | if (this->onWritePixels(surface, origin, left, top, width, height, config, |
| 379 | texels, mipLevelCount)) { |
jvanverth | 900bd4a | 2016-04-29 13:53:12 -0700 | [diff] [blame] | 380 | SkIRect rect = SkIRect::MakeXYWH(left, top, width, height); |
Robert Phillips | 590533f | 2017-07-11 14:22:35 -0400 | [diff] [blame] | 381 | this->didWriteToSurface(surface, &rect, mipLevelCount); |
bsalomon | b12ea41 | 2015-02-02 21:19:50 -0800 | [diff] [blame] | 382 | fStats.incTextureUploads(); |
| 383 | return true; |
| 384 | } |
| 385 | return false; |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 386 | } |
| 387 | |
Robert Phillips | b0e93a2 | 2017-08-29 08:26:54 -0400 | [diff] [blame] | 388 | bool GrGpu::writePixels(GrSurface* surface, GrSurfaceOrigin origin, |
cblume | 55f2d2d | 2016-02-26 13:20:48 -0800 | [diff] [blame] | 389 | int left, int top, int width, int height, |
| 390 | GrPixelConfig config, const void* buffer, |
| 391 | size_t rowBytes) { |
Robert Phillips | 590533f | 2017-07-11 14:22:35 -0400 | [diff] [blame] | 392 | GrMipLevel mipLevel = { buffer, rowBytes }; |
cblume | 55f2d2d | 2016-02-26 13:20:48 -0800 | [diff] [blame] | 393 | |
Robert Phillips | b0e93a2 | 2017-08-29 08:26:54 -0400 | [diff] [blame] | 394 | return this->writePixels(surface, origin, left, top, width, height, config, &mipLevel, 1); |
cblume | 55f2d2d | 2016-02-26 13:20:48 -0800 | [diff] [blame] | 395 | } |
| 396 | |
Jim Van Verth | 2e5eaf0 | 2017-06-21 15:55:46 -0400 | [diff] [blame] | 397 | bool GrGpu::transferPixels(GrTexture* texture, |
jvanverth | 17aa047 | 2016-01-05 10:41:27 -0800 | [diff] [blame] | 398 | int left, int top, int width, int height, |
cdalton | 397536c | 2016-03-25 12:15:03 -0700 | [diff] [blame] | 399 | GrPixelConfig config, GrBuffer* transferBuffer, |
Jim Van Verth | 2e5eaf0 | 2017-06-21 15:55:46 -0400 | [diff] [blame] | 400 | size_t offset, size_t rowBytes) { |
cdalton | 397536c | 2016-03-25 12:15:03 -0700 | [diff] [blame] | 401 | SkASSERT(transferBuffer); |
jvanverth | 17aa047 | 2016-01-05 10:41:27 -0800 | [diff] [blame] | 402 | |
Brian Salomon | bf7b620 | 2016-11-11 16:08:03 -0500 | [diff] [blame] | 403 | // We don't allow conversion between integer configs and float/fixed configs. |
Jim Van Verth | 2e5eaf0 | 2017-06-21 15:55:46 -0400 | [diff] [blame] | 404 | if (GrPixelConfigIsSint(texture->config()) != GrPixelConfigIsSint(config)) { |
Brian Salomon | bf7b620 | 2016-11-11 16:08:03 -0500 | [diff] [blame] | 405 | return false; |
| 406 | } |
| 407 | |
Greg Daniel | 660cc99 | 2017-06-26 14:55:05 -0400 | [diff] [blame] | 408 | // We require that the write region is contained in the texture |
| 409 | SkIRect subRect = SkIRect::MakeXYWH(left, top, width, height); |
| 410 | SkIRect bounds = SkIRect::MakeWH(texture->width(), texture->height()); |
| 411 | if (!bounds.contains(subRect)) { |
| 412 | return false; |
| 413 | } |
| 414 | |
jvanverth | 17aa047 | 2016-01-05 10:41:27 -0800 | [diff] [blame] | 415 | this->handleDirtyContext(); |
Jim Van Verth | 2e5eaf0 | 2017-06-21 15:55:46 -0400 | [diff] [blame] | 416 | if (this->onTransferPixels(texture, left, top, width, height, config, |
cdalton | 397536c | 2016-03-25 12:15:03 -0700 | [diff] [blame] | 417 | transferBuffer, offset, rowBytes)) { |
jvanverth | 900bd4a | 2016-04-29 13:53:12 -0700 | [diff] [blame] | 418 | SkIRect rect = SkIRect::MakeXYWH(left, top, width, height); |
Jim Van Verth | 2e5eaf0 | 2017-06-21 15:55:46 -0400 | [diff] [blame] | 419 | this->didWriteToSurface(texture, &rect); |
jvanverth | 17aa047 | 2016-01-05 10:41:27 -0800 | [diff] [blame] | 420 | fStats.incTransfersToTexture(); |
jvanverth | 84741b3 | 2016-09-30 08:39:02 -0700 | [diff] [blame] | 421 | |
jvanverth | 17aa047 | 2016-01-05 10:41:27 -0800 | [diff] [blame] | 422 | return true; |
| 423 | } |
| 424 | return false; |
| 425 | } |
| 426 | |
Robert Phillips | b0e93a2 | 2017-08-29 08:26:54 -0400 | [diff] [blame] | 427 | void GrGpu::resolveRenderTarget(GrRenderTarget* target, GrSurfaceOrigin origin) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 428 | SkASSERT(target); |
bsalomon@google.com | 75f9f25 | 2012-01-31 13:35:56 +0000 | [diff] [blame] | 429 | this->handleDirtyContext(); |
Robert Phillips | b0e93a2 | 2017-08-29 08:26:54 -0400 | [diff] [blame] | 430 | this->onResolveRenderTarget(target, origin); |
bsalomon@google.com | 75f9f25 | 2012-01-31 13:35:56 +0000 | [diff] [blame] | 431 | } |
| 432 | |
jvanverth | 900bd4a | 2016-04-29 13:53:12 -0700 | [diff] [blame] | 433 | void GrGpu::didWriteToSurface(GrSurface* surface, const SkIRect* bounds, uint32_t mipLevels) const { |
| 434 | SkASSERT(surface); |
| 435 | // Mark any MIP chain and resolve buffer as dirty if and only if there is a non-empty bounds. |
| 436 | if (nullptr == bounds || !bounds->isEmpty()) { |
| 437 | if (GrRenderTarget* target = surface->asRenderTarget()) { |
| 438 | target->flagAsNeedingResolve(bounds); |
| 439 | } |
| 440 | GrTexture* texture = surface->asTexture(); |
| 441 | if (texture && 1 == mipLevels) { |
| 442 | texture->texturePriv().dirtyMipMaps(true); |
| 443 | } |
| 444 | } |
| 445 | } |
| 446 | |
csmartdalton | c633abb | 2016-11-01 08:55:55 -0700 | [diff] [blame] | 447 | const GrGpu::MultisampleSpecs& GrGpu::queryMultisampleSpecs(const GrPipeline& pipeline) { |
Robert Phillips | 2890fbf | 2017-07-26 15:48:41 -0400 | [diff] [blame] | 448 | GrRenderTarget* rt = pipeline.renderTarget(); |
Brian Salomon | 154ce91 | 2017-05-17 10:40:02 -0400 | [diff] [blame] | 449 | SkASSERT(rt->numStencilSamples() > 1); |
csmartdalton | 0d28e57 | 2016-07-06 09:59:43 -0700 | [diff] [blame] | 450 | |
csmartdalton | c633abb | 2016-11-01 08:55:55 -0700 | [diff] [blame] | 451 | GrStencilSettings stencil; |
| 452 | if (pipeline.isStencilEnabled()) { |
| 453 | // TODO: attach stencil and create settings during render target flush. |
| 454 | SkASSERT(rt->renderTargetPriv().getStencilAttachment()); |
| 455 | stencil.reset(*pipeline.getUserStencil(), pipeline.hasStencilClip(), |
| 456 | rt->renderTargetPriv().numStencilBits()); |
| 457 | } |
| 458 | |
cdalton | 28f45b9 | 2016-03-07 13:58:26 -0800 | [diff] [blame] | 459 | int effectiveSampleCnt; |
csmartdalton | 0d28e57 | 2016-07-06 09:59:43 -0700 | [diff] [blame] | 460 | SkSTArray<16, SkPoint, true> pattern; |
Robert Phillips | b0e93a2 | 2017-08-29 08:26:54 -0400 | [diff] [blame] | 461 | this->onQueryMultisampleSpecs(rt, pipeline.proxy()->origin(), stencil, |
| 462 | &effectiveSampleCnt, &pattern); |
Brian Salomon | 154ce91 | 2017-05-17 10:40:02 -0400 | [diff] [blame] | 463 | SkASSERT(effectiveSampleCnt >= rt->numStencilSamples()); |
csmartdalton | 0d28e57 | 2016-07-06 09:59:43 -0700 | [diff] [blame] | 464 | |
| 465 | uint8_t id; |
| 466 | if (this->caps()->sampleLocationsSupport()) { |
| 467 | SkASSERT(pattern.count() == effectiveSampleCnt); |
| 468 | const auto& insertResult = fMultisampleSpecsIdMap.insert( |
| 469 | MultisampleSpecsIdMap::value_type(pattern, SkTMin(fMultisampleSpecs.count(), 255))); |
| 470 | id = insertResult.first->second; |
| 471 | if (insertResult.second) { |
| 472 | // This means the insert did not find the pattern in the map already, and therefore an |
| 473 | // actual insertion took place. (We don't expect to see many unique sample patterns.) |
| 474 | const SkPoint* sampleLocations = insertResult.first->first.begin(); |
| 475 | SkASSERT(id == fMultisampleSpecs.count()); |
| 476 | fMultisampleSpecs.emplace_back(id, effectiveSampleCnt, sampleLocations); |
| 477 | } |
| 478 | } else { |
| 479 | id = effectiveSampleCnt; |
| 480 | for (int i = fMultisampleSpecs.count(); i <= id; ++i) { |
| 481 | fMultisampleSpecs.emplace_back(i, i, nullptr); |
| 482 | } |
cdalton | 28f45b9 | 2016-03-07 13:58:26 -0800 | [diff] [blame] | 483 | } |
csmartdalton | 0d28e57 | 2016-07-06 09:59:43 -0700 | [diff] [blame] | 484 | SkASSERT(id > 0); |
csmartdalton | 0d28e57 | 2016-07-06 09:59:43 -0700 | [diff] [blame] | 485 | |
csmartdalton | 0d28e57 | 2016-07-06 09:59:43 -0700 | [diff] [blame] | 486 | return fMultisampleSpecs[id]; |
cdalton | 28f45b9 | 2016-03-07 13:58:26 -0800 | [diff] [blame] | 487 | } |
| 488 | |
csmartdalton | 0d28e57 | 2016-07-06 09:59:43 -0700 | [diff] [blame] | 489 | bool GrGpu::SamplePatternComparator::operator()(const SamplePattern& a, |
| 490 | const SamplePattern& b) const { |
| 491 | if (a.count() != b.count()) { |
| 492 | return a.count() < b.count(); |
| 493 | } |
| 494 | for (int i = 0; i < a.count(); ++i) { |
| 495 | // This doesn't have geometric meaning. We just need to define an ordering for std::map. |
| 496 | if (a[i].x() != b[i].x()) { |
| 497 | return a[i].x() < b[i].x(); |
| 498 | } |
| 499 | if (a[i].y() != b[i].y()) { |
| 500 | return a[i].y() < b[i].y(); |
| 501 | } |
| 502 | } |
| 503 | return false; // Equal. |
| 504 | } |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 505 | |
| 506 | GrSemaphoresSubmitted GrGpu::finishFlush(int numSemaphores, |
| 507 | GrBackendSemaphore backendSemaphores[]) { |
| 508 | if (this->caps()->fenceSyncSupport()) { |
| 509 | for (int i = 0; i < numSemaphores; ++i) { |
| 510 | sk_sp<GrSemaphore> semaphore; |
| 511 | if (backendSemaphores[i].isInitialized()) { |
| 512 | semaphore = fContext->resourceProvider()->wrapBackendSemaphore( |
| 513 | backendSemaphores[i], kBorrow_GrWrapOwnership); |
| 514 | } else { |
| 515 | semaphore = fContext->resourceProvider()->makeSemaphore(false); |
| 516 | } |
| 517 | this->insertSemaphore(semaphore, false); |
| 518 | |
| 519 | if (!backendSemaphores[i].isInitialized()) { |
| 520 | semaphore->setBackendSemaphore(&backendSemaphores[i]); |
| 521 | } |
| 522 | } |
| 523 | } |
| 524 | this->onFinishFlush((numSemaphores > 0 && this->caps()->fenceSyncSupport())); |
| 525 | return this->caps()->fenceSyncSupport() ? GrSemaphoresSubmitted::kYes |
| 526 | : GrSemaphoresSubmitted::kNo; |
| 527 | } |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 528 | |
| 529 | void GrGpu::dumpJSON(SkJSONWriter* writer) const { |
| 530 | writer->beginObject(); |
| 531 | |
| 532 | // TODO: Is there anything useful in the base class to dump here? |
| 533 | |
| 534 | this->onDumpJSON(writer); |
| 535 | |
| 536 | writer->endObject(); |
| 537 | } |