| 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 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 GrResourceKey resourceKey = GrStencilBuffer::ComputeKey(width, | 264 GrResourceKey resourceKey = GrStencilBuffer::ComputeKey(width, |
| 265 height, | 265 height, |
| 266 sampleCnt); | 266 sampleCnt); |
| 267 GrCacheable* resource = fResourceCache->find(resourceKey); | 267 GrCacheable* resource = fResourceCache->find(resourceKey); |
| 268 return static_cast<GrStencilBuffer*>(resource); | 268 return static_cast<GrStencilBuffer*>(resource); |
| 269 } | 269 } |
| 270 | 270 |
| 271 static void stretch_image(void* dst, | 271 static void stretch_image(void* dst, |
| 272 int dstW, | 272 int dstW, |
| 273 int dstH, | 273 int dstH, |
| 274 void* src, | 274 const void* src, |
| 275 int srcW, | 275 int srcW, |
| 276 int srcH, | 276 int srcH, |
| 277 size_t bpp) { | 277 size_t bpp) { |
| 278 SkFixed dx = (srcW << 16) / dstW; | 278 SkFixed dx = (srcW << 16) / dstW; |
| 279 SkFixed dy = (srcH << 16) / dstH; | 279 SkFixed dy = (srcH << 16) / dstH; |
| 280 | 280 |
| 281 SkFixed y = dy >> 1; | 281 SkFixed y = dy >> 1; |
| 282 | 282 |
| 283 size_t dstXLimit = dstW*bpp; | 283 size_t dstXLimit = dstW*bpp; |
| 284 for (int j = 0; j < dstH; ++j) { | 284 for (int j = 0; j < dstH; ++j) { |
| 285 SkFixed x = dx >> 1; | 285 SkFixed x = dx >> 1; |
| 286 void* srcRow = (uint8_t*)src + (y>>16)*srcW*bpp; | 286 const uint8_t* srcRow = reinterpret_cast<const uint8_t *>(src) + (y>>16)
*srcW*bpp; |
| 287 void* dstRow = (uint8_t*)dst + j*dstW*bpp; | 287 uint8_t* dstRow = reinterpret_cast<uint8_t *>(dst) + j*dstW*bpp; |
| 288 for (size_t i = 0; i < dstXLimit; i += bpp) { | 288 for (size_t i = 0; i < dstXLimit; i += bpp) { |
| 289 memcpy((uint8_t*) dstRow + i, | 289 memcpy(dstRow + i, srcRow + (x>>16)*bpp, bpp); |
| 290 (uint8_t*) srcRow + (x>>16)*bpp, | |
| 291 bpp); | |
| 292 x += dx; | 290 x += dx; |
| 293 } | 291 } |
| 294 y += dy; | 292 y += dy; |
| 295 } | 293 } |
| 296 } | 294 } |
| 297 | 295 |
| 298 namespace { | 296 namespace { |
| 299 | 297 |
| 300 // position + local coordinate | 298 // position + local coordinate |
| 301 extern const GrVertexAttrib gVertexAttribs[] = { | 299 extern const GrVertexAttrib gVertexAttribs[] = { |
| 302 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding
}, | 300 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding
}, |
| 303 {kVec2f_GrVertexAttribType, sizeof(SkPoint), kLocalCoord_GrVertexAttribBindi
ng} | 301 {kVec2f_GrVertexAttribType, sizeof(SkPoint), kLocalCoord_GrVertexAttribBindi
ng} |
| 304 }; | 302 }; |
| 305 | 303 |
| 306 }; | 304 }; |
| 307 | 305 |
| 308 // The desired texture is NPOT and tiled but that isn't supported by | 306 // The desired texture is NPOT and tiled but that isn't supported by |
| 309 // the current hardware. Resize the texture to be a POT | 307 // the current hardware. Resize the texture to be a POT |
| 310 GrTexture* GrContext::createResizedTexture(const GrTextureDesc& desc, | 308 GrTexture* GrContext::createResizedTexture(const GrTextureDesc& desc, |
| 311 const GrCacheID& cacheID, | 309 const GrCacheID& cacheID, |
| 312 void* srcData, | 310 const void* srcData, |
| 313 size_t rowBytes, | 311 size_t rowBytes, |
| 314 bool filter) { | 312 bool filter) { |
| 315 SkAutoTUnref<GrTexture> clampedTexture(this->findAndRefTexture(desc, cacheID
, NULL)); | 313 SkAutoTUnref<GrTexture> clampedTexture(this->findAndRefTexture(desc, cacheID
, NULL)); |
| 316 if (NULL == clampedTexture) { | 314 if (NULL == clampedTexture) { |
| 317 clampedTexture.reset(this->createTexture(NULL, desc, cacheID, srcData, r
owBytes)); | 315 clampedTexture.reset(this->createTexture(NULL, desc, cacheID, srcData, r
owBytes)); |
| 318 | 316 |
| 319 if (NULL == clampedTexture) { | 317 if (NULL == clampedTexture) { |
| 320 return NULL; | 318 return NULL; |
| 321 } | 319 } |
| 322 } | 320 } |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 texture = fGpu->createTexture(rtDesc, stretchedPixels.get(), stretchedRo
wBytes); | 370 texture = fGpu->createTexture(rtDesc, stretchedPixels.get(), stretchedRo
wBytes); |
| 373 SkASSERT(NULL != texture); | 371 SkASSERT(NULL != texture); |
| 374 } | 372 } |
| 375 | 373 |
| 376 return texture; | 374 return texture; |
| 377 } | 375 } |
| 378 | 376 |
| 379 GrTexture* GrContext::createTexture(const GrTextureParams* params, | 377 GrTexture* GrContext::createTexture(const GrTextureParams* params, |
| 380 const GrTextureDesc& desc, | 378 const GrTextureDesc& desc, |
| 381 const GrCacheID& cacheID, | 379 const GrCacheID& cacheID, |
| 382 void* srcData, | 380 const void* srcData, |
| 383 size_t rowBytes, | 381 size_t rowBytes, |
| 384 GrResourceKey* cacheKey) { | 382 GrResourceKey* cacheKey) { |
| 385 GrResourceKey resourceKey = GrTextureImpl::ComputeKey(fGpu, params, desc, ca
cheID); | 383 GrResourceKey resourceKey = GrTextureImpl::ComputeKey(fGpu, params, desc, ca
cheID); |
| 386 | 384 |
| 387 GrTexture* texture; | 385 GrTexture* texture; |
| 388 if (GrTextureImpl::NeedsResizing(resourceKey)) { | 386 if (GrTextureImpl::NeedsResizing(resourceKey)) { |
| 389 texture = this->createResizedTexture(desc, cacheID, | 387 texture = this->createResizedTexture(desc, cacheID, |
| 390 srcData, rowBytes, | 388 srcData, rowBytes, |
| 391 GrTextureImpl::NeedsBilerp(resource
Key)); | 389 GrTextureImpl::NeedsBilerp(resource
Key)); |
| 392 } else { | 390 } else { |
| (...skipping 1440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1833 SkSafeRef(resource); | 1831 SkSafeRef(resource); |
| 1834 return resource; | 1832 return resource; |
| 1835 } | 1833 } |
| 1836 | 1834 |
| 1837 /////////////////////////////////////////////////////////////////////////////// | 1835 /////////////////////////////////////////////////////////////////////////////// |
| 1838 #if GR_CACHE_STATS | 1836 #if GR_CACHE_STATS |
| 1839 void GrContext::printCacheStats() const { | 1837 void GrContext::printCacheStats() const { |
| 1840 fResourceCache->printStats(); | 1838 fResourceCache->printStats(); |
| 1841 } | 1839 } |
| 1842 #endif | 1840 #endif |
| OLD | NEW |