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