Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(178)

Side by Side Diff: src/gpu/GrContext.cpp

Issue 638403003: Remove uses of GrAutoScratchTexture. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: comment change Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 430 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 GrTexture* GrContext::createNewScratchTexture(const GrTextureDesc& desc) { 441 GrTexture* GrContext::createNewScratchTexture(const GrTextureDesc& desc) {
442 GrTexture* texture = fGpu->createTexture(desc, NULL, 0); 442 GrTexture* texture = fGpu->createTexture(desc, NULL, 0);
443 if (!texture) { 443 if (!texture) {
444 return NULL; 444 return NULL;
445 } 445 }
446 fResourceCache->addResource(texture->getScratchKey(), texture); 446 fResourceCache->addResource(texture->getScratchKey(), texture);
447 texture->fIsScratch = GrGpuResource::kYes_IsScratch; 447 texture->fIsScratch = GrGpuResource::kYes_IsScratch;
448 return texture; 448 return texture;
449 } 449 }
450 450
451 GrTexture* GrContext::lockAndRefScratchTexture(const GrTextureDesc& inDesc, Scra tchTexMatch match, 451 GrTexture* GrContext::refScratchTexture(const GrTextureDesc& inDesc, ScratchTexM atch match,
452 bool calledDuringFlush) { 452 bool calledDuringFlush) {
453
454 // kNoStencil has no meaning if kRT isn't set. 453 // kNoStencil has no meaning if kRT isn't set.
455 SkASSERT((inDesc.fFlags & kRenderTarget_GrTextureFlagBit) || 454 SkASSERT((inDesc.fFlags & kRenderTarget_GrTextureFlagBit) ||
456 !(inDesc.fFlags & kNoStencil_GrTextureFlagBit)); 455 !(inDesc.fFlags & kNoStencil_GrTextureFlagBit));
457 456
458 // Make sure caller has checked for renderability if kRT is set. 457 // Make sure caller has checked for renderability if kRT is set.
459 SkASSERT(!(inDesc.fFlags & kRenderTarget_GrTextureFlagBit) || 458 SkASSERT(!(inDesc.fFlags & kRenderTarget_GrTextureFlagBit) ||
460 this->isConfigRenderable(inDesc.fConfig, inDesc.fSampleCnt > 0)); 459 this->isConfigRenderable(inDesc.fConfig, inDesc.fSampleCnt > 0));
461 460
462 SkTCopyOnFirstWrite<GrTextureDesc> desc(inDesc); 461 SkTCopyOnFirstWrite<GrTextureDesc> desc(inDesc);
463 462
(...skipping 817 matching lines...) Expand 10 before | Expand all | Expand 10 after
1281 GrRenderTarget* target = texture->asRenderTarget(); 1280 GrRenderTarget* target = texture->asRenderTarget();
1282 if (target) { 1281 if (target) {
1283 return this->readRenderTargetPixels(target, 1282 return this->readRenderTargetPixels(target,
1284 left, top, width, height, 1283 left, top, width, height,
1285 config, buffer, rowBytes, 1284 config, buffer, rowBytes,
1286 flags); 1285 flags);
1287 } else { 1286 } else {
1288 // TODO: make this more efficient for cases where we're reading the enti re 1287 // TODO: make this more efficient for cases where we're reading the enti re
1289 // texture, i.e., use GetTexImage() instead 1288 // texture, i.e., use GetTexImage() instead
1290 1289
1291 // create scratch rendertarget and read from that
1292 GrAutoScratchTexture ast;
1293 GrTextureDesc desc; 1290 GrTextureDesc desc;
1294 desc.fFlags = kRenderTarget_GrTextureFlagBit; 1291 desc.fFlags = kRenderTarget_GrTextureFlagBit;
1295 desc.fWidth = width; 1292 desc.fWidth = width;
1296 desc.fHeight = height; 1293 desc.fHeight = height;
1297 desc.fConfig = config; 1294 desc.fConfig = config;
1298 desc.fOrigin = kTopLeft_GrSurfaceOrigin; 1295 desc.fOrigin = kTopLeft_GrSurfaceOrigin;
1299 ast.set(this, desc, kExact_ScratchTexMatch); 1296 SkAutoTUnref<GrTexture> dst(this->refScratchTexture(desc, kExact_Scratch TexMatch));
1300 GrTexture* dst = ast.texture(); 1297 if (dst) {
robertphillips 2014/10/09 17:19:50 target = dst->asRenderTarget(); ?
bsalomon 2014/10/13 15:42:02 this code was removed.
1301 if (dst && (target = dst->asRenderTarget())) {
1302 this->copySurface(target, texture, SkIRect::MakeXYWH(top, left, widt h, height), 1298 this->copySurface(target, texture, SkIRect::MakeXYWH(top, left, widt h, height),
1303 SkIPoint::Make(0,0)); 1299 SkIPoint::Make(0,0));
1304 return this->readRenderTargetPixels(target, 1300 return this->readRenderTargetPixels(target,
1305 left, top, width, height, 1301 left, top, width, height,
1306 config, buffer, rowBytes, 1302 config, buffer, rowBytes,
1307 flags); 1303 flags);
1308 } 1304 }
1309 1305
1310 return false; 1306 return false;
1311 } 1307 }
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1365 if (unpremul && !GrPixelConfigIs8888(dstConfig)) { 1361 if (unpremul && !GrPixelConfigIs8888(dstConfig)) {
1366 // The unpremul flag is only allowed for these two configs. 1362 // The unpremul flag is only allowed for these two configs.
1367 return false; 1363 return false;
1368 } 1364 }
1369 1365
1370 // If the src is a texture and we would have to do conversions after read pi xels, we instead 1366 // If the src is a texture and we would have to do conversions after read pi xels, we instead
1371 // do the conversions by drawing the src to a scratch texture. If we handle any of the 1367 // do the conversions by drawing the src to a scratch texture. If we handle any of the
1372 // conversions in the draw we set the corresponding bool to false so that we don't reapply it 1368 // conversions in the draw we set the corresponding bool to false so that we don't reapply it
1373 // on the read back pixels. 1369 // on the read back pixels.
1374 GrTexture* src = target->asTexture(); 1370 GrTexture* src = target->asTexture();
1375 GrAutoScratchTexture ast;
1376 if (src && (swapRAndB || unpremul || flipY)) { 1371 if (src && (swapRAndB || unpremul || flipY)) {
1377 // Make the scratch a render target because we don't have a robust readT exturePixels as of 1372 // Make the scratch a render target because we don't have a robust readT exturePixels as of
1378 // yet. It calls this function. 1373 // yet. It calls this function.
1379 GrTextureDesc desc; 1374 GrTextureDesc desc;
1380 desc.fFlags = kRenderTarget_GrTextureFlagBit; 1375 desc.fFlags = kRenderTarget_GrTextureFlagBit;
1381 desc.fWidth = width; 1376 desc.fWidth = width;
1382 desc.fHeight = height; 1377 desc.fHeight = height;
1383 desc.fConfig = readConfig; 1378 desc.fConfig = readConfig;
1384 desc.fOrigin = kTopLeft_GrSurfaceOrigin; 1379 desc.fOrigin = kTopLeft_GrSurfaceOrigin;
1385 1380
1386 // When a full read back is faster than a partial we could always make t he scratch exactly 1381 // When a full read back is faster than a partial we could always make t he scratch exactly
1387 // match the passed rect. However, if we see many different size rectang les we will trash 1382 // match the passed rect. However, if we see many different size rectang les we will trash
1388 // our texture cache and pay the cost of creating and destroying many te xtures. So, we only 1383 // our texture cache and pay the cost of creating and destroying many te xtures. So, we only
1389 // request an exact match when the caller is reading an entire RT. 1384 // request an exact match when the caller is reading an entire RT.
1390 ScratchTexMatch match = kApprox_ScratchTexMatch; 1385 ScratchTexMatch match = kApprox_ScratchTexMatch;
1391 if (0 == left && 1386 if (0 == left &&
1392 0 == top && 1387 0 == top &&
1393 target->width() == width && 1388 target->width() == width &&
1394 target->height() == height && 1389 target->height() == height &&
1395 fGpu->fullReadPixelsIsFasterThanPartial()) { 1390 fGpu->fullReadPixelsIsFasterThanPartial()) {
1396 match = kExact_ScratchTexMatch; 1391 match = kExact_ScratchTexMatch;
1397 } 1392 }
1398 ast.set(this, desc, match); 1393 SkAutoTUnref<GrTexture> texture(this->refScratchTexture(desc, match));
1399 GrTexture* texture = ast.texture();
1400 if (texture) { 1394 if (texture) {
1401 // compute a matrix to perform the draw 1395 // compute a matrix to perform the draw
1402 SkMatrix textureMatrix; 1396 SkMatrix textureMatrix;
1403 textureMatrix.setTranslate(SK_Scalar1 *left, SK_Scalar1 *top); 1397 textureMatrix.setTranslate(SK_Scalar1 *left, SK_Scalar1 *top);
1404 textureMatrix.postIDiv(src->width(), src->height()); 1398 textureMatrix.postIDiv(src->width(), src->height());
1405 1399
1406 SkAutoTUnref<const GrFragmentProcessor> fp; 1400 SkAutoTUnref<const GrFragmentProcessor> fp;
1407 if (unpremul) { 1401 if (unpremul) {
1408 fp.reset(this->createPMToUPMEffect(src, swapRAndB, textureMatrix )); 1402 fp.reset(this->createPMToUPMEffect(src, swapRAndB, textureMatrix ));
1409 if (fp) { 1403 if (fp) {
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
1557 if (GrPixelConfigSwapRAndB(srcConfig) == 1551 if (GrPixelConfigSwapRAndB(srcConfig) ==
1558 fGpu->preferredWritePixelsConfig(srcConfig, renderTarget->config())) { 1552 fGpu->preferredWritePixelsConfig(srcConfig, renderTarget->config())) {
1559 writeConfig = GrPixelConfigSwapRAndB(srcConfig); 1553 writeConfig = GrPixelConfigSwapRAndB(srcConfig);
1560 swapRAndB = true; 1554 swapRAndB = true;
1561 } 1555 }
1562 1556
1563 GrTextureDesc desc; 1557 GrTextureDesc desc;
1564 desc.fWidth = width; 1558 desc.fWidth = width;
1565 desc.fHeight = height; 1559 desc.fHeight = height;
1566 desc.fConfig = writeConfig; 1560 desc.fConfig = writeConfig;
1567 GrAutoScratchTexture ast(this, desc); 1561 SkAutoTUnref<GrTexture> texture(this->refScratchTexture(desc, kApprox_Scratc hTexMatch));
1568 GrTexture* texture = ast.texture(); 1562 if (!texture) {
1569 if (NULL == texture) {
1570 return false; 1563 return false;
1571 } 1564 }
1572 1565
1573 SkAutoTUnref<const GrFragmentProcessor> fp; 1566 SkAutoTUnref<const GrFragmentProcessor> fp;
1574 SkMatrix textureMatrix; 1567 SkMatrix textureMatrix;
1575 textureMatrix.setIDiv(texture->width(), texture->height()); 1568 textureMatrix.setIDiv(texture->width(), texture->height());
1576 1569
1577 // allocate a tmp buffer and sw convert the pixels to premul 1570 // allocate a tmp buffer and sw convert the pixels to premul
1578 SkAutoSTMalloc<128 * 128, uint32_t> tmpPixels(0); 1571 SkAutoSTMalloc<128 * 128, uint32_t> tmpPixels(0);
1579 1572
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
1864 fResourceCache->printStats(); 1857 fResourceCache->printStats();
1865 } 1858 }
1866 #endif 1859 #endif
1867 1860
1868 #if GR_GPU_STATS 1861 #if GR_GPU_STATS
1869 const GrContext::GPUStats* GrContext::gpuStats() const { 1862 const GrContext::GPUStats* GrContext::gpuStats() const {
1870 return fGpu->gpuStats(); 1863 return fGpu->gpuStats();
1871 } 1864 }
1872 #endif 1865 #endif
1873 1866
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698