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

Side by Side Diff: src/gpu/gl/GrGLGpu.cpp

Issue 1684993002: Revert of skia: Add support for CHROMIUM_image backed textures. (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: Created 4 years, 10 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
« no previous file with comments | « src/gpu/gl/GrGLGpu.h ('k') | src/gpu/gl/GrGLTexture.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2011 Google Inc. 2 * Copyright 2011 Google Inc.
3 * 3 *
4 * 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
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "GrGLGpu.h" 8 #include "GrGLGpu.h"
9 #include "GrGLGLSL.h" 9 #include "GrGLGLSL.h"
10 #include "GrGLStencilAttachment.h" 10 #include "GrGLStencilAttachment.h"
(...skipping 911 matching lines...) Expand 10 before | Expand all | Expand 10 after
922 GL_CALL(PixelStorei(GR_GL_UNPACK_FLIP_Y, GR_GL_TRUE)); 922 GL_CALL(PixelStorei(GR_GL_UNPACK_FLIP_Y, GR_GL_TRUE));
923 } 923 }
924 GL_CALL(PixelStorei(GR_GL_UNPACK_ALIGNMENT, config_alignment(dataConfig) )); 924 GL_CALL(PixelStorei(GR_GL_UNPACK_ALIGNMENT, config_alignment(dataConfig) ));
925 } 925 }
926 bool succeeded = true; 926 bool succeeded = true;
927 if (kNewTexture_UploadType == uploadType) { 927 if (kNewTexture_UploadType == uploadType) {
928 if (dataOrOffset && 928 if (dataOrOffset &&
929 !(0 == left && 0 == top && desc.fWidth == width && desc.fHeight == h eight)) { 929 !(0 == left && 0 == top && desc.fWidth == width && desc.fHeight == h eight)) {
930 succeeded = false; 930 succeeded = false;
931 } else { 931 } else {
932 if (desc.fTextureStorageAllocator.fAllocateTextureStorage) { 932 CLEAR_ERROR_BEFORE_ALLOC(this->glInterface());
933 if (dataOrOffset) { 933 GL_ALLOC_CALL(this->glInterface(), TexImage2D(target, 0, internalFor mat, desc.fWidth,
934 GL_CALL(TexSubImage2D(target, 934 desc.fHeight, 0, exter nalFormat,
935 0, // level 935 externalType, dataOrOf fset));
936 left, top, 936 GrGLenum error = check_alloc_error(desc, this->glInterface());
937 width, height, 937 if (error != GR_GL_NO_ERROR) {
938 externalFormat, externalType, dataOrOf fset)); 938 succeeded = false;
939 } 939 }
940 } else {
941 CLEAR_ERROR_BEFORE_ALLOC(this->glInterface());
942 GL_ALLOC_CALL(this->glInterface(), TexImage2D(
943 target, 0, internalFormat, desc.fWidth, desc.fHeight, 0, ext ernalFormat,
944 externalType, dataOrOffset));
945 GrGLenum error = check_alloc_error(desc, this->glInterface());
946 if (error != GR_GL_NO_ERROR) {
947 succeeded = false;
948 }
949 }
950 } 940 }
951 } else { 941 } else {
952 if (swFlipY || glFlipY) { 942 if (swFlipY || glFlipY) {
953 top = desc.fHeight - (top + height); 943 top = desc.fHeight - (top + height);
954 } 944 }
955 GL_CALL(TexSubImage2D(target, 945 GL_CALL(TexSubImage2D(target,
956 0, // level 946 0, // level
957 left, top, 947 left, top,
958 width, height, 948 width, height,
959 externalFormat, externalType, dataOrOffset)); 949 externalFormat, externalType, dataOrOffset));
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
1208 const void* srcData, size_t rowBytes) { 1198 const void* srcData, size_t rowBytes) {
1209 // We fail if the MSAA was requested and is not available. 1199 // We fail if the MSAA was requested and is not available.
1210 if (GrGLCaps::kNone_MSFBOType == this->glCaps().msFBOType() && desc.fSampleC nt) { 1200 if (GrGLCaps::kNone_MSFBOType == this->glCaps().msFBOType() && desc.fSampleC nt) {
1211 //SkDebugf("MSAA RT requested but not supported on this platform."); 1201 //SkDebugf("MSAA RT requested but not supported on this platform.");
1212 return return_null_texture(); 1202 return return_null_texture();
1213 } 1203 }
1214 1204
1215 bool renderTarget = SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag); 1205 bool renderTarget = SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag);
1216 1206
1217 GrGLTexture::IDDesc idDesc; 1207 GrGLTexture::IDDesc idDesc;
1208 idDesc.fInfo.fID = 0;
1209 GL_CALL(GenTextures(1, &idDesc.fInfo.fID));
1218 idDesc.fLifeCycle = lifeCycle; 1210 idDesc.fLifeCycle = lifeCycle;
1219 GrGLTexture::TexParams initialTexParams; 1211 // We only support GL_TEXTURE_2D at the moment.
1220 if (!this->createTextureImpl(desc, &idDesc.fInfo, renderTarget, srcData, 1212 idDesc.fInfo.fTarget = GR_GL_TEXTURE_2D;
1221 &initialTexParams, rowBytes)) { 1213
1214 if (!idDesc.fInfo.fID) {
1222 return return_null_texture(); 1215 return return_null_texture();
1223 } 1216 }
1224 1217
1218 this->setScratchTextureUnit();
1219 GL_CALL(BindTexture(idDesc.fInfo.fTarget, idDesc.fInfo.fID));
1220
1221 if (renderTarget && this->glCaps().textureUsageSupport()) {
1222 // provides a hint about how this texture will be used
1223 GL_CALL(TexParameteri(idDesc.fInfo.fTarget,
1224 GR_GL_TEXTURE_USAGE,
1225 GR_GL_FRAMEBUFFER_ATTACHMENT));
1226 }
1227
1228 // Some drivers like to know filter/wrap before seeing glTexImage2D. Some
1229 // drivers have a bug where an FBO won't be complete if it includes a
1230 // texture that is not mipmap complete (considering the filter in use).
1231 GrGLTexture::TexParams initialTexParams;
1232 // we only set a subset here so invalidate first
1233 initialTexParams.invalidate();
1234 initialTexParams.fMinFilter = GR_GL_NEAREST;
1235 initialTexParams.fMagFilter = GR_GL_NEAREST;
1236 initialTexParams.fWrapS = GR_GL_CLAMP_TO_EDGE;
1237 initialTexParams.fWrapT = GR_GL_CLAMP_TO_EDGE;
1238 GL_CALL(TexParameteri(idDesc.fInfo.fTarget,
1239 GR_GL_TEXTURE_MAG_FILTER,
1240 initialTexParams.fMagFilter));
1241 GL_CALL(TexParameteri(idDesc.fInfo.fTarget,
1242 GR_GL_TEXTURE_MIN_FILTER,
1243 initialTexParams.fMinFilter));
1244 GL_CALL(TexParameteri(idDesc.fInfo.fTarget,
1245 GR_GL_TEXTURE_WRAP_S,
1246 initialTexParams.fWrapS));
1247 GL_CALL(TexParameteri(idDesc.fInfo.fTarget,
1248 GR_GL_TEXTURE_WRAP_T,
1249 initialTexParams.fWrapT));
1250 if (!this->uploadTexData(desc, idDesc.fInfo.fTarget, kNewTexture_UploadType, 0, 0,
1251 desc.fWidth, desc.fHeight,
1252 desc.fConfig, srcData, rowBytes)) {
1253 GL_CALL(DeleteTextures(1, &idDesc.fInfo.fID));
1254 return return_null_texture();
1255 }
1256
1225 GrGLTexture* tex; 1257 GrGLTexture* tex;
1226 if (renderTarget) { 1258 if (renderTarget) {
1227 // unbind the texture from the texture unit before binding it to the fra me buffer 1259 // unbind the texture from the texture unit before binding it to the fra me buffer
1228 GL_CALL(BindTexture(idDesc.fInfo.fTarget, 0)); 1260 GL_CALL(BindTexture(idDesc.fInfo.fTarget, 0));
1229 GrGLRenderTarget::IDDesc rtIDDesc; 1261 GrGLRenderTarget::IDDesc rtIDDesc;
1230 1262
1231 if (!this->createRenderTargetObjects(desc, lifeCycle, idDesc.fInfo, &rtI DDesc)) { 1263 if (!this->createRenderTargetObjects(desc, lifeCycle, idDesc.fInfo, &rtI DDesc)) {
1232 GL_CALL(DeleteTextures(1, &idDesc.fInfo.fID)); 1264 GL_CALL(DeleteTextures(1, &idDesc.fInfo.fID));
1233 return return_null_texture(); 1265 return return_null_texture();
1234 } 1266 }
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
1434 GL_CALL(DeleteRenderbuffers(1, &sbRBID)); 1466 GL_CALL(DeleteRenderbuffers(1, &sbRBID));
1435 } 1467 }
1436 GL_CALL(DeleteTextures(1, &colorID)); 1468 GL_CALL(DeleteTextures(1, &colorID));
1437 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, 0)); 1469 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, 0));
1438 GL_CALL(DeleteFramebuffers(1, &fb)); 1470 GL_CALL(DeleteFramebuffers(1, &fb));
1439 fGLContext->caps()->setStencilFormatIndexForConfig(config, firstWorkingS tencilFormatIndex); 1471 fGLContext->caps()->setStencilFormatIndexForConfig(config, firstWorkingS tencilFormatIndex);
1440 } 1472 }
1441 return this->glCaps().getStencilFormatIndexForConfig(config); 1473 return this->glCaps().getStencilFormatIndexForConfig(config);
1442 } 1474 }
1443 1475
1444 bool GrGLGpu::createTextureImpl(const GrSurfaceDesc& desc, GrGLTextureInfo* info ,
1445 bool renderTarget, const void* srcData,
1446 GrGLTexture::TexParams* initialTexParams, size_t rowBytes) {
1447 // Some drivers like to know filter/wrap before seeing glTexImage2D. Some
1448 // drivers have a bug where an FBO won't be complete if it includes a
1449 // texture that is not mipmap complete (considering the filter in use).
1450
1451 // we only set a subset here so invalidate first
1452 initialTexParams->invalidate();
1453 initialTexParams->fMinFilter = GR_GL_NEAREST;
1454 initialTexParams->fMagFilter = GR_GL_NEAREST;
1455 initialTexParams->fWrapS = GR_GL_CLAMP_TO_EDGE;
1456 initialTexParams->fWrapT = GR_GL_CLAMP_TO_EDGE;
1457
1458 if (desc.fTextureStorageAllocator.fAllocateTextureStorage) {
1459 return this->createTextureExternalAllocatorImpl(desc, info, srcData, row Bytes);
1460 }
1461
1462 info->fID = 0;
1463 info->fTarget = GR_GL_TEXTURE_2D;
1464 GL_CALL(GenTextures(1, &(info->fID)));
1465
1466 if (!info->fID) {
1467 return false;
1468 }
1469
1470 this->setScratchTextureUnit();
1471 GL_CALL(BindTexture(info->fTarget, info->fID));
1472
1473 if (renderTarget && this->glCaps().textureUsageSupport()) {
1474 // provides a hint about how this texture will be used
1475 GL_CALL(TexParameteri(info->fTarget,
1476 GR_GL_TEXTURE_USAGE,
1477 GR_GL_FRAMEBUFFER_ATTACHMENT));
1478 }
1479
1480 GL_CALL(TexParameteri(info->fTarget,
1481 GR_GL_TEXTURE_MAG_FILTER,
1482 initialTexParams->fMagFilter));
1483 GL_CALL(TexParameteri(info->fTarget,
1484 GR_GL_TEXTURE_MIN_FILTER,
1485 initialTexParams->fMinFilter));
1486 GL_CALL(TexParameteri(info->fTarget,
1487 GR_GL_TEXTURE_WRAP_S,
1488 initialTexParams->fWrapS));
1489 GL_CALL(TexParameteri(info->fTarget,
1490 GR_GL_TEXTURE_WRAP_T,
1491 initialTexParams->fWrapT));
1492 if (!this->uploadTexData(desc, info->fTarget, kNewTexture_UploadType, 0, 0,
1493 desc.fWidth, desc.fHeight,
1494 desc.fConfig, srcData, rowBytes)) {
1495 GL_CALL(DeleteTextures(1, &(info->fID)));
1496 return false;
1497 }
1498 return true;
1499 }
1500
1501 bool GrGLGpu::createTextureExternalAllocatorImpl(
1502 const GrSurfaceDesc& desc, GrGLTextureInfo* info, const void* srcData, s ize_t rowBytes) {
1503 switch (desc.fTextureStorageAllocator.fAllocateTextureStorage(
1504 desc.fTextureStorageAllocator.fCtx, reinterpret_cast<GrBacke ndObject>(info),
1505 desc.fWidth, desc.fHeight, desc.fConfig, srcData, desc.fOrig in)) {
1506 case GrTextureStorageAllocator::Result::kSucceededAndUploaded:
1507 return true;
1508 case GrTextureStorageAllocator::Result::kFailed:
1509 return false;
1510 case GrTextureStorageAllocator::Result::kSucceededWithoutUpload:
1511 break;
1512 }
1513
1514 if (!this->uploadTexData(desc, info->fTarget, kNewTexture_UploadType, 0, 0,
1515 desc.fWidth, desc.fHeight,
1516 desc.fConfig, srcData, rowBytes)) {
1517 desc.fTextureStorageAllocator.fDeallocateTextureStorage(
1518 desc.fTextureStorageAllocator.fCtx, reinterpret_cast<GrBackendOb ject>(info));
1519 return false;
1520 }
1521 return true;
1522 }
1523
1524 GrStencilAttachment* GrGLGpu::createStencilAttachmentForRenderTarget(const GrRen derTarget* rt, 1476 GrStencilAttachment* GrGLGpu::createStencilAttachmentForRenderTarget(const GrRen derTarget* rt,
1525 int width, 1477 int width,
1526 int height) { 1478 int height) {
1527 // All internally created RTs are also textures. We don't create 1479 // All internally created RTs are also textures. We don't create
1528 // SBs for a client's standalone RT (that is a RT that isn't also a texture) . 1480 // SBs for a client's standalone RT (that is a RT that isn't also a texture) .
1529 SkASSERT(rt->asTexture()); 1481 SkASSERT(rt->asTexture());
1530 SkASSERT(width >= rt->width()); 1482 SkASSERT(width >= rt->width());
1531 SkASSERT(height >= rt->height()); 1483 SkASSERT(height >= rt->height());
1532 1484
1533 int samples = rt->numStencilSamples(); 1485 int samples = rt->numStencilSamples();
(...skipping 2357 matching lines...) Expand 10 before | Expand all | Expand 10 after
3891 if (GR_GL_TEXTURE_EXTERNAL == glTexture->target() || 3843 if (GR_GL_TEXTURE_EXTERNAL == glTexture->target() ||
3892 GR_GL_TEXTURE_RECTANGLE == glTexture->target()) { 3844 GR_GL_TEXTURE_RECTANGLE == glTexture->target()) {
3893 copyParams->fFilter = GrTextureParams::kNone_FilterMode; 3845 copyParams->fFilter = GrTextureParams::kNone_FilterMode;
3894 copyParams->fWidth = texture->width(); 3846 copyParams->fWidth = texture->width();
3895 copyParams->fHeight = texture->height(); 3847 copyParams->fHeight = texture->height();
3896 return true; 3848 return true;
3897 } 3849 }
3898 } 3850 }
3899 return false; 3851 return false;
3900 } 3852 }
OLDNEW
« no previous file with comments | « src/gpu/gl/GrGLGpu.h ('k') | src/gpu/gl/GrGLTexture.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698