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* script_state, | 36 ScriptState* script_state, |
37 GLenum target, | 37 GLenum target, |
38 GLintptr src_byte_offset, | 38 GLintptr src_byte_offset, |
39 NotShared<DOMArrayBufferView> dst_data, | 39 DOMArrayBufferView* dst_data, |
40 GLuint dst_offset, | 40 GLuint dst_offset, |
41 GLuint length) { | 41 GLuint length) { |
42 ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state); | 42 ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state); |
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(kInvalidStateError, "context lost"); | 48 DOMException::Create(kInvalidStateError, "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* context_base = scoped.Context(); | 55 WebGLRenderingContextBase* context_base = scoped.Context(); |
56 DCHECK_GE(context_base->Version(), 2u); | 56 DCHECK_GE(context_base->Version(), 2u); |
57 context = static_cast<WebGL2RenderingContextBase*>(context_base); | 57 context = static_cast<WebGL2RenderingContextBase*>(context_base); |
58 } | 58 } |
59 | 59 |
60 WebGLBuffer* source_buffer = nullptr; | 60 WebGLBuffer* source_buffer = nullptr; |
61 void* destination_data_ptr = nullptr; | 61 void* destination_data_ptr = nullptr; |
62 long long destination_byte_length = 0; | 62 long long destination_byte_length = 0; |
63 const char* message = context->ValidateGetBufferSubData( | 63 const char* message = context->ValidateGetBufferSubData( |
64 __FUNCTION__, target, src_byte_offset, dst_data.View(), dst_offset, | 64 __FUNCTION__, target, src_byte_offset, dst_data, dst_offset, length, |
65 length, &source_buffer, &destination_data_ptr, &destination_byte_length); | 65 &source_buffer, &destination_data_ptr, &destination_byte_length); |
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(kInvalidStateError, message); | 69 DOMException* exception = DOMException::Create(kInvalidStateError, 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__, source_buffer, src_byte_offset, destination_byte_length); | 75 __FUNCTION__, source_buffer, src_byte_offset, destination_byte_length); |
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(kInvalidStateError, message); | 79 DOMException* exception = DOMException::Create(kInvalidStateError, 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 (!destination_byte_length) { | 85 if (!destination_byte_length) { |
86 resolver->Resolve(dst_data.View()); | 86 resolver->Resolve(dst_data); |
87 return promise; | 87 return promise; |
88 } | 88 } |
89 | 89 |
90 GLuint query_id; | 90 GLuint query_id; |
91 context->ContextGL()->GenQueriesEXT(1, &query_id); | 91 context->ContextGL()->GenQueriesEXT(1, &query_id); |
92 context->ContextGL()->BeginQueryEXT(GL_COMMANDS_ISSUED_CHROMIUM, query_id); | 92 context->ContextGL()->BeginQueryEXT(GL_COMMANDS_ISSUED_CHROMIUM, query_id); |
93 void* mapped_data = context->ContextGL()->GetBufferSubDataAsyncCHROMIUM( | 93 void* mapped_data = context->ContextGL()->GetBufferSubDataAsyncCHROMIUM( |
94 target, src_byte_offset, destination_byte_length); | 94 target, src_byte_offset, destination_byte_length); |
95 context->ContextGL()->EndQueryEXT(GL_COMMANDS_ISSUED_CHROMIUM); | 95 context->ContextGL()->EndQueryEXT(GL_COMMANDS_ISSUED_CHROMIUM); |
96 if (!mapped_data) { | 96 if (!mapped_data) { |
97 DOMException* exception = | 97 DOMException* exception = |
98 DOMException::Create(kInvalidStateError, "Out of memory"); | 98 DOMException::Create(kInvalidStateError, "Out of memory"); |
99 resolver->Reject(exception); | 99 resolver->Reject(exception); |
100 return promise; | 100 return promise; |
101 } | 101 } |
102 | 102 |
103 auto callback_object = new WebGLGetBufferSubDataAsyncCallback( | 103 auto callback_object = new WebGLGetBufferSubDataAsyncCallback( |
104 context, resolver, mapped_data, query_id, dst_data.View(), | 104 context, resolver, mapped_data, query_id, dst_data, destination_data_ptr, |
105 destination_data_ptr, destination_byte_length); | 105 destination_byte_length); |
106 context->RegisterGetBufferSubDataAsyncCallback(callback_object); | 106 context->RegisterGetBufferSubDataAsyncCallback(callback_object); |
107 auto callback = WTF::Bind(&WebGLGetBufferSubDataAsyncCallback::Resolve, | 107 auto callback = WTF::Bind(&WebGLGetBufferSubDataAsyncCallback::Resolve, |
108 WrapPersistent(callback_object)); | 108 WrapPersistent(callback_object)); |
109 context->GetDrawingBuffer()->ContextProvider()->SignalQuery( | 109 context->GetDrawingBuffer()->ContextProvider()->SignalQuery( |
110 query_id, ConvertToBaseCallback(std::move(callback))); | 110 query_id, 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 context_->UnregisterGetBufferSubDataAsyncCallback(this); | 165 context_->UnregisterGetBufferSubDataAsyncCallback(this); |
166 } | 166 } |
167 | 167 |
168 DEFINE_TRACE(WebGLGetBufferSubDataAsyncCallback) { | 168 DEFINE_TRACE(WebGLGetBufferSubDataAsyncCallback) { |
169 visitor->Trace(context_); | 169 visitor->Trace(context_); |
170 visitor->Trace(promise_resolver_); | 170 visitor->Trace(promise_resolver_); |
171 visitor->Trace(destination_array_buffer_view_); | 171 visitor->Trace(destination_array_buffer_view_); |
172 } | 172 } |
173 | 173 |
174 } // namespace blink | 174 } // namespace blink |
OLD | NEW |