| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2010 Google Inc. | 3 * Copyright 2010 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 | 9 |
| 10 #include "GrGpu.h" | 10 #include "GrGpu.h" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 // By default, GrRenderTargets are GL's normal orientation so that they | 57 // By default, GrRenderTargets are GL's normal orientation so that they |
| 58 // can be drawn to by the outside world without the client having | 58 // can be drawn to by the outside world without the client having |
| 59 // to render upside down. | 59 // to render upside down. |
| 60 if (kDefault_GrSurfaceOrigin == origin) { | 60 if (kDefault_GrSurfaceOrigin == origin) { |
| 61 return renderTarget ? kBottomLeft_GrSurfaceOrigin : kTopLeft_GrSurfaceOr
igin; | 61 return renderTarget ? kBottomLeft_GrSurfaceOrigin : kTopLeft_GrSurfaceOr
igin; |
| 62 } else { | 62 } else { |
| 63 return origin; | 63 return origin; |
| 64 } | 64 } |
| 65 } | 65 } |
| 66 | 66 |
| 67 /** |
| 68 * Prior to creating a texture, make sure the type of texture being created is |
| 69 * supported by calling check_texture_creation_params. |
| 70 * |
| 71 * @param caps The capabilities of the GL device. |
| 72 * @param desc The descriptor of the texture to create. |
| 73 * @param isRT Indicates if the texture be a render target. |
| 74 */ |
| 75 static bool check_texture_creation_params(const GrCaps& caps, const GrSurfaceDes
c& desc, |
| 76 bool* isRT) { |
| 77 if (!caps.isConfigTexturable(desc.fConfig)) { |
| 78 return false; |
| 79 } |
| 80 |
| 81 *isRT = SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag); |
| 82 if (*isRT && !caps.isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) { |
| 83 return false; |
| 84 } |
| 85 |
| 86 // We currently do not support multisampled textures |
| 87 if (!*isRT && desc.fSampleCnt > 0) { |
| 88 return false; |
| 89 } |
| 90 |
| 91 if (*isRT) { |
| 92 int maxRTSize = caps.maxRenderTargetSize(); |
| 93 if (desc.fWidth > maxRTSize || desc.fHeight > maxRTSize) { |
| 94 return false; |
| 95 } |
| 96 } else { |
| 97 int maxSize = caps.maxTextureSize(); |
| 98 if (desc.fWidth > maxSize || desc.fHeight > maxSize) { |
| 99 return false; |
| 100 } |
| 101 } |
| 102 return true; |
| 103 } |
| 104 |
| 67 GrTexture* GrGpu::createTexture(const GrSurfaceDesc& origDesc, bool budgeted, | 105 GrTexture* GrGpu::createTexture(const GrSurfaceDesc& origDesc, bool budgeted, |
| 68 const void* srcData, size_t rowBytes) { | 106 const void* srcData, size_t rowBytes) { |
| 69 GrSurfaceDesc desc = origDesc; | 107 GrSurfaceDesc desc = origDesc; |
| 70 | 108 |
| 71 if (!this->caps()->isConfigTexturable(desc.fConfig)) { | 109 const GrCaps* caps = this->caps(); |
| 110 if (!caps) { |
| 72 return NULL; | 111 return NULL; |
| 73 } | |
| 74 | |
| 75 bool isRT = SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag); | |
| 76 if (isRT && !this->caps()->isConfigRenderable(desc.fConfig, desc.fSampleCnt
> 0)) { | |
| 77 return NULL; | |
| 78 } | |
| 79 | |
| 80 // We currently not support multisampled textures | |
| 81 if (!isRT && desc.fSampleCnt > 0) { | |
| 82 return NULL; | |
| 83 } | |
| 84 | |
| 85 GrTexture *tex = NULL; | |
| 86 | |
| 87 if (isRT) { | |
| 88 int maxRTSize = this->caps()->maxRenderTargetSize(); | |
| 89 if (desc.fWidth > maxRTSize || desc.fHeight > maxRTSize) { | |
| 90 return NULL; | |
| 91 } | |
| 92 } else { | 112 } else { |
| 93 int maxSize = this->caps()->maxTextureSize(); | 113 bool isRT = false; |
| 94 if (desc.fWidth > maxSize || desc.fHeight > maxSize) { | 114 bool textureCreationParamsValid = check_texture_creation_params(*caps, d
esc, &isRT); |
| 95 return NULL; | 115 if (!textureCreationParamsValid) { |
| 96 } | |
| 97 } | |
| 98 | |
| 99 GrGpuResource::LifeCycle lifeCycle = budgeted ? GrGpuResource::kCached_LifeC
ycle : | |
| 100 GrGpuResource::kUncached_Lif
eCycle; | |
| 101 | |
| 102 desc.fSampleCnt = SkTMin(desc.fSampleCnt, this->caps()->maxSampleCount()); | |
| 103 // Attempt to catch un- or wrongly initialized sample counts; | |
| 104 SkASSERT(desc.fSampleCnt >= 0 && desc.fSampleCnt <= 64); | |
| 105 | |
| 106 desc.fOrigin = resolve_origin(desc.fOrigin, isRT); | |
| 107 | |
| 108 if (GrPixelConfigIsCompressed(desc.fConfig)) { | |
| 109 // We shouldn't be rendering into this | |
| 110 SkASSERT(!isRT); | |
| 111 SkASSERT(0 == desc.fSampleCnt); | |
| 112 | |
| 113 if (!this->caps()->npotTextureTileSupport() && | |
| 114 (!SkIsPow2(desc.fWidth) || !SkIsPow2(desc.fHeight))) { | |
| 115 return NULL; | 116 return NULL; |
| 116 } | 117 } |
| 117 | 118 |
| 118 this->handleDirtyContext(); | 119 desc.fSampleCnt = SkTMin(desc.fSampleCnt, caps->maxSampleCount()); |
| 119 tex = this->onCreateCompressedTexture(desc, lifeCycle, srcData); | 120 // Attempt to catch un- or wrongly initialized sample counts; |
| 121 SkASSERT(desc.fSampleCnt >= 0 && desc.fSampleCnt <= 64); |
| 122 |
| 123 desc.fOrigin = resolve_origin(desc.fOrigin, isRT); |
| 124 |
| 125 GrTexture *tex = NULL; |
| 126 GrGpuResource::LifeCycle lifeCycle = budgeted ? GrGpuResource::kCached_L
ifeCycle : |
| 127 GrGpuResource::kUncached
_LifeCycle; |
| 128 |
| 129 if (GrPixelConfigIsCompressed(desc.fConfig)) { |
| 130 // We shouldn't be rendering into this |
| 131 SkASSERT(!isRT); |
| 132 SkASSERT(0 == desc.fSampleCnt); |
| 133 |
| 134 if (!caps->npotTextureTileSupport() && |
| 135 (!SkIsPow2(desc.fWidth) || !SkIsPow2(desc.fHeight))) { |
| 136 return NULL; |
| 137 } |
| 138 |
| 139 this->handleDirtyContext(); |
| 140 tex = this->onCreateCompressedTexture(desc, lifeCycle, srcData); |
| 141 } else { |
| 142 this->handleDirtyContext(); |
| 143 tex = this->onCreateTexture(desc, lifeCycle, srcData, rowBytes); |
| 144 } |
| 145 if (!caps->reuseScratchTextures() && !isRT) { |
| 146 tex->resourcePriv().removeScratchKey(); |
| 147 } |
| 148 if (tex) { |
| 149 fStats.incTextureCreates(); |
| 150 if (srcData) { |
| 151 fStats.incTextureUploads(); |
| 152 } |
| 153 } |
| 154 return tex; |
| 155 } |
| 156 } |
| 157 |
| 158 GrTexture* GrGpu::createMipmappedTexture(const GrSurfaceDesc& origDesc, bool bud
geted, |
| 159 const SkMipMap& srcData) { |
| 160 GrSurfaceDesc desc = origDesc; |
| 161 |
| 162 const GrCaps* caps = this->caps(); |
| 163 if (!caps) { |
| 164 return NULL; |
| 120 } else { | 165 } else { |
| 121 this->handleDirtyContext(); | 166 bool isRT = false; |
| 122 tex = this->onCreateTexture(desc, lifeCycle, srcData, rowBytes); | 167 bool textureCreationParamsValid = check_texture_creation_params(*caps, d
esc, &isRT); |
| 123 } | 168 if (!textureCreationParamsValid) { |
| 124 if (!this->caps()->reuseScratchTextures() && !isRT) { | 169 return NULL; |
| 125 tex->resourcePriv().removeScratchKey(); | 170 } |
| 126 } | 171 |
| 127 if (tex) { | 172 desc.fSampleCnt = SkTMin(desc.fSampleCnt, caps->maxSampleCount()); |
| 128 fStats.incTextureCreates(); | 173 // Attempt to catch un- or wrongly initialized sample counts; |
| 129 if (srcData) { | 174 SkASSERT(desc.fSampleCnt >= 0 && desc.fSampleCnt <= 64); |
| 175 |
| 176 desc.fOrigin = resolve_origin(desc.fOrigin, isRT); |
| 177 |
| 178 GrTexture *tex = NULL; |
| 179 GrGpuResource::LifeCycle lifeCycle = budgeted ? GrGpuResource::kCached_L
ifeCycle : |
| 180 GrGpuResource::kUncached
_LifeCycle; |
| 181 |
| 182 if (GrPixelConfigIsCompressed(desc.fConfig)) { |
| 183 // We shouldn't be rendering into this |
| 184 SkASSERT(!isRT); |
| 185 SkASSERT(0 == desc.fSampleCnt); |
| 186 |
| 187 if (!caps->npotTextureTileSupport() && |
| 188 (!SkIsPow2(desc.fWidth) || !SkIsPow2(desc.fHeight))) { |
| 189 return NULL; |
| 190 } |
| 191 |
| 192 this->handleDirtyContext(); |
| 193 tex = this->onCreateCompressedMipmappedTexture(desc, lifeCycle, srcD
ata); |
| 194 } else { |
| 195 this->handleDirtyContext(); |
| 196 tex = this->onCreateMipmappedTexture(desc, lifeCycle, srcData); |
| 197 } |
| 198 if (!caps->reuseScratchTextures() && !isRT) { |
| 199 tex->resourcePriv().removeScratchKey(); |
| 200 } |
| 201 if (tex) { |
| 202 fStats.incTextureCreates(); |
| 130 fStats.incTextureUploads(); | 203 fStats.incTextureUploads(); |
| 131 } | 204 } |
| 205 return tex; |
| 132 } | 206 } |
| 133 return tex; | |
| 134 } | 207 } |
| 135 | 208 |
| 136 bool GrGpu::attachStencilAttachmentToRenderTarget(GrRenderTarget* rt) { | 209 bool GrGpu::attachStencilAttachmentToRenderTarget(GrRenderTarget* rt) { |
| 137 SkASSERT(NULL == rt->renderTargetPriv().getStencilAttachment()); | 210 SkASSERT(NULL == rt->renderTargetPriv().getStencilAttachment()); |
| 138 GrUniqueKey sbKey; | 211 GrUniqueKey sbKey; |
| 139 | 212 |
| 140 int width = rt->width(); | 213 int width = rt->width(); |
| 141 int height = rt->height(); | 214 int height = rt->height(); |
| 142 #if 0 | 215 #if 0 |
| 143 if (this->caps()->oversizedStencilSupport()) { | 216 if (this->caps()->oversizedStencilSupport()) { |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 //////////////////////////////////////////////////////////////////////////////// | 377 //////////////////////////////////////////////////////////////////////////////// |
| 305 | 378 |
| 306 void GrGpu::draw(const DrawArgs& args, const GrVertices& vertices) { | 379 void GrGpu::draw(const DrawArgs& args, const GrVertices& vertices) { |
| 307 this->handleDirtyContext(); | 380 this->handleDirtyContext(); |
| 308 GrVertices::Iterator iter; | 381 GrVertices::Iterator iter; |
| 309 const GrNonInstancedVertices* verts = iter.init(vertices); | 382 const GrNonInstancedVertices* verts = iter.init(vertices); |
| 310 do { | 383 do { |
| 311 this->onDraw(args, *verts); | 384 this->onDraw(args, *verts); |
| 312 } while ((verts = iter.next())); | 385 } while ((verts = iter.next())); |
| 313 } | 386 } |
| OLD | NEW |