OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "modules/webgl/WebGLGetBufferSubDataAsync.h" | 5 #include "modules/webgl/WebGLGetBufferSubDataAsync.h" |
6 | 6 |
7 #include "core/dom/DOMException.h" | 7 #include "core/dom/DOMException.h" |
8 #include "gpu/GLES2/gl2extchromium.h" | 8 #include "gpu/GLES2/gl2extchromium.h" |
9 #include "gpu/command_buffer/client/gles2_interface.h" | 9 #include "gpu/command_buffer/client/gles2_interface.h" |
10 #include "modules/webgl/WebGL2RenderingContextBase.h" | 10 #include "modules/webgl/WebGL2RenderingContextBase.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 } | 29 } |
30 | 30 |
31 const char* WebGLGetBufferSubDataAsync::extensionName() { | 31 const char* WebGLGetBufferSubDataAsync::extensionName() { |
32 return "WEBGL_get_buffer_sub_data_async"; | 32 return "WEBGL_get_buffer_sub_data_async"; |
33 } | 33 } |
34 | 34 |
35 ScriptPromise WebGLGetBufferSubDataAsync::getBufferSubDataAsync( | 35 ScriptPromise WebGLGetBufferSubDataAsync::getBufferSubDataAsync( |
36 ScriptState* scriptState, | 36 ScriptState* scriptState, |
37 GLenum target, | 37 GLenum target, |
38 GLintptr srcByteOffset, | 38 GLintptr srcByteOffset, |
39 DOMArrayBufferView* dstData, | 39 const NotShared<DOMArrayBufferView>& dstData, |
40 GLuint dstOffset, | 40 GLuint dstOffset, |
41 GLuint length) { | 41 GLuint length) { |
42 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); | 42 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); |
43 ScriptPromise promise = resolver->promise(); | 43 ScriptPromise promise = resolver->promise(); |
44 | 44 |
45 WebGLExtensionScopedContext scoped(this); | 45 WebGLExtensionScopedContext scoped(this); |
46 if (scoped.isLost()) { | 46 if (scoped.isLost()) { |
47 DOMException* exception = | 47 DOMException* exception = |
48 DOMException::create(InvalidStateError, "context lost"); | 48 DOMException::create(InvalidStateError, "context lost"); |
49 resolver->reject(exception); | 49 resolver->reject(exception); |
50 return promise; | 50 return promise; |
51 } | 51 } |
52 | 52 |
53 WebGL2RenderingContextBase* context = nullptr; | 53 WebGL2RenderingContextBase* context = nullptr; |
54 { | 54 { |
55 WebGLRenderingContextBase* contextBase = scoped.context(); | 55 WebGLRenderingContextBase* contextBase = scoped.context(); |
56 DCHECK_GE(contextBase->version(), 2u); | 56 DCHECK_GE(contextBase->version(), 2u); |
57 context = static_cast<WebGL2RenderingContextBase*>(contextBase); | 57 context = static_cast<WebGL2RenderingContextBase*>(contextBase); |
58 } | 58 } |
59 | 59 |
60 WebGLBuffer* sourceBuffer = nullptr; | 60 WebGLBuffer* sourceBuffer = nullptr; |
61 void* destinationDataPtr = nullptr; | 61 void* destinationDataPtr = nullptr; |
62 long long destinationByteLength = 0; | 62 long long destinationByteLength = 0; |
63 const char* message = context->validateGetBufferSubData( | 63 const char* message = context->validateGetBufferSubData( |
64 __FUNCTION__, target, srcByteOffset, dstData, dstOffset, length, | 64 __FUNCTION__, target, srcByteOffset, dstData.view(), dstOffset, length, |
65 &sourceBuffer, &destinationDataPtr, &destinationByteLength); | 65 &sourceBuffer, &destinationDataPtr, &destinationByteLength); |
66 if (message) { | 66 if (message) { |
67 // If there was a GL error, it was already synthesized in | 67 // If there was a GL error, it was already synthesized in |
68 // validateGetBufferSubData, so it's not done here. | 68 // validateGetBufferSubData, so it's not done here. |
69 DOMException* exception = DOMException::create(InvalidStateError, message); | 69 DOMException* exception = DOMException::create(InvalidStateError, message); |
70 resolver->reject(exception); | 70 resolver->reject(exception); |
71 return promise; | 71 return promise; |
72 } | 72 } |
73 | 73 |
74 message = context->validateGetBufferSubDataBounds( | 74 message = context->validateGetBufferSubDataBounds( |
75 __FUNCTION__, sourceBuffer, srcByteOffset, destinationByteLength); | 75 __FUNCTION__, sourceBuffer, srcByteOffset, destinationByteLength); |
76 if (message) { | 76 if (message) { |
77 // If there was a GL error, it was already synthesized in | 77 // If there was a GL error, it was already synthesized in |
78 // validateGetBufferSubDataBounds, so it's not done here. | 78 // validateGetBufferSubDataBounds, so it's not done here. |
79 DOMException* exception = DOMException::create(InvalidStateError, message); | 79 DOMException* exception = DOMException::create(InvalidStateError, message); |
80 resolver->reject(exception); | 80 resolver->reject(exception); |
81 return promise; | 81 return promise; |
82 } | 82 } |
83 | 83 |
84 // If the length of the copy is zero, this is a no-op. | 84 // If the length of the copy is zero, this is a no-op. |
85 if (!destinationByteLength) { | 85 if (!destinationByteLength) { |
86 resolver->resolve(dstData); | 86 resolver->resolve(dstData.view()); |
87 return promise; | 87 return promise; |
88 } | 88 } |
89 | 89 |
90 GLuint queryID; | 90 GLuint queryID; |
91 context->contextGL()->GenQueriesEXT(1, &queryID); | 91 context->contextGL()->GenQueriesEXT(1, &queryID); |
92 context->contextGL()->BeginQueryEXT(GL_COMMANDS_ISSUED_CHROMIUM, queryID); | 92 context->contextGL()->BeginQueryEXT(GL_COMMANDS_ISSUED_CHROMIUM, queryID); |
93 void* mappedData = context->contextGL()->GetBufferSubDataAsyncCHROMIUM( | 93 void* mappedData = context->contextGL()->GetBufferSubDataAsyncCHROMIUM( |
94 target, srcByteOffset, destinationByteLength); | 94 target, srcByteOffset, destinationByteLength); |
95 context->contextGL()->EndQueryEXT(GL_COMMANDS_ISSUED_CHROMIUM); | 95 context->contextGL()->EndQueryEXT(GL_COMMANDS_ISSUED_CHROMIUM); |
96 if (!mappedData) { | 96 if (!mappedData) { |
97 DOMException* exception = | 97 DOMException* exception = |
98 DOMException::create(InvalidStateError, "Out of memory"); | 98 DOMException::create(InvalidStateError, "Out of memory"); |
99 resolver->reject(exception); | 99 resolver->reject(exception); |
100 return promise; | 100 return promise; |
101 } | 101 } |
102 | 102 |
103 auto callbackObject = new WebGLGetBufferSubDataAsyncCallback( | 103 auto callbackObject = new WebGLGetBufferSubDataAsyncCallback( |
104 context, resolver, mappedData, queryID, dstData, destinationDataPtr, | 104 context, resolver, mappedData, queryID, dstData.view(), |
105 destinationByteLength); | 105 destinationDataPtr, destinationByteLength); |
106 context->registerGetBufferSubDataAsyncCallback(callbackObject); | 106 context->registerGetBufferSubDataAsyncCallback(callbackObject); |
107 auto callback = WTF::bind(&WebGLGetBufferSubDataAsyncCallback::resolve, | 107 auto callback = WTF::bind(&WebGLGetBufferSubDataAsyncCallback::resolve, |
108 wrapPersistent(callbackObject)); | 108 wrapPersistent(callbackObject)); |
109 context->drawingBuffer()->contextProvider()->signalQuery( | 109 context->drawingBuffer()->contextProvider()->signalQuery( |
110 queryID, convertToBaseCallback(std::move(callback))); | 110 queryID, convertToBaseCallback(std::move(callback))); |
111 | 111 |
112 return promise; | 112 return promise; |
113 } | 113 } |
114 | 114 |
115 WebGLGetBufferSubDataAsyncCallback::WebGLGetBufferSubDataAsyncCallback( | 115 WebGLGetBufferSubDataAsyncCallback::WebGLGetBufferSubDataAsyncCallback( |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 m_context->unregisterGetBufferSubDataAsyncCallback(this); | 165 m_context->unregisterGetBufferSubDataAsyncCallback(this); |
166 } | 166 } |
167 | 167 |
168 DEFINE_TRACE(WebGLGetBufferSubDataAsyncCallback) { | 168 DEFINE_TRACE(WebGLGetBufferSubDataAsyncCallback) { |
169 visitor->trace(m_context); | 169 visitor->trace(m_context); |
170 visitor->trace(m_promiseResolver); | 170 visitor->trace(m_promiseResolver); |
171 visitor->trace(m_destinationArrayBufferView); | 171 visitor->trace(m_destinationArrayBufferView); |
172 } | 172 } |
173 | 173 |
174 } // namespace blink | 174 } // namespace blink |
OLD | NEW |