OLD | NEW |
---|---|
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 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 "GrContext.h" | 10 #include "GrContext.h" |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
299 }; | 299 }; |
300 | 300 |
301 }; | 301 }; |
302 | 302 |
303 // The desired texture is NPOT and tiled but that isn't supported by | 303 // The desired texture is NPOT and tiled but that isn't supported by |
304 // the current hardware. Resize the texture to be a POT | 304 // the current hardware. Resize the texture to be a POT |
305 GrTexture* GrContext::createResizedTexture(const GrTextureDesc& desc, | 305 GrTexture* GrContext::createResizedTexture(const GrTextureDesc& desc, |
306 const GrCacheID& cacheID, | 306 const GrCacheID& cacheID, |
307 void* srcData, | 307 void* srcData, |
308 size_t rowBytes, | 308 size_t rowBytes, |
309 bool needsFiltering) { | 309 GrTextureParams::FilterMode filterMod e) { |
310 SkAutoTUnref<GrTexture> clampedTexture(this->findAndRefTexture(desc, cacheID , NULL)); | 310 SkAutoTUnref<GrTexture> clampedTexture(this->findAndRefTexture(desc, cacheID , NULL)); |
311 if (NULL == clampedTexture) { | 311 if (NULL == clampedTexture) { |
312 clampedTexture.reset(this->createTexture(NULL, desc, cacheID, srcData, r owBytes)); | 312 clampedTexture.reset(this->createTexture(NULL, desc, cacheID, srcData, r owBytes)); |
313 | 313 |
314 if (NULL == clampedTexture) { | 314 if (NULL == clampedTexture) { |
315 return NULL; | 315 return NULL; |
316 } | 316 } |
317 } | 317 } |
318 | 318 |
319 GrTextureDesc rtDesc = desc; | 319 GrTextureDesc rtDesc = desc; |
320 rtDesc.fFlags = rtDesc.fFlags | | 320 rtDesc.fFlags = rtDesc.fFlags | |
321 kRenderTarget_GrTextureFlagBit | | 321 kRenderTarget_GrTextureFlagBit | |
322 kNoStencil_GrTextureFlagBit; | 322 kNoStencil_GrTextureFlagBit; |
323 rtDesc.fWidth = GrNextPow2(GrMax(desc.fWidth, 64)); | 323 rtDesc.fWidth = GrNextPow2(GrMax(desc.fWidth, 64)); |
324 rtDesc.fHeight = GrNextPow2(GrMax(desc.fHeight, 64)); | 324 rtDesc.fHeight = GrNextPow2(GrMax(desc.fHeight, 64)); |
325 | 325 |
326 GrTexture* texture = fGpu->createTexture(rtDesc, NULL, 0); | 326 GrTexture* texture = fGpu->createTexture(rtDesc, NULL, 0); |
327 | 327 |
328 if (NULL != texture) { | 328 if (NULL != texture) { |
329 GrDrawTarget::AutoStateRestore asr(fGpu, GrDrawTarget::kReset_ASRInit); | 329 GrDrawTarget::AutoStateRestore asr(fGpu, GrDrawTarget::kReset_ASRInit); |
330 GrDrawState* drawState = fGpu->drawState(); | 330 GrDrawState* drawState = fGpu->drawState(); |
331 drawState->setRenderTarget(texture->asRenderTarget()); | 331 drawState->setRenderTarget(texture->asRenderTarget()); |
332 | 332 |
333 // if filtering is not desired then we want to ensure all | 333 // if filtering is not desired then we want to ensure all |
334 // texels in the resampled image are copies of texels from | 334 // texels in the resampled image are copies of texels from |
335 // the original. | 335 // the original. |
336 GrTextureParams params(SkShader::kClamp_TileMode, needsFiltering); | 336 GrTextureParams params(SkShader::kClamp_TileMode, filterMode); |
bsalomon
2013/07/25 17:41:48
Actually I think we just want to set knone or kbil
| |
337 drawState->addColorTextureEffect(clampedTexture, SkMatrix::I(), params); | 337 drawState->addColorTextureEffect(clampedTexture, SkMatrix::I(), params); |
338 | 338 |
339 drawState->setVertexAttribs<gVertexAttribs>(SK_ARRAY_COUNT(gVertexAttrib s)); | 339 drawState->setVertexAttribs<gVertexAttribs>(SK_ARRAY_COUNT(gVertexAttrib s)); |
340 | 340 |
341 GrDrawTarget::AutoReleaseGeometry arg(fGpu, 4, 0); | 341 GrDrawTarget::AutoReleaseGeometry arg(fGpu, 4, 0); |
342 | 342 |
343 if (arg.succeeded()) { | 343 if (arg.succeeded()) { |
344 GrPoint* verts = (GrPoint*) arg.vertices(); | 344 GrPoint* verts = (GrPoint*) arg.vertices(); |
345 verts[0].setIRectFan(0, 0, texture->width(), texture->height(), 2 * sizeof(GrPoint)); | 345 verts[0].setIRectFan(0, 0, texture->width(), texture->height(), 2 * sizeof(GrPoint)); |
346 verts[1].setIRectFan(0, 0, 1, 1, 2 * sizeof(GrPoint)); | 346 verts[1].setIRectFan(0, 0, 1, 1, 2 * sizeof(GrPoint)); |
(...skipping 28 matching lines...) Expand all Loading... | |
375 const GrTextureDesc& desc, | 375 const GrTextureDesc& desc, |
376 const GrCacheID& cacheID, | 376 const GrCacheID& cacheID, |
377 void* srcData, | 377 void* srcData, |
378 size_t rowBytes) { | 378 size_t rowBytes) { |
379 SK_TRACE_EVENT0("GrContext::createTexture"); | 379 SK_TRACE_EVENT0("GrContext::createTexture"); |
380 | 380 |
381 GrResourceKey resourceKey = GrTexture::ComputeKey(fGpu, params, desc, cacheI D); | 381 GrResourceKey resourceKey = GrTexture::ComputeKey(fGpu, params, desc, cacheI D); |
382 | 382 |
383 GrTexture* texture; | 383 GrTexture* texture; |
384 if (GrTexture::NeedsResizing(resourceKey)) { | 384 if (GrTexture::NeedsResizing(resourceKey)) { |
385 GrTextureParams::FilterMode textureFilterMode = GrTextureParams::kNone_F ilterMode; | |
386 if (GrTexture::NeedsBilerp(resourceKey)) { | |
387 textureFilterMode = GrTextureParams::kBilerp_FilterMode; | |
388 } else if (GrTexture::NeedsMipMap(resourceKey)) { | |
389 textureFilterMode = GrTextureParams::kMipMap_FilterMode; | |
390 } | |
385 texture = this->createResizedTexture(desc, cacheID, | 391 texture = this->createResizedTexture(desc, cacheID, |
386 srcData, rowBytes, | 392 srcData, rowBytes, |
387 GrTexture::NeedsFiltering(resourceK ey)); | 393 textureFilterMode); |
388 } else { | 394 } else { |
389 texture= fGpu->createTexture(desc, srcData, rowBytes); | 395 texture= fGpu->createTexture(desc, srcData, rowBytes); |
390 } | 396 } |
391 | 397 |
392 if (NULL != texture) { | 398 if (NULL != texture) { |
393 // Adding a resource could put us overbudget. Try to free up the | 399 // Adding a resource could put us overbudget. Try to free up the |
394 // necessary space before adding it. | 400 // necessary space before adding it. |
395 fTextureCache->purgeAsNeeded(1, texture->sizeInBytes()); | 401 fTextureCache->purgeAsNeeded(1, texture->sizeInBytes()); |
396 fTextureCache->addResource(resourceKey, texture); | 402 fTextureCache->addResource(resourceKey, texture); |
397 } | 403 } |
(...skipping 1306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1704 return NULL; | 1710 return NULL; |
1705 } | 1711 } |
1706 } | 1712 } |
1707 | 1713 |
1708 /////////////////////////////////////////////////////////////////////////////// | 1714 /////////////////////////////////////////////////////////////////////////////// |
1709 #if GR_CACHE_STATS | 1715 #if GR_CACHE_STATS |
1710 void GrContext::printCacheStats() const { | 1716 void GrContext::printCacheStats() const { |
1711 fTextureCache->printStats(); | 1717 fTextureCache->printStats(); |
1712 } | 1718 } |
1713 #endif | 1719 #endif |
OLD | NEW |