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