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 601 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
612 return false; | 612 return false; |
613 } | 613 } |
614 | 614 |
615 this->setScratchTextureUnit(); | 615 this->setScratchTextureUnit(); |
616 GL_CALL(BindTexture(glTex->target(), glTex->textureID())); | 616 GL_CALL(BindTexture(glTex->target(), glTex->textureID())); |
617 | 617 |
618 bool success = false; | 618 bool success = false; |
619 if (GrPixelConfigIsCompressed(glTex->desc().fConfig)) { | 619 if (GrPixelConfigIsCompressed(glTex->desc().fConfig)) { |
620 // We check that config == desc.fConfig in GrGLGpu::canWriteTexturePixel s() | 620 // We check that config == desc.fConfig in GrGLGpu::canWriteTexturePixel s() |
621 SkASSERT(config == glTex->desc().fConfig); | 621 SkASSERT(config == glTex->desc().fConfig); |
622 success = this->uploadCompressedTexData(glTex->desc(), glTex->target(), buffer, false, left, | 622 success = this->uploadCompressedTexData(glTex->desc(), glTex->target(), buffer, |
623 top, width, height); | 623 kDefault_UploadType, left, top, width, height); |
624 } else { | 624 } else { |
625 success = this->uploadTexData(glTex->desc(), glTex->target(), false, lef t, top, width, | 625 success = this->uploadTexData(glTex->desc(), glTex->target(), kDefault_U ploadType, |
626 height, config, buffer, rowBytes); | 626 left, top, width, height, config, buffer, rowBytes); |
627 } | 627 } |
628 | |
629 if (success) { | |
630 glTex->texturePriv().dirtyMipMaps(true); | |
631 return true; | |
632 } | |
633 | |
634 return false; | |
635 } | |
636 | |
637 bool GrGLGpu::onTransferPixels(GrSurface* surface, | |
638 int left, int top, int width, int height, | |
639 GrPixelConfig config, GrTransferBuffer* buffer, | |
640 size_t offset, size_t rowBytes) { | |
641 GrGLTexture* glTex = static_cast<GrGLTexture*>(surface->asTexture()); | |
642 if (!glTex) { | |
bsalomon
2016/01/05 14:01:17
If there is a simple way to share this preamble of
jvanverth1
2016/01/05 17:21:28
Done.
| |
643 return false; | |
644 } | |
645 | |
646 // OpenGL doesn't do sRGB <-> linear conversions when reading and writing pi xels. | |
647 if (GrPixelConfigIsSRGB(surface->config()) != GrPixelConfigIsSRGB(config)) { | |
648 return false; | |
649 } | |
650 | |
651 // Transfer pixels is only implemented for TEXTURE_2D textures | |
652 if (GR_GL_TEXTURE_2D != glTex->target()) { | |
653 return false; | |
654 } | |
655 | |
656 // For the moment, can't transfer compressed data | |
657 if (GrPixelConfigIsCompressed(glTex->desc().fConfig)) { | |
658 return false; | |
659 } | |
660 | |
661 this->setScratchTextureUnit(); | |
662 GL_CALL(BindTexture(glTex->target(), glTex->textureID())); | |
663 | |
664 SkASSERT(!buffer->isMapped()); | |
665 GrGLTransferBuffer* glBuffer = reinterpret_cast<GrGLTransferBuffer*>(buffer) ; | |
666 // bind the transfer buffer | |
667 SkASSERT(GR_GL_PIXEL_UNPACK_BUFFER == glBuffer->bufferType() || | |
668 GR_GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM == glBuffer->bufferType ()); | |
669 GL_CALL(BindBuffer(glBuffer->bufferType(), glBuffer->bufferID())); | |
670 | |
671 bool success = false; | |
672 success = this->uploadTexData(glTex->desc(), glTex->target(), kTransfer_Uplo adType, | |
673 left, top, width, height, config, buffer, rowB ytes); | |
628 | 674 |
629 if (success) { | 675 if (success) { |
630 glTex->texturePriv().dirtyMipMaps(true); | 676 glTex->texturePriv().dirtyMipMaps(true); |
631 return true; | 677 return true; |
632 } | 678 } |
633 | 679 |
634 return false; | 680 return false; |
635 } | 681 } |
636 | 682 |
637 // For GL_[UN]PACK_ALIGNMENT. | 683 // For GL_[UN]PACK_ALIGNMENT. |
(...skipping 21 matching lines...) Expand all Loading... | |
659 const GrGLInterface* interface) { | 705 const GrGLInterface* interface) { |
660 if (SkToBool(desc.fFlags & kCheckAllocation_GrSurfaceFlag)) { | 706 if (SkToBool(desc.fFlags & kCheckAllocation_GrSurfaceFlag)) { |
661 return GR_GL_GET_ERROR(interface); | 707 return GR_GL_GET_ERROR(interface); |
662 } else { | 708 } else { |
663 return CHECK_ALLOC_ERROR(interface); | 709 return CHECK_ALLOC_ERROR(interface); |
664 } | 710 } |
665 } | 711 } |
666 | 712 |
667 bool GrGLGpu::uploadTexData(const GrSurfaceDesc& desc, | 713 bool GrGLGpu::uploadTexData(const GrSurfaceDesc& desc, |
668 GrGLenum target, | 714 GrGLenum target, |
669 bool isNewTexture, | 715 UploadType uploadType, |
670 int left, int top, int width, int height, | 716 int left, int top, int width, int height, |
671 GrPixelConfig dataConfig, | 717 GrPixelConfig dataConfig, |
672 const void* data, | 718 const void* dataOrOffset, |
673 size_t rowBytes) { | 719 size_t rowBytes) { |
674 SkASSERT(data || isNewTexture); | 720 SkASSERT(dataOrOffset || kNewTexture_UploadType == uploadType || |
721 kTransfer_UploadType == uploadType); | |
675 | 722 |
676 // If we're uploading compressed data then we should be using uploadCompress edTexData | 723 // If we're uploading compressed data then we should be using uploadCompress edTexData |
677 SkASSERT(!GrPixelConfigIsCompressed(dataConfig)); | 724 SkASSERT(!GrPixelConfigIsCompressed(dataConfig)); |
678 | 725 |
679 SkASSERT(this->caps()->isConfigTexturable(desc.fConfig)); | 726 SkASSERT(this->caps()->isConfigTexturable(desc.fConfig)); |
680 | 727 |
681 size_t bpp = GrBytesPerPixel(dataConfig); | 728 size_t bpp = GrBytesPerPixel(dataConfig); |
682 if (!GrSurfacePriv::AdjustWritePixelParams(desc.fWidth, desc.fHeight, bpp, & left, &top, | 729 if (!GrSurfacePriv::AdjustWritePixelParams(desc.fWidth, desc.fHeight, bpp, & left, &top, |
683 &width, &height, &data, &rowBytes )) { | 730 &width, &height, &dataOrOffset, & rowBytes)) { |
684 return false; | 731 return false; |
685 } | 732 } |
686 size_t trimRowBytes = width * bpp; | 733 size_t trimRowBytes = width * bpp; |
687 | 734 |
688 // in case we need a temporary, trimmed copy of the src pixels | 735 // in case we need a temporary, trimmed copy of the src pixels |
689 #if defined(GOOGLE3) | 736 #if defined(GOOGLE3) |
690 // Stack frame size is limited in GOOGLE3. | 737 // Stack frame size is limited in GOOGLE3. |
691 SkAutoSMalloc<64 * 128> tempStorage; | 738 SkAutoSMalloc<64 * 128> tempStorage; |
692 #else | 739 #else |
693 SkAutoSMalloc<128 * 128> tempStorage; | 740 SkAutoSMalloc<128 * 128> tempStorage; |
(...skipping 10 matching lines...) Expand all Loading... | |
704 | 751 |
705 /* | 752 /* |
706 * Check whether to allocate a temporary buffer for flipping y or | 753 * Check whether to allocate a temporary buffer for flipping y or |
707 * because our srcData has extra bytes past each row. If so, we need | 754 * because our srcData has extra bytes past each row. If so, we need |
708 * to trim those off here, since GL ES may not let us specify | 755 * to trim those off here, since GL ES may not let us specify |
709 * GL_UNPACK_ROW_LENGTH. | 756 * GL_UNPACK_ROW_LENGTH. |
710 */ | 757 */ |
711 bool restoreGLRowLength = false; | 758 bool restoreGLRowLength = false; |
712 bool swFlipY = false; | 759 bool swFlipY = false; |
713 bool glFlipY = false; | 760 bool glFlipY = false; |
714 if (data) { | 761 if (dataOrOffset) { |
715 if (kBottomLeft_GrSurfaceOrigin == desc.fOrigin) { | 762 if (kBottomLeft_GrSurfaceOrigin == desc.fOrigin) { |
716 if (this->glCaps().unpackFlipYSupport()) { | 763 if (this->glCaps().unpackFlipYSupport()) { |
717 glFlipY = true; | 764 glFlipY = true; |
718 } else { | 765 } else { |
719 swFlipY = true; | 766 swFlipY = true; |
720 } | 767 } |
721 } | 768 } |
722 if (this->glCaps().unpackRowLengthSupport() && !swFlipY) { | 769 if (this->glCaps().unpackRowLengthSupport() && !swFlipY) { |
723 // can't use this for flipping, only non-neg values allowed. :( | 770 // can't use this for flipping, only non-neg values allowed. :( |
724 if (rowBytes != trimRowBytes) { | 771 if (rowBytes != trimRowBytes) { |
725 GrGLint rowLength = static_cast<GrGLint>(rowBytes / bpp); | 772 GrGLint rowLength = static_cast<GrGLint>(rowBytes / bpp); |
726 GL_CALL(PixelStorei(GR_GL_UNPACK_ROW_LENGTH, rowLength)); | 773 GL_CALL(PixelStorei(GR_GL_UNPACK_ROW_LENGTH, rowLength)); |
727 restoreGLRowLength = true; | 774 restoreGLRowLength = true; |
728 } | 775 } |
729 } else { | 776 } else if (kTransfer_UploadType != uploadType) { |
730 if (trimRowBytes != rowBytes || swFlipY) { | 777 if (trimRowBytes != rowBytes || swFlipY) { |
731 // copy data into our new storage, skipping the trailing bytes | 778 // copy data into our new storage, skipping the trailing bytes |
732 size_t trimSize = height * trimRowBytes; | 779 size_t trimSize = height * trimRowBytes; |
733 const char* src = (const char*)data; | 780 const char* src = (const char*)dataOrOffset; |
734 if (swFlipY) { | 781 if (swFlipY) { |
735 src += (height - 1) * rowBytes; | 782 src += (height - 1) * rowBytes; |
736 } | 783 } |
737 char* dst = (char*)tempStorage.reset(trimSize); | 784 char* dst = (char*)tempStorage.reset(trimSize); |
738 for (int y = 0; y < height; y++) { | 785 for (int y = 0; y < height; y++) { |
739 memcpy(dst, src, trimRowBytes); | 786 memcpy(dst, src, trimRowBytes); |
740 if (swFlipY) { | 787 if (swFlipY) { |
741 src -= rowBytes; | 788 src -= rowBytes; |
742 } else { | 789 } else { |
743 src += rowBytes; | 790 src += rowBytes; |
744 } | 791 } |
745 dst += trimRowBytes; | 792 dst += trimRowBytes; |
746 } | 793 } |
747 // now point data to our copied version | 794 // now point data to our copied version |
748 data = tempStorage.get(); | 795 dataOrOffset = tempStorage.get(); |
749 } | 796 } |
797 } else { | |
798 return false; | |
750 } | 799 } |
751 if (glFlipY) { | 800 if (glFlipY) { |
752 GL_CALL(PixelStorei(GR_GL_UNPACK_FLIP_Y, GR_GL_TRUE)); | 801 GL_CALL(PixelStorei(GR_GL_UNPACK_FLIP_Y, GR_GL_TRUE)); |
753 } | 802 } |
754 GL_CALL(PixelStorei(GR_GL_UNPACK_ALIGNMENT, config_alignment(dataConfig) )); | 803 GL_CALL(PixelStorei(GR_GL_UNPACK_ALIGNMENT, config_alignment(dataConfig) )); |
755 } | 804 } |
756 bool succeeded = true; | 805 bool succeeded = true; |
757 if (isNewTexture) { | 806 if (kNewTexture_UploadType == uploadType) { |
758 if (data && !(0 == left && 0 == top && desc.fWidth == width && desc.fHei ght == height)) { | 807 if (dataOrOffset && |
808 !(0 == left && 0 == top && desc.fWidth == width && desc.fHeight == h eight)) { | |
759 succeeded = false; | 809 succeeded = false; |
760 } else { | 810 } else { |
761 CLEAR_ERROR_BEFORE_ALLOC(this->glInterface()); | 811 CLEAR_ERROR_BEFORE_ALLOC(this->glInterface()); |
762 GL_ALLOC_CALL(this->glInterface(), TexImage2D(target, 0, internalFor mat, desc.fWidth, | 812 GL_ALLOC_CALL(this->glInterface(), TexImage2D(target, 0, internalFor mat, desc.fWidth, |
763 desc.fHeight, 0, exte rnalFormat, | 813 desc.fHeight, 0, exte rnalFormat, |
764 externalType, data)); | 814 externalType, dataOrOf fset)); |
765 GrGLenum error = check_alloc_error(desc, this->glInterface()); | 815 GrGLenum error = check_alloc_error(desc, this->glInterface()); |
766 if (error != GR_GL_NO_ERROR) { | 816 if (error != GR_GL_NO_ERROR) { |
767 succeeded = false; | 817 succeeded = false; |
768 } | 818 } |
769 } | 819 } |
770 } else { | 820 } else { |
771 if (swFlipY || glFlipY) { | 821 if (swFlipY || glFlipY) { |
772 top = desc.fHeight - (top + height); | 822 top = desc.fHeight - (top + height); |
773 } | 823 } |
774 GL_CALL(TexSubImage2D(target, | 824 GL_CALL(TexSubImage2D(target, |
775 0, // level | 825 0, // level |
776 left, top, | 826 left, top, |
777 width, height, | 827 width, height, |
778 externalFormat, externalType, data)); | 828 externalFormat, externalType, dataOrOffset)); |
779 } | 829 } |
780 | 830 |
781 if (restoreGLRowLength) { | 831 if (restoreGLRowLength) { |
782 SkASSERT(this->glCaps().unpackRowLengthSupport()); | 832 SkASSERT(this->glCaps().unpackRowLengthSupport()); |
783 GL_CALL(PixelStorei(GR_GL_UNPACK_ROW_LENGTH, 0)); | 833 GL_CALL(PixelStorei(GR_GL_UNPACK_ROW_LENGTH, 0)); |
784 } | 834 } |
785 if (glFlipY) { | 835 if (glFlipY) { |
786 GL_CALL(PixelStorei(GR_GL_UNPACK_FLIP_Y, GR_GL_FALSE)); | 836 GL_CALL(PixelStorei(GR_GL_UNPACK_FLIP_Y, GR_GL_FALSE)); |
787 } | 837 } |
788 return succeeded; | 838 return succeeded; |
789 } | 839 } |
790 | 840 |
791 // TODO: This function is using a lot of wonky semantics like, if width == -1 | 841 // TODO: This function is using a lot of wonky semantics like, if width == -1 |
792 // then set width = desc.fWdith ... blah. A better way to do it might be to | 842 // then set width = desc.fWdith ... blah. A better way to do it might be to |
793 // create a CompressedTexData struct that takes a desc/ptr and figures out | 843 // create a CompressedTexData struct that takes a desc/ptr and figures out |
794 // the proper upload semantics. Then users can construct this function how they | 844 // the proper upload semantics. Then users can construct this function how they |
795 // see fit if they want to go against the "standard" way to do it. | 845 // see fit if they want to go against the "standard" way to do it. |
796 bool GrGLGpu::uploadCompressedTexData(const GrSurfaceDesc& desc, | 846 bool GrGLGpu::uploadCompressedTexData(const GrSurfaceDesc& desc, |
797 GrGLenum target, | 847 GrGLenum target, |
798 const void* data, | 848 const void* data, |
799 bool isNewTexture, | 849 UploadType uploadType, |
800 int left, int top, int width, int height) { | 850 int left, int top, int width, int height) { |
801 SkASSERT(this->caps()->isConfigTexturable(desc.fConfig)); | 851 SkASSERT(this->caps()->isConfigTexturable(desc.fConfig)); |
802 SkASSERT(data || isNewTexture); | 852 SkASSERT(kTransfer_UploadType != uploadType && |
853 (data || kNewTexture_UploadType != uploadType)); | |
803 | 854 |
804 // No support for software flip y, yet... | 855 // No support for software flip y, yet... |
805 SkASSERT(kBottomLeft_GrSurfaceOrigin != desc.fOrigin); | 856 SkASSERT(kBottomLeft_GrSurfaceOrigin != desc.fOrigin); |
806 | 857 |
807 if (-1 == width) { | 858 if (-1 == width) { |
808 width = desc.fWidth; | 859 width = desc.fWidth; |
809 } | 860 } |
810 #ifdef SK_DEBUG | 861 #ifdef SK_DEBUG |
811 else { | 862 else { |
812 SkASSERT(width <= desc.fWidth); | 863 SkASSERT(width <= desc.fWidth); |
(...skipping 10 matching lines...) Expand all Loading... | |
823 #endif | 874 #endif |
824 | 875 |
825 // Make sure that the width and height that we pass to OpenGL | 876 // Make sure that the width and height that we pass to OpenGL |
826 // is a multiple of the block size. | 877 // is a multiple of the block size. |
827 size_t dataSize = GrCompressedFormatDataSize(desc.fConfig, width, height); | 878 size_t dataSize = GrCompressedFormatDataSize(desc.fConfig, width, height); |
828 | 879 |
829 // We only need the internal format for compressed 2D textures. There is on | 880 // We only need the internal format for compressed 2D textures. There is on |
830 // sized vs base internal format distinction for compressed textures. | 881 // sized vs base internal format distinction for compressed textures. |
831 GrGLenum internalFormat =this->glCaps().configGLFormats(desc.fConfig).fSized InternalFormat; | 882 GrGLenum internalFormat =this->glCaps().configGLFormats(desc.fConfig).fSized InternalFormat; |
832 | 883 |
833 if (isNewTexture) { | 884 if (kNewTexture_UploadType == uploadType) { |
834 CLEAR_ERROR_BEFORE_ALLOC(this->glInterface()); | 885 CLEAR_ERROR_BEFORE_ALLOC(this->glInterface()); |
835 GL_ALLOC_CALL(this->glInterface(), | 886 GL_ALLOC_CALL(this->glInterface(), |
836 CompressedTexImage2D(target, | 887 CompressedTexImage2D(target, |
837 0, // level | 888 0, // level |
838 internalFormat, | 889 internalFormat, |
839 width, height, | 890 width, height, |
840 0, // border | 891 0, // border |
841 SkToInt(dataSize), | 892 SkToInt(dataSize), |
842 data)); | 893 data)); |
843 GrGLenum error = check_alloc_error(desc, this->glInterface()); | 894 GrGLenum error = check_alloc_error(desc, this->glInterface()); |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1069 initialTexParams.fMagFilter)); | 1120 initialTexParams.fMagFilter)); |
1070 GL_CALL(TexParameteri(idDesc.fInfo.fTarget, | 1121 GL_CALL(TexParameteri(idDesc.fInfo.fTarget, |
1071 GR_GL_TEXTURE_MIN_FILTER, | 1122 GR_GL_TEXTURE_MIN_FILTER, |
1072 initialTexParams.fMinFilter)); | 1123 initialTexParams.fMinFilter)); |
1073 GL_CALL(TexParameteri(idDesc.fInfo.fTarget, | 1124 GL_CALL(TexParameteri(idDesc.fInfo.fTarget, |
1074 GR_GL_TEXTURE_WRAP_S, | 1125 GR_GL_TEXTURE_WRAP_S, |
1075 initialTexParams.fWrapS)); | 1126 initialTexParams.fWrapS)); |
1076 GL_CALL(TexParameteri(idDesc.fInfo.fTarget, | 1127 GL_CALL(TexParameteri(idDesc.fInfo.fTarget, |
1077 GR_GL_TEXTURE_WRAP_T, | 1128 GR_GL_TEXTURE_WRAP_T, |
1078 initialTexParams.fWrapT)); | 1129 initialTexParams.fWrapT)); |
1079 if (!this->uploadTexData(desc, idDesc.fInfo.fTarget, true, 0, 0, | 1130 if (!this->uploadTexData(desc, idDesc.fInfo.fTarget, kNewTexture_UploadType, 0, 0, |
1080 desc.fWidth, desc.fHeight, | 1131 desc.fWidth, desc.fHeight, |
1081 desc.fConfig, srcData, rowBytes)) { | 1132 desc.fConfig, srcData, rowBytes)) { |
1082 GL_CALL(DeleteTextures(1, &idDesc.fInfo.fID)); | 1133 GL_CALL(DeleteTextures(1, &idDesc.fInfo.fID)); |
1083 return return_null_texture(); | 1134 return return_null_texture(); |
1084 } | 1135 } |
1085 | 1136 |
1086 GrGLTexture* tex; | 1137 GrGLTexture* tex; |
1087 if (renderTarget) { | 1138 if (renderTarget) { |
1088 // unbind the texture from the texture unit before binding it to the fra me buffer | 1139 // unbind the texture from the texture unit before binding it to the fra me buffer |
1089 GL_CALL(BindTexture(idDesc.fInfo.fTarget, 0)); | 1140 GL_CALL(BindTexture(idDesc.fInfo.fTarget, 0)); |
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1431 GrGLTransferBuffer::Desc desc; | 1482 GrGLTransferBuffer::Desc desc; |
1432 bool toGpu = (kCpuToGpu_TransferType == xferType); | 1483 bool toGpu = (kCpuToGpu_TransferType == xferType); |
1433 desc.fUsage = toGpu ? GrGLBufferImpl::kStreamDraw_Usage : GrGLBufferImpl::kS treamRead_Usage; | 1484 desc.fUsage = toGpu ? GrGLBufferImpl::kStreamDraw_Usage : GrGLBufferImpl::kS treamRead_Usage; |
1434 | 1485 |
1435 desc.fSizeInBytes = size; | 1486 desc.fSizeInBytes = size; |
1436 desc.fID = 0; | 1487 desc.fID = 0; |
1437 GL_CALL(GenBuffers(1, &desc.fID)); | 1488 GL_CALL(GenBuffers(1, &desc.fID)); |
1438 if (desc.fID) { | 1489 if (desc.fID) { |
1439 CLEAR_ERROR_BEFORE_ALLOC(this->glInterface()); | 1490 CLEAR_ERROR_BEFORE_ALLOC(this->glInterface()); |
1440 // make sure driver can allocate memory for this bmapuffer | 1491 // make sure driver can allocate memory for this bmapuffer |
1441 GrGLenum type; | 1492 GrGLenum target; |
1442 if (GrGLCaps::kChromium_TransferBufferType == xferBufferType) { | 1493 if (GrGLCaps::kChromium_TransferBufferType == xferBufferType) { |
1443 type = toGpu ? GR_GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM | 1494 target = toGpu ? GR_GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM |
1444 : GR_GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM; | 1495 : GR_GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM; |
1445 } else { | 1496 } else { |
1446 SkASSERT(GrGLCaps::kPBO_TransferBufferType == xferBufferType); | 1497 SkASSERT(GrGLCaps::kPBO_TransferBufferType == xferBufferType); |
1447 type = toGpu ? GR_GL_PIXEL_UNPACK_BUFFER : GR_GL_PIXEL_PACK_BUFFER; | 1498 target = toGpu ? GR_GL_PIXEL_UNPACK_BUFFER : GR_GL_PIXEL_PACK_BUFFER ; |
1448 } | 1499 } |
1449 GL_ALLOC_CALL(this->glInterface(), | 1500 GL_CALL(BindBuffer(target, desc.fID)); |
1450 BufferData(type, | 1501 GL_ALLOC_CALL(this->glInterface(), |
1502 BufferData(target, | |
1451 (GrGLsizeiptr) desc.fSizeInBytes, | 1503 (GrGLsizeiptr) desc.fSizeInBytes, |
1452 nullptr, // data ptr | 1504 nullptr, // data ptr |
1453 (toGpu ? GR_GL_STREAM_DRAW : GR_GL_STREAM_READ) )); | 1505 (toGpu ? GR_GL_STREAM_DRAW : GR_GL_STREAM_READ) )); |
1454 if (CHECK_ALLOC_ERROR(this->glInterface()) != GR_GL_NO_ERROR) { | 1506 if (CHECK_ALLOC_ERROR(this->glInterface()) != GR_GL_NO_ERROR) { |
1455 GL_CALL(DeleteBuffers(1, &desc.fID)); | 1507 GL_CALL(DeleteBuffers(1, &desc.fID)); |
1456 return nullptr; | 1508 return nullptr; |
1457 } | 1509 } |
1458 GrTransferBuffer* transferBuffer = new GrGLTransferBuffer(this, desc, ty pe); | 1510 GrTransferBuffer* transferBuffer = new GrGLTransferBuffer(this, desc, ta rget); |
1459 return transferBuffer; | 1511 return transferBuffer; |
1460 } | 1512 } |
1461 | 1513 |
1462 return nullptr; | 1514 return nullptr; |
1463 } | 1515 } |
1464 | 1516 |
1465 void GrGLGpu::flushScissor(const GrScissorState& scissorState, | 1517 void GrGLGpu::flushScissor(const GrScissorState& scissorState, |
1466 const GrGLIRect& rtViewport, | 1518 const GrGLIRect& rtViewport, |
1467 GrSurfaceOrigin rtOrigin) { | 1519 GrSurfaceOrigin rtOrigin) { |
1468 if (scissorState.enabled()) { | 1520 if (scissorState.enabled()) { |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1648 GL_CALL(BufferData(type, requestedSize, nullptr, glUsage)); | 1700 GL_CALL(BufferData(type, requestedSize, nullptr, glUsage)); |
1649 } | 1701 } |
1650 GL_CALL_RET(mapPtr, MapBuffer(type, readOnly ? GR_GL_READ_ONLY : GR_ GL_WRITE_ONLY)); | 1702 GL_CALL_RET(mapPtr, MapBuffer(type, readOnly ? GR_GL_READ_ONLY : GR_ GL_WRITE_ONLY)); |
1651 break; | 1703 break; |
1652 case GrGLCaps::kMapBufferRange_MapBufferType: { | 1704 case GrGLCaps::kMapBufferRange_MapBufferType: { |
1653 this->bindBuffer(id, type); | 1705 this->bindBuffer(id, type); |
1654 // Make sure the GL buffer size agrees with fDesc before mapping. | 1706 // Make sure the GL buffer size agrees with fDesc before mapping. |
1655 if (currentSize != requestedSize) { | 1707 if (currentSize != requestedSize) { |
1656 GL_CALL(BufferData(type, requestedSize, nullptr, glUsage)); | 1708 GL_CALL(BufferData(type, requestedSize, nullptr, glUsage)); |
1657 } | 1709 } |
1658 static const GrGLbitfield kWriteAccess = GR_GL_MAP_INVALIDATE_BUFFER _BIT | | 1710 GrGLbitfield writeAccess = GR_GL_MAP_WRITE_BIT; |
1659 GR_GL_MAP_WRITE_BIT; | 1711 // TODO: allow the client to specify invalidation in the stream draw case |
1712 if (GrGLBufferImpl::kStreamDraw_Usage != usage) { | |
1713 writeAccess |= GR_GL_MAP_INVALIDATE_BUFFER_BIT; | |
1714 } | |
1660 GL_CALL_RET(mapPtr, MapBufferRange(type, 0, requestedSize, readOnly ? | 1715 GL_CALL_RET(mapPtr, MapBufferRange(type, 0, requestedSize, readOnly ? |
1661 GR_GL_MAP _READ_BIT : | 1716 GR_GL_MAP _READ_BIT : |
1662 kWriteAcc ess)); | 1717 writeAcce ss)); |
1663 break; | 1718 break; |
1664 } | 1719 } |
1665 case GrGLCaps::kChromium_MapBufferType: | 1720 case GrGLCaps::kChromium_MapBufferType: |
1666 this->bindBuffer(id, type); | 1721 this->bindBuffer(id, type); |
1667 // Make sure the GL buffer size agrees with fDesc before mapping. | 1722 // Make sure the GL buffer size agrees with fDesc before mapping. |
1668 if (currentSize != requestedSize) { | 1723 if (currentSize != requestedSize) { |
1669 GL_CALL(BufferData(type, requestedSize, nullptr, glUsage)); | 1724 GL_CALL(BufferData(type, requestedSize, nullptr, glUsage)); |
1670 } | 1725 } |
1671 GL_CALL_RET(mapPtr, MapBufferSubData(type, 0, requestedSize, readOnl y ? | 1726 GL_CALL_RET(mapPtr, MapBufferSubData(type, 0, requestedSize, readOnl y ? |
1672 GR_GL_R EAD_ONLY : | 1727 GR_GL_R EAD_ONLY : |
(...skipping 1699 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3372 this->setVertexArrayID(gpu, 0); | 3427 this->setVertexArrayID(gpu, 0); |
3373 } | 3428 } |
3374 int attrCount = gpu->glCaps().maxVertexAttributes(); | 3429 int attrCount = gpu->glCaps().maxVertexAttributes(); |
3375 if (fDefaultVertexArrayAttribState.count() != attrCount) { | 3430 if (fDefaultVertexArrayAttribState.count() != attrCount) { |
3376 fDefaultVertexArrayAttribState.resize(attrCount); | 3431 fDefaultVertexArrayAttribState.resize(attrCount); |
3377 } | 3432 } |
3378 attribState = &fDefaultVertexArrayAttribState; | 3433 attribState = &fDefaultVertexArrayAttribState; |
3379 } | 3434 } |
3380 return attribState; | 3435 return attribState; |
3381 } | 3436 } |
OLD | NEW |