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 "GrGLGpu.h" | 9 #include "GrGLGpu.h" |
10 #include "GrGLGLSL.h" | 10 #include "GrGLGLSL.h" |
(...skipping 630 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
641 } | 641 } |
642 | 642 |
643 if (success) { | 643 if (success) { |
644 glTex->texturePriv().dirtyMipMaps(true); | 644 glTex->texturePriv().dirtyMipMaps(true); |
645 return true; | 645 return true; |
646 } | 646 } |
647 | 647 |
648 return false; | 648 return false; |
649 } | 649 } |
650 | 650 |
| 651 // For GL_[UN]PACK_ALIGNMENT. |
| 652 static inline GrGLint config_alignment(GrPixelConfig config) { |
| 653 SkASSERT(!GrPixelConfigIsCompressed(config)); |
| 654 switch (config) { |
| 655 case kAlpha_8_GrPixelConfig: |
| 656 return 1; |
| 657 case kRGB_565_GrPixelConfig: |
| 658 case kRGBA_4444_GrPixelConfig: |
| 659 case kAlpha_half_GrPixelConfig: |
| 660 case kRGBA_half_GrPixelConfig: |
| 661 return 2; |
| 662 case kRGBA_8888_GrPixelConfig: |
| 663 case kBGRA_8888_GrPixelConfig: |
| 664 case kSRGBA_8888_GrPixelConfig: |
| 665 case kRGBA_float_GrPixelConfig: |
| 666 return 4; |
| 667 default: |
| 668 return 0; |
| 669 } |
| 670 } |
| 671 |
651 static inline GrGLenum check_alloc_error(const GrSurfaceDesc& desc, | 672 static inline GrGLenum check_alloc_error(const GrSurfaceDesc& desc, |
652 const GrGLInterface* interface) { | 673 const GrGLInterface* interface) { |
653 if (SkToBool(desc.fFlags & kCheckAllocation_GrSurfaceFlag)) { | 674 if (SkToBool(desc.fFlags & kCheckAllocation_GrSurfaceFlag)) { |
654 return GR_GL_GET_ERROR(interface); | 675 return GR_GL_GET_ERROR(interface); |
655 } else { | 676 } else { |
656 return CHECK_ALLOC_ERROR(interface); | 677 return CHECK_ALLOC_ERROR(interface); |
657 } | 678 } |
658 } | 679 } |
659 | 680 |
660 bool GrGLGpu::uploadTexData(const GrSurfaceDesc& desc, | 681 bool GrGLGpu::uploadTexData(const GrSurfaceDesc& desc, |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
761 } | 782 } |
762 dst += trimRowBytes; | 783 dst += trimRowBytes; |
763 } | 784 } |
764 // now point data to our copied version | 785 // now point data to our copied version |
765 data = tempStorage.get(); | 786 data = tempStorage.get(); |
766 } | 787 } |
767 } | 788 } |
768 if (glFlipY) { | 789 if (glFlipY) { |
769 GL_CALL(PixelStorei(GR_GL_UNPACK_FLIP_Y, GR_GL_TRUE)); | 790 GL_CALL(PixelStorei(GR_GL_UNPACK_FLIP_Y, GR_GL_TRUE)); |
770 } | 791 } |
771 GL_CALL(PixelStorei(GR_GL_UNPACK_ALIGNMENT, | 792 GL_CALL(PixelStorei(GR_GL_UNPACK_ALIGNMENT, config_alignment(dataConfig)
)); |
772 static_cast<GrGLint>(GrUnpackAlignment(dataConfig)))); | |
773 } | 793 } |
774 bool succeeded = true; | 794 bool succeeded = true; |
775 if (isNewTexture && | 795 if (isNewTexture && |
776 0 == left && 0 == top && | 796 0 == left && 0 == top && |
777 desc.fWidth == width && desc.fHeight == height) { | 797 desc.fWidth == width && desc.fHeight == height) { |
778 CLEAR_ERROR_BEFORE_ALLOC(this->glInterface()); | 798 CLEAR_ERROR_BEFORE_ALLOC(this->glInterface()); |
779 if (useTexStorage) { | 799 if (useTexStorage) { |
780 // We never resize or change formats of textures. | 800 // We never resize or change formats of textures. |
781 GL_ALLOC_CALL(this->glInterface(), | 801 GL_ALLOC_CALL(this->glInterface(), |
782 TexStorage2D(target, | 802 TexStorage2D(target, |
(...skipping 1291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2074 static_cast<GrGLint>(rowBytes / sizeof(GrColor))
)); | 2094 static_cast<GrGLint>(rowBytes / sizeof(GrColor))
)); |
2075 readDstRowBytes = rowBytes; | 2095 readDstRowBytes = rowBytes; |
2076 } else { | 2096 } else { |
2077 scratch.reset(tightRowBytes * height); | 2097 scratch.reset(tightRowBytes * height); |
2078 readDst = scratch.get(); | 2098 readDst = scratch.get(); |
2079 } | 2099 } |
2080 } | 2100 } |
2081 if (flipY && this->glCaps().packFlipYSupport()) { | 2101 if (flipY && this->glCaps().packFlipYSupport()) { |
2082 GL_CALL(PixelStorei(GR_GL_PACK_REVERSE_ROW_ORDER, 1)); | 2102 GL_CALL(PixelStorei(GR_GL_PACK_REVERSE_ROW_ORDER, 1)); |
2083 } | 2103 } |
| 2104 GL_CALL(PixelStorei(GR_GL_PACK_ALIGNMENT, config_alignment(config))); |
| 2105 |
2084 GL_CALL(ReadPixels(readRect.fLeft, readRect.fBottom, | 2106 GL_CALL(ReadPixels(readRect.fLeft, readRect.fBottom, |
2085 readRect.fWidth, readRect.fHeight, | 2107 readRect.fWidth, readRect.fHeight, |
2086 format, type, readDst)); | 2108 format, type, readDst)); |
2087 if (readDstRowBytes != tightRowBytes) { | 2109 if (readDstRowBytes != tightRowBytes) { |
2088 SkASSERT(this->glCaps().packRowLengthSupport()); | 2110 SkASSERT(this->glCaps().packRowLengthSupport()); |
2089 GL_CALL(PixelStorei(GR_GL_PACK_ROW_LENGTH, 0)); | 2111 GL_CALL(PixelStorei(GR_GL_PACK_ROW_LENGTH, 0)); |
2090 } | 2112 } |
2091 if (flipY && this->glCaps().packFlipYSupport()) { | 2113 if (flipY && this->glCaps().packFlipYSupport()) { |
2092 GL_CALL(PixelStorei(GR_GL_PACK_REVERSE_ROW_ORDER, 0)); | 2114 GL_CALL(PixelStorei(GR_GL_PACK_REVERSE_ROW_ORDER, 0)); |
2093 flipY = false; | 2115 flipY = false; |
(...skipping 1533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3627 this->setVertexArrayID(gpu, 0); | 3649 this->setVertexArrayID(gpu, 0); |
3628 } | 3650 } |
3629 int attrCount = gpu->glCaps().maxVertexAttributes(); | 3651 int attrCount = gpu->glCaps().maxVertexAttributes(); |
3630 if (fDefaultVertexArrayAttribState.count() != attrCount) { | 3652 if (fDefaultVertexArrayAttribState.count() != attrCount) { |
3631 fDefaultVertexArrayAttribState.resize(attrCount); | 3653 fDefaultVertexArrayAttribState.resize(attrCount); |
3632 } | 3654 } |
3633 attribState = &fDefaultVertexArrayAttribState; | 3655 attribState = &fDefaultVertexArrayAttribState; |
3634 } | 3656 } |
3635 return attribState; | 3657 return attribState; |
3636 } | 3658 } |
OLD | NEW |