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

Commit

Permalink
[Blink] WebCL support for Crosswalk.
Browse files Browse the repository at this point in the history
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.

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-4254
  • Loading branch information
hujiajie authored and Raphael Kubo da Costa committed Nov 18, 2015
1 parent 22d7a73 commit 46b7436
Show file tree
Hide file tree
Showing 74 changed files with 10,784 additions and 0 deletions.
12 changes: 12 additions & 0 deletions third_party/WebKit/Source/bindings/core/v8/ExceptionState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,18 @@ void ExceptionState::throwDOMException(const ExceptionCode& ec, const String& me
setException(V8ThrowException::createDOMException(m_isolate, ec, processedMessage, m_creationContext));
}

void ExceptionState::throwWebCLException(const ExceptionCode& ec, const String& message)
{
ASSERT(ec);
ASSERT(m_isolate);
ASSERT(!m_creationContext.IsEmpty());

m_code = ec;
String processedMessage = addExceptionContext(message);
m_message = processedMessage;
setException(V8ThrowException::createWebCLException(m_isolate, ec, message, processedMessage, m_creationContext));
}

void ExceptionState::throwSecurityError(const String& sanitizedMessage, const String& unsanitizedMessage)
{
ASSERT(m_isolate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class CORE_EXPORT ExceptionState {
, m_isolate(isolate) { ASSERT(m_context == ConstructionContext || m_context == EnumerationContext || m_context == IndexedSetterContext || m_context == IndexedGetterContext || m_context == IndexedDeletionContext); }

virtual void throwDOMException(const ExceptionCode&, const String& message);
virtual void throwWebCLException(const ExceptionCode&, const String& message);
virtual void throwTypeError(const String& message);
virtual void throwSecurityError(const String& sanitizedMessage, const String& unsanitizedMessage = String());
virtual void throwRangeError(const String& message);
Expand Down
43 changes: 43 additions & 0 deletions third_party/WebKit/Source/bindings/core/v8/V8ThrowException.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@
#include "bindings/core/v8/BindingSecurity.h"
#include "bindings/core/v8/V8Binding.h"
#include "bindings/core/v8/V8DOMException.h"
#include "bindings/core/v8/V8WebCLException.h"
#include "core/dom/DOMException.h"
#include "core/dom/ExceptionCode.h"
#include "core/webcl/WebCLException.h"
#include "wtf/RefPtr.h"

namespace blink {

Expand All @@ -47,6 +50,19 @@ static void domExceptionStackSetter(v8::Local<v8::Name> name, v8::Local<v8::Valu
ALLOW_UNUSED_LOCAL(unused);
}

static void webclExceptionStackGetter(v8::Local<v8::Name> name, const v8::PropertyCallbackInfo<v8::Value>& info)
{
v8::Isolate* isolate = info.GetIsolate();
v8::Local<v8::Value> value;
if (info.Data().As<v8::Object>()->Get(isolate->GetCurrentContext(), v8AtomicString(isolate, "stack")).ToLocal(&value))
v8SetReturnValue(info, value);
}

static void webclExceptionStackSetter(v8::Local<v8::Name> name, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<void>& info)
{
info.Data().As<v8::Object>()->Set(v8AtomicString(info.GetIsolate(), "stack"), value);
}

v8::Local<v8::Value> V8ThrowException::createDOMException(v8::Isolate* isolate, int ec, const String& sanitizedMessage, const String& unsanitizedMessage, const v8::Local<v8::Object>& creationContext)
{
if (ec <= 0 || v8::V8::IsExecutionTerminating())
Expand Down Expand Up @@ -104,6 +120,33 @@ v8::Local<v8::Value> V8ThrowException::throwDOMException(int ec, const String& s
return V8ThrowException::throwException(exception, isolate);
}

v8::Local<v8::Value> V8ThrowException::createWebCLException(v8::Isolate* isolate, int ec, const String& name, const String& message, const v8::Local<v8::Object>& creationContext)
{
if (ec <= 0 || v8::V8::IsExecutionTerminating())
return v8Undefined();

v8::TryCatch tryCatch;

RefPtr<WebCLException> webclException = WebCLException::create(ec, name, message);
v8::Local<v8::Value> exception = toV8(webclException, creationContext, isolate);

if (tryCatch.HasCaught()) {
ASSERT(exception.IsEmpty());
return tryCatch.Exception();
}
ASSERT(!exception.IsEmpty());

// Attach an Error object to the WebCLException. This is then lazily used to get the stack value.
v8::Local<v8::Value> error = v8::Exception::Error(v8String(isolate, webclException->message()));
ASSERT(!error.IsEmpty());
v8::Local<v8::Object> exceptionObject = exception.As<v8::Object>();
v8::Maybe<bool> result = exceptionObject->SetAccessor(isolate->GetCurrentContext(), v8AtomicString(isolate, "stack"), webclExceptionStackGetter, webclExceptionStackSetter, v8::MaybeLocal<v8::Value>(error));
ASSERT_UNUSED(result, result.FromJust());
V8HiddenValue::setHiddenValue(isolate, exceptionObject, V8HiddenValue::error(isolate), error);

return exception;
}

v8::Local<v8::Value> V8ThrowException::createGeneralError(v8::Isolate* isolate, const String& message)
{
return v8::Exception::Error(v8String(isolate, message.isNull() ? "Error" : message));
Expand Down
2 changes: 2 additions & 0 deletions third_party/WebKit/Source/bindings/core/v8/V8ThrowException.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ class CORE_EXPORT V8ThrowException {
}
static v8::Local<v8::Value> throwDOMException(int, const String& sanitizedMessage, const String& unsanitizedMessage, const v8::Local<v8::Object>& creationContext, v8::Isolate*);

static v8::Local<v8::Value> createWebCLException(v8::Isolate*, int, const String& name, const String& message, const v8::Local<v8::Object>& creationContext);

static v8::Local<v8::Value> throwException(v8::Local<v8::Value>, v8::Isolate*);

static v8::Local<v8::Value> createGeneralError(v8::Isolate*, const String&);
Expand Down
Loading

0 comments on commit 46b7436

Please sign in to comment.