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

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

Issue 1531343002: Add fExternalFormatForTexImage to GrGLGpu::ConfigEntry. Use it in GrGLGpu::uploadTexData. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: update comment Created 5 years 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') | 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 "GrGLGLSL.h" 10 #include "GrGLGLSL.h"
(...skipping 683 matching lines...) Expand 10 before | Expand all | Expand 10 after
694 bool isNewTexture, 694 bool isNewTexture,
695 int left, int top, int width, int height, 695 int left, int top, int width, int height,
696 GrPixelConfig dataConfig, 696 GrPixelConfig dataConfig,
697 const void* data, 697 const void* data,
698 size_t rowBytes) { 698 size_t rowBytes) {
699 SkASSERT(data || isNewTexture); 699 SkASSERT(data || isNewTexture);
700 700
701 // If we're uploading compressed data then we should be using uploadCompress edTexData 701 // If we're uploading compressed data then we should be using uploadCompress edTexData
702 SkASSERT(!GrPixelConfigIsCompressed(dataConfig)); 702 SkASSERT(!GrPixelConfigIsCompressed(dataConfig));
703 703
704 SkASSERT(this->caps()->isConfigTexturable(desc.fConfig));
705
704 size_t bpp = GrBytesPerPixel(dataConfig); 706 size_t bpp = GrBytesPerPixel(dataConfig);
705 if (!GrSurfacePriv::AdjustWritePixelParams(desc.fWidth, desc.fHeight, bpp, & left, &top, 707 if (!GrSurfacePriv::AdjustWritePixelParams(desc.fWidth, desc.fHeight, bpp, & left, &top,
706 &width, &height, &data, &rowBytes )) { 708 &width, &height, &data, &rowBytes )) {
707 return false; 709 return false;
708 } 710 }
709 size_t trimRowBytes = width * bpp; 711 size_t trimRowBytes = width * bpp;
710 712
711 // in case we need a temporary, trimmed copy of the src pixels 713 // in case we need a temporary, trimmed copy of the src pixels
712 #if defined(GOOGLE3) 714 #if defined(GOOGLE3)
713 // Stack frame size is limited in GOOGLE3. 715 // Stack frame size is limited in GOOGLE3.
(...skipping 11 matching lines...) Expand all
725 this->glCaps().texStorageSupport(); 727 this->glCaps().texStorageSupport();
726 728
727 if (useTexStorage && kGL_GrGLStandard == this->glStandard()) { 729 if (useTexStorage && kGL_GrGLStandard == this->glStandard()) {
728 // 565 is not a sized internal format on desktop GL. So on desktop with 730 // 565 is not a sized internal format on desktop GL. So on desktop with
729 // 565 we always use an unsized internal format to let the system pick 731 // 565 we always use an unsized internal format to let the system pick
730 // the best sized format to convert the 565 data to. Since TexStorage 732 // the best sized format to convert the 565 data to. Since TexStorage
731 // only allows sized internal formats we will instead use TexImage2D. 733 // only allows sized internal formats we will instead use TexImage2D.
732 useTexStorage = desc.fConfig != kRGB_565_GrPixelConfig; 734 useTexStorage = desc.fConfig != kRGB_565_GrPixelConfig;
733 } 735 }
734 736
735 GrGLenum internalFormat = 0x0; // suppress warning
736 GrGLenum externalFormat = 0x0; // suppress warning
737 GrGLenum externalType = 0x0; // suppress warning
738 737
739 bool useSizedFormat = use_sized_format_for_texture(useTexStorage, this->ctxI nfo(), 738 bool useSizedFormat = use_sized_format_for_texture(useTexStorage, this->ctxI nfo(),
740 desc.fConfig); 739 desc.fConfig);
741 740
742 if (!this->configToGLFormats(desc.fConfig, useSizedFormat, &internalFormat, 741 // Internal format comes from the texture desc.
743 &externalFormat, &externalType)) { 742 GrGLenum internalFormat = useSizedFormat ?
744 return false; 743 fConfigTable[desc.fConfig].fSizedInternalFormat:
745 } 744 fConfigTable[desc.fConfig].fBaseInternalFormat;
746 745
747 if (dataConfig != desc.fConfig) { 746 // External format and type come from the upload data.
748 // call this again if we're going to upload a different config than the texture's config. 747 GrGLenum externalFormat = fConfigTable[dataConfig].fExternalFormatForTexImag e;
749 if (!this->configToGLFormats(dataConfig, false, nullptr, &externalFormat , 748 GrGLenum externalType = fConfigTable[dataConfig].fExternalType;
750 &externalType)) {
751 return false;
752 }
753 }
754 749
755 /* 750 /*
756 * check whether to allocate a temporary buffer for flipping y or 751 * Check whether to allocate a temporary buffer for flipping y or
757 * because our srcData has extra bytes past each row. If so, we need 752 * because our srcData has extra bytes past each row. If so, we need
758 * to trim those off here, since GL ES may not let us specify 753 * to trim those off here, since GL ES may not let us specify
759 * GL_UNPACK_ROW_LENGTH. 754 * GL_UNPACK_ROW_LENGTH.
760 */ 755 */
761 bool restoreGLRowLength = false; 756 bool restoreGLRowLength = false;
762 bool swFlipY = false; 757 bool swFlipY = false;
763 bool glFlipY = false; 758 bool glFlipY = false;
764 if (data) { 759 if (data) {
765 if (kBottomLeft_GrSurfaceOrigin == desc.fOrigin) { 760 if (kBottomLeft_GrSurfaceOrigin == desc.fOrigin) {
766 if (this->glCaps().unpackFlipYSupport()) { 761 if (this->glCaps().unpackFlipYSupport()) {
(...skipping 1279 matching lines...) Expand 10 before | Expand all | Expand 10 after
2046 return false; 2041 return false;
2047 } 2042 }
2048 2043
2049 GrGLenum format = 0; 2044 GrGLenum format = 0;
2050 GrGLenum type = 0; 2045 GrGLenum type = 0;
2051 bool flipY = kBottomLeft_GrSurfaceOrigin == surface->origin(); 2046 bool flipY = kBottomLeft_GrSurfaceOrigin == surface->origin();
2052 if (!this->configToGLFormats(config, false, nullptr, &format, &type)) { 2047 if (!this->configToGLFormats(config, false, nullptr, &format, &type)) {
2053 return false; 2048 return false;
2054 } 2049 }
2055 2050
2056 // glReadPixels does not allow GL_SRGB_ALPHA. Instead use GL_RGBA. This will not trigger a
2057 // conversion when the src is srgb.
2058 if (GR_GL_SRGB_ALPHA == format) {
2059 format = GR_GL_RGBA;
2060 }
2061
2062 // resolve the render target if necessary 2051 // resolve the render target if necessary
2063 switch (tgt->getResolveType()) { 2052 switch (tgt->getResolveType()) {
2064 case GrGLRenderTarget::kCantResolve_ResolveType: 2053 case GrGLRenderTarget::kCantResolve_ResolveType:
2065 return false; 2054 return false;
2066 case GrGLRenderTarget::kAutoResolves_ResolveType: 2055 case GrGLRenderTarget::kAutoResolves_ResolveType:
2067 this->flushRenderTarget(tgt, &SkIRect::EmptyIRect()); 2056 this->flushRenderTarget(tgt, &SkIRect::EmptyIRect());
2068 break; 2057 break;
2069 case GrGLRenderTarget::kCanResolve_ResolveType: 2058 case GrGLRenderTarget::kCanResolve_ResolveType:
2070 this->onResolveRenderTarget(tgt); 2059 this->onResolveRenderTarget(tgt);
2071 // we don't track the state of the READ FBO ID. 2060 // we don't track the state of the READ FBO ID.
(...skipping 616 matching lines...) Expand 10 before | Expand all | Expand 10 after
2688 } else { 2677 } else {
2689 fConfigTable[kBGRA_8888_GrPixelConfig].fBaseInternalFormat = GR_GL_RGBA; 2678 fConfigTable[kBGRA_8888_GrPixelConfig].fBaseInternalFormat = GR_GL_RGBA;
2690 fConfigTable[kBGRA_8888_GrPixelConfig].fSizedInternalFormat = GR_GL_RGBA 8; 2679 fConfigTable[kBGRA_8888_GrPixelConfig].fSizedInternalFormat = GR_GL_RGBA 8;
2691 } 2680 }
2692 fConfigTable[kBGRA_8888_GrPixelConfig].fExternalFormat= GR_GL_BGRA; 2681 fConfigTable[kBGRA_8888_GrPixelConfig].fExternalFormat= GR_GL_BGRA;
2693 fConfigTable[kBGRA_8888_GrPixelConfig].fExternalType = GR_GL_UNSIGNED_BYTE; 2682 fConfigTable[kBGRA_8888_GrPixelConfig].fExternalType = GR_GL_UNSIGNED_BYTE;
2694 2683
2695 2684
2696 fConfigTable[kSRGBA_8888_GrPixelConfig].fBaseInternalFormat = GR_GL_SRGB_ALP HA; 2685 fConfigTable[kSRGBA_8888_GrPixelConfig].fBaseInternalFormat = GR_GL_SRGB_ALP HA;
2697 fConfigTable[kSRGBA_8888_GrPixelConfig].fSizedInternalFormat = GR_GL_SRGB8_A LPHA8; 2686 fConfigTable[kSRGBA_8888_GrPixelConfig].fSizedInternalFormat = GR_GL_SRGB8_A LPHA8;
2698 // OpenGL ES 2.0 + GL_EXT_sRGB allows GL_SRGB_ALPHA to be specified as the < format> 2687 // GL does not do srgb<->rgb conversions when transferring between cpu and g pu. Thus, the
2699 // param to Tex(Sub)Image2D. ES 2.0 requires the internalFormat and format t o match. 2688 // external format is GL_RGBA. See below for note about ES2.0 and glTex[Sub] Image.
2700 // Thus, on ES 2.0 we will use GL_SRGB_ALPHA as the externalFormat. However, 2689 fConfigTable[kSRGBA_8888_GrPixelConfig].fExternalFormat = GR_GL_RGBA;
2701 // onReadPixels needs code to override that because GL_SRGB_ALPHA is not all owed as a
2702 // glReadPixels format.
2703 // On OpenGL and ES 3.0 GL_SRGB_ALPHA does not work for the <format> param t o
2704 // glReadPixels nor does it work with Tex(Sub)Image2D So we always set the e xternalFormat
2705 // return to GL_RGBA.
2706 if (this->glStandard() == kGLES_GrGLStandard &&
2707 this->glVersion() == GR_GL_VER(2,0)) {
2708 fConfigTable[kSRGBA_8888_GrPixelConfig].fExternalFormat = GR_GL_SRGB_ALP HA;
2709 } else {
2710 fConfigTable[kSRGBA_8888_GrPixelConfig].fExternalFormat = GR_GL_RGBA;
2711 }
2712 fConfigTable[kSRGBA_8888_GrPixelConfig].fExternalType = GR_GL_UNSIGNED_BYTE; 2690 fConfigTable[kSRGBA_8888_GrPixelConfig].fExternalType = GR_GL_UNSIGNED_BYTE;
2713 2691
2714 2692
2715 fConfigTable[kRGB_565_GrPixelConfig].fBaseInternalFormat = GR_GL_RGB; 2693 fConfigTable[kRGB_565_GrPixelConfig].fBaseInternalFormat = GR_GL_RGB;
2716 if (this->glCaps().ES2CompatibilitySupport()) { 2694 if (this->glCaps().ES2CompatibilitySupport()) {
2717 fConfigTable[kRGB_565_GrPixelConfig].fSizedInternalFormat = GR_GL_RGB565 ; 2695 fConfigTable[kRGB_565_GrPixelConfig].fSizedInternalFormat = GR_GL_RGB565 ;
2718 } else { 2696 } else {
2719 fConfigTable[kRGB_565_GrPixelConfig].fSizedInternalFormat = GR_GL_RGB5; 2697 fConfigTable[kRGB_565_GrPixelConfig].fSizedInternalFormat = GR_GL_RGB5;
2720 } 2698 }
2721 fConfigTable[kRGB_565_GrPixelConfig].fExternalFormat = GR_GL_RGB; 2699 fConfigTable[kRGB_565_GrPixelConfig].fExternalFormat = GR_GL_RGB;
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
2801 fConfigTable[kR11_EAC_GrPixelConfig].fBaseInternalFormat = GR_GL_COMPRESSED_ R11_EAC; 2779 fConfigTable[kR11_EAC_GrPixelConfig].fBaseInternalFormat = GR_GL_COMPRESSED_ R11_EAC;
2802 fConfigTable[kR11_EAC_GrPixelConfig].fSizedInternalFormat = GR_GL_COMPRESSED _R11_EAC; 2780 fConfigTable[kR11_EAC_GrPixelConfig].fSizedInternalFormat = GR_GL_COMPRESSED _R11_EAC;
2803 fConfigTable[kR11_EAC_GrPixelConfig].fExternalFormat = 0; 2781 fConfigTable[kR11_EAC_GrPixelConfig].fExternalFormat = 0;
2804 fConfigTable[kR11_EAC_GrPixelConfig].fExternalType = 0; 2782 fConfigTable[kR11_EAC_GrPixelConfig].fExternalType = 0;
2805 2783
2806 fConfigTable[kASTC_12x12_GrPixelConfig].fBaseInternalFormat = GR_GL_COMPRESS ED_RGBA_ASTC_12x12; 2784 fConfigTable[kASTC_12x12_GrPixelConfig].fBaseInternalFormat = GR_GL_COMPRESS ED_RGBA_ASTC_12x12;
2807 fConfigTable[kASTC_12x12_GrPixelConfig].fSizedInternalFormat = GR_GL_COMPRES SED_RGBA_ASTC_12x12; 2785 fConfigTable[kASTC_12x12_GrPixelConfig].fSizedInternalFormat = GR_GL_COMPRES SED_RGBA_ASTC_12x12;
2808 fConfigTable[kASTC_12x12_GrPixelConfig].fExternalFormat = 0; 2786 fConfigTable[kASTC_12x12_GrPixelConfig].fExternalFormat = 0;
2809 fConfigTable[kASTC_12x12_GrPixelConfig].fExternalType = 0; 2787 fConfigTable[kASTC_12x12_GrPixelConfig].fExternalType = 0;
2810 2788
2789
2790 // Almost always we want to pass fExternalFormat as the <format> param to gl Tex[Sub]Image.
2791 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
2792 fConfigTable[i].fExternalFormatForTexImage = fConfigTable[i].fExternalFo rmat;
2793 }
jvanverth1 2015/12/17 19:21:50 What about iOS, BGRA, and ES 3.0? Didn't we see so
bsalomon 2015/12/17 19:35:11 I don't recall that. AFAIK there is no sRGB BGRA f
2794 // OpenGL ES 2.0 + GL_EXT_sRGB allows GL_SRGB_ALPHA to be specified as the < format>
2795 // param to Tex(Sub)Image. ES 2.0 requires the <internalFormat> and <format> params to match.
2796 // Thus, on ES 2.0 we will use GL_SRGB_ALPHA as the <format> param.
2797 // On OpenGL and ES 3.0+ GL_SRGB_ALPHA does not work for the <format> param to glTexImage.
2798 if (this->glStandard() == kGLES_GrGLStandard && this->glVersion() == GR_GL_V ER(2,0)) {
2799 fConfigTable[kSRGBA_8888_GrPixelConfig].fExternalFormatForTexImage = GR_ GL_SRGB_ALPHA;
2800 }
2801
2811 #ifdef SK_DEBUG 2802 #ifdef SK_DEBUG
2812 // Make sure we initialized everything. 2803 // Make sure we initialized everything.
2813 ConfigEntry defaultEntry; 2804 ConfigEntry defaultEntry;
2814 for (int i = 0; i < kLast_GrPixelConfig; ++i) { 2805 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
2815 SkASSERT(defaultEntry.fBaseInternalFormat != fConfigTable[i].fBaseIntern alFormat); 2806 SkASSERT(defaultEntry.fBaseInternalFormat != fConfigTable[i].fBaseIntern alFormat);
2816 SkASSERT(defaultEntry.fSizedInternalFormat != fConfigTable[i].fSizedInte rnalFormat); 2807 SkASSERT(defaultEntry.fSizedInternalFormat != fConfigTable[i].fSizedInte rnalFormat);
2817 SkASSERT(defaultEntry.fExternalFormat != fConfigTable[i].fExternalFormat ); 2808 SkASSERT(defaultEntry.fExternalFormat != fConfigTable[i].fExternalFormat );
2818 SkASSERT(defaultEntry.fExternalType != fConfigTable[i].fExternalType); 2809 SkASSERT(defaultEntry.fExternalType != fConfigTable[i].fExternalType);
2819 } 2810 }
2820 #endif 2811 #endif
2821 } 2812 }
2822 2813
2823 bool GrGLGpu::configToGLFormats(GrPixelConfig config, 2814 bool GrGLGpu::configToGLFormats(GrPixelConfig config,
2824 bool getSizedInternalFormat, 2815 bool getSizedInternalFormat,
(...skipping 817 matching lines...) Expand 10 before | Expand all | Expand 10 after
3642 this->setVertexArrayID(gpu, 0); 3633 this->setVertexArrayID(gpu, 0);
3643 } 3634 }
3644 int attrCount = gpu->glCaps().maxVertexAttributes(); 3635 int attrCount = gpu->glCaps().maxVertexAttributes();
3645 if (fDefaultVertexArrayAttribState.count() != attrCount) { 3636 if (fDefaultVertexArrayAttribState.count() != attrCount) {
3646 fDefaultVertexArrayAttribState.resize(attrCount); 3637 fDefaultVertexArrayAttribState.resize(attrCount);
3647 } 3638 }
3648 attribState = &fDefaultVertexArrayAttribState; 3639 attribState = &fDefaultVertexArrayAttribState;
3649 } 3640 }
3650 return attribState; 3641 return attribState;
3651 } 3642 }
OLDNEW
« no previous file with comments | « src/gpu/gl/GrGLGpu.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698