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 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 |
706 bool GrGpuGL::uploadCompressedTexData(const GrGLTexture::Desc& desc, | 715 bool GrGpuGL::uploadCompressedTexData(const GrGLTexture::Desc& desc, |
707 const void* data) { | 716 const void* data, |
708 SkASSERT(NULL != data); | 717 bool isNewTexture, |
718 int left, int top, int width, int height) { | |
719 SkASSERT(NULL != data || isNewTexture); | |
709 | 720 |
710 // No support for software flip y, yet... | 721 // No support for software flip y, yet... |
711 SkASSERT(kBottomLeft_GrSurfaceOrigin != desc.fOrigin); | 722 SkASSERT(kBottomLeft_GrSurfaceOrigin != desc.fOrigin); |
712 | 723 |
724 if (-1 == width) { | |
725 width = desc.fWidth; | |
726 } | |
727 | |
728 if (-1 == height) { | |
729 height = desc.fHeight; | |
730 } | |
731 | |
713 // Make sure that the width and height that we pass to OpenGL | 732 // Make sure that the width and height that we pass to OpenGL |
714 // is a multiple of the block size. | 733 // is a multiple of the block size. |
715 int dataSize = GrCompressedFormatDataSize(desc.fConfig, desc.fWidth, desc.fH eight); | 734 int dataSize = GrCompressedFormatDataSize(desc.fConfig, width, height); |
716 | 735 |
717 // We only need the internal format for compressed 2D textures. | 736 // We only need the internal format for compressed 2D textures. |
718 GrGLenum internalFormat = 0; | 737 GrGLenum internalFormat = 0; |
719 if (!this->configToGLFormats(desc.fConfig, false, &internalFormat, NULL, NUL L)) { | 738 if (!this->configToGLFormats(desc.fConfig, false, &internalFormat, NULL, NUL L)) { |
720 return false; | 739 return false; |
721 } | 740 } |
722 | 741 |
723 bool succeeded = true; | 742 bool succeeded = true; |
724 CLEAR_ERROR_BEFORE_ALLOC(this->glInterface()); | 743 CLEAR_ERROR_BEFORE_ALLOC(this->glInterface()); |
725 GL_ALLOC_CALL(this->glInterface(), | 744 |
726 CompressedTexImage2D(GR_GL_TEXTURE_2D, | 745 if (isNewTexture) { |
727 0, // level | 746 GL_ALLOC_CALL(this->glInterface(), |
728 internalFormat, | 747 CompressedTexImage2D(GR_GL_TEXTURE_2D, |
729 desc.fWidth, desc.fHeight, | 748 0, // level |
730 0, // border | 749 internalFormat, |
robertphillips
2014/06/11 19:24:46
Is this path okay if width != desc.fWidth || heigh
krajcevski
2014/06/11 21:21:43
OK, I've added asserts up above.
| |
731 dataSize, | 750 width, height, |
732 data)); | 751 0, // border |
752 dataSize, | |
753 data)); | |
754 } else { | |
755 GL_ALLOC_CALL(this->glInterface(), | |
756 CompressedTexSubImage2D(GR_GL_TEXTURE_2D, | |
757 0, // level | |
758 left, top, | |
759 width, height, | |
760 internalFormat, | |
761 dataSize, | |
762 data)); | |
763 } | |
733 | 764 |
734 GrGLenum error = check_alloc_error(desc, this->glInterface()); | 765 GrGLenum error = check_alloc_error(desc, this->glInterface()); |
735 if (error != GR_GL_NO_ERROR) { | 766 if (error != GR_GL_NO_ERROR) { |
736 succeeded = false; | 767 succeeded = false; |
737 } | 768 } |
738 return succeeded; | 769 return succeeded; |
739 } | 770 } |
740 | 771 |
741 static bool renderbuffer_storage_msaa(GrGLContext& ctx, | 772 static bool renderbuffer_storage_msaa(GrGLContext& ctx, |
742 int sampleCount, | 773 int sampleCount, |
(...skipping 2226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2969 this->setVertexArrayID(gpu, 0); | 3000 this->setVertexArrayID(gpu, 0); |
2970 } | 3001 } |
2971 int attrCount = gpu->glCaps().maxVertexAttributes(); | 3002 int attrCount = gpu->glCaps().maxVertexAttributes(); |
2972 if (fDefaultVertexArrayAttribState.count() != attrCount) { | 3003 if (fDefaultVertexArrayAttribState.count() != attrCount) { |
2973 fDefaultVertexArrayAttribState.resize(attrCount); | 3004 fDefaultVertexArrayAttribState.resize(attrCount); |
2974 } | 3005 } |
2975 attribState = &fDefaultVertexArrayAttribState; | 3006 attribState = &fDefaultVertexArrayAttribState; |
2976 } | 3007 } |
2977 return attribState; | 3008 return attribState; |
2978 } | 3009 } |
OLD | NEW |