Chromium Code Reviews| 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 success = this->uploadCompressedTexData(desc, buffer, false, |
| 484 texture->impl()->dirtyMipMaps(true); | 483 left, top, width, height); |
| 485 return true; | |
| 486 } else { | 484 } else { |
| 487 return false; | 485 success = this->uploadTexData(desc, false, |
| 486 left, top, width, height, | |
| 487 config, buffer, rowBytes); | |
| 488 } | 488 } |
| 489 | |
|
robertphillips
2014/06/11 18:20:57
if (success) {
texture->impl()->dirtyMipMaps(tru
krajcevski
2014/06/11 18:58:41
Done.
| |
| 490 texture->impl()->dirtyMipMaps(true); | |
| 491 return success; | |
| 489 } | 492 } |
| 490 | 493 |
| 491 namespace { | 494 namespace { |
| 492 bool adjust_pixel_ops_params(int surfaceWidth, | 495 bool adjust_pixel_ops_params(int surfaceWidth, |
| 493 int surfaceHeight, | 496 int surfaceHeight, |
| 494 size_t bpp, | 497 size_t bpp, |
| 495 int* left, int* top, int* width, int* height, | 498 int* left, int* top, int* width, int* height, |
| 496 const void** data, | 499 const void** data, |
| 497 size_t* rowBytes) { | 500 size_t* rowBytes) { |
| 498 if (!*rowBytes) { | 501 if (!*rowBytes) { |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 697 SkASSERT(this->glCaps().unpackRowLengthSupport()); | 700 SkASSERT(this->glCaps().unpackRowLengthSupport()); |
| 698 GL_CALL(PixelStorei(GR_GL_UNPACK_ROW_LENGTH, 0)); | 701 GL_CALL(PixelStorei(GR_GL_UNPACK_ROW_LENGTH, 0)); |
| 699 } | 702 } |
| 700 if (glFlipY) { | 703 if (glFlipY) { |
| 701 GL_CALL(PixelStorei(GR_GL_UNPACK_FLIP_Y, GR_GL_FALSE)); | 704 GL_CALL(PixelStorei(GR_GL_UNPACK_FLIP_Y, GR_GL_FALSE)); |
| 702 } | 705 } |
| 703 return succeeded; | 706 return succeeded; |
| 704 } | 707 } |
| 705 | 708 |
| 706 bool GrGpuGL::uploadCompressedTexData(const GrGLTexture::Desc& desc, | 709 bool GrGpuGL::uploadCompressedTexData(const GrGLTexture::Desc& desc, |
| 707 const void* data) { | 710 const void* data, |
| 708 SkASSERT(NULL != data); | 711 bool isNewTexture, |
| 712 int left, int top, int width, int height) { | |
| 713 SkASSERT(NULL != data || isNewTexture); | |
| 709 | 714 |
| 710 // No support for software flip y, yet... | 715 // No support for software flip y, yet... |
| 711 SkASSERT(kBottomLeft_GrSurfaceOrigin != desc.fOrigin); | 716 SkASSERT(kBottomLeft_GrSurfaceOrigin != desc.fOrigin); |
| 712 | 717 |
| 718 if (-1 == width) { | |
| 719 width = desc.fWidth; | |
| 720 } | |
| 721 | |
| 722 if (-1 == height) { | |
| 723 height = desc.fHeight; | |
| 724 } | |
| 725 | |
| 713 // Make sure that the width and height that we pass to OpenGL | 726 // Make sure that the width and height that we pass to OpenGL |
| 714 // is a multiple of the block size. | 727 // is a multiple of the block size. |
| 715 int dataSize = GrCompressedFormatDataSize(desc.fConfig, desc.fWidth, desc.fH eight); | 728 int dataSize = GrCompressedFormatDataSize(desc.fConfig, width, height); |
| 716 | 729 |
| 717 // We only need the internal format for compressed 2D textures. | 730 // We only need the internal format for compressed 2D textures. |
| 718 GrGLenum internalFormat = 0; | 731 GrGLenum internalFormat = 0; |
| 719 if (!this->configToGLFormats(desc.fConfig, false, &internalFormat, NULL, NUL L)) { | 732 if (!this->configToGLFormats(desc.fConfig, false, &internalFormat, NULL, NUL L)) { |
| 720 return false; | 733 return false; |
| 721 } | 734 } |
| 722 | 735 |
| 723 bool succeeded = true; | 736 bool succeeded = true; |
| 724 CLEAR_ERROR_BEFORE_ALLOC(this->glInterface()); | 737 CLEAR_ERROR_BEFORE_ALLOC(this->glInterface()); |
| 725 GL_ALLOC_CALL(this->glInterface(), | 738 |
| 726 CompressedTexImage2D(GR_GL_TEXTURE_2D, | 739 if (isNewTexture) { |
| 727 0, // level | 740 GL_ALLOC_CALL(this->glInterface(), |
| 728 internalFormat, | 741 CompressedTexImage2D(GR_GL_TEXTURE_2D, |
| 729 desc.fWidth, desc.fHeight, | 742 0, // level |
| 730 0, // border | 743 internalFormat, |
| 731 dataSize, | 744 width, height, |
| 732 data)); | 745 0, // border |
| 746 dataSize, | |
| 747 data)); | |
| 748 } else { | |
| 749 GL_ALLOC_CALL(this->glInterface(), | |
| 750 CompressedTexSubImage2D(GR_GL_TEXTURE_2D, | |
| 751 0, // level | |
| 752 left, top, | |
| 753 width, height, | |
| 754 internalFormat, | |
| 755 dataSize, | |
| 756 data)); | |
| 757 } | |
| 733 | 758 |
| 734 GrGLenum error = check_alloc_error(desc, this->glInterface()); | 759 GrGLenum error = check_alloc_error(desc, this->glInterface()); |
| 735 if (error != GR_GL_NO_ERROR) { | 760 if (error != GR_GL_NO_ERROR) { |
| 736 succeeded = false; | 761 succeeded = false; |
| 737 } | 762 } |
| 738 return succeeded; | 763 return succeeded; |
| 739 } | 764 } |
| 740 | 765 |
| 741 static bool renderbuffer_storage_msaa(GrGLContext& ctx, | 766 static bool renderbuffer_storage_msaa(GrGLContext& ctx, |
| 742 int sampleCount, | 767 int sampleCount, |
| (...skipping 2226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2969 this->setVertexArrayID(gpu, 0); | 2994 this->setVertexArrayID(gpu, 0); |
| 2970 } | 2995 } |
| 2971 int attrCount = gpu->glCaps().maxVertexAttributes(); | 2996 int attrCount = gpu->glCaps().maxVertexAttributes(); |
| 2972 if (fDefaultVertexArrayAttribState.count() != attrCount) { | 2997 if (fDefaultVertexArrayAttribState.count() != attrCount) { |
| 2973 fDefaultVertexArrayAttribState.resize(attrCount); | 2998 fDefaultVertexArrayAttribState.resize(attrCount); |
| 2974 } | 2999 } |
| 2975 attribState = &fDefaultVertexArrayAttribState; | 3000 attribState = &fDefaultVertexArrayAttribState; |
| 2976 } | 3001 } |
| 2977 return attribState; | 3002 return attribState; |
| 2978 } | 3003 } |
| OLD | NEW |