Skip to content
This repository was archived by the owner on Apr 3, 2020. It is now read-only.

Commit 20dcb32

Browse files
junmin-zhuMrunal Kapade
authored and
Mrunal Kapade
committed
[Android] WebCL support for Crosswalk.
WebCL 1.0 defines a JavaScript binding to the Khronos OpenCL standard for heterogeneous parallel computing. Its spec is available at: http://www.khronos.org/registry/webcl/specs/latest/1.0/ This patch includes WebCL basic APIs support, dynamic loading mechanism etc. WebCL support is controlled by "ENABLE_WEBCL" flag, and it's enabled by default on Android. If you want to disable with WebCL, please add "-Denable_webcl=0" when running the "xwalk/gyp_xwalk" before building. And run conformance test(src/third_party/webcl/src/) in the XWalkCoreShell. Currently, Intel CPU/GPU, Qualcomm CPU/GPU and Power VR GPU are supported. But OpenCL library isn't always shipped with device by default, even it supports OpenCL. For example: Google Nexus series. It requires to install OpenCL library manually. TEST=WebCL conformances test on Asus MemoPad and Xiaomi3. Known issue: 1. miss oilpan support. 2. miss cl_khr_gl_sharing extension support. 3. load library in render process. [email protected], [email protected], [email protected] BUG=XWALK-2550
1 parent 2b9d086 commit 20dcb32

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+10374
-0
lines changed

Source/bindings/core/v8/ExceptionState.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,17 @@ void ExceptionState::throwDOMException(const ExceptionCode& ec, const String& me
6565
setException(V8ThrowException::createDOMException(m_isolate, ec, processedMessage, m_creationContext));
6666
}
6767

68+
void ExceptionState::throwWebCLException(const ExceptionCode& ec, const String& message)
69+
{
70+
ASSERT(ec);
71+
ASSERT(m_isolate);
72+
73+
m_code = ec;
74+
m_message = message;
75+
String finalMessage = addExceptionContext("WEBCL_IMPL_" + message);
76+
setException(V8ThrowException::createWebCLException(ec, message, finalMessage, m_creationContext, m_isolate));
77+
}
78+
6879
void ExceptionState::throwSecurityError(const String& sanitizedMessage, const String& unsanitizedMessage)
6980
{
7081
ASSERT(m_isolate);

Source/bindings/core/v8/ExceptionState.h

+1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ class ExceptionState {
7878
, m_isolate(isolate) { ASSERT(m_context == ConstructionContext || m_context == EnumerationContext || m_context == IndexedSetterContext || m_context == IndexedGetterContext || m_context == IndexedDeletionContext); }
7979

8080
virtual void throwDOMException(const ExceptionCode&, const String& message);
81+
virtual void throwWebCLException(const ExceptionCode&, const String& message);
8182
virtual void throwTypeError(const String& message);
8283
virtual void throwSecurityError(const String& sanitizedMessage, const String& unsanitizedMessage = String());
8384
virtual void throwRangeError(const String& message);

Source/bindings/core/v8/V8ThrowException.cpp

+18
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@
2727

2828
#include "bindings/core/v8/V8Binding.h"
2929
#include "bindings/core/v8/V8DOMException.h"
30+
#include "bindings/modules/v8/V8WebCLException.h"
3031
#include "core/dom/DOMException.h"
3132
#include "core/dom/ExceptionCode.h"
33+
#include "modules/webcl/WebCLException.h"
3234

3335
namespace blink {
3436

@@ -150,4 +152,20 @@ v8::Handle<v8::Value> V8ThrowException::throwException(v8::Handle<v8::Value> exc
150152
return v8::Undefined(isolate);
151153
}
152154

155+
v8::Handle<v8::Value> V8ThrowException::createWebCLException(int ec, const String& name, const String& message, const v8::Handle<v8::Object>& creationContext, v8::Isolate* isolate)
156+
{
157+
if (ec <= 0 || v8::V8::IsExecutionTerminating())
158+
return v8Undefined();
159+
160+
if (ec == V8TypeError)
161+
return V8ThrowException::createTypeError(isolate, message);
162+
163+
RefPtr<WebCLException> webclException = WebCLException::create(ec, name, message);
164+
v8::Handle<v8::Value> exception = toV8(webclException, creationContext, isolate);
165+
166+
if (exception.IsEmpty())
167+
return v8Undefined();
168+
169+
return exception;
170+
}
153171
} // namespace blink

Source/bindings/core/v8/V8ThrowException.h

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class V8ThrowException {
5757
static v8::Handle<v8::Value> throwSyntaxError(v8::Isolate*, const String&);
5858
static v8::Handle<v8::Value> createReferenceError(v8::Isolate*, const String&);
5959
static v8::Handle<v8::Value> throwReferenceError(v8::Isolate*, const String&);
60+
static v8::Handle<v8::Value> createWebCLException(int, const String&, const String&, const v8::Handle<v8::Object>&, v8::Isolate*);
6061
};
6162

6263
} // namespace blink

Source/bindings/modules/v8/custom/V8WebCLCommandQueueCustom.cpp

+1,298
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Copyright (C) 2015 Intel Corporation All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#include "config.h"
6+
7+
#if ENABLE(WEBCL)
8+
9+
#include "bindings/modules/v8/V8WebCLCallback.h"
10+
#include "bindings/modules/v8/V8WebCLDevice.h"
11+
#include "bindings/modules/v8/V8WebCLProgram.h"
12+
13+
namespace blink {
14+
15+
void V8WebCLProgram::buildMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& info)
16+
{
17+
ExceptionState es(ExceptionState::ExecutionContext, "build", "WebCLProgram", info.Holder(), info.GetIsolate());
18+
WebCLProgram* impl = V8WebCLProgram::toImpl(info.Holder());
19+
Vector<RefPtr<WebCLDevice>> devices;
20+
V8StringResource<TreatNullAndUndefinedAsNullString> options;
21+
WebCLCallback* whenFinished = nullptr;
22+
{
23+
if (info.Length() > 0 && !isUndefinedOrNull(info[0]))
24+
TONATIVE_VOID_EXCEPTIONSTATE_INTERNAL(devices, (toRefPtrNativeArray<WebCLDevice, V8WebCLDevice>(info[0], 1, info.GetIsolate(), es)), es);
25+
26+
TOSTRING_VOID_INTERNAL(options, info[1]);
27+
if (!isUndefinedOrNull(info[2])) {
28+
if (!info[2]->IsFunction()) {
29+
es.throwTypeError("The callback provided as parameter 3 is not a function.");
30+
es.throwIfNeeded();
31+
return;
32+
}
33+
34+
whenFinished = V8WebCLCallback::create(v8::Handle<v8::Function>::Cast(info[2]), ScriptState::current(info.GetIsolate()));
35+
}
36+
}
37+
38+
if (!devices.isEmpty())
39+
impl->build(devices, options, whenFinished, es);
40+
else
41+
impl->build(options, whenFinished, es);
42+
43+
if (es.hadException())
44+
es.throwIfNeeded();
45+
}
46+
47+
}
48+
#endif // ENABLE(WEBCL)

Source/bindings/modules/v8/custom/custom.gypi

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
'V8SQLResultSetRowListCustom.cpp',
1616
'V8SQLTransactionCustom.cpp',
1717
'V8ServiceWorkerCustom.cpp',
18+
'V8WebCLCommandQueueCustom.cpp',
19+
'V8WebCLProgramCustom.cpp',
1820
],
1921
},
2022
}

Source/modules/modules.gypi

+67
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,22 @@
214214
'webmidi/MIDISuccessCallback.idl',
215215
'websockets/CloseEvent.idl',
216216
'websockets/WebSocket.idl',
217+
'webcl/WebCL.idl',
218+
'webcl/WebCLBuffer.idl',
219+
'webcl/WebCLCallback.idl',
220+
'webcl/WebCLCommandQueue.idl',
221+
'webcl/WebCLContext.idl',
222+
'webcl/WebCLDevice.idl',
223+
'webcl/WebCLException.idl',
224+
'webcl/WebCLEvent.idl',
225+
'webcl/WebCLImage.idl',
226+
'webcl/WebCLKernel.idl',
227+
'webcl/WebCLKernelArgInfo.idl',
228+
'webcl/WebCLMemoryObject.idl',
229+
'webcl/WebCLPlatform.idl',
230+
'webcl/WebCLProgram.idl',
231+
'webcl/WebCLSampler.idl',
232+
'webcl/WebCLUserEvent.idl'
217233
],
218234
# 'partial interface' or target (right side of) 'implements'
219235
'modules_dependency_idl_files': [
@@ -269,6 +285,7 @@
269285
'speech/WindowSpeechSynthesis.idl',
270286
'vibration/NavigatorVibration.idl',
271287
'webaudio/WindowWebAudio.idl',
288+
'webcl/WindowWebCL.idl',
272289
'webdatabase/WindowWebDatabase.idl',
273290
'webmidi/NavigatorWebMIDI.idl',
274291
],
@@ -331,6 +348,7 @@
331348
'serviceworkers/RegistrationOptions.idl',
332349
'speech/SpeechRecognitionErrorInit.idl',
333350
'speech/SpeechRecognitionEventInit.idl',
351+
'webcl/WebCLImageDescriptor.idl',
334352
'webmidi/MIDIConnectionEventInit.idl',
335353
'webmidi/MIDIMessageEventInit.idl',
336354
'webmidi/MIDIOptions.idl',
@@ -410,6 +428,8 @@
410428
'<(blink_modules_output_dir)/webmidi/MIDIMessageEventInit.cpp',
411429
'<(blink_modules_output_dir)/webmidi/MIDIOptions.cpp',
412430
'<(blink_modules_output_dir)/webmidi/MIDIOptions.h',
431+
'<(blink_modules_output_dir)/webcl/WebCLImageDescriptor.cpp',
432+
'<(blink_modules_output_dir)/webcl/WebCLImageDescriptor.h',
413433
'<(blink_modules_output_dir)/websockets/CloseEventInit.cpp',
414434
'<(blink_modules_output_dir)/websockets/CloseEventInit.h',
415435
],
@@ -1081,6 +1101,53 @@
10811101
'webaudio/WaveShaperNode.h',
10821102
'webaudio/WaveShaperProcessor.cpp',
10831103
'webaudio/WaveShaperProcessor.h',
1104+
'webcl/DOMWindowWebCL.cpp',
1105+
'webcl/DOMWindowWebCL.h',
1106+
'webcl/WebCL.cpp',
1107+
'webcl/WebCL.h',
1108+
'webcl/WebCLBuffer.cpp',
1109+
'webcl/WebCLBuffer.h',
1110+
'webcl/WebCLCallback.h',
1111+
'webcl/WebCLCommandQueue.cpp',
1112+
'webcl/WebCLCommandQueue.h',
1113+
'webcl/WebCLConfig.h',
1114+
'webcl/WebCLContext.cpp',
1115+
'webcl/WebCLContext.h',
1116+
'webcl/WebCLDevice.cpp',
1117+
'webcl/WebCLDevice.h',
1118+
'webcl/WebCLException.cpp',
1119+
'webcl/WebCLException.h',
1120+
'webcl/WebCLExtension.cpp',
1121+
'webcl/WebCLExtension.h',
1122+
'webcl/WebCLEvent.cpp',
1123+
'webcl/WebCLEvent.h',
1124+
'webcl/WebCLHTMLUtil.cpp',
1125+
'webcl/WebCLHTMLUtil.h',
1126+
'webcl/WebCLImage.cpp',
1127+
'webcl/WebCLImage.h',
1128+
'webcl/WebCLInputChecker.cpp',
1129+
'webcl/WebCLInputChecker.h',
1130+
'webcl/WebCLKernel.cpp',
1131+
'webcl/WebCLKernel.h',
1132+
'webcl/WebCLKernelArgInfo.h',
1133+
'webcl/WebCLKernelArgInfoProvider.cpp',
1134+
'webcl/WebCLKernelArgInfoProvider.h',
1135+
'webcl/WebCLMemoryUtil.cpp',
1136+
'webcl/WebCLMemoryUtil.h',
1137+
'webcl/WebCLMemoryObject.cpp',
1138+
'webcl/WebCLMemoryObject.h',
1139+
'webcl/WebCLObject.cpp',
1140+
'webcl/WebCLObject.h',
1141+
'webcl/WebCLOpenCL.cpp',
1142+
'webcl/WebCLOpenCL.h',
1143+
'webcl/WebCLPlatform.cpp',
1144+
'webcl/WebCLPlatform.h',
1145+
'webcl/WebCLProgram.cpp',
1146+
'webcl/WebCLProgram.h',
1147+
'webcl/WebCLSampler.cpp',
1148+
'webcl/WebCLSampler.h',
1149+
'webcl/WebCLUserEvent.cpp',
1150+
'webcl/WebCLUserEvent.h',
10841151
'webdatabase/ChangeVersionData.h',
10851152
'webdatabase/ChangeVersionWrapper.cpp',
10861153
'webdatabase/ChangeVersionWrapper.h',
+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// Copyright (C) 2015 Intel Corporation All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#include "config.h"
6+
#if ENABLE(WEBCL)
7+
8+
#include "core/dom/Document.h"
9+
#include "core/frame/LocalDOMWindow.h"
10+
#include "core/page/Page.h"
11+
#include "DOMWindowWebCL.h"
12+
#include "modules/webcl/WebCL.h"
13+
14+
namespace blink {
15+
16+
DOMWindowWebCL::DOMWindowWebCL(LocalDOMWindow& window)
17+
: DOMWindowProperty(window.frame())
18+
, m_window(window)
19+
{
20+
}
21+
22+
DEFINE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(DOMWindowWebCL);
23+
24+
void DOMWindowWebCL::trace(Visitor* visitor)
25+
{
26+
visitor->trace(m_webcl);
27+
WillBeHeapSupplement<LocalDOMWindow>::trace(visitor);
28+
DOMWindowProperty::trace(visitor);
29+
}
30+
31+
DOMWindowWebCL& DOMWindowWebCL::from(LocalDOMWindow& window)
32+
{
33+
DOMWindowWebCL* supplement = static_cast<DOMWindowWebCL*>(WillBeHeapSupplement<LocalDOMWindow>::from(window, supplementName()));
34+
if (!supplement) {
35+
supplement = new DOMWindowWebCL(window);
36+
provideTo(window, supplementName(), adoptPtrWillBeNoop(supplement));
37+
}
38+
39+
return *supplement;
40+
}
41+
42+
void DOMWindowWebCL::willDestroyGlobalObjectInFrame()
43+
{
44+
m_webcl = nullptr;
45+
DOMWindowProperty::willDestroyGlobalObjectInFrame();
46+
}
47+
48+
void DOMWindowWebCL::willDetachGlobalObjectFromFrame()
49+
{
50+
m_webcl = nullptr;
51+
DOMWindowProperty::willDetachGlobalObjectFromFrame();
52+
}
53+
54+
WebCL* DOMWindowWebCL::webcl(DOMWindow& window)
55+
{
56+
return from(toLocalDOMWindow(window)).webcl();
57+
}
58+
59+
WebCL* DOMWindowWebCL::webcl()
60+
{
61+
if (!m_window.document() || !m_window.document()->page())
62+
return nullptr;
63+
64+
if (!m_webcl)
65+
m_webcl = WebCL::create();
66+
67+
return m_webcl.get();
68+
}
69+
70+
const char* DOMWindowWebCL::supplementName()
71+
{
72+
return "DOMWindowWebCL";
73+
}
74+
75+
} // namespace blink
76+
77+
#endif // ENABLE(WEBCL)

Source/modules/webcl/DOMWindowWebCL.h

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright (C) 2015 Intel Corporation All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#ifndef DOMWindowWebCL_h
6+
#define DOMWindowWebCL_h
7+
8+
#if ENABLE(WEBCL)
9+
#include "core/frame/DOMWindowProperty.h"
10+
#include "platform/Supplementable.h"
11+
12+
namespace blink {
13+
14+
class LocalDOMWindow;
15+
class WebCL;
16+
17+
class DOMWindowWebCL : public NoBaseWillBeGarbageCollected<DOMWindowWebCL>, public WillBeHeapSupplement<LocalDOMWindow>, public DOMWindowProperty {
18+
WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(DOMWindowWebCL);
19+
DECLARE_EMPTY_VIRTUAL_DESTRUCTOR_WILL_BE_REMOVED(DOMWindowWebCL);
20+
public:
21+
static DOMWindowWebCL& from(LocalDOMWindow&);
22+
static WebCL* webcl(DOMWindow&);
23+
24+
void willDestroyGlobalObjectInFrame() override;
25+
void willDetachGlobalObjectFromFrame() override;
26+
27+
void trace(Visitor*);
28+
29+
private:
30+
explicit DOMWindowWebCL(LocalDOMWindow&);
31+
32+
WebCL* webcl();
33+
static const char* supplementName();
34+
35+
LocalDOMWindow& m_window;
36+
RefPtr<WebCL> m_webcl;
37+
};
38+
39+
} // namespace blink
40+
41+
#endif // ENABLE(WEBCL)
42+
#endif // DOMWindowWebCL_h

0 commit comments

Comments
 (0)