OLD | NEW |
1 | |
2 /* | 1 /* |
3 * Copyright 2010 Google Inc. | 2 * Copyright 2010 Google Inc. |
4 * | 3 * |
5 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 5 * found in the LICENSE file. |
7 */ | 6 */ |
8 | 7 |
9 | 8 |
10 #include "GrGpu.h" | 9 #include "GrGpu.h" |
11 | 10 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 // By default, GrRenderTargets are GL's normal orientation so that they | 81 // By default, GrRenderTargets are GL's normal orientation so that they |
83 // can be drawn to by the outside world without the client having | 82 // can be drawn to by the outside world without the client having |
84 // to render upside down. | 83 // to render upside down. |
85 if (kDefault_GrSurfaceOrigin == origin) { | 84 if (kDefault_GrSurfaceOrigin == origin) { |
86 return renderTarget ? kBottomLeft_GrSurfaceOrigin : kTopLeft_GrSurfaceOr
igin; | 85 return renderTarget ? kBottomLeft_GrSurfaceOrigin : kTopLeft_GrSurfaceOr
igin; |
87 } else { | 86 } else { |
88 return origin; | 87 return origin; |
89 } | 88 } |
90 } | 89 } |
91 | 90 |
| 91 /** |
| 92 * Prior to creating a texture, make sure the type of texture being created is |
| 93 * supported by calling check_texture_creation_params. |
| 94 * |
| 95 * @param caps The capabilities of the GL device. |
| 96 * @param desc The descriptor of the texture to create. |
| 97 * @param isRT Indicates if the texture can be a render target. |
| 98 */ |
| 99 static bool check_texture_creation_params(const GrCaps& caps, const GrSurfaceDes
c& desc, |
| 100 bool* isRT) { |
| 101 if (!caps.isConfigTexturable(desc.fConfig)) { |
| 102 return false; |
| 103 } |
| 104 |
| 105 *isRT = SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag); |
| 106 if (*isRT && !caps.isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) { |
| 107 return false; |
| 108 } |
| 109 |
| 110 // We currently do not support multisampled textures |
| 111 if (!*isRT && desc.fSampleCnt > 0) { |
| 112 return false; |
| 113 } |
| 114 |
| 115 if (*isRT) { |
| 116 int maxRTSize = caps.maxRenderTargetSize(); |
| 117 if (desc.fWidth > maxRTSize || desc.fHeight > maxRTSize) { |
| 118 return false; |
| 119 } |
| 120 } else { |
| 121 int maxSize = caps.maxTextureSize(); |
| 122 if (desc.fWidth > maxSize || desc.fHeight > maxSize) { |
| 123 return false; |
| 124 } |
| 125 } |
| 126 return true; |
| 127 } |
| 128 |
92 GrTexture* GrGpu::createTexture(const GrSurfaceDesc& origDesc, bool budgeted, | 129 GrTexture* GrGpu::createTexture(const GrSurfaceDesc& origDesc, bool budgeted, |
93 const void* srcData, size_t rowBytes) { | 130 const SkTArray<SkMipMapLevel>& texels) { |
94 GrSurfaceDesc desc = origDesc; | 131 GrSurfaceDesc desc = origDesc; |
95 | 132 |
96 if (!this->caps()->isConfigTexturable(desc.fConfig)) { | 133 const GrCaps* caps = this->caps(); |
| 134 bool isRT = false; |
| 135 bool textureCreationParamsValid = check_texture_creation_params(*caps, desc,
&isRT); |
| 136 if (!textureCreationParamsValid) { |
97 return nullptr; | 137 return nullptr; |
98 } | 138 } |
99 | 139 |
100 bool isRT = SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag); | 140 desc.fSampleCnt = SkTMin(desc.fSampleCnt, caps->maxSampleCount()); |
101 if (isRT && !this->caps()->isConfigRenderable(desc.fConfig, desc.fSampleCnt
> 0)) { | 141 // Attempt to catch un- or wrongly intialized sample counts; |
102 return nullptr; | |
103 } | |
104 | |
105 // We currently do not support multisampled textures | |
106 if (!isRT && desc.fSampleCnt > 0) { | |
107 return nullptr; | |
108 } | |
109 | |
110 GrTexture *tex = nullptr; | |
111 | |
112 if (isRT) { | |
113 int maxRTSize = this->caps()->maxRenderTargetSize(); | |
114 if (desc.fWidth > maxRTSize || desc.fHeight > maxRTSize) { | |
115 return nullptr; | |
116 } | |
117 } else { | |
118 int maxSize = this->caps()->maxTextureSize(); | |
119 if (desc.fWidth > maxSize || desc.fHeight > maxSize) { | |
120 return nullptr; | |
121 } | |
122 } | |
123 | |
124 GrGpuResource::LifeCycle lifeCycle = budgeted ? GrGpuResource::kCached_LifeC
ycle : | |
125 GrGpuResource::kUncached_Lif
eCycle; | |
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); | 142 SkASSERT(desc.fSampleCnt >= 0 && desc.fSampleCnt <= 64); |
130 | 143 |
131 desc.fOrigin = resolve_origin(desc.fOrigin, isRT); | 144 desc.fOrigin = resolve_origin(desc.fOrigin, isRT); |
132 | 145 |
| 146 GrTexture* tex = nullptr; |
| 147 GrGpuResource::LifeCycle lifeCycle = budgeted ? GrGpuResource::kCached_LifeC
ycle : |
| 148 GrGpuResource::kUncached_Lif
eCycle; |
| 149 |
133 if (GrPixelConfigIsCompressed(desc.fConfig)) { | 150 if (GrPixelConfigIsCompressed(desc.fConfig)) { |
134 // We shouldn't be rendering into this | 151 // We shouldn't be rendering into this |
135 SkASSERT(!isRT); | 152 SkASSERT(!isRT); |
136 SkASSERT(0 == desc.fSampleCnt); | 153 SkASSERT(0 == desc.fSampleCnt); |
137 | 154 |
138 if (!this->caps()->npotTextureTileSupport() && | 155 if (!caps->npotTextureTileSupport() && |
139 (!SkIsPow2(desc.fWidth) || !SkIsPow2(desc.fHeight))) { | 156 (!SkIsPow2(desc.fWidth) || !SkIsPow2(desc.fHeight))) { |
140 return nullptr; | 157 return nullptr; |
141 } | 158 } |
142 | 159 |
143 this->handleDirtyContext(); | 160 this->handleDirtyContext(); |
144 tex = this->onCreateCompressedTexture(desc, lifeCycle, srcData); | 161 tex = this->onCreateCompressedTexture(desc, lifeCycle, texels); |
145 } else { | 162 } else { |
146 this->handleDirtyContext(); | 163 this->handleDirtyContext(); |
147 tex = this->onCreateTexture(desc, lifeCycle, srcData, rowBytes); | 164 tex = this->onCreateTexture(desc, lifeCycle, texels); |
148 } | |
149 if (!this->caps()->reuseScratchTextures() && !isRT) { | |
150 tex->resourcePriv().removeScratchKey(); | |
151 } | 165 } |
152 if (tex) { | 166 if (tex) { |
| 167 if (!caps->reuseScratchTextures() && !isRT) { |
| 168 tex->resourcePriv().removeScratchKey(); |
| 169 } |
153 fStats.incTextureCreates(); | 170 fStats.incTextureCreates(); |
154 if (srcData) { | 171 if (!texels.empty()) { |
155 fStats.incTextureUploads(); | 172 if (texels[0].fTexelsOrOffset) { |
| 173 fStats.incTextureUploads(); |
| 174 } |
156 } | 175 } |
157 } | 176 } |
158 return tex; | 177 return tex; |
159 } | 178 } |
160 | 179 |
| 180 GrTexture* GrGpu::createTexture(const GrSurfaceDesc& desc, bool budgeted, |
| 181 const void* srcData, size_t rowBytes) { |
| 182 SkMipMapLevel level(srcData, rowBytes, desc.fWidth, desc.fHeight); |
| 183 SkSTArray<1, SkMipMapLevel> levels; |
| 184 levels.push_back(level); |
| 185 |
| 186 return this->createTexture(desc, budgeted, levels); |
| 187 } |
| 188 |
161 GrTexture* GrGpu::wrapBackendTexture(const GrBackendTextureDesc& desc, GrWrapOwn
ership ownership) { | 189 GrTexture* GrGpu::wrapBackendTexture(const GrBackendTextureDesc& desc, GrWrapOwn
ership ownership) { |
162 this->handleDirtyContext(); | 190 this->handleDirtyContext(); |
163 if (!this->caps()->isConfigTexturable(desc.fConfig)) { | 191 if (!this->caps()->isConfigTexturable(desc.fConfig)) { |
164 return nullptr; | 192 return nullptr; |
165 } | 193 } |
166 if ((desc.fFlags & kRenderTarget_GrBackendTextureFlag) && | 194 if ((desc.fFlags & kRenderTarget_GrBackendTextureFlag) && |
167 !this->caps()->isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) { | 195 !this->caps()->isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) { |
168 return nullptr; | 196 return nullptr; |
169 } | 197 } |
170 GrTexture* tex = this->onWrapBackendTexture(desc, ownership); | 198 GrTexture* tex = this->onWrapBackendTexture(desc, ownership); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 !this->caps()->isConfigRenderable(tempDrawInfo->fTempSurfaceDesc.fConfig
, false)) { | 290 !this->caps()->isConfigRenderable(tempDrawInfo->fTempSurfaceDesc.fConfig
, false)) { |
263 // If we don't have a fallback to a straight read then fail. | 291 // If we don't have a fallback to a straight read then fail. |
264 if (kRequireDraw_DrawPreference == *drawPreference) { | 292 if (kRequireDraw_DrawPreference == *drawPreference) { |
265 return false; | 293 return false; |
266 } | 294 } |
267 *drawPreference = kNoDraw_DrawPreference; | 295 *drawPreference = kNoDraw_DrawPreference; |
268 } | 296 } |
269 | 297 |
270 return true; | 298 return true; |
271 } | 299 } |
272 bool GrGpu::getWritePixelsInfo(GrSurface* dstSurface, int width, int height, siz
e_t rowBytes, | 300 bool GrGpu::getWritePixelsInfo(GrSurface* dstSurface, int width, int height, |
273 GrPixelConfig srcConfig, DrawPreference* drawPref
erence, | 301 GrPixelConfig srcConfig, DrawPreference* drawPref
erence, |
274 WritePixelTempDrawInfo* tempDrawInfo) { | 302 WritePixelTempDrawInfo* tempDrawInfo) { |
275 SkASSERT(drawPreference); | 303 SkASSERT(drawPreference); |
276 SkASSERT(tempDrawInfo); | 304 SkASSERT(tempDrawInfo); |
277 SkASSERT(kGpuPrefersDraw_DrawPreference != *drawPreference); | 305 SkASSERT(kGpuPrefersDraw_DrawPreference != *drawPreference); |
278 | 306 |
279 if (GrPixelConfigIsCompressed(dstSurface->desc().fConfig) && | 307 if (GrPixelConfigIsCompressed(dstSurface->desc().fConfig) && |
280 dstSurface->desc().fConfig != srcConfig) { | 308 dstSurface->desc().fConfig != srcConfig) { |
281 return false; | 309 return false; |
282 } | 310 } |
283 | 311 |
284 if (this->caps()->useDrawInsteadOfPartialRenderTargetWrite() && | 312 if (this->caps()->useDrawInsteadOfPartialRenderTargetWrite() && |
285 SkToBool(dstSurface->asRenderTarget()) && | 313 SkToBool(dstSurface->asRenderTarget()) && |
286 (width < dstSurface->width() || height < dstSurface->height())) { | 314 (width < dstSurface->width() || height < dstSurface->height())) { |
287 ElevateDrawPreference(drawPreference, kRequireDraw_DrawPreference); | 315 ElevateDrawPreference(drawPreference, kRequireDraw_DrawPreference); |
288 } | 316 } |
289 | 317 |
290 if (!this->onGetWritePixelsInfo(dstSurface, width, height, rowBytes, srcConf
ig, drawPreference, | 318 if (!this->onGetWritePixelsInfo(dstSurface, width, height, srcConfig, drawPr
eference, |
291 tempDrawInfo)) { | 319 tempDrawInfo)) { |
292 return false; | 320 return false; |
293 } | 321 } |
294 | 322 |
295 // Check to see if we're going to request that the caller draw when drawing
is not possible. | 323 // Check to see if we're going to request that the caller draw when drawing
is not possible. |
296 if (!dstSurface->asRenderTarget() || | 324 if (!dstSurface->asRenderTarget() || |
297 !this->caps()->isConfigTexturable(tempDrawInfo->fTempSurfaceDesc.fConfig
)) { | 325 !this->caps()->isConfigTexturable(tempDrawInfo->fTempSurfaceDesc.fConfig
)) { |
298 // If we don't have a fallback to a straight upload then fail. | 326 // If we don't have a fallback to a straight upload then fail. |
299 if (kRequireDraw_DrawPreference == *drawPreference || | 327 if (kRequireDraw_DrawPreference == *drawPreference || |
300 !this->caps()->isConfigTexturable(srcConfig)) { | 328 !this->caps()->isConfigTexturable(srcConfig)) { |
(...skipping 24 matching lines...) Expand all Loading... |
325 } | 353 } |
326 | 354 |
327 return this->onReadPixels(surface, | 355 return this->onReadPixels(surface, |
328 left, top, width, height, | 356 left, top, width, height, |
329 config, buffer, | 357 config, buffer, |
330 rowBytes); | 358 rowBytes); |
331 } | 359 } |
332 | 360 |
333 bool GrGpu::writePixels(GrSurface* surface, | 361 bool GrGpu::writePixels(GrSurface* surface, |
334 int left, int top, int width, int height, | 362 int left, int top, int width, int height, |
335 GrPixelConfig config, const void* buffer, | 363 GrPixelConfig config, const SkTArray<SkMipMapLevel>& tex
els) { |
336 size_t rowBytes) { | 364 if (!surface) { |
337 if (!buffer || !surface) { | 365 return false; |
| 366 } |
| 367 bool validMipDataFound = false; |
| 368 for (int currentMipLevel = 0; currentMipLevel < texels.count(); currentMipLe
vel++) { |
| 369 if (texels[currentMipLevel].fTexelsOrOffset != nullptr) { |
| 370 validMipDataFound = true; |
| 371 break; |
| 372 } |
| 373 } |
| 374 if (!validMipDataFound) { |
338 return false; | 375 return false; |
339 } | 376 } |
340 | 377 |
341 this->handleDirtyContext(); | 378 this->handleDirtyContext(); |
342 if (this->onWritePixels(surface, left, top, width, height, config, buffer, r
owBytes)) { | 379 if (this->onWritePixels(surface, left, top, width, height, config, texels))
{ |
343 fStats.incTextureUploads(); | 380 fStats.incTextureUploads(); |
344 return true; | 381 return true; |
345 } | 382 } |
346 return false; | 383 return false; |
347 } | 384 } |
348 | 385 |
| 386 bool GrGpu::writePixels(GrSurface* surface, |
| 387 int left, int top, int width, int height, |
| 388 GrPixelConfig config, const void* buffer, |
| 389 size_t rowBytes) { |
| 390 SkMipMapLevel mipLevel(buffer, rowBytes, width, height); |
| 391 SkSTArray<1, SkMipMapLevel> texels; |
| 392 texels.push_back(mipLevel); |
| 393 |
| 394 return this->writePixels(surface, left, top, width, height, config, texels); |
| 395 } |
| 396 |
349 bool GrGpu::transferPixels(GrSurface* surface, | 397 bool GrGpu::transferPixels(GrSurface* surface, |
350 int left, int top, int width, int height, | 398 int left, int top, int width, int height, |
351 GrPixelConfig config, GrTransferBuffer* buffer, | 399 GrPixelConfig config, GrTransferBuffer* buffer, |
352 size_t offset, size_t rowBytes) { | 400 size_t offset, size_t rowBytes) { |
353 SkASSERT(buffer); | 401 SkASSERT(buffer); |
354 | 402 |
355 this->handleDirtyContext(); | 403 this->handleDirtyContext(); |
356 if (this->onTransferPixels(surface, left, top, width, height, config, | 404 if (this->onTransferPixels(surface, left, top, width, height, config, |
357 buffer, offset, rowBytes)) { | 405 buffer, offset, rowBytes)) { |
358 fStats.incTransfersToTexture(); | 406 fStats.incTransfersToTexture(); |
(...skipping 16 matching lines...) Expand all Loading... |
375 this->xferBarrier(args.fPipeline->getRenderTarget(), barrierType); | 423 this->xferBarrier(args.fPipeline->getRenderTarget(), barrierType); |
376 } | 424 } |
377 | 425 |
378 GrVertices::Iterator iter; | 426 GrVertices::Iterator iter; |
379 const GrNonInstancedVertices* verts = iter.init(vertices); | 427 const GrNonInstancedVertices* verts = iter.init(vertices); |
380 do { | 428 do { |
381 this->onDraw(args, *verts); | 429 this->onDraw(args, *verts); |
382 fStats.incNumDraws(); | 430 fStats.incNumDraws(); |
383 } while ((verts = iter.next())); | 431 } while ((verts = iter.next())); |
384 } | 432 } |
OLD | NEW |