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

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

Issue 1102663002: Refactor createTexture and onCreateTexture (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: change descCopy name Created 5 years, 8 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
« src/gpu/GrGpu.cpp ('K') | « src/gpu/gl/GrGLGpu.h ('k') | no next file » | 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 8
9 #include "GrGLGpu.h" 9 #include "GrGLGpu.h"
10 #include "GrGLStencilAttachment.h" 10 #include "GrGLStencilAttachment.h"
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 // glTexDesc.fOrigin = resolve_origin(desc.fOrigin, renderTarget); 409 // glTexDesc.fOrigin = resolve_origin(desc.fOrigin, renderTarget);
410 if (kDefault_GrSurfaceOrigin == desc.fOrigin) { 410 if (kDefault_GrSurfaceOrigin == desc.fOrigin) {
411 surfDesc.fOrigin = kBottomLeft_GrSurfaceOrigin; 411 surfDesc.fOrigin = kBottomLeft_GrSurfaceOrigin;
412 } else { 412 } else {
413 surfDesc.fOrigin = desc.fOrigin; 413 surfDesc.fOrigin = desc.fOrigin;
414 } 414 }
415 415
416 GrGLTexture* texture = NULL; 416 GrGLTexture* texture = NULL;
417 if (renderTarget) { 417 if (renderTarget) {
418 GrGLRenderTarget::IDDesc rtIDDesc; 418 GrGLRenderTarget::IDDesc rtIDDesc;
419 if (!this->createRenderTargetObjects(surfDesc, false, idDesc.fTextureID, &rtIDDesc)) { 419 if (!this->createRenderTargetObjects(surfDesc, GrGpuResource::kUncached_ LifeCycle,
420 idDesc.fTextureID, &rtIDDesc)) {
420 return NULL; 421 return NULL;
421 } 422 }
422 texture = SkNEW_ARGS(GrGLTextureRenderTarget, (this, surfDesc, idDesc, r tIDDesc)); 423 texture = SkNEW_ARGS(GrGLTextureRenderTarget, (this, surfDesc, idDesc, r tIDDesc));
423 } else { 424 } else {
424 texture = SkNEW_ARGS(GrGLTexture, (this, surfDesc, idDesc)); 425 texture = SkNEW_ARGS(GrGLTexture, (this, surfDesc, idDesc));
425 } 426 }
426 if (NULL == texture) { 427 if (NULL == texture) {
427 return NULL; 428 return NULL;
428 } 429 }
429 430
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after
804 format, 805 format,
805 width, height)); 806 width, height));
806 break; 807 break;
807 case GrGLCaps::kNone_MSFBOType: 808 case GrGLCaps::kNone_MSFBOType:
808 SkFAIL("Shouldn't be here if we don't support multisampled renderbuf fers."); 809 SkFAIL("Shouldn't be here if we don't support multisampled renderbuf fers.");
809 break; 810 break;
810 } 811 }
811 return (GR_GL_NO_ERROR == CHECK_ALLOC_ERROR(ctx.interface())); 812 return (GR_GL_NO_ERROR == CHECK_ALLOC_ERROR(ctx.interface()));
812 } 813 }
813 814
814 bool GrGLGpu::createRenderTargetObjects(const GrSurfaceDesc& desc, bool budgeted , GrGLuint texID, 815 bool GrGLGpu::createRenderTargetObjects(const GrSurfaceDesc& desc,
816 GrGpuResource::LifeCycle lifeCycle,
817 GrGLuint texID,
815 GrGLRenderTarget::IDDesc* idDesc) { 818 GrGLRenderTarget::IDDesc* idDesc) {
816 idDesc->fMSColorRenderbufferID = 0; 819 idDesc->fMSColorRenderbufferID = 0;
817 idDesc->fRTFBOID = 0; 820 idDesc->fRTFBOID = 0;
818 idDesc->fTexFBOID = 0; 821 idDesc->fTexFBOID = 0;
819 idDesc->fLifeCycle = budgeted ? GrGpuResource::kCached_LifeCycle : 822 idDesc->fLifeCycle = lifeCycle;
820 GrGpuResource::kUncached_LifeCycle;
821 823
822 GrGLenum status; 824 GrGLenum status;
823 825
824 GrGLenum msColorFormat = 0; // suppress warning 826 GrGLenum msColorFormat = 0; // suppress warning
825 827
826 if (desc.fSampleCnt > 0 && GrGLCaps::kNone_MSFBOType == this->glCaps().msFBO Type()) { 828 if (desc.fSampleCnt > 0 && GrGLCaps::kNone_MSFBOType == this->glCaps().msFBO Type()) {
827 goto FAILED; 829 goto FAILED;
828 } 830 }
829 831
830 GL_CALL(GenFramebuffers(1, &idDesc->fTexFBOID)); 832 GL_CALL(GenFramebuffers(1, &idDesc->fTexFBOID));
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
923 // SkDEBUGFAIL("null texture"); 925 // SkDEBUGFAIL("null texture");
924 return NULL; 926 return NULL;
925 } 927 }
926 928
927 #if 0 && defined(SK_DEBUG) 929 #if 0 && defined(SK_DEBUG)
928 static size_t as_size_t(int x) { 930 static size_t as_size_t(int x) {
929 return x; 931 return x;
930 } 932 }
931 #endif 933 #endif
932 934
933 GrTexture* GrGLGpu::onCreateTexture(const GrSurfaceDesc& origDesc, bool budgeted , 935 GrTexture* GrGLGpu::onCreateTexture(const GrSurfaceDesc& desc,
936 GrGpuResource::LifeCycle lifeCycle,
934 const void* srcData, size_t rowBytes) { 937 const void* srcData, size_t rowBytes) {
935
936 GrSurfaceDesc desc = origDesc;
937
938 // Attempt to catch un- or wrongly initialized sample counts;
939 SkASSERT(desc.fSampleCnt >= 0 && desc.fSampleCnt <= 64);
940 // We fail if the MSAA was requested and is not available. 938 // We fail if the MSAA was requested and is not available.
941 if (GrGLCaps::kNone_MSFBOType == this->glCaps().msFBOType() && desc.fSampleC nt) { 939 if (GrGLCaps::kNone_MSFBOType == this->glCaps().msFBOType() && desc.fSampleC nt) {
942 //SkDebugf("MSAA RT requested but not supported on this platform."); 940 //SkDebugf("MSAA RT requested but not supported on this platform.");
943 return return_null_texture(); 941 return return_null_texture();
944 } 942 }
945 943
946 bool renderTarget = SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag); 944 bool renderTarget = SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag);
947 945
948 // If the sample count exceeds the max then we clamp it.
949 desc.fSampleCnt = SkTMin(desc.fSampleCnt, this->caps()->maxSampleCount());
950 desc.fOrigin = resolve_origin(desc.fOrigin, renderTarget);
951
952 if (GrGLCaps::kNone_MSFBOType == this->glCaps().msFBOType() && desc.fSampleC nt) {
953 //SkDebugf("MSAA RT requested but not supported on this platform.");
954 return return_null_texture();
955 }
956
957 if (renderTarget) {
958 int maxRTSize = this->caps()->maxRenderTargetSize();
959 if (desc.fWidth > maxRTSize || desc.fHeight > maxRTSize) {
960 return return_null_texture();
961 }
962 } else {
963 int maxSize = this->caps()->maxTextureSize();
964 if (desc.fWidth > maxSize || desc.fHeight > maxSize) {
965 return return_null_texture();
966 }
967 }
968
969 GrGLTexture::IDDesc idDesc; 946 GrGLTexture::IDDesc idDesc;
970 GL_CALL(GenTextures(1, &idDesc.fTextureID)); 947 GL_CALL(GenTextures(1, &idDesc.fTextureID));
971 idDesc.fLifeCycle = budgeted ? GrGpuResource::kCached_LifeCycle : 948 idDesc.fLifeCycle = lifeCycle;
972 GrGpuResource::kUncached_LifeCycle;
973 949
974 if (!idDesc.fTextureID) { 950 if (!idDesc.fTextureID) {
975 return return_null_texture(); 951 return return_null_texture();
976 } 952 }
977 953
978 this->setScratchTextureUnit(); 954 this->setScratchTextureUnit();
979 GL_CALL(BindTexture(GR_GL_TEXTURE_2D, idDesc.fTextureID)); 955 GL_CALL(BindTexture(GR_GL_TEXTURE_2D, idDesc.fTextureID));
980 956
981 if (renderTarget && this->glCaps().textureUsageSupport()) { 957 if (renderTarget && this->glCaps().textureUsageSupport()) {
982 // provides a hint about how this texture will be used 958 // provides a hint about how this texture will be used
(...skipping 30 matching lines...) Expand all
1013 GL_CALL(DeleteTextures(1, &idDesc.fTextureID)); 989 GL_CALL(DeleteTextures(1, &idDesc.fTextureID));
1014 return return_null_texture(); 990 return return_null_texture();
1015 } 991 }
1016 992
1017 GrGLTexture* tex; 993 GrGLTexture* tex;
1018 if (renderTarget) { 994 if (renderTarget) {
1019 // unbind the texture from the texture unit before binding it to the fra me buffer 995 // unbind the texture from the texture unit before binding it to the fra me buffer
1020 GL_CALL(BindTexture(GR_GL_TEXTURE_2D, 0)); 996 GL_CALL(BindTexture(GR_GL_TEXTURE_2D, 0));
1021 GrGLRenderTarget::IDDesc rtIDDesc; 997 GrGLRenderTarget::IDDesc rtIDDesc;
1022 998
1023 if (!this->createRenderTargetObjects(desc, budgeted, idDesc.fTextureID, &rtIDDesc)) { 999 if (!this->createRenderTargetObjects(desc, lifeCycle, idDesc.fTextureID, &rtIDDesc)) {
1024 GL_CALL(DeleteTextures(1, &idDesc.fTextureID)); 1000 GL_CALL(DeleteTextures(1, &idDesc.fTextureID));
1025 return return_null_texture(); 1001 return return_null_texture();
1026 } 1002 }
1027 tex = SkNEW_ARGS(GrGLTextureRenderTarget, (this, desc, idDesc, rtIDDesc) ); 1003 tex = SkNEW_ARGS(GrGLTextureRenderTarget, (this, desc, idDesc, rtIDDesc) );
1028 } else { 1004 } else {
1029 tex = SkNEW_ARGS(GrGLTexture, (this, desc, idDesc)); 1005 tex = SkNEW_ARGS(GrGLTexture, (this, desc, idDesc));
1030 } 1006 }
1031 tex->setCachedTexParams(initialTexParams, this->getResetTimestamp()); 1007 tex->setCachedTexParams(initialTexParams, this->getResetTimestamp());
1032 #ifdef TRACE_TEXTURE_CREATION 1008 #ifdef TRACE_TEXTURE_CREATION
1033 SkDebugf("--- new texture [%d] size=(%d %d) config=%d\n", 1009 SkDebugf("--- new texture [%d] size=(%d %d) config=%d\n",
1034 glTexDesc.fTextureID, desc.fWidth, desc.fHeight, desc.fConfig); 1010 glTexDesc.fTextureID, desc.fWidth, desc.fHeight, desc.fConfig);
1035 #endif 1011 #endif
1036 return tex; 1012 return tex;
1037 } 1013 }
1038 1014
1039 GrTexture* GrGLGpu::onCreateCompressedTexture(const GrSurfaceDesc& origDesc, boo l budgeted, 1015 GrTexture* GrGLGpu::onCreateCompressedTexture(const GrSurfaceDesc& desc,
1016 GrGpuResource::LifeCycle lifeCycle ,
1040 const void* srcData) { 1017 const void* srcData) {
1041
1042 if(SkToBool(origDesc.fFlags & kRenderTarget_GrSurfaceFlag) || origDesc.fSamp leCnt > 0) {
1043 return return_null_texture();
1044 }
1045
1046 // Make sure that we're not flipping Y. 1018 // Make sure that we're not flipping Y.
1047 GrSurfaceOrigin texOrigin = resolve_origin(origDesc.fOrigin, false); 1019 if (kBottomLeft_GrSurfaceOrigin == desc.fOrigin) {
1048 if (kBottomLeft_GrSurfaceOrigin == texOrigin) {
1049 return return_null_texture();
1050 }
1051 GrSurfaceDesc desc = origDesc;
1052 desc.fOrigin = texOrigin;
1053
1054 int maxSize = this->caps()->maxTextureSize();
1055 if (desc.fWidth > maxSize || desc.fHeight > maxSize) {
1056 return return_null_texture(); 1020 return return_null_texture();
1057 } 1021 }
1058 1022
1059 GrGLTexture::IDDesc idDesc; 1023 GrGLTexture::IDDesc idDesc;
1060 GL_CALL(GenTextures(1, &idDesc.fTextureID)); 1024 GL_CALL(GenTextures(1, &idDesc.fTextureID));
1061 idDesc.fLifeCycle = budgeted ? GrGpuResource::kCached_LifeCycle : 1025 idDesc.fLifeCycle = lifeCycle;
1062 GrGpuResource::kUncached_LifeCycle;
1063 1026
1064 if (!idDesc.fTextureID) { 1027 if (!idDesc.fTextureID) {
1065 return return_null_texture(); 1028 return return_null_texture();
1066 } 1029 }
1067 1030
1068 this->setScratchTextureUnit(); 1031 this->setScratchTextureUnit();
1069 GL_CALL(BindTexture(GR_GL_TEXTURE_2D, idDesc.fTextureID)); 1032 GL_CALL(BindTexture(GR_GL_TEXTURE_2D, idDesc.fTextureID));
1070 1033
1071 // Some drivers like to know filter/wrap before seeing glTexImage2D. Some 1034 // Some drivers like to know filter/wrap before seeing glTexImage2D. Some
1072 // drivers have a bug where an FBO won't be complete if it includes a 1035 // drivers have a bug where an FBO won't be complete if it includes a
(...skipping 1743 matching lines...) Expand 10 before | Expand all | Expand 10 after
2816 this->setVertexArrayID(gpu, 0); 2779 this->setVertexArrayID(gpu, 0);
2817 } 2780 }
2818 int attrCount = gpu->glCaps().maxVertexAttributes(); 2781 int attrCount = gpu->glCaps().maxVertexAttributes();
2819 if (fDefaultVertexArrayAttribState.count() != attrCount) { 2782 if (fDefaultVertexArrayAttribState.count() != attrCount) {
2820 fDefaultVertexArrayAttribState.resize(attrCount); 2783 fDefaultVertexArrayAttribState.resize(attrCount);
2821 } 2784 }
2822 attribState = &fDefaultVertexArrayAttribState; 2785 attribState = &fDefaultVertexArrayAttribState;
2823 } 2786 }
2824 return attribState; 2787 return attribState;
2825 } 2788 }
OLDNEW
« src/gpu/GrGpu.cpp ('K') | « src/gpu/gl/GrGLGpu.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698