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

[M48: adapted to the following upstream changes:
 - https://codereview.chromium.org/1303153005
 - https://codereview.chromium.org/1362103002
 - https://codereview.chromium.org/1372463002
 - https://codereview.chromium.org/1441573002]

[M49: adapted to the following changes:
WebCL: Only set ENABLE_WEBCL in the relevant files.
WebCL: Remove "config.h" in WebCL Related Implementation and Fix
Compile Error
WebCL: Using gyp to enable or disable WebCL. BUG=XWALK-6200
WebCL: Fix calling convention of callbacks.
WebCL: Build WebCL for all platforms and enable it during runtime.
WebCL: Use the CPU() macro provided by WTF for CPU arch detection.
WebCL: Fix build with component=shared_library.]

[M50: adapted to the following changes:
WebCL: Modified corresponding class to final for warning error
elimation.
WebCL: Change WebCLCallback parent class from RefCounted to
GarbageCollectedFinalized for idl generation rule changed. Now the
upstream generate callbakc interface with oilpan support.
WebCL: Due to WebCLCallback is oilpan supported, Modifined RefPtr to
Persistent or Member, Vector to HeapVector/PersistentHeapVector in
corresponding non-garbage-collected class to elimate compile error.]
  • Loading branch information
shaoboyan authored and Mrunal Kapade committed May 13, 2016
1 parent 2e5ea07 commit 172493f
Show file tree
Hide file tree
Showing 75 changed files with 10,635 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 @@ -71,6 +71,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 @@ -82,6 +82,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
53 changes: 53 additions & 0 deletions third_party/WebKit/Source/bindings/core/v8/V8ThrowException.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,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 @@ -46,6 +49,20 @@ 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)
{
v8::Maybe<bool> unused = info.Data().As<v8::Object>()->Set(info.GetIsolate()->GetCurrentContext(), v8AtomicString(info.GetIsolate(), "stack"), value);
ALLOW_UNUSED_LOCAL(unused);
}

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 || isolate->IsExecutionTerminating())
Expand Down Expand Up @@ -96,6 +113,42 @@ v8::Local<v8::Value> V8ThrowException::createDOMException(v8::Isolate* isolate,
return exception;
}

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 || isolate->IsExecutionTerminating())
return v8Undefined();

v8::Local<v8::Object> sanitizedCreationContext = creationContext;

ScriptState* scriptState = ScriptState::from(creationContext->CreationContext());
Frame* frame = toFrameIfNotDetached(scriptState->context());
if (!frame || !BindingSecurity::shouldAllowAccessToFrame(isolate, callingDOMWindow(isolate), frame, DoNotReportSecurityError)) {
scriptState = ScriptState::current(isolate);
sanitizedCreationContext = scriptState->context()->Global();
}

v8::TryCatch tryCatch(isolate);

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(scriptState, 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 @@ -42,6 +42,8 @@ class CORE_EXPORT V8ThrowException {
}
static v8::Local<v8::Value> createDOMException(v8::Isolate*, int, const String& sanitizedMessage, const String& unsanitizedMessage, const v8::Local<v8::Object>& creationContext);

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 172493f

Please sign in to comment.