| OLD | NEW |
| 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 "GrGpuGL.h" | 9 #include "GrGpuGL.h" |
| 10 #include "GrGLNameAllocator.h" | 10 #include "GrGLNameAllocator.h" |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 GrPixelConfig GrGpuGL::preferredWritePixelsConfig(GrPixelConfig writeConfig, | 194 GrPixelConfig GrGpuGL::preferredWritePixelsConfig(GrPixelConfig writeConfig, |
| 195 GrPixelConfig surfaceConfig) c
onst { | 195 GrPixelConfig surfaceConfig) c
onst { |
| 196 if (GR_GL_RGBA_8888_PIXEL_OPS_SLOW && kRGBA_8888_GrPixelConfig == writeConfi
g) { | 196 if (GR_GL_RGBA_8888_PIXEL_OPS_SLOW && kRGBA_8888_GrPixelConfig == writeConfi
g) { |
| 197 return kBGRA_8888_GrPixelConfig; | 197 return kBGRA_8888_GrPixelConfig; |
| 198 } else { | 198 } else { |
| 199 return writeConfig; | 199 return writeConfig; |
| 200 } | 200 } |
| 201 } | 201 } |
| 202 | 202 |
| 203 bool GrGpuGL::canWriteTexturePixels(const GrTexture* texture, GrPixelConfig srcC
onfig) const { | 203 bool GrGpuGL::canWriteTexturePixels(const GrTexture* texture, GrPixelConfig srcC
onfig) const { |
| 204 if (kIndex_8_GrPixelConfig == srcConfig || kIndex_8_GrPixelConfig == texture
->config() || | 204 if (kIndex_8_GrPixelConfig == srcConfig || kIndex_8_GrPixelConfig == texture
->config()) { |
| 205 GrPixelConfigIsCompressed(srcConfig) || GrPixelConfigIsCompressed(textur
e->config())) { | |
| 206 return false; | 205 return false; |
| 207 } | 206 } |
| 208 if (srcConfig != texture->config() && kGLES_GrGLStandard == this->glStandard
()) { | 207 if (srcConfig != texture->config() && kGLES_GrGLStandard == this->glStandard
()) { |
| 209 // In general ES2 requires the internal format of the texture and the fo
rmat of the src | 208 // In general ES2 requires the internal format of the texture and the fo
rmat of the src |
| 210 // pixels to match. However, It may or may not be possible to upload BGR
A data to a RGBA | 209 // pixels to match. However, It may or may not be possible to upload BGR
A data to a RGBA |
| 211 // texture. It depends upon which extension added BGRA. The Apple extens
ion allows it | 210 // texture. It depends upon which extension added BGRA. The Apple extens
ion allows it |
| 212 // (BGRA's internal format is RGBA) while the EXT extension does not (BG
RA is its own | 211 // (BGRA's internal format is RGBA) while the EXT extension does not (BG
RA is its own |
| 213 // internal format). | 212 // internal format). |
| 214 if (this->glCaps().isConfigTexturable(kBGRA_8888_GrPixelConfig) && | 213 if (this->glCaps().isConfigTexturable(kBGRA_8888_GrPixelConfig) && |
| 215 !this->glCaps().bgraIsInternalFormat() && | 214 !this->glCaps().bgraIsInternalFormat() && |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 471 GL_CALL(BindTexture(GR_GL_TEXTURE_2D, glTex->textureID())); | 470 GL_CALL(BindTexture(GR_GL_TEXTURE_2D, glTex->textureID())); |
| 472 GrGLTexture::Desc desc; | 471 GrGLTexture::Desc desc; |
| 473 desc.fFlags = glTex->desc().fFlags; | 472 desc.fFlags = glTex->desc().fFlags; |
| 474 desc.fWidth = glTex->width(); | 473 desc.fWidth = glTex->width(); |
| 475 desc.fHeight = glTex->height(); | 474 desc.fHeight = glTex->height(); |
| 476 desc.fConfig = glTex->config(); | 475 desc.fConfig = glTex->config(); |
| 477 desc.fSampleCnt = glTex->desc().fSampleCnt; | 476 desc.fSampleCnt = glTex->desc().fSampleCnt; |
| 478 desc.fTextureID = glTex->textureID(); | 477 desc.fTextureID = glTex->textureID(); |
| 479 desc.fOrigin = glTex->origin(); | 478 desc.fOrigin = glTex->origin(); |
| 480 | 479 |
| 481 if (this->uploadTexData(desc, false, | 480 bool success = false; |
| 482 left, top, width, height, | 481 if (GrPixelConfigIsCompressed(desc.fConfig)) { |
| 483 config, buffer, rowBytes)) { | 482 // We check that config == desc.fConfig in GrGpuGL::canWriteTexturePixel
s() |
| 483 SkASSERT(config == desc.fConfig); |
| 484 success = this->uploadCompressedTexData(desc, buffer, false, |
| 485 left, top, width, height); |
| 486 } else { |
| 487 success = this->uploadTexData(desc, false, |
| 488 left, top, width, height, |
| 489 config, buffer, rowBytes); |
| 490 } |
| 491 |
| 492 if (success) { |
| 484 texture->impl()->dirtyMipMaps(true); | 493 texture->impl()->dirtyMipMaps(true); |
| 485 return true; | 494 return true; |
| 486 } else { | |
| 487 return false; | |
| 488 } | 495 } |
| 496 |
| 497 return false; |
| 489 } | 498 } |
| 490 | 499 |
| 491 namespace { | 500 namespace { |
| 492 bool adjust_pixel_ops_params(int surfaceWidth, | 501 bool adjust_pixel_ops_params(int surfaceWidth, |
| 493 int surfaceHeight, | 502 int surfaceHeight, |
| 494 size_t bpp, | 503 size_t bpp, |
| 495 int* left, int* top, int* width, int* height, | 504 int* left, int* top, int* width, int* height, |
| 496 const void** data, | 505 const void** data, |
| 497 size_t* rowBytes) { | 506 size_t* rowBytes) { |
| 498 if (!*rowBytes) { | 507 if (!*rowBytes) { |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 696 if (restoreGLRowLength) { | 705 if (restoreGLRowLength) { |
| 697 SkASSERT(this->glCaps().unpackRowLengthSupport()); | 706 SkASSERT(this->glCaps().unpackRowLengthSupport()); |
| 698 GL_CALL(PixelStorei(GR_GL_UNPACK_ROW_LENGTH, 0)); | 707 GL_CALL(PixelStorei(GR_GL_UNPACK_ROW_LENGTH, 0)); |
| 699 } | 708 } |
| 700 if (glFlipY) { | 709 if (glFlipY) { |
| 701 GL_CALL(PixelStorei(GR_GL_UNPACK_FLIP_Y, GR_GL_FALSE)); | 710 GL_CALL(PixelStorei(GR_GL_UNPACK_FLIP_Y, GR_GL_FALSE)); |
| 702 } | 711 } |
| 703 return succeeded; | 712 return succeeded; |
| 704 } | 713 } |
| 705 | 714 |
| 715 // TODO: This function is using a lot of wonky semantics like, if width == -1 |
| 716 // then set width = desc.fWdith ... blah. A better way to do it might be to |
| 717 // create a CompressedTexData struct that takes a desc/ptr and figures out |
| 718 // the proper upload semantics. Then users can construct this function how they |
| 719 // see fit if they want to go against the "standard" way to do it. |
| 706 bool GrGpuGL::uploadCompressedTexData(const GrGLTexture::Desc& desc, | 720 bool GrGpuGL::uploadCompressedTexData(const GrGLTexture::Desc& desc, |
| 707 const void* data) { | 721 const void* data, |
| 708 SkASSERT(NULL != data); | 722 bool isNewTexture, |
| 723 int left, int top, int width, int height)
{ |
| 724 SkASSERT(NULL != data || isNewTexture); |
| 709 | 725 |
| 710 // No support for software flip y, yet... | 726 // No support for software flip y, yet... |
| 711 SkASSERT(kBottomLeft_GrSurfaceOrigin != desc.fOrigin); | 727 SkASSERT(kBottomLeft_GrSurfaceOrigin != desc.fOrigin); |
| 712 | 728 |
| 729 if (-1 == width) { |
| 730 width = desc.fWidth; |
| 731 } |
| 732 #ifdef SK_DEBUG |
| 733 else { |
| 734 SkASSERT(width <= desc.fWidth); |
| 735 } |
| 736 #endif |
| 737 |
| 738 if (-1 == height) { |
| 739 height = desc.fHeight; |
| 740 } |
| 741 #ifdef SK_DEBUG |
| 742 else { |
| 743 SkASSERT(height <= desc.fHeight); |
| 744 } |
| 745 #endif |
| 746 |
| 713 // Make sure that the width and height that we pass to OpenGL | 747 // Make sure that the width and height that we pass to OpenGL |
| 714 // is a multiple of the block size. | 748 // is a multiple of the block size. |
| 715 int dataSize = GrCompressedFormatDataSize(desc.fConfig, desc.fWidth, desc.fH
eight); | 749 int dataSize = GrCompressedFormatDataSize(desc.fConfig, width, height); |
| 716 | 750 |
| 717 // We only need the internal format for compressed 2D textures. | 751 // We only need the internal format for compressed 2D textures. |
| 718 GrGLenum internalFormat = 0; | 752 GrGLenum internalFormat = 0; |
| 719 if (!this->configToGLFormats(desc.fConfig, false, &internalFormat, NULL, NUL
L)) { | 753 if (!this->configToGLFormats(desc.fConfig, false, &internalFormat, NULL, NUL
L)) { |
| 720 return false; | 754 return false; |
| 721 } | 755 } |
| 722 | 756 |
| 723 bool succeeded = true; | 757 bool succeeded = true; |
| 724 CLEAR_ERROR_BEFORE_ALLOC(this->glInterface()); | 758 CLEAR_ERROR_BEFORE_ALLOC(this->glInterface()); |
| 725 GL_ALLOC_CALL(this->glInterface(), | 759 |
| 726 CompressedTexImage2D(GR_GL_TEXTURE_2D, | 760 if (isNewTexture) { |
| 727 0, // level | 761 GL_ALLOC_CALL(this->glInterface(), |
| 728 internalFormat, | 762 CompressedTexImage2D(GR_GL_TEXTURE_2D, |
| 729 desc.fWidth, desc.fHeight, | 763 0, // level |
| 730 0, // border | 764 internalFormat, |
| 731 dataSize, | 765 width, height, |
| 732 data)); | 766 0, // border |
| 767 dataSize, |
| 768 data)); |
| 769 } else { |
| 770 GL_ALLOC_CALL(this->glInterface(), |
| 771 CompressedTexSubImage2D(GR_GL_TEXTURE_2D, |
| 772 0, // level |
| 773 left, top, |
| 774 width, height, |
| 775 internalFormat, |
| 776 dataSize, |
| 777 data)); |
| 778 } |
| 733 | 779 |
| 734 GrGLenum error = check_alloc_error(desc, this->glInterface()); | 780 GrGLenum error = check_alloc_error(desc, this->glInterface()); |
| 735 if (error != GR_GL_NO_ERROR) { | 781 if (error != GR_GL_NO_ERROR) { |
| 736 succeeded = false; | 782 succeeded = false; |
| 737 } | 783 } |
| 738 return succeeded; | 784 return succeeded; |
| 739 } | 785 } |
| 740 | 786 |
| 741 static bool renderbuffer_storage_msaa(GrGLContext& ctx, | 787 static bool renderbuffer_storage_msaa(GrGLContext& ctx, |
| 742 int sampleCount, | 788 int sampleCount, |
| (...skipping 2226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2969 this->setVertexArrayID(gpu, 0); | 3015 this->setVertexArrayID(gpu, 0); |
| 2970 } | 3016 } |
| 2971 int attrCount = gpu->glCaps().maxVertexAttributes(); | 3017 int attrCount = gpu->glCaps().maxVertexAttributes(); |
| 2972 if (fDefaultVertexArrayAttribState.count() != attrCount) { | 3018 if (fDefaultVertexArrayAttribState.count() != attrCount) { |
| 2973 fDefaultVertexArrayAttribState.resize(attrCount); | 3019 fDefaultVertexArrayAttribState.resize(attrCount); |
| 2974 } | 3020 } |
| 2975 attribState = &fDefaultVertexArrayAttribState; | 3021 attribState = &fDefaultVertexArrayAttribState; |
| 2976 } | 3022 } |
| 2977 return attribState; | 3023 return attribState; |
| 2978 } | 3024 } |
| OLD | NEW |