epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 3 | * Copyright 2010 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 9 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 10 | #include "GrGpu.h" |
bsalomon@google.com | 558a75b | 2011-08-08 17:01:14 +0000 | [diff] [blame] | 11 | |
bsalomon | eb1cb5c | 2015-05-22 08:01:09 -0700 | [diff] [blame] | 12 | #include "GrCaps.h" |
bsalomon@google.com | 558a75b | 2011-08-08 17:01:14 +0000 | [diff] [blame] | 13 | #include "GrContext.h" |
bsalomon | 3582d3e | 2015-02-13 14:20:05 -0800 | [diff] [blame] | 14 | #include "GrGpuResourcePriv.h" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 15 | #include "GrIndexBuffer.h" |
kkinnunen | cabe20c | 2015-06-01 01:37:26 -0700 | [diff] [blame] | 16 | #include "GrPathRendering.h" |
bsalomon | cb02b38 | 2015-08-12 11:14:50 -0700 | [diff] [blame] | 17 | #include "GrPipeline.h" |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 18 | #include "GrResourceCache.h" |
egdaniel | ec00d94 | 2015-09-14 12:56:10 -0700 | [diff] [blame] | 19 | #include "GrResourceProvider.h" |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 20 | #include "GrRenderTargetPriv.h" |
egdaniel | 8dc7c3a | 2015-04-16 11:22:42 -0700 | [diff] [blame] | 21 | #include "GrStencilAttachment.h" |
egdaniel | 6d901da | 2015-07-30 12:02:15 -0700 | [diff] [blame] | 22 | #include "GrSurfacePriv.h" |
jvanverth | 73063dc | 2015-12-03 09:15:47 -0800 | [diff] [blame] | 23 | #include "GrTransferBuffer.h" |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 24 | #include "GrVertexBuffer.h" |
bsalomon | cb8979d | 2015-05-05 09:51:38 -0700 | [diff] [blame] | 25 | #include "GrVertices.h" |
| 26 | |
| 27 | GrVertices& GrVertices::operator =(const GrVertices& di) { |
| 28 | fPrimitiveType = di.fPrimitiveType; |
| 29 | fStartVertex = di.fStartVertex; |
| 30 | fStartIndex = di.fStartIndex; |
| 31 | fVertexCount = di.fVertexCount; |
| 32 | fIndexCount = di.fIndexCount; |
| 33 | |
| 34 | fInstanceCount = di.fInstanceCount; |
| 35 | fVerticesPerInstance = di.fVerticesPerInstance; |
| 36 | fIndicesPerInstance = di.fIndicesPerInstance; |
bsalomon | e64eb57 | 2015-05-07 11:35:55 -0700 | [diff] [blame] | 37 | fMaxInstancesPerDraw = di.fMaxInstancesPerDraw; |
bsalomon | cb8979d | 2015-05-05 09:51:38 -0700 | [diff] [blame] | 38 | |
| 39 | fVertexBuffer.reset(di.vertexBuffer()); |
| 40 | fIndexBuffer.reset(di.indexBuffer()); |
| 41 | |
| 42 | return *this; |
| 43 | } |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +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 | |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 47 | GrGpu::GrGpu(GrContext* context) |
joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame] | 48 | : fResetTimestamp(kExpiredTimestamp+1) |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 49 | , fResetBits(kAll_GrBackendState) |
joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame] | 50 | , fContext(context) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 51 | } |
| 52 | |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 53 | GrGpu::~GrGpu() {} |
bsalomon | 1d89ddc | 2014-08-19 14:20:58 -0700 | [diff] [blame] | 54 | |
robertphillips | e337130 | 2014-09-17 06:01:06 -0700 | [diff] [blame] | 55 | void GrGpu::contextAbandoned() {} |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 56 | |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 57 | //////////////////////////////////////////////////////////////////////////////// |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 58 | |
bsalomon | 045802d | 2015-10-20 07:58:01 -0700 | [diff] [blame] | 59 | bool GrGpu::makeCopyForTextureParams(int width, int height, const GrTextureParams& textureParams, |
bsalomon | 89fe56b | 2015-10-29 10:49:28 -0700 | [diff] [blame] | 60 | GrTextureProducer::CopyParams* copyParams) const { |
bsalomon | 045802d | 2015-10-20 07:58:01 -0700 | [diff] [blame] | 61 | const GrCaps& caps = *this->caps(); |
| 62 | if (textureParams.isTiled() && !caps.npotTextureTileSupport() && |
| 63 | (!SkIsPow2(width) || !SkIsPow2(height))) { |
bsalomon | 100b8f8 | 2015-10-28 08:37:44 -0700 | [diff] [blame] | 64 | copyParams->fWidth = GrNextPow2(width); |
| 65 | copyParams->fHeight = GrNextPow2(height); |
bsalomon | 045802d | 2015-10-20 07:58:01 -0700 | [diff] [blame] | 66 | switch (textureParams.filterMode()) { |
| 67 | case GrTextureParams::kNone_FilterMode: |
| 68 | copyParams->fFilter = GrTextureParams::kNone_FilterMode; |
| 69 | break; |
| 70 | case GrTextureParams::kBilerp_FilterMode: |
| 71 | case GrTextureParams::kMipMap_FilterMode: |
| 72 | // We are only ever scaling up so no reason to ever indicate kMipMap. |
| 73 | copyParams->fFilter = GrTextureParams::kBilerp_FilterMode; |
| 74 | break; |
| 75 | } |
bsalomon | 100b8f8 | 2015-10-28 08:37:44 -0700 | [diff] [blame] | 76 | return true; |
bsalomon | 045802d | 2015-10-20 07:58:01 -0700 | [diff] [blame] | 77 | } |
bsalomon | 100b8f8 | 2015-10-28 08:37:44 -0700 | [diff] [blame] | 78 | return false; |
bsalomon | 045802d | 2015-10-20 07:58:01 -0700 | [diff] [blame] | 79 | } |
| 80 | |
egdaniel | cf614fd | 2015-04-22 13:58:58 -0700 | [diff] [blame] | 81 | static GrSurfaceOrigin resolve_origin(GrSurfaceOrigin origin, bool renderTarget) { |
egdaniel | b0e1be2 | 2015-04-22 13:27:39 -0700 | [diff] [blame] | 82 | // By default, GrRenderTargets are GL's normal orientation so that they |
| 83 | // can be drawn to by the outside world without the client having |
| 84 | // to render upside down. |
| 85 | if (kDefault_GrSurfaceOrigin == origin) { |
| 86 | return renderTarget ? kBottomLeft_GrSurfaceOrigin : kTopLeft_GrSurfaceOrigin; |
| 87 | } else { |
| 88 | return origin; |
| 89 | } |
| 90 | } |
| 91 | |
egdaniel | b0e1be2 | 2015-04-22 13:27:39 -0700 | [diff] [blame] | 92 | GrTexture* GrGpu::createTexture(const GrSurfaceDesc& origDesc, bool budgeted, |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 93 | const void* srcData, size_t rowBytes) { |
egdaniel | b0e1be2 | 2015-04-22 13:27:39 -0700 | [diff] [blame] | 94 | GrSurfaceDesc desc = origDesc; |
| 95 | |
krajcevski | 9c0e629 | 2014-06-02 07:38:14 -0700 | [diff] [blame] | 96 | if (!this->caps()->isConfigTexturable(desc.fConfig)) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 97 | return nullptr; |
robertphillips@google.com | d3eb336 | 2012-10-31 13:56:35 +0000 | [diff] [blame] | 98 | } |
krajcevski | 9c0e629 | 2014-06-02 07:38:14 -0700 | [diff] [blame] | 99 | |
bsalomon | db558dd | 2015-01-23 13:19:00 -0800 | [diff] [blame] | 100 | bool isRT = SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag); |
| 101 | if (isRT && !this->caps()->isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 102 | return nullptr; |
commit-bot@chromium.org | 6b7938f | 2013-10-15 14:18:16 +0000 | [diff] [blame] | 103 | } |
robertphillips@google.com | d3eb336 | 2012-10-31 13:56:35 +0000 | [diff] [blame] | 104 | |
robertphillips | 6e83ac7 | 2015-08-13 05:19:14 -0700 | [diff] [blame] | 105 | // We currently do not support multisampled textures |
egdaniel | 8c9b6f1 | 2015-05-12 13:36:30 -0700 | [diff] [blame] | 106 | if (!isRT && desc.fSampleCnt > 0) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 107 | return nullptr; |
egdaniel | 8c9b6f1 | 2015-05-12 13:36:30 -0700 | [diff] [blame] | 108 | } |
| 109 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 110 | GrTexture *tex = nullptr; |
egdaniel | b0e1be2 | 2015-04-22 13:27:39 -0700 | [diff] [blame] | 111 | |
| 112 | if (isRT) { |
| 113 | int maxRTSize = this->caps()->maxRenderTargetSize(); |
| 114 | if (desc.fWidth > maxRTSize || desc.fHeight > maxRTSize) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 115 | return nullptr; |
egdaniel | b0e1be2 | 2015-04-22 13:27:39 -0700 | [diff] [blame] | 116 | } |
| 117 | } else { |
| 118 | int maxSize = this->caps()->maxTextureSize(); |
| 119 | if (desc.fWidth > maxSize || desc.fHeight > maxSize) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 120 | return nullptr; |
egdaniel | b0e1be2 | 2015-04-22 13:27:39 -0700 | [diff] [blame] | 121 | } |
| 122 | } |
| 123 | |
| 124 | GrGpuResource::LifeCycle lifeCycle = budgeted ? GrGpuResource::kCached_LifeCycle : |
| 125 | GrGpuResource::kUncached_LifeCycle; |
| 126 | |
| 127 | desc.fSampleCnt = SkTMin(desc.fSampleCnt, this->caps()->maxSampleCount()); |
| 128 | // Attempt to catch un- or wrongly initialized sample counts; |
| 129 | SkASSERT(desc.fSampleCnt >= 0 && desc.fSampleCnt <= 64); |
| 130 | |
| 131 | desc.fOrigin = resolve_origin(desc.fOrigin, isRT); |
| 132 | |
krajcevski | 9c0e629 | 2014-06-02 07:38:14 -0700 | [diff] [blame] | 133 | if (GrPixelConfigIsCompressed(desc.fConfig)) { |
| 134 | // We shouldn't be rendering into this |
egdaniel | b0e1be2 | 2015-04-22 13:27:39 -0700 | [diff] [blame] | 135 | SkASSERT(!isRT); |
| 136 | SkASSERT(0 == desc.fSampleCnt); |
krajcevski | 9c0e629 | 2014-06-02 07:38:14 -0700 | [diff] [blame] | 137 | |
| 138 | if (!this->caps()->npotTextureTileSupport() && |
tfarina | f9dae78 | 2014-06-06 06:35:28 -0700 | [diff] [blame] | 139 | (!SkIsPow2(desc.fWidth) || !SkIsPow2(desc.fHeight))) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 140 | return nullptr; |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 141 | } |
tfarina | f9dae78 | 2014-06-06 06:35:28 -0700 | [diff] [blame] | 142 | |
krajcevski | 9c0e629 | 2014-06-02 07:38:14 -0700 | [diff] [blame] | 143 | this->handleDirtyContext(); |
egdaniel | b0e1be2 | 2015-04-22 13:27:39 -0700 | [diff] [blame] | 144 | tex = this->onCreateCompressedTexture(desc, lifeCycle, srcData); |
krajcevski | 9c0e629 | 2014-06-02 07:38:14 -0700 | [diff] [blame] | 145 | } else { |
| 146 | this->handleDirtyContext(); |
egdaniel | b0e1be2 | 2015-04-22 13:27:39 -0700 | [diff] [blame] | 147 | tex = this->onCreateTexture(desc, lifeCycle, srcData, rowBytes); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 148 | } |
bsalomon | db558dd | 2015-01-23 13:19:00 -0800 | [diff] [blame] | 149 | if (!this->caps()->reuseScratchTextures() && !isRT) { |
bsalomon | 3582d3e | 2015-02-13 14:20:05 -0800 | [diff] [blame] | 150 | tex->resourcePriv().removeScratchKey(); |
bsalomon | db558dd | 2015-01-23 13:19:00 -0800 | [diff] [blame] | 151 | } |
bsalomon | b12ea41 | 2015-02-02 21:19:50 -0800 | [diff] [blame] | 152 | if (tex) { |
| 153 | fStats.incTextureCreates(); |
| 154 | if (srcData) { |
| 155 | fStats.incTextureUploads(); |
| 156 | } |
| 157 | } |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 158 | return tex; |
| 159 | } |
| 160 | |
bsalomon | 6dc6f5f | 2015-06-18 09:12:16 -0700 | [diff] [blame] | 161 | GrTexture* GrGpu::wrapBackendTexture(const GrBackendTextureDesc& desc, GrWrapOwnership ownership) { |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 162 | this->handleDirtyContext(); |
bsalomon | 5b30c6f | 2015-12-17 14:17:34 -0800 | [diff] [blame] | 163 | if (!this->caps()->isConfigTexturable(desc.fConfig)) { |
| 164 | return nullptr; |
| 165 | } |
| 166 | if ((desc.fFlags & kRenderTarget_GrBackendTextureFlag) && |
| 167 | !this->caps()->isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) { |
| 168 | return nullptr; |
| 169 | } |
bsalomon | 6dc6f5f | 2015-06-18 09:12:16 -0700 | [diff] [blame] | 170 | GrTexture* tex = this->onWrapBackendTexture(desc, ownership); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 171 | if (nullptr == tex) { |
| 172 | return nullptr; |
bsalomon@google.com | a14dd6d | 2012-01-03 21:08:12 +0000 | [diff] [blame] | 173 | } |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 174 | // TODO: defer this and attach dynamically |
| 175 | GrRenderTarget* tgt = tex->asRenderTarget(); |
egdaniel | ec00d94 | 2015-09-14 12:56:10 -0700 | [diff] [blame] | 176 | if (tgt && !fContext->resourceProvider()->attachStencilAttachment(tgt)) { |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 177 | tex->unref(); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 178 | return nullptr; |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 179 | } else { |
| 180 | return tex; |
| 181 | } |
| 182 | } |
| 183 | |
bsalomon | 6dc6f5f | 2015-06-18 09:12:16 -0700 | [diff] [blame] | 184 | GrRenderTarget* GrGpu::wrapBackendRenderTarget(const GrBackendRenderTargetDesc& desc, |
| 185 | GrWrapOwnership ownership) { |
bsalomon | 5b30c6f | 2015-12-17 14:17:34 -0800 | [diff] [blame] | 186 | if (!this->caps()->isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) { |
| 187 | return nullptr; |
| 188 | } |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 189 | this->handleDirtyContext(); |
bsalomon | 6dc6f5f | 2015-06-18 09:12:16 -0700 | [diff] [blame] | 190 | return this->onWrapBackendRenderTarget(desc, ownership); |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 191 | } |
| 192 | |
robertphillips@google.com | adacc70 | 2013-10-14 21:53:24 +0000 | [diff] [blame] | 193 | GrVertexBuffer* GrGpu::createVertexBuffer(size_t size, bool dynamic) { |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 194 | this->handleDirtyContext(); |
robertphillips | 1b8e1b5 | 2015-06-24 06:54:10 -0700 | [diff] [blame] | 195 | GrVertexBuffer* vb = this->onCreateVertexBuffer(size, dynamic); |
| 196 | if (!this->caps()->reuseScratchBuffers()) { |
| 197 | vb->resourcePriv().removeScratchKey(); |
| 198 | } |
| 199 | return vb; |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 200 | } |
| 201 | |
robertphillips@google.com | adacc70 | 2013-10-14 21:53:24 +0000 | [diff] [blame] | 202 | GrIndexBuffer* GrGpu::createIndexBuffer(size_t size, bool dynamic) { |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 203 | this->handleDirtyContext(); |
robertphillips | 1b8e1b5 | 2015-06-24 06:54:10 -0700 | [diff] [blame] | 204 | GrIndexBuffer* ib = this->onCreateIndexBuffer(size, dynamic); |
| 205 | if (!this->caps()->reuseScratchBuffers()) { |
| 206 | ib->resourcePriv().removeScratchKey(); |
| 207 | } |
| 208 | return ib; |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 209 | } |
| 210 | |
jvanverth | 73063dc | 2015-12-03 09:15:47 -0800 | [diff] [blame] | 211 | GrTransferBuffer* GrGpu::createTransferBuffer(size_t size, TransferType type) { |
| 212 | this->handleDirtyContext(); |
| 213 | GrTransferBuffer* tb = this->onCreateTransferBuffer(size, type); |
| 214 | return tb; |
| 215 | } |
| 216 | |
egdaniel | 51c8d40 | 2015-08-06 10:54:13 -0700 | [diff] [blame] | 217 | void GrGpu::clear(const SkIRect& rect, |
joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame] | 218 | GrColor color, |
joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame] | 219 | GrRenderTarget* renderTarget) { |
bsalomon | 89c6298 | 2014-11-03 12:08:42 -0800 | [diff] [blame] | 220 | SkASSERT(renderTarget); |
egdaniel | 51c8d40 | 2015-08-06 10:54:13 -0700 | [diff] [blame] | 221 | SkASSERT(SkIRect::MakeWH(renderTarget->width(), renderTarget->height()).contains(rect)); |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 222 | this->handleDirtyContext(); |
egdaniel | 51c8d40 | 2015-08-06 10:54:13 -0700 | [diff] [blame] | 223 | this->onClear(renderTarget, rect, color); |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 224 | } |
| 225 | |
joshualitt | 6db519c | 2014-10-29 08:48:18 -0700 | [diff] [blame] | 226 | void GrGpu::clearStencilClip(const SkIRect& rect, |
| 227 | bool insideClip, |
| 228 | GrRenderTarget* renderTarget) { |
joshualitt | d53a827 | 2014-11-10 16:03:14 -0800 | [diff] [blame] | 229 | SkASSERT(renderTarget); |
joshualitt | 6db519c | 2014-10-29 08:48:18 -0700 | [diff] [blame] | 230 | this->handleDirtyContext(); |
| 231 | this->onClearStencilClip(renderTarget, rect, insideClip); |
| 232 | } |
| 233 | |
joshualitt | 1cbdcde | 2015-08-21 11:53:29 -0700 | [diff] [blame] | 234 | bool GrGpu::copySurface(GrSurface* dst, |
| 235 | GrSurface* src, |
| 236 | const SkIRect& srcRect, |
| 237 | const SkIPoint& dstPoint) { |
| 238 | SkASSERT(dst && src); |
| 239 | this->handleDirtyContext(); |
| 240 | return this->onCopySurface(dst, src, srcRect, dstPoint); |
| 241 | } |
| 242 | |
bsalomon | f067451 | 2015-07-28 13:26:15 -0700 | [diff] [blame] | 243 | bool GrGpu::getReadPixelsInfo(GrSurface* srcSurface, int width, int height, size_t rowBytes, |
| 244 | GrPixelConfig readConfig, DrawPreference* drawPreference, |
| 245 | ReadPixelTempDrawInfo* tempDrawInfo) { |
| 246 | SkASSERT(drawPreference); |
| 247 | SkASSERT(tempDrawInfo); |
| 248 | SkASSERT(kGpuPrefersDraw_DrawPreference != *drawPreference); |
| 249 | |
egdaniel | 6d901da | 2015-07-30 12:02:15 -0700 | [diff] [blame] | 250 | // We currently do not support reading into a compressed buffer |
| 251 | if (GrPixelConfigIsCompressed(readConfig)) { |
| 252 | return false; |
| 253 | } |
| 254 | |
bsalomon | f067451 | 2015-07-28 13:26:15 -0700 | [diff] [blame] | 255 | if (!this->onGetReadPixelsInfo(srcSurface, width, height, rowBytes, readConfig, drawPreference, |
| 256 | tempDrawInfo)) { |
| 257 | return false; |
| 258 | } |
| 259 | |
| 260 | // Check to see if we're going to request that the caller draw when drawing is not possible. |
| 261 | if (!srcSurface->asTexture() || |
| 262 | !this->caps()->isConfigRenderable(tempDrawInfo->fTempSurfaceDesc.fConfig, false)) { |
| 263 | // If we don't have a fallback to a straight read then fail. |
| 264 | if (kRequireDraw_DrawPreference == *drawPreference) { |
| 265 | return false; |
| 266 | } |
| 267 | *drawPreference = kNoDraw_DrawPreference; |
| 268 | } |
| 269 | |
| 270 | return true; |
| 271 | } |
| 272 | bool GrGpu::getWritePixelsInfo(GrSurface* dstSurface, int width, int height, size_t rowBytes, |
| 273 | GrPixelConfig srcConfig, DrawPreference* drawPreference, |
| 274 | WritePixelTempDrawInfo* tempDrawInfo) { |
| 275 | SkASSERT(drawPreference); |
| 276 | SkASSERT(tempDrawInfo); |
| 277 | SkASSERT(kGpuPrefersDraw_DrawPreference != *drawPreference); |
| 278 | |
jvanverth | 2dc2994 | 2015-09-01 07:16:46 -0700 | [diff] [blame] | 279 | if (GrPixelConfigIsCompressed(dstSurface->desc().fConfig) && |
| 280 | dstSurface->desc().fConfig != srcConfig) { |
| 281 | return false; |
| 282 | } |
| 283 | |
bsalomon | f067451 | 2015-07-28 13:26:15 -0700 | [diff] [blame] | 284 | if (this->caps()->useDrawInsteadOfPartialRenderTargetWrite() && |
| 285 | SkToBool(dstSurface->asRenderTarget()) && |
| 286 | (width < dstSurface->width() || height < dstSurface->height())) { |
| 287 | ElevateDrawPreference(drawPreference, kRequireDraw_DrawPreference); |
| 288 | } |
| 289 | |
| 290 | if (!this->onGetWritePixelsInfo(dstSurface, width, height, rowBytes, srcConfig, drawPreference, |
| 291 | tempDrawInfo)) { |
| 292 | return false; |
| 293 | } |
| 294 | |
| 295 | // Check to see if we're going to request that the caller draw when drawing is not possible. |
| 296 | if (!dstSurface->asRenderTarget() || |
| 297 | !this->caps()->isConfigTexturable(tempDrawInfo->fTempSurfaceDesc.fConfig)) { |
| 298 | // If we don't have a fallback to a straight upload then fail. |
| 299 | if (kRequireDraw_DrawPreference == *drawPreference || |
| 300 | !this->caps()->isConfigTexturable(srcConfig)) { |
| 301 | return false; |
| 302 | } |
| 303 | *drawPreference = kNoDraw_DrawPreference; |
| 304 | } |
| 305 | return true; |
| 306 | } |
| 307 | |
bsalomon | 6cb3cbe | 2015-07-30 07:34:27 -0700 | [diff] [blame] | 308 | bool GrGpu::readPixels(GrSurface* surface, |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 309 | int left, int top, int width, int height, |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 310 | GrPixelConfig config, void* buffer, |
senorblanco@chromium.org | 3cb406b | 2013-02-05 19:50:46 +0000 | [diff] [blame] | 311 | size_t rowBytes) { |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 312 | this->handleDirtyContext(); |
egdaniel | 6d901da | 2015-07-30 12:02:15 -0700 | [diff] [blame] | 313 | |
| 314 | // We cannot read pixels into a compressed buffer |
| 315 | if (GrPixelConfigIsCompressed(config)) { |
| 316 | return false; |
| 317 | } |
| 318 | |
| 319 | size_t bpp = GrBytesPerPixel(config); |
| 320 | if (!GrSurfacePriv::AdjustReadPixelParams(surface->width(), surface->height(), bpp, |
| 321 | &left, &top, &width, &height, |
| 322 | &buffer, |
| 323 | &rowBytes)) { |
| 324 | return false; |
| 325 | } |
| 326 | |
| 327 | return this->onReadPixels(surface, |
| 328 | left, top, width, height, |
| 329 | config, buffer, |
| 330 | rowBytes); |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 331 | } |
| 332 | |
bsalomon | 6cb3cbe | 2015-07-30 07:34:27 -0700 | [diff] [blame] | 333 | bool GrGpu::writePixels(GrSurface* surface, |
| 334 | int left, int top, int width, int height, |
| 335 | GrPixelConfig config, const void* buffer, |
| 336 | size_t rowBytes) { |
jvanverth | 17aa047 | 2016-01-05 10:41:27 -0800 | [diff] [blame^] | 337 | if (!buffer || !surface) { |
jvanverth | 2dc2994 | 2015-09-01 07:16:46 -0700 | [diff] [blame] | 338 | return false; |
| 339 | } |
| 340 | |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 341 | this->handleDirtyContext(); |
bsalomon | 6cb3cbe | 2015-07-30 07:34:27 -0700 | [diff] [blame] | 342 | if (this->onWritePixels(surface, left, top, width, height, config, buffer, rowBytes)) { |
bsalomon | b12ea41 | 2015-02-02 21:19:50 -0800 | [diff] [blame] | 343 | fStats.incTextureUploads(); |
| 344 | return true; |
| 345 | } |
| 346 | return false; |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 347 | } |
| 348 | |
jvanverth | 17aa047 | 2016-01-05 10:41:27 -0800 | [diff] [blame^] | 349 | bool GrGpu::transferPixels(GrSurface* surface, |
| 350 | int left, int top, int width, int height, |
| 351 | GrPixelConfig config, GrTransferBuffer* buffer, |
| 352 | size_t offset, size_t rowBytes) { |
| 353 | SkASSERT(buffer); |
| 354 | |
| 355 | this->handleDirtyContext(); |
| 356 | if (this->onTransferPixels(surface, left, top, width, height, config, |
| 357 | buffer, offset, rowBytes)) { |
| 358 | fStats.incTransfersToTexture(); |
| 359 | return true; |
| 360 | } |
| 361 | return false; |
| 362 | } |
| 363 | |
bsalomon@google.com | 75f9f25 | 2012-01-31 13:35:56 +0000 | [diff] [blame] | 364 | void GrGpu::resolveRenderTarget(GrRenderTarget* target) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 365 | SkASSERT(target); |
bsalomon@google.com | 75f9f25 | 2012-01-31 13:35:56 +0000 | [diff] [blame] | 366 | this->handleDirtyContext(); |
| 367 | this->onResolveRenderTarget(target); |
| 368 | } |
| 369 | |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 370 | //////////////////////////////////////////////////////////////////////////////// |
| 371 | |
bsalomon | cb8979d | 2015-05-05 09:51:38 -0700 | [diff] [blame] | 372 | void GrGpu::draw(const DrawArgs& args, const GrVertices& vertices) { |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 373 | this->handleDirtyContext(); |
bsalomon | cb02b38 | 2015-08-12 11:14:50 -0700 | [diff] [blame] | 374 | if (GrXferBarrierType barrierType = args.fPipeline->xferBarrierType(*this->caps())) { |
| 375 | this->xferBarrier(args.fPipeline->getRenderTarget(), barrierType); |
| 376 | } |
| 377 | |
bsalomon | e64eb57 | 2015-05-07 11:35:55 -0700 | [diff] [blame] | 378 | GrVertices::Iterator iter; |
| 379 | const GrNonInstancedVertices* verts = iter.init(vertices); |
| 380 | do { |
| 381 | this->onDraw(args, *verts); |
joshualitt | 336cda3 | 2015-09-09 08:29:47 -0700 | [diff] [blame] | 382 | fStats.incNumDraws(); |
bsalomon | e64eb57 | 2015-05-07 11:35:55 -0700 | [diff] [blame] | 383 | } while ((verts = iter.next())); |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 384 | } |