| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2012 Google Inc. | 3 * Copyright 2012 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 #include "DebugGLTestContext.h" | 9 #include "DebugGLTestContext.h" |
| 10 | 10 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 | 28 |
| 29 // Helper macro to make creating an object (where you need to get back a derived
type) easier | 29 // Helper macro to make creating an object (where you need to get back a derived
type) easier |
| 30 #define FIND(id, className, classEnum) \ | 30 #define FIND(id, className, classEnum) \ |
| 31 reinterpret_cast<className *>(this->findObject(id, classEnum)) | 31 reinterpret_cast<className *>(this->findObject(id, classEnum)) |
| 32 | 32 |
| 33 class DebugInterface : public GrGLTestInterface { | 33 class DebugInterface : public GrGLTestInterface { |
| 34 public: | 34 public: |
| 35 DebugInterface() | 35 DebugInterface() |
| 36 : fCurrGenericID(0) | 36 : fCurrGenericID(0) |
| 37 , fCurrTextureUnit(0) | 37 , fCurrTextureUnit(0) |
| 38 , fArrayBuffer(nullptr) | |
| 39 , fElementArrayBuffer(nullptr) | |
| 40 , fVertexArray(nullptr) | 38 , fVertexArray(nullptr) |
| 41 , fPackRowLength(0) | 39 , fPackRowLength(0) |
| 42 , fUnpackRowLength(0) | 40 , fUnpackRowLength(0) |
| 43 , fPackAlignment(4) | 41 , fPackAlignment(4) |
| 44 , fFrameBuffer(nullptr) | 42 , fFrameBuffer(nullptr) |
| 45 , fRenderBuffer(nullptr) | 43 , fRenderBuffer(nullptr) |
| 46 , fProgram(nullptr) | 44 , fProgram(nullptr) |
| 47 , fAbandoned(false) { | 45 , fAbandoned(false) { |
| 48 for (int i = 0; i < kDefaultMaxTextureUnits; ++i) { | 46 for (int i = 0; i < kDefaultMaxTextureUnits; ++i) { |
| 49 fTextureUnits[i] = | 47 fTextureUnits[i] = |
| 50 reinterpret_cast<GrTextureUnitObj*>(this->createObj(kTextureUnit
_ObjTypes)); | 48 reinterpret_cast<GrTextureUnitObj*>(this->createObj(kTextureUnit
_ObjTypes)); |
| 51 fTextureUnits[i]->ref(); | 49 fTextureUnits[i]->ref(); |
| 52 fTextureUnits[i]->setNumber(i); | 50 fTextureUnits[i]->setNumber(i); |
| 53 } | 51 } |
| 52 memset(fBoundBuffers, 0, sizeof(fBoundBuffers)); |
| 54 this->init(kGL_GrGLStandard); | 53 this->init(kGL_GrGLStandard); |
| 55 } | 54 } |
| 56 | 55 |
| 57 ~DebugInterface() override { | 56 ~DebugInterface() override { |
| 58 // unref & delete the texture units first so they don't show up on the l
eak report | 57 // unref & delete the texture units first so they don't show up on the l
eak report |
| 59 for (int i = 0; i < kDefaultMaxTextureUnits; ++i) { | 58 for (int i = 0; i < kDefaultMaxTextureUnits; ++i) { |
| 60 fTextureUnits[i]->unref(); | 59 fTextureUnits[i]->unref(); |
| 61 fTextureUnits[i]->deleteAction(); | 60 fTextureUnits[i]->deleteAction(); |
| 62 } | 61 } |
| 63 for (int i = 0; i < fObjects.count(); ++i) { | 62 for (int i = 0; i < fObjects.count(); ++i) { |
| 64 delete fObjects[i]; | 63 delete fObjects[i]; |
| 65 } | 64 } |
| 66 fObjects.reset(); | 65 fObjects.reset(); |
| 67 | 66 |
| 68 fArrayBuffer = nullptr; | 67 memset(fBoundBuffers, 0, sizeof(fBoundBuffers)); |
| 69 fElementArrayBuffer = nullptr; | |
| 70 fVertexArray = nullptr; | 68 fVertexArray = nullptr; |
| 71 | 69 |
| 72 this->report(); | 70 this->report(); |
| 73 } | 71 } |
| 74 | 72 |
| 75 void abandon() const override { fAbandoned = true; } | 73 void abandon() const override { fAbandoned = true; } |
| 76 | 74 |
| 77 GrGLvoid activeTexture(GrGLenum texture) override { | 75 GrGLvoid activeTexture(GrGLenum texture) override { |
| 78 // Ganesh offsets the texture unit indices | 76 // Ganesh offsets the texture unit indices |
| 79 texture -= GR_GL_TEXTURE0; | 77 texture -= GR_GL_TEXTURE0; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 100 | 98 |
| 101 // a textureID of 0 is acceptable - it binds to the default texture targ
et | 99 // a textureID of 0 is acceptable - it binds to the default texture targ
et |
| 102 GrTextureObj *texture = FIND(textureID, GrTextureObj, kTexture_ObjTypes)
; | 100 GrTextureObj *texture = FIND(textureID, GrTextureObj, kTexture_ObjTypes)
; |
| 103 | 101 |
| 104 this->setTexture(texture); | 102 this->setTexture(texture); |
| 105 } | 103 } |
| 106 | 104 |
| 107 ////////////////////////////////////////////////////////////////////////////
//// | 105 ////////////////////////////////////////////////////////////////////////////
//// |
| 108 GrGLvoid bufferData(GrGLenum target, GrGLsizeiptr size, const GrGLvoid* data
, | 106 GrGLvoid bufferData(GrGLenum target, GrGLsizeiptr size, const GrGLvoid* data
, |
| 109 GrGLenum usage) override { | 107 GrGLenum usage) override { |
| 110 GrAlwaysAssert(GR_GL_ARRAY_BUFFER == target || | |
| 111 GR_GL_ELEMENT_ARRAY_BUFFER == target); | |
| 112 GrAlwaysAssert(size >= 0); | 108 GrAlwaysAssert(size >= 0); |
| 113 GrAlwaysAssert(GR_GL_STREAM_DRAW == usage || | 109 GrAlwaysAssert(GR_GL_STREAM_DRAW == usage || |
| 114 GR_GL_STATIC_DRAW == usage || | 110 GR_GL_STATIC_DRAW == usage || |
| 115 GR_GL_DYNAMIC_DRAW == usage); | 111 GR_GL_DYNAMIC_DRAW == usage); |
| 116 | 112 |
| 117 GrBufferObj *buffer = nullptr; | 113 GrBufferObj *buffer = fBoundBuffers[GetBufferIndex(target)]; |
| 118 switch (target) { | |
| 119 case GR_GL_ARRAY_BUFFER: | |
| 120 buffer = this->getArrayBuffer(); | |
| 121 break; | |
| 122 case GR_GL_ELEMENT_ARRAY_BUFFER: | |
| 123 buffer = this->getElementArrayBuffer(); | |
| 124 break; | |
| 125 default: | |
| 126 SkFAIL("Unexpected target to glBufferData"); | |
| 127 break; | |
| 128 } | |
| 129 | |
| 130 GrAlwaysAssert(buffer); | 114 GrAlwaysAssert(buffer); |
| 131 GrAlwaysAssert(buffer->getBound()); | 115 GrAlwaysAssert(buffer->getBound()); |
| 132 | 116 |
| 133 buffer->allocate(size, reinterpret_cast<const GrGLchar *>(data)); | 117 buffer->allocate(size, reinterpret_cast<const GrGLchar *>(data)); |
| 134 buffer->setUsage(usage); | 118 buffer->setUsage(usage); |
| 135 } | 119 } |
| 136 | 120 |
| 137 | 121 |
| 138 GrGLvoid pixelStorei(GrGLenum pname, GrGLint param) override { | 122 GrGLvoid pixelStorei(GrGLenum pname, GrGLint param) override { |
| 139 | 123 |
| (...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 719 } | 703 } |
| 720 } | 704 } |
| 721 | 705 |
| 722 GrGLvoid bindVertexArray(GrGLuint id) override { | 706 GrGLvoid bindVertexArray(GrGLuint id) override { |
| 723 GrVertexArrayObj* array = FIND(id, GrVertexArrayObj, kVertexArray_ObjTyp
es); | 707 GrVertexArrayObj* array = FIND(id, GrVertexArrayObj, kVertexArray_ObjTyp
es); |
| 724 GrAlwaysAssert((0 == id) || array); | 708 GrAlwaysAssert((0 == id) || array); |
| 725 this->setVertexArray(array); | 709 this->setVertexArray(array); |
| 726 } | 710 } |
| 727 | 711 |
| 728 GrGLvoid bindBuffer(GrGLenum target, GrGLuint bufferID) override { | 712 GrGLvoid bindBuffer(GrGLenum target, GrGLuint bufferID) override { |
| 729 GrAlwaysAssert(GR_GL_ARRAY_BUFFER == target || GR_GL_ELEMENT_ARRAY_BUFFE
R == target); | |
| 730 | |
| 731 GrBufferObj *buffer = FIND(bufferID, GrBufferObj, kBuffer_ObjTypes); | 713 GrBufferObj *buffer = FIND(bufferID, GrBufferObj, kBuffer_ObjTypes); |
| 732 // 0 is a permissible bufferID - it unbinds the current buffer | 714 // 0 is a permissible bufferID - it unbinds the current buffer |
| 733 | 715 |
| 734 switch (target) { | 716 this->setBuffer(GetBufferIndex(target), buffer); |
| 735 case GR_GL_ARRAY_BUFFER: | |
| 736 this->setArrayBuffer(buffer); | |
| 737 break; | |
| 738 case GR_GL_ELEMENT_ARRAY_BUFFER: | |
| 739 this->setElementArrayBuffer(buffer); | |
| 740 break; | |
| 741 default: | |
| 742 SkFAIL("Unexpected target to glBindBuffer"); | |
| 743 break; | |
| 744 } | |
| 745 } | 717 } |
| 746 | 718 |
| 747 // deleting a bound buffer has the side effect of binding 0 | 719 // deleting a bound buffer has the side effect of binding 0 |
| 748 GrGLvoid deleteBuffers(GrGLsizei n, const GrGLuint* ids) override { | 720 GrGLvoid deleteBuffers(GrGLsizei n, const GrGLuint* ids) override { |
| 749 // first potentially unbind the buffers | 721 // first potentially unbind the buffers |
| 750 for (int i = 0; i < n; ++i) { | 722 for (int buffIdx = 0; buffIdx < kNumBufferTargets; ++buffIdx) { |
| 751 | 723 GrBufferObj* buffer = fBoundBuffers[buffIdx]; |
| 752 if (this->getArrayBuffer() && | 724 if (!buffer) { |
| 753 ids[i] == this->getArrayBuffer()->getID()) { | 725 continue; |
| 754 // this ID is the current array buffer | |
| 755 this->setArrayBuffer(nullptr); | |
| 756 } | 726 } |
| 757 if (this->getElementArrayBuffer() && | 727 for (int i = 0; i < n; ++i) { |
| 758 ids[i] == this->getElementArrayBuffer()->getID()) { | 728 if (ids[i] == buffer->getID()) { |
| 759 // this ID is the current element array buffer | 729 this->setBuffer(buffIdx, nullptr); |
| 760 this->setElementArrayBuffer(nullptr); | 730 break; |
| 731 } |
| 761 } | 732 } |
| 762 } | 733 } |
| 763 | 734 |
| 764 // then actually "delete" the buffers | 735 // then actually "delete" the buffers |
| 765 for (int i = 0; i < n; ++i) { | 736 for (int i = 0; i < n; ++i) { |
| 766 GrBufferObj *buffer = FIND(ids[i], GrBufferObj, kBuffer_ObjTypes); | 737 GrBufferObj *buffer = FIND(ids[i], GrBufferObj, kBuffer_ObjTypes); |
| 767 GrAlwaysAssert(buffer); | 738 GrAlwaysAssert(buffer); |
| 768 | 739 |
| 769 GrAlwaysAssert(!buffer->getDeleted()); | 740 GrAlwaysAssert(!buffer->getDeleted()); |
| 770 buffer->deleteAction(); | 741 buffer->deleteAction(); |
| 771 } | 742 } |
| 772 } | 743 } |
| 773 | 744 |
| 774 // map a buffer to the caller's address space | 745 // map a buffer to the caller's address space |
| 775 GrGLvoid* mapBufferRange(GrGLenum target, GrGLintptr offset, GrGLsizeiptr le
ngth, | 746 GrGLvoid* mapBufferRange(GrGLenum target, GrGLintptr offset, GrGLsizeiptr le
ngth, |
| 776 GrGLbitfield access) override { | 747 GrGLbitfield access) override { |
| 777 GrAlwaysAssert(GR_GL_ARRAY_BUFFER == target || | |
| 778 GR_GL_ELEMENT_ARRAY_BUFFER == target); | |
| 779 | |
| 780 // We only expect read access and we expect that the buffer or range is
always invalidated. | 748 // We only expect read access and we expect that the buffer or range is
always invalidated. |
| 781 GrAlwaysAssert(!SkToBool(GR_GL_MAP_READ_BIT & access)); | 749 GrAlwaysAssert(!SkToBool(GR_GL_MAP_READ_BIT & access)); |
| 782 GrAlwaysAssert((GR_GL_MAP_INVALIDATE_BUFFER_BIT | GR_GL_MAP_INVALIDATE_R
ANGE_BIT) & access); | 750 GrAlwaysAssert((GR_GL_MAP_INVALIDATE_BUFFER_BIT | GR_GL_MAP_INVALIDATE_R
ANGE_BIT) & access); |
| 783 | 751 |
| 784 GrBufferObj *buffer = nullptr; | 752 GrBufferObj *buffer = fBoundBuffers[GetBufferIndex(target)]; |
| 785 switch (target) { | |
| 786 case GR_GL_ARRAY_BUFFER: | |
| 787 buffer = this->getArrayBuffer(); | |
| 788 break; | |
| 789 case GR_GL_ELEMENT_ARRAY_BUFFER: | |
| 790 buffer = this->getElementArrayBuffer(); | |
| 791 break; | |
| 792 default: | |
| 793 SkFAIL("Unexpected target to glMapBufferRange"); | |
| 794 break; | |
| 795 } | |
| 796 | |
| 797 if (buffer) { | 753 if (buffer) { |
| 798 GrAlwaysAssert(offset >= 0 && offset + length <= buffer->getSize()); | 754 GrAlwaysAssert(offset >= 0 && offset + length <= buffer->getSize()); |
| 799 GrAlwaysAssert(!buffer->getMapped()); | 755 GrAlwaysAssert(!buffer->getMapped()); |
| 800 buffer->setMapped(offset, length); | 756 buffer->setMapped(offset, length); |
| 801 return buffer->getDataPtr() + offset; | 757 return buffer->getDataPtr() + offset; |
| 802 } | 758 } |
| 803 | 759 |
| 804 GrAlwaysAssert(false); | 760 GrAlwaysAssert(false); |
| 805 return nullptr; // no buffer bound to the target | 761 return nullptr; // no buffer bound to the target |
| 806 } | 762 } |
| 807 | 763 |
| 808 GrGLvoid* mapBuffer(GrGLenum target, GrGLenum access) override { | 764 GrGLvoid* mapBuffer(GrGLenum target, GrGLenum access) override { |
| 809 GrAlwaysAssert(GR_GL_WRITE_ONLY == access); | 765 GrAlwaysAssert(GR_GL_WRITE_ONLY == access); |
| 810 | 766 GrBufferObj *buffer = fBoundBuffers[GetBufferIndex(target)]; |
| 811 GrBufferObj *buffer = nullptr; | |
| 812 switch (target) { | |
| 813 case GR_GL_ARRAY_BUFFER: | |
| 814 buffer = this->getArrayBuffer(); | |
| 815 break; | |
| 816 case GR_GL_ELEMENT_ARRAY_BUFFER: | |
| 817 buffer = this->getElementArrayBuffer(); | |
| 818 break; | |
| 819 default: | |
| 820 SkFAIL("Unexpected target to glMapBuffer"); | |
| 821 break; | |
| 822 } | |
| 823 | |
| 824 return this->mapBufferRange(target, 0, buffer->getSize(), | 767 return this->mapBufferRange(target, 0, buffer->getSize(), |
| 825 GR_GL_MAP_WRITE_BIT | GR_GL_MAP_INVALIDATE_B
UFFER_BIT); | 768 GR_GL_MAP_WRITE_BIT | GR_GL_MAP_INVALIDATE_B
UFFER_BIT); |
| 826 } | 769 } |
| 827 | 770 |
| 828 // remove a buffer from the caller's address space | 771 // remove a buffer from the caller's address space |
| 829 // TODO: check if the "access" method from "glMapBuffer" was honored | 772 // TODO: check if the "access" method from "glMapBuffer" was honored |
| 830 GrGLboolean unmapBuffer(GrGLenum target) override { | 773 GrGLboolean unmapBuffer(GrGLenum target) override { |
| 831 GrAlwaysAssert(GR_GL_ARRAY_BUFFER == target || | 774 GrBufferObj *buffer = fBoundBuffers[GetBufferIndex(target)]; |
| 832 GR_GL_ELEMENT_ARRAY_BUFFER == target); | |
| 833 | |
| 834 GrBufferObj *buffer = nullptr; | |
| 835 switch (target) { | |
| 836 case GR_GL_ARRAY_BUFFER: | |
| 837 buffer = this->getArrayBuffer(); | |
| 838 break; | |
| 839 case GR_GL_ELEMENT_ARRAY_BUFFER: | |
| 840 buffer = this->getElementArrayBuffer(); | |
| 841 break; | |
| 842 default: | |
| 843 SkFAIL("Unexpected target to glUnmapBuffer"); | |
| 844 break; | |
| 845 } | |
| 846 | |
| 847 if (buffer) { | 775 if (buffer) { |
| 848 GrAlwaysAssert(buffer->getMapped()); | 776 GrAlwaysAssert(buffer->getMapped()); |
| 849 buffer->resetMapped(); | 777 buffer->resetMapped(); |
| 850 return GR_GL_TRUE; | 778 return GR_GL_TRUE; |
| 851 } | 779 } |
| 852 | 780 |
| 853 GrAlwaysAssert(false); | 781 GrAlwaysAssert(false); |
| 854 return GR_GL_FALSE; // GR_GL_INVALID_OPERATION; | 782 return GR_GL_FALSE; // GR_GL_INVALID_OPERATION; |
| 855 } | 783 } |
| 856 | 784 |
| 857 GrGLvoid flushMappedBufferRange(GrGLenum target, GrGLintptr offset, | 785 GrGLvoid flushMappedBufferRange(GrGLenum target, GrGLintptr offset, |
| 858 GrGLsizeiptr length) override { | 786 GrGLsizeiptr length) override { |
| 859 GrAlwaysAssert(GR_GL_ARRAY_BUFFER == target || | 787 GrBufferObj *buffer = fBoundBuffers[GetBufferIndex(target)]; |
| 860 GR_GL_ELEMENT_ARRAY_BUFFER == target); | |
| 861 | |
| 862 GrBufferObj *buffer = nullptr; | |
| 863 switch (target) { | |
| 864 case GR_GL_ARRAY_BUFFER: | |
| 865 buffer = this->getArrayBuffer(); | |
| 866 break; | |
| 867 case GR_GL_ELEMENT_ARRAY_BUFFER: | |
| 868 buffer = this->getElementArrayBuffer(); | |
| 869 break; | |
| 870 default: | |
| 871 SkFAIL("Unexpected target to glUnmapBuffer"); | |
| 872 break; | |
| 873 } | |
| 874 | |
| 875 if (buffer) { | 788 if (buffer) { |
| 876 GrAlwaysAssert(buffer->getMapped()); | 789 GrAlwaysAssert(buffer->getMapped()); |
| 877 GrAlwaysAssert(offset >= 0 && (offset + length) <= buffer->getMapped
Length()); | 790 GrAlwaysAssert(offset >= 0 && (offset + length) <= buffer->getMapped
Length()); |
| 878 } else { | 791 } else { |
| 879 GrAlwaysAssert(false); | 792 GrAlwaysAssert(false); |
| 880 } | 793 } |
| 881 } | 794 } |
| 882 | 795 |
| 883 GrGLvoid getBufferParameteriv(GrGLenum target, GrGLenum value, GrGLint* para
ms) override { | 796 GrGLvoid getBufferParameteriv(GrGLenum target, GrGLenum value, GrGLint* para
ms) override { |
| 884 | 797 |
| 885 GrAlwaysAssert(GR_GL_ARRAY_BUFFER == target || | |
| 886 GR_GL_ELEMENT_ARRAY_BUFFER == target); | |
| 887 GrAlwaysAssert(GR_GL_BUFFER_SIZE == value || | 798 GrAlwaysAssert(GR_GL_BUFFER_SIZE == value || |
| 888 GR_GL_BUFFER_USAGE == value); | 799 GR_GL_BUFFER_USAGE == value); |
| 889 | 800 |
| 890 GrBufferObj *buffer = nullptr; | 801 GrBufferObj *buffer = fBoundBuffers[GetBufferIndex(target)]; |
| 891 switch (target) { | |
| 892 case GR_GL_ARRAY_BUFFER: | |
| 893 buffer = this->getArrayBuffer(); | |
| 894 break; | |
| 895 case GR_GL_ELEMENT_ARRAY_BUFFER: | |
| 896 buffer = this->getElementArrayBuffer(); | |
| 897 break; | |
| 898 } | |
| 899 | |
| 900 GrAlwaysAssert(buffer); | 802 GrAlwaysAssert(buffer); |
| 901 | 803 |
| 902 switch (value) { | 804 switch (value) { |
| 903 case GR_GL_BUFFER_MAPPED: | 805 case GR_GL_BUFFER_MAPPED: |
| 904 *params = GR_GL_FALSE; | 806 *params = GR_GL_FALSE; |
| 905 if (buffer) | 807 if (buffer) |
| 906 *params = buffer->getMapped() ? GR_GL_TRUE : GR_GL_FALSE; | 808 *params = buffer->getMapped() ? GR_GL_TRUE : GR_GL_FALSE; |
| 907 break; | 809 break; |
| 908 case GR_GL_BUFFER_SIZE: | 810 case GR_GL_BUFFER_SIZE: |
| 909 *params = 0; | 811 *params = 0; |
| 910 if (buffer) | 812 if (buffer) |
| 911 *params = SkToInt(buffer->getSize()); | 813 *params = SkToInt(buffer->getSize()); |
| 912 break; | 814 break; |
| 913 case GR_GL_BUFFER_USAGE: | 815 case GR_GL_BUFFER_USAGE: |
| 914 *params = GR_GL_STATIC_DRAW; | 816 *params = GR_GL_STATIC_DRAW; |
| 915 if (buffer) | 817 if (buffer) |
| 916 *params = buffer->getUsage(); | 818 *params = buffer->getUsage(); |
| 917 break; | 819 break; |
| 918 default: | 820 default: |
| 919 SkFAIL("Unexpected value to glGetBufferParamateriv"); | 821 SkFAIL("Unexpected value to glGetBufferParamateriv"); |
| 920 break; | 822 break; |
| 921 } | 823 } |
| 922 } | 824 } |
| 923 | 825 |
| 924 private: | 826 private: |
| 827 inline int static GetBufferIndex(GrGLenum glTarget) { |
| 828 switch (glTarget) { |
| 829 default: SkFAIL("Unexpected GL target to G
etBufferIndex"); |
| 830 case GR_GL_ARRAY_BUFFER: return 0; |
| 831 case GR_GL_ELEMENT_ARRAY_BUFFER: return 1; |
| 832 case GR_GL_TEXTURE_BUFFER: return 2; |
| 833 case GR_GL_DRAW_INDIRECT_BUFFER: return 3; |
| 834 } |
| 835 } |
| 836 constexpr int static kNumBufferTargets = 4; |
| 837 |
| 925 // the OpenGLES 2.0 spec says this must be >= 128 | 838 // the OpenGLES 2.0 spec says this must be >= 128 |
| 926 static const GrGLint kDefaultMaxVertexUniformVectors = 128; | 839 static const GrGLint kDefaultMaxVertexUniformVectors = 128; |
| 927 | 840 |
| 928 // the OpenGLES 2.0 spec says this must be >=16 | 841 // the OpenGLES 2.0 spec says this must be >=16 |
| 929 static const GrGLint kDefaultMaxFragmentUniformVectors = 16; | 842 static const GrGLint kDefaultMaxFragmentUniformVectors = 16; |
| 930 | 843 |
| 931 // the OpenGLES 2.0 spec says this must be >= 8 | 844 // the OpenGLES 2.0 spec says this must be >= 8 |
| 932 static const GrGLint kDefaultMaxVertexAttribs = 8; | 845 static const GrGLint kDefaultMaxVertexAttribs = 8; |
| 933 | 846 |
| 934 // the OpenGLES 2.0 spec says this must be >= 8 | 847 // the OpenGLES 2.0 spec says this must be >= 8 |
| 935 static const GrGLint kDefaultMaxVaryingVectors = 8; | 848 static const GrGLint kDefaultMaxVaryingVectors = 8; |
| 936 | 849 |
| 937 // the OpenGLES 2.0 spec says this must be >= 2 | 850 // the OpenGLES 2.0 spec says this must be >= 2 |
| 938 static const GrGLint kDefaultMaxTextureUnits = 8; | 851 static const GrGLint kDefaultMaxTextureUnits = 8; |
| 939 | 852 |
| 940 static const char* kExtensions[]; | 853 static const char* kExtensions[]; |
| 941 | 854 |
| 942 GrGLuint fCurrGenericID; | 855 GrGLuint fCurrGenericID; |
| 943 GrGLuint fCurrTextureUnit; | 856 GrGLuint fCurrTextureUnit; |
| 944 GrTextureUnitObj* fTextureUnits[kDefaultMaxTextureUnits]; | 857 GrTextureUnitObj* fTextureUnits[kDefaultMaxTextureUnits]; |
| 945 GrBufferObj* fArrayBuffer; | 858 GrBufferObj* fBoundBuffers[kNumBufferTargets]; |
| 946 GrBufferObj* fElementArrayBuffer; | |
| 947 GrVertexArrayObj* fVertexArray; | 859 GrVertexArrayObj* fVertexArray; |
| 948 GrGLint fPackRowLength; | 860 GrGLint fPackRowLength; |
| 949 GrGLint fUnpackRowLength; | 861 GrGLint fUnpackRowLength; |
| 950 GrGLint fPackAlignment; | 862 GrGLint fPackAlignment; |
| 951 GrFrameBufferObj* fFrameBuffer; | 863 GrFrameBufferObj* fFrameBuffer; |
| 952 GrRenderBufferObj* fRenderBuffer; | 864 GrRenderBufferObj* fRenderBuffer; |
| 953 GrProgramObj* fProgram; | 865 GrProgramObj* fProgram; |
| 954 mutable bool fAbandoned; | 866 mutable bool fAbandoned; |
| 955 // global store of all objects | 867 // global store of all objects |
| 956 SkTArray<GrFakeRefObj *> fObjects; | 868 SkTArray<GrFakeRefObj *> fObjects; |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1065 } | 977 } |
| 1066 return nullptr; | 978 return nullptr; |
| 1067 } | 979 } |
| 1068 | 980 |
| 1069 GrTextureUnitObj* getTextureUnit(int unit) { | 981 GrTextureUnitObj* getTextureUnit(int unit) { |
| 1070 GrAlwaysAssert(0 <= unit && kDefaultMaxTextureUnits > unit); | 982 GrAlwaysAssert(0 <= unit && kDefaultMaxTextureUnits > unit); |
| 1071 | 983 |
| 1072 return fTextureUnits[unit]; | 984 return fTextureUnits[unit]; |
| 1073 } | 985 } |
| 1074 | 986 |
| 1075 void setArrayBuffer(GrBufferObj *arrayBuffer) { | 987 GrGLvoid setBuffer(int buffIdx, GrBufferObj* buffer) { |
| 1076 if (fArrayBuffer) { | 988 if (fBoundBuffers[buffIdx]) { |
| 1077 // automatically break the binding of the old buffer | 989 // automatically break the binding of the old buffer |
| 1078 GrAlwaysAssert(fArrayBuffer->getBound()); | 990 GrAlwaysAssert(fBoundBuffers[buffIdx]->getBound()); |
| 1079 fArrayBuffer->resetBound(); | 991 fBoundBuffers[buffIdx]->resetBound(); |
| 1080 | 992 |
| 1081 GrAlwaysAssert(!fArrayBuffer->getDeleted()); | 993 GrAlwaysAssert(!fBoundBuffers[buffIdx]->getDeleted()); |
| 1082 fArrayBuffer->unref(); | 994 fBoundBuffers[buffIdx]->unref(); |
| 1083 } | 995 } |
| 1084 | 996 |
| 1085 fArrayBuffer = arrayBuffer; | 997 if (buffer) { |
| 998 GrAlwaysAssert(!buffer->getDeleted()); |
| 999 buffer->ref(); |
| 1086 | 1000 |
| 1087 if (fArrayBuffer) { | 1001 GrAlwaysAssert(!buffer->getBound()); |
| 1088 GrAlwaysAssert(!fArrayBuffer->getDeleted()); | 1002 buffer->setBound(); |
| 1089 fArrayBuffer->ref(); | |
| 1090 | |
| 1091 GrAlwaysAssert(!fArrayBuffer->getBound()); | |
| 1092 fArrayBuffer->setBound(); | |
| 1093 } | |
| 1094 } | |
| 1095 | |
| 1096 GrBufferObj* getArrayBuffer() { return fArrayBuffer; } | |
| 1097 void setElementArrayBuffer(GrBufferObj *elementArrayBuffer) { | |
| 1098 if (fElementArrayBuffer) { | |
| 1099 // automatically break the binding of the old buffer | |
| 1100 GrAlwaysAssert(fElementArrayBuffer->getBound()); | |
| 1101 fElementArrayBuffer->resetBound(); | |
| 1102 | |
| 1103 GrAlwaysAssert(!fElementArrayBuffer->getDeleted()); | |
| 1104 fElementArrayBuffer->unref(); | |
| 1105 } | 1003 } |
| 1106 | 1004 |
| 1107 fElementArrayBuffer = elementArrayBuffer; | 1005 fBoundBuffers[buffIdx] = buffer; |
| 1108 | |
| 1109 if (fElementArrayBuffer) { | |
| 1110 GrAlwaysAssert(!fElementArrayBuffer->getDeleted()); | |
| 1111 fElementArrayBuffer->ref(); | |
| 1112 | |
| 1113 GrAlwaysAssert(!fElementArrayBuffer->getBound()); | |
| 1114 fElementArrayBuffer->setBound(); | |
| 1115 } | |
| 1116 } | 1006 } |
| 1117 | 1007 |
| 1118 GrBufferObj *getElementArrayBuffer() { return fElementArrayBuffer; } | |
| 1119 | |
| 1120 void setVertexArray(GrVertexArrayObj* vertexArray) { | 1008 void setVertexArray(GrVertexArrayObj* vertexArray) { |
| 1121 if (vertexArray) { | 1009 if (vertexArray) { |
| 1122 SkASSERT(!vertexArray->getDeleted()); | 1010 SkASSERT(!vertexArray->getDeleted()); |
| 1123 } | 1011 } |
| 1124 SkRefCnt_SafeAssign(fVertexArray, vertexArray); | 1012 SkRefCnt_SafeAssign(fVertexArray, vertexArray); |
| 1125 } | 1013 } |
| 1126 | 1014 |
| 1127 GrVertexArrayObj* getVertexArray() { return fVertexArray; } | 1015 GrVertexArrayObj* getVertexArray() { return fVertexArray; } |
| 1128 | 1016 |
| 1129 void setTexture(GrTextureObj *texture) { | 1017 void setTexture(GrTextureObj *texture) { |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1247 namespace sk_gpu_test { | 1135 namespace sk_gpu_test { |
| 1248 GLTestContext* CreateDebugGLTestContext() { | 1136 GLTestContext* CreateDebugGLTestContext() { |
| 1249 GLTestContext* ctx = new DebugGLContext(); | 1137 GLTestContext* ctx = new DebugGLContext(); |
| 1250 if (ctx->isValid()) { | 1138 if (ctx->isValid()) { |
| 1251 return ctx; | 1139 return ctx; |
| 1252 } | 1140 } |
| 1253 delete ctx; | 1141 delete ctx; |
| 1254 return nullptr; | 1142 return nullptr; |
| 1255 } | 1143 } |
| 1256 } | 1144 } |
| OLD | NEW |