Changeset 207715 in webkit


Ignore:
Timestamp:
Oct 22, 2016 1:46:34 PM (8 years ago)
Author:
Chris Dumez
Message:

WebGLRenderingContextBase.bufferData() should use a union instead of overloading
https://bugs.webkit.org/show_bug.cgi?id=163795

Reviewed by Darin Adler.

Source/JavaScriptCore:

  • runtime/ArrayBufferView.h:

(JSC::ArrayBufferView::data):
Add a data() method which aliases baseAddress() to align the API with
ArrayBuffer and reduce special handling at call sites.

  • runtime/JSArrayBuffer.h:

(JSC::toArrayBuffer):
(JSC::JSArrayBuffer::toWrapped):
Add toWrapped() method similarly with WebCore wrapper types to
reduce special handling of JSArrayBuffer type.

  • runtime/JSArrayBufferView.cpp:

(JSC::JSArrayBufferView::toWrapped):

  • runtime/JSArrayBufferView.h:

Add toWrapped() method similarly with WebCore wrapper types to
reduce special handling of JSArrayBufferView type.

Source/WebCore:

WebGLRenderingContextBase.bufferData() / bufferSubData() should use a union
instead of overloading:

No new tests, no web-exposed behavior change.

  • bindings/js/JSDOMConvert.h:

(WebCore::Converter<IDLInterface<T>>::convert):

  • bindings/scripts/CodeGeneratorJS.pm:

(GenerateHeader):

  • bindings/scripts/test/JS/JSInterfaceName.h:
  • bindings/scripts/test/JS/JSTestActiveDOMObject.h:
  • bindings/scripts/test/JS/JSTestCEReactions.h:
  • bindings/scripts/test/JS/JSTestCEReactionsStringifier.h:
  • bindings/scripts/test/JS/JSTestClassWithJSBuiltinConstructor.h:
  • bindings/scripts/test/JS/JSTestCustomConstructorWithNoInterfaceObject.h:
  • bindings/scripts/test/JS/JSTestCustomNamedGetter.h:
  • bindings/scripts/test/JS/JSTestEventConstructor.h:
  • bindings/scripts/test/JS/JSTestEventTarget.h:
  • bindings/scripts/test/JS/JSTestException.h:
  • bindings/scripts/test/JS/JSTestGenerateIsReachable.h:
  • bindings/scripts/test/JS/JSTestGlobalObject.h:
  • bindings/scripts/test/JS/JSTestInterface.h:
  • bindings/scripts/test/JS/JSTestIterable.h:
  • bindings/scripts/test/JS/JSTestMediaQueryListListener.h:
  • bindings/scripts/test/JS/JSTestNamedConstructor.h:
  • bindings/scripts/test/JS/JSTestNode.h:
  • bindings/scripts/test/JS/JSTestNondeterministic.h:
  • bindings/scripts/test/JS/JSTestObj.h:
  • bindings/scripts/test/JS/JSTestOverloadedConstructors.h:
  • bindings/scripts/test/JS/JSTestOverloadedConstructorsWithSequence.h:
  • bindings/scripts/test/JS/JSTestOverrideBuiltins.h:
  • bindings/scripts/test/JS/JSTestSerialization.h:
  • bindings/scripts/test/JS/JSTestSerializedScriptValueInterface.h:
  • bindings/scripts/test/JS/JSTestTypedefs.h:
  • bindings/scripts/test/JS/JSattribute.h:
  • bindings/scripts/test/JS/JSreadonly.h:
  • html/canvas/WebGL2RenderingContext.cpp:

(WebCore::WebGL2RenderingContext::bufferData):
(WebCore::WebGL2RenderingContext::bufferSubData):

  • html/canvas/WebGLRenderingContextBase.cpp:

(WebCore::WebGLRenderingContextBase::bufferData):
(WebCore::WebGLRenderingContextBase::bufferSubData):

  • html/canvas/WebGLRenderingContextBase.h:
  • html/canvas/WebGLRenderingContextBase.idl:
Location:
trunk/Source
Files:
39 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r207714 r207715  
     12016-10-22  Chris Dumez  <cdumez@apple.com>
     2
     3        WebGLRenderingContextBase.bufferData() should use a union instead of overloading
     4        https://bugs.webkit.org/show_bug.cgi?id=163795
     5
     6        Reviewed by Darin Adler.
     7
     8        * runtime/ArrayBufferView.h:
     9        (JSC::ArrayBufferView::data):
     10        Add a data() method which aliases baseAddress() to align the API with
     11        ArrayBuffer and reduce special handling at call sites.
     12
     13        * runtime/JSArrayBuffer.h:
     14        (JSC::toArrayBuffer):
     15        (JSC::JSArrayBuffer::toWrapped):
     16        Add toWrapped() method similarly with WebCore wrapper types to
     17        reduce special handling of JSArrayBuffer type.
     18
     19        * runtime/JSArrayBufferView.cpp:
     20        (JSC::JSArrayBufferView::toWrapped):
     21        * runtime/JSArrayBufferView.h:
     22        Add toWrapped() method similarly with WebCore wrapper types to
     23        reduce special handling of JSArrayBufferView type.
     24
    1252016-10-21  Filip Pizlo  <fpizlo@apple.com>
    226
  • trunk/Source/JavaScriptCore/runtime/ArrayBufferView.h

    r206525 r207715  
    6363    }
    6464
     65    void* data() const { return baseAddress(); }
     66
    6567    unsigned byteOffset() const
    6668    {
  • trunk/Source/JavaScriptCore/runtime/JSArrayBuffer.h

    r206525 r207715  
    4747   
    4848    static Structure* createStructure(VM&, JSGlobalObject*, JSValue prototype);
     49
     50    static ArrayBuffer* toWrapped(JSValue);
    4951   
    5052    DECLARE_EXPORT_INFO;
     
    6870    JSArrayBuffer* wrapper = jsDynamicCast<JSArrayBuffer*>(value);
    6971    if (!wrapper)
    70         return 0;
     72        return nullptr;
    7173    return wrapper->impl();
    7274}
    7375
     76inline ArrayBuffer* JSArrayBuffer::toWrapped(JSValue value)
     77{
     78    return toArrayBuffer(value);
     79}
     80
    7481} // namespace JSC
  • trunk/Source/JavaScriptCore/runtime/JSArrayBufferView.cpp

    r205648 r207715  
    187187}
    188188
     189RefPtr<ArrayBufferView> JSArrayBufferView::toWrapped(JSValue value)
     190{
     191    auto* wrapper = jsDynamicCast<JSArrayBufferView*>(value);
     192    if (!wrapper)
     193        return nullptr;
     194    return wrapper->impl();
     195}
     196
    189197} // namespace JSC
    190198
  • trunk/Source/JavaScriptCore/runtime/JSArrayBufferView.h

    r206525 r207715  
    175175    static ptrdiff_t offsetOfMode() { return OBJECT_OFFSETOF(JSArrayBufferView, m_mode); }
    176176
     177    JS_EXPORT_PRIVATE static RefPtr<ArrayBufferView> toWrapped(JSValue);
     178
    177179private:
    178180    static void finalize(JSCell*);
  • trunk/Source/WebCore/ChangeLog

    r207712 r207715  
     12016-10-22  Chris Dumez  <cdumez@apple.com>
     2
     3        WebGLRenderingContextBase.bufferData() should use a union instead of overloading
     4        https://bugs.webkit.org/show_bug.cgi?id=163795
     5
     6        Reviewed by Darin Adler.
     7
     8        WebGLRenderingContextBase.bufferData() / bufferSubData() should use a union
     9        instead of overloading:
     10        - https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14
     11
     12        No new tests, no web-exposed behavior change.
     13
     14        * bindings/js/JSDOMConvert.h:
     15        (WebCore::Converter<IDLInterface<T>>::convert):
     16        * bindings/scripts/CodeGeneratorJS.pm:
     17        (GenerateHeader):
     18        * bindings/scripts/test/JS/JSInterfaceName.h:
     19        * bindings/scripts/test/JS/JSTestActiveDOMObject.h:
     20        * bindings/scripts/test/JS/JSTestCEReactions.h:
     21        * bindings/scripts/test/JS/JSTestCEReactionsStringifier.h:
     22        * bindings/scripts/test/JS/JSTestClassWithJSBuiltinConstructor.h:
     23        * bindings/scripts/test/JS/JSTestCustomConstructorWithNoInterfaceObject.h:
     24        * bindings/scripts/test/JS/JSTestCustomNamedGetter.h:
     25        * bindings/scripts/test/JS/JSTestEventConstructor.h:
     26        * bindings/scripts/test/JS/JSTestEventTarget.h:
     27        * bindings/scripts/test/JS/JSTestException.h:
     28        * bindings/scripts/test/JS/JSTestGenerateIsReachable.h:
     29        * bindings/scripts/test/JS/JSTestGlobalObject.h:
     30        * bindings/scripts/test/JS/JSTestInterface.h:
     31        * bindings/scripts/test/JS/JSTestIterable.h:
     32        * bindings/scripts/test/JS/JSTestMediaQueryListListener.h:
     33        * bindings/scripts/test/JS/JSTestNamedConstructor.h:
     34        * bindings/scripts/test/JS/JSTestNode.h:
     35        * bindings/scripts/test/JS/JSTestNondeterministic.h:
     36        * bindings/scripts/test/JS/JSTestObj.h:
     37        * bindings/scripts/test/JS/JSTestOverloadedConstructors.h:
     38        * bindings/scripts/test/JS/JSTestOverloadedConstructorsWithSequence.h:
     39        * bindings/scripts/test/JS/JSTestOverrideBuiltins.h:
     40        * bindings/scripts/test/JS/JSTestSerialization.h:
     41        * bindings/scripts/test/JS/JSTestSerializedScriptValueInterface.h:
     42        * bindings/scripts/test/JS/JSTestTypedefs.h:
     43        * bindings/scripts/test/JS/JSattribute.h:
     44        * bindings/scripts/test/JS/JSreadonly.h:
     45        * html/canvas/WebGL2RenderingContext.cpp:
     46        (WebCore::WebGL2RenderingContext::bufferData):
     47        (WebCore::WebGL2RenderingContext::bufferSubData):
     48        * html/canvas/WebGLRenderingContextBase.cpp:
     49        (WebCore::WebGLRenderingContextBase::bufferData):
     50        (WebCore::WebGLRenderingContextBase::bufferSubData):
     51        * html/canvas/WebGLRenderingContextBase.h:
     52        * html/canvas/WebGLRenderingContextBase.idl:
     53
    1542016-10-22  Darin Adler  <darin@apple.com>
    255
  • trunk/Source/WebCore/bindings/js/JSDOMConvert.h

    r207575 r207715  
    105105};
    106106
     107// ArrayBuffer support.
     108template<> struct JSDOMWrapperConverterTraits<JSC::ArrayBuffer> {
     109    using WrapperClass = JSC::JSArrayBuffer;
     110    using ToWrappedReturnType = JSC::ArrayBuffer*;
     111};
     112
     113// ArrayBufferView support.
     114template<> struct JSDOMWrapperConverterTraits<JSC::ArrayBufferView> {
     115    using WrapperClass = JSC::JSArrayBufferView;
     116    using ToWrappedReturnType = RefPtr<ArrayBufferView>;
     117};
     118
    107119// MARK: -
    108120// MARK: Interface type
    109121
    110122template<typename T> struct Converter<IDLInterface<T>> : DefaultConverter<IDLInterface<T>> {
    111     using ReturnType = T*;
     123    using ReturnType = typename JSDOMWrapperConverterTraits<T>::ToWrappedReturnType;
    112124    using WrapperType = typename JSDOMWrapperConverterTraits<T>::WrapperClass;
    113125
    114     static T* convert(JSC::ExecState& state, JSC::JSValue value)
     126    static ReturnType convert(JSC::ExecState& state, JSC::JSValue value)
    115127    {
    116128        JSC::VM& vm = state.vm();
    117129        auto scope = DECLARE_THROW_SCOPE(vm);
    118         T* object = WrapperType::toWrapped(value);
     130        ReturnType object = WrapperType::toWrapped(value);
    119131        if (!object)
    120132            throwTypeError(&state, scope);
     
    122134    }
    123135};
    124 
    125136
    126137// Typed arrays support.
     
    541552                using WrapperType = typename JSDOMWrapperConverterTraits<ImplementationType>::WrapperClass;
    542553
    543                 auto* castedValue = WrapperType::toWrapped(value);
     554                auto castedValue = WrapperType::toWrapped(value);
    544555                if (!castedValue)
    545556                    return;
  • trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm

    r207711 r207715  
    17331733        push(@headerContent, "template<> struct JSDOMWrapperConverterTraits<${implType}> {\n");
    17341734        push(@headerContent, "    using WrapperClass = ${className};\n");
     1735        push(@headerContent, "    using ToWrappedReturnType = ${implType}*;\n");
    17351736        push(@headerContent, "};\n");
    17361737    }
  • trunk/Source/WebCore/bindings/scripts/test/JS/JSInterfaceName.h

    r206723 r207715  
    8888template<> struct JSDOMWrapperConverterTraits<InterfaceName> {
    8989    using WrapperClass = JSInterfaceName;
     90    using ToWrappedReturnType = InterfaceName*;
    9091};
    9192
  • trunk/Source/WebCore/bindings/scripts/test/JS/JSTestActiveDOMObject.h

    r207192 r207715  
    8787template<> struct JSDOMWrapperConverterTraits<TestActiveDOMObject> {
    8888    using WrapperClass = JSTestActiveDOMObject;
     89    using ToWrappedReturnType = TestActiveDOMObject*;
    8990};
    9091
  • trunk/Source/WebCore/bindings/scripts/test/JS/JSTestCEReactions.h

    r207192 r207715  
    8585template<> struct JSDOMWrapperConverterTraits<TestCEReactions> {
    8686    using WrapperClass = JSTestCEReactions;
     87    using ToWrappedReturnType = TestCEReactions*;
    8788};
    8889
  • trunk/Source/WebCore/bindings/scripts/test/JS/JSTestCEReactionsStringifier.h

    r207192 r207715  
    8585template<> struct JSDOMWrapperConverterTraits<TestCEReactionsStringifier> {
    8686    using WrapperClass = JSTestCEReactionsStringifier;
     87    using ToWrappedReturnType = TestCEReactionsStringifier*;
    8788};
    8889
  • trunk/Source/WebCore/bindings/scripts/test/JS/JSTestClassWithJSBuiltinConstructor.h

    r206723 r207715  
    8787template<> struct JSDOMWrapperConverterTraits<TestClassWithJSBuiltinConstructor> {
    8888    using WrapperClass = JSTestClassWithJSBuiltinConstructor;
     89    using ToWrappedReturnType = TestClassWithJSBuiltinConstructor*;
    8990};
    9091
  • trunk/Source/WebCore/bindings/scripts/test/JS/JSTestCustomConstructorWithNoInterfaceObject.h

    r206723 r207715  
    8787template<> struct JSDOMWrapperConverterTraits<TestCustomConstructorWithNoInterfaceObject> {
    8888    using WrapperClass = JSTestCustomConstructorWithNoInterfaceObject;
     89    using ToWrappedReturnType = TestCustomConstructorWithNoInterfaceObject*;
    8990};
    9091
  • trunk/Source/WebCore/bindings/scripts/test/JS/JSTestCustomNamedGetter.h

    r206723 r207715  
    9191template<> struct JSDOMWrapperConverterTraits<TestCustomNamedGetter> {
    9292    using WrapperClass = JSTestCustomNamedGetter;
     93    using ToWrappedReturnType = TestCustomNamedGetter*;
    9394};
    9495
  • trunk/Source/WebCore/bindings/scripts/test/JS/JSTestEventConstructor.h

    r207498 r207715  
    7171template<> struct JSDOMWrapperConverterTraits<TestEventConstructor> {
    7272    using WrapperClass = JSTestEventConstructor;
     73    using ToWrappedReturnType = TestEventConstructor*;
    7374};
    7475template<> TestEventConstructor::Init convertDictionary<TestEventConstructor::Init>(JSC::ExecState&, JSC::JSValue);
  • trunk/Source/WebCore/bindings/scripts/test/JS/JSTestEventTarget.h

    r206723 r207715  
    8181template<> struct JSDOMWrapperConverterTraits<TestEventTarget> {
    8282    using WrapperClass = JSTestEventTarget;
     83    using ToWrappedReturnType = TestEventTarget*;
    8384};
    8485
  • trunk/Source/WebCore/bindings/scripts/test/JS/JSTestException.h

    r207192 r207715  
    8888template<> struct JSDOMWrapperConverterTraits<TestException> {
    8989    using WrapperClass = JSTestException;
     90    using ToWrappedReturnType = TestException*;
    9091};
    9192
  • trunk/Source/WebCore/bindings/scripts/test/JS/JSTestGenerateIsReachable.h

    r206723 r207715  
    8585template<> struct JSDOMWrapperConverterTraits<TestGenerateIsReachable> {
    8686    using WrapperClass = JSTestGenerateIsReachable;
     87    using ToWrappedReturnType = TestGenerateIsReachable*;
    8788};
    8889
  • trunk/Source/WebCore/bindings/scripts/test/JS/JSTestGlobalObject.h

    r207192 r207715  
    115115template<> struct JSDOMWrapperConverterTraits<TestGlobalObject> {
    116116    using WrapperClass = JSTestGlobalObject;
     117    using ToWrappedReturnType = TestGlobalObject*;
    117118};
    118119
  • trunk/Source/WebCore/bindings/scripts/test/JS/JSTestInterface.h

    r207192 r207715  
    112112template<> struct JSDOMWrapperConverterTraits<TestInterface> {
    113113    using WrapperClass = JSTestInterface;
     114    using ToWrappedReturnType = TestInterface*;
    114115};
    115116
  • trunk/Source/WebCore/bindings/scripts/test/JS/JSTestIterable.h

    r206723 r207715  
    8585template<> struct JSDOMWrapperConverterTraits<TestIterable> {
    8686    using WrapperClass = JSTestIterable;
     87    using ToWrappedReturnType = TestIterable*;
    8788};
    8889
  • trunk/Source/WebCore/bindings/scripts/test/JS/JSTestMediaQueryListListener.h

    r206723 r207715  
    8585template<> struct JSDOMWrapperConverterTraits<TestMediaQueryListListener> {
    8686    using WrapperClass = JSTestMediaQueryListListener;
     87    using ToWrappedReturnType = TestMediaQueryListListener*;
    8788};
    8889
  • trunk/Source/WebCore/bindings/scripts/test/JS/JSTestNamedConstructor.h

    r206723 r207715  
    8686template<> struct JSDOMWrapperConverterTraits<TestNamedConstructor> {
    8787    using WrapperClass = JSTestNamedConstructor;
     88    using ToWrappedReturnType = TestNamedConstructor*;
    8889};
    8990
  • trunk/Source/WebCore/bindings/scripts/test/JS/JSTestNode.h

    r207192 r207715  
    7272template<> struct JSDOMWrapperConverterTraits<TestNode> {
    7373    using WrapperClass = JSTestNode;
     74    using ToWrappedReturnType = TestNode*;
    7475};
    7576
  • trunk/Source/WebCore/bindings/scripts/test/JS/JSTestNondeterministic.h

    r207192 r207715  
    8585template<> struct JSDOMWrapperConverterTraits<TestNondeterministic> {
    8686    using WrapperClass = JSTestNondeterministic;
     87    using ToWrappedReturnType = TestNondeterministic*;
    8788};
    8889
  • trunk/Source/WebCore/bindings/scripts/test/JS/JSTestObj.h

    r207498 r207715  
    105105template<> struct JSDOMWrapperConverterTraits<TestObj> {
    106106    using WrapperClass = JSTestObj;
     107    using ToWrappedReturnType = TestObj*;
    107108};
    108109JSC::JSString* jsStringWithCache(JSC::ExecState*, TestObj::EnumType);
  • trunk/Source/WebCore/bindings/scripts/test/JS/JSTestOverloadedConstructors.h

    r206723 r207715  
    8585template<> struct JSDOMWrapperConverterTraits<TestOverloadedConstructors> {
    8686    using WrapperClass = JSTestOverloadedConstructors;
     87    using ToWrappedReturnType = TestOverloadedConstructors*;
    8788};
    8889
  • trunk/Source/WebCore/bindings/scripts/test/JS/JSTestOverloadedConstructorsWithSequence.h

    r206723 r207715  
    8585template<> struct JSDOMWrapperConverterTraits<TestOverloadedConstructorsWithSequence> {
    8686    using WrapperClass = JSTestOverloadedConstructorsWithSequence;
     87    using ToWrappedReturnType = TestOverloadedConstructorsWithSequence*;
    8788};
    8889
  • trunk/Source/WebCore/bindings/scripts/test/JS/JSTestOverrideBuiltins.h

    r206723 r207715  
    9292template<> struct JSDOMWrapperConverterTraits<TestOverrideBuiltins> {
    9393    using WrapperClass = JSTestOverrideBuiltins;
     94    using ToWrappedReturnType = TestOverrideBuiltins*;
    9495};
    9596
  • trunk/Source/WebCore/bindings/scripts/test/JS/JSTestSerialization.h

    r207378 r207715  
    8585template<> struct JSDOMWrapperConverterTraits<TestSerialization> {
    8686    using WrapperClass = JSTestSerialization;
     87    using ToWrappedReturnType = TestSerialization*;
    8788};
    8889
  • trunk/Source/WebCore/bindings/scripts/test/JS/JSTestSerializedScriptValueInterface.h

    r207192 r207715  
    9191template<> struct JSDOMWrapperConverterTraits<TestSerializedScriptValueInterface> {
    9292    using WrapperClass = JSTestSerializedScriptValueInterface;
     93    using ToWrappedReturnType = TestSerializedScriptValueInterface*;
    9394};
    9495
  • trunk/Source/WebCore/bindings/scripts/test/JS/JSTestTypedefs.h

    r207192 r207715  
    8787template<> struct JSDOMWrapperConverterTraits<TestTypedefs> {
    8888    using WrapperClass = JSTestTypedefs;
     89    using ToWrappedReturnType = TestTypedefs*;
    8990};
    9091
  • trunk/Source/WebCore/bindings/scripts/test/JS/JSattribute.h

    r207192 r207715  
    8888template<> struct JSDOMWrapperConverterTraits<attribute> {
    8989    using WrapperClass = JSattribute;
     90    using ToWrappedReturnType = attribute*;
    9091};
    9192
  • trunk/Source/WebCore/bindings/scripts/test/JS/JSreadonly.h

    r206723 r207715  
    8585template<> struct JSDOMWrapperConverterTraits<readonly> {
    8686    using WrapperClass = JSreadonly;
     87    using ToWrappedReturnType = readonly*;
    8788};
    8889
  • trunk/Source/WebCore/html/canvas/WebGL2RenderingContext.cpp

    r207685 r207715  
    100100        return;
    101101    }
    102     WebGLRenderingContextBase::bufferData(target, slice.get(), usage);
     102    WebGLRenderingContextBase::bufferData(target, BufferDataSource(slice.get()), usage);
    103103}
    104104
     
    114114        return;
    115115    }
    116     WebGLRenderingContextBase::bufferSubData(target, offset, slice);
     116    WebGLRenderingContextBase::bufferSubData(target, offset, BufferDataSource(slice.get()));
    117117}
    118118
  • trunk/Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp

    r207644 r207715  
    10761076}
    10771077
    1078 void WebGLRenderingContextBase::bufferData(GC3Denum target, ArrayBuffer* data, GC3Denum usage)
     1078void WebGLRenderingContextBase::bufferData(GC3Denum target, Optional<BufferDataSource>&& data, GC3Denum usage)
    10791079{
    10801080    if (isContextLostOrPending())
     
    10871087    if (!buffer)
    10881088        return;
    1089     if (!isErrorGeneratedOnOutOfBoundsAccesses()) {
    1090         if (!buffer->associateBufferData(data)) {
    1091             synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "bufferData", "invalid buffer");
    1092             return;
    1093         }
    1094     }
    1095 
    1096     m_context->moveErrorsToSyntheticErrorList();
    1097     m_context->bufferData(target, data->byteLength(), data->data(), usage);
    1098     if (m_context->moveErrorsToSyntheticErrorList()) {
    1099         // The bufferData function failed. Tell the buffer it doesn't have the data it thinks it does.
    1100         buffer->disassociateBufferData();
    1101     }
    1102 }
    1103 
    1104 void WebGLRenderingContextBase::bufferData(GC3Denum target, RefPtr<ArrayBufferView>&& data, GC3Denum usage)
    1105 {
    1106     if (isContextLostOrPending())
    1107         return;
    1108     if (!data) {
    1109         synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "bufferData", "null data");
    1110         return;
    1111     }
    1112     WebGLBuffer* buffer = validateBufferDataParameters("bufferData", target, usage);
    1113     if (!buffer)
    1114         return;
    1115     if (!isErrorGeneratedOnOutOfBoundsAccesses()) {
    1116         if (!buffer->associateBufferData(data.get())) {
    1117             synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "bufferData", "invalid buffer");
    1118             return;
    1119         }
    1120     }
    1121 
    1122     m_context->moveErrorsToSyntheticErrorList();
    1123     m_context->bufferData(target, data->byteLength(), data->baseAddress(), usage);
    1124     if (m_context->moveErrorsToSyntheticErrorList()) {
    1125         // The bufferData function failed. Tell the buffer it doesn't have the data it thinks it does.
    1126         buffer->disassociateBufferData();
    1127     }
    1128 }
    1129 
    1130 void WebGLRenderingContextBase::bufferSubData(GC3Denum target, long long offset, ArrayBuffer* data)
     1089
     1090    WTF::visit([&](auto& data) {
     1091        if (!this->isErrorGeneratedOnOutOfBoundsAccesses()) {
     1092            if (!buffer->associateBufferData(data.get())) {
     1093                this->synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "bufferData", "invalid buffer");
     1094                return;
     1095            }
     1096        }
     1097
     1098        m_context->moveErrorsToSyntheticErrorList();
     1099        m_context->bufferData(target, data->byteLength(), data->data(), usage);
     1100        if (m_context->moveErrorsToSyntheticErrorList()) {
     1101            // The bufferData function failed. Tell the buffer it doesn't have the data it thinks it does.
     1102            buffer->disassociateBufferData();
     1103        }
     1104    }, data.value());
     1105}
     1106
     1107void WebGLRenderingContextBase::bufferSubData(GC3Denum target, long long offset, Optional<BufferDataSource>&& data)
    11311108{
    11321109    if (isContextLostOrPending())
     
    11411118    if (!data)
    11421119        return;
    1143     if (!isErrorGeneratedOnOutOfBoundsAccesses()) {
    1144         if (!buffer->associateBufferSubData(static_cast<GC3Dintptr>(offset), data)) {
    1145             synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "bufferSubData", "offset out of range");
    1146             return;
    1147         }
    1148     }
    1149 
    1150     m_context->moveErrorsToSyntheticErrorList();
    1151     m_context->bufferSubData(target, static_cast<GC3Dintptr>(offset), data->byteLength(), data->data());
    1152     if (m_context->moveErrorsToSyntheticErrorList()) {
    1153         // The bufferSubData function failed. Tell the buffer it doesn't have the data it thinks it does.
    1154         buffer->disassociateBufferData();
    1155     }
    1156 }
    1157 
    1158 void WebGLRenderingContextBase::bufferSubData(GC3Denum target, long long offset, RefPtr<ArrayBufferView>&& data)
    1159 {
    1160     if (isContextLostOrPending())
    1161         return;
    1162     WebGLBuffer* buffer = validateBufferDataParameters("bufferSubData", target, GraphicsContext3D::STATIC_DRAW);
    1163     if (!buffer)
    1164         return;
    1165     if (offset < 0) {
    1166         synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "bufferSubData", "offset < 0");
    1167         return;
    1168     }
    1169     if (!data)
    1170         return;
    1171     if (!isErrorGeneratedOnOutOfBoundsAccesses()) {
    1172         if (!buffer->associateBufferSubData(static_cast<GC3Dintptr>(offset), data.get())) {
    1173             synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "bufferSubData", "offset out of range");
    1174             return;
    1175         }
    1176     }
    1177 
    1178     m_context->moveErrorsToSyntheticErrorList();
    1179     m_context->bufferSubData(target, static_cast<GC3Dintptr>(offset), data->byteLength(), data->baseAddress());
    1180     if (m_context->moveErrorsToSyntheticErrorList()) {
    1181         // The bufferSubData function failed. Tell the buffer it doesn't have the data it thinks it does.
    1182         buffer->disassociateBufferData();
    1183     }
     1120
     1121    WTF::visit([&](auto& data) {
     1122        if (!this->isErrorGeneratedOnOutOfBoundsAccesses()) {
     1123            if (!buffer->associateBufferSubData(static_cast<GC3Dintptr>(offset), data.get())) {
     1124                this->synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "bufferSubData", "offset out of range");
     1125                return;
     1126            }
     1127        }
     1128
     1129        m_context->moveErrorsToSyntheticErrorList();
     1130        m_context->bufferSubData(target, static_cast<GC3Dintptr>(offset), data->byteLength(), data->data());
     1131        if (m_context->moveErrorsToSyntheticErrorList()) {
     1132            // The bufferSubData function failed. Tell the buffer it doesn't have the data it thinks it does.
     1133            buffer->disassociateBufferData();
     1134        }
     1135    }, data.value());
    11841136}
    11851137
  • trunk/Source/WebCore/html/canvas/WebGLRenderingContextBase.h

    r207644 r207715  
    3838#include <runtime/Float32Array.h>
    3939#include <runtime/Int32Array.h>
     40#include <wtf/Variant.h>
    4041#include <wtf/text/WTFString.h>
    4142
     
    139140    void blendFuncSeparate(GC3Denum srcRGB, GC3Denum dstRGB, GC3Denum srcAlpha, GC3Denum dstAlpha);
    140141
     142    using BufferDataSource = WTF::Variant<RefPtr<ArrayBuffer>, RefPtr<ArrayBufferView>>;
    141143    void bufferData(GC3Denum target, long long size, GC3Denum usage);
    142     void bufferData(GC3Denum target, ArrayBuffer* data, GC3Denum usage);
    143     void bufferData(GC3Denum target, RefPtr<ArrayBufferView>&& data, GC3Denum usage);
    144     void bufferSubData(GC3Denum target, long long offset, ArrayBuffer* data);
    145     void bufferSubData(GC3Denum target, long long offset, RefPtr<ArrayBufferView>&& data);
     144    void bufferData(GC3Denum target, Optional<BufferDataSource>&&, GC3Denum usage);
     145    void bufferSubData(GC3Denum target, long long offset, Optional<BufferDataSource>&&);
    146146
    147147    GC3Denum checkFramebufferStatus(GC3Denum target);
  • trunk/Source/WebCore/html/canvas/WebGLRenderingContextBase.idl

    r207644 r207715  
    3838typedef unrestricted float GLfloat;
    3939typedef unrestricted float GLclampf;
     40typedef (ArrayBuffer or ArrayBufferView) BufferDataSource;
    4041
    4142[
     
    485486    void blendFunc(GLenum sfactor, GLenum dfactor);
    486487    void blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha);
    487     void bufferData(GLenum target, ArrayBuffer? data, GLenum usage);
    488     void bufferData(GLenum target, ArrayBufferView? data, GLenum usage);
     488    void bufferData(GLenum target, BufferDataSource? data, GLenum usage);
    489489    void bufferData(GLenum target, GLsizeiptr size, GLenum usage);
    490     void bufferSubData(GLenum target, GLintptr offset, ArrayBuffer? data);
    491     void bufferSubData(GLenum target, GLintptr offset, ArrayBufferView? data);
     490    void bufferSubData(GLenum target, GLintptr offset, BufferDataSource? data);
    492491
    493492    GLenum checkFramebufferStatus(GLenum target);
Note: See TracChangeset for help on using the changeset viewer.