本文整理汇总了C++中HTMLCanvasElement::getContext方法的典型用法代码示例。如果您正苦于以下问题:C++ HTMLCanvasElement::getContext方法的具体用法?C++ HTMLCanvasElement::getContext怎么用?C++ HTMLCanvasElement::getContext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HTMLCanvasElement
的用法示例。
在下文中一共展示了HTMLCanvasElement::getContext方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getContext
JSValue JSHTMLCanvasElement::getContext(ExecState* exec)
{
HTMLCanvasElement* canvas = static_cast<HTMLCanvasElement*>(impl());
const String& contextId = exec->argument(0).toString(exec)->value(exec);
RefPtr<CanvasContextAttributes> attrs;
#if ENABLE(WEBGL)
if (HTMLCanvasElement::is3dType(contextId)) {
get3DContextAttributes(exec, attrs);
if (exec->hadException())
return jsUndefined();
}
#endif
CanvasRenderingContext* context = canvas->getContext(contextId, attrs.get());
if (!context)
return jsNull();
JSValue jsValue = toJS(exec, globalObject(), WTF::getPtr(context));
if (InspectorInstrumentation::canvasAgentEnabled(canvas->document())) {
ScriptObject contextObject(exec, jsValue.getObject());
ScriptObject wrapped;
if (context->is2d())
wrapped = InspectorInstrumentation::wrapCanvas2DRenderingContextForInstrumentation(canvas->document(), contextObject);
#if ENABLE(WEBGL)
else if (context->is3d())
wrapped = InspectorInstrumentation::wrapWebGLRenderingContextForInstrumentation(canvas->document(), contextObject);
#endif
if (!wrapped.hasNoValue())
return wrapped.jsValue();
}
return jsValue;
}
示例2:
void V8HTMLCanvasElement::getContextMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& info)
{
v8::Handle<v8::Object> holder = info.Holder();
v8::Isolate* isolate = info.GetIsolate();
HTMLCanvasElement* impl = V8HTMLCanvasElement::toNative(holder);
TOSTRING_VOID(V8StringResource<>, contextIdResource, info[0]);
String contextId = contextIdResource;
RefPtr<CanvasContextAttributes> attributes = nullptr;
if (contextId == "webgl" || contextId == "experimental-webgl") {
RefPtr<WebGLContextAttributes> webGLAttributes = WebGLContextAttributes::create();
if (info.Length() > 1 && info[1]->IsObject()) {
v8::Handle<v8::Object> jsAttributes = info[1]->ToObject();
v8::Handle<v8::String> alpha = v8AtomicString(isolate, "alpha");
if (jsAttributes->Has(alpha) && !isUndefinedOrNull(jsAttributes->Get(alpha)))
webGLAttributes->setAlpha(jsAttributes->Get(alpha)->BooleanValue());
v8::Handle<v8::String> depth = v8AtomicString(isolate, "depth");
if (jsAttributes->Has(depth) && !isUndefinedOrNull(jsAttributes->Get(depth)))
webGLAttributes->setDepth(jsAttributes->Get(depth)->BooleanValue());
v8::Handle<v8::String> stencil = v8AtomicString(isolate, "stencil");
if (jsAttributes->Has(stencil) && !isUndefinedOrNull(jsAttributes->Get(stencil)))
webGLAttributes->setStencil(jsAttributes->Get(stencil)->BooleanValue());
v8::Handle<v8::String> antialias = v8AtomicString(isolate, "antialias");
if (jsAttributes->Has(antialias) && !isUndefinedOrNull(jsAttributes->Get(antialias)))
webGLAttributes->setAntialias(jsAttributes->Get(antialias)->BooleanValue());
v8::Handle<v8::String> premultipliedAlpha = v8AtomicString(isolate, "premultipliedAlpha");
if (jsAttributes->Has(premultipliedAlpha) && !isUndefinedOrNull(jsAttributes->Get(premultipliedAlpha)))
webGLAttributes->setPremultipliedAlpha(jsAttributes->Get(premultipliedAlpha)->BooleanValue());
v8::Handle<v8::String> preserveDrawingBuffer = v8AtomicString(isolate, "preserveDrawingBuffer");
if (jsAttributes->Has(preserveDrawingBuffer) && !isUndefinedOrNull(jsAttributes->Get(preserveDrawingBuffer)))
webGLAttributes->setPreserveDrawingBuffer(jsAttributes->Get(preserveDrawingBuffer)->BooleanValue());
v8::Handle<v8::String> failIfMajorPerformanceCaveat = v8AtomicString(isolate, "failIfMajorPerformanceCaveat");
if (jsAttributes->Has(failIfMajorPerformanceCaveat) && !isUndefinedOrNull(jsAttributes->Get(failIfMajorPerformanceCaveat)))
webGLAttributes->setFailIfMajorPerformanceCaveat(jsAttributes->Get(failIfMajorPerformanceCaveat)->BooleanValue());
}
attributes = webGLAttributes;
} else {
RefPtr<Canvas2DContextAttributes> canvas2DAttributes = Canvas2DContextAttributes::create();
attributes = canvas2DAttributes;
}
CanvasRenderingContext* result = impl->getContext(contextId, attributes.get());
if (!result) {
v8SetReturnValueNull(info);
return;
}
if (result->is2d()) {
v8::Handle<v8::Value> v8Result = toV8(toCanvasRenderingContext2D(result), info.Holder(), info.GetIsolate());
v8SetReturnValue(info, v8Result);
return;
}
if (result->is3d()) {
v8::Handle<v8::Value> v8Result = toV8(toWebGLRenderingContext(result), info.Holder(), info.GetIsolate());
v8SetReturnValue(info, v8Result);
return;
}
ASSERT_NOT_REACHED();
v8SetReturnValueNull(info);
}
示例3: jsHTMLCanvasElementPrototypeFunctionGetContext
JSValue* jsHTMLCanvasElementPrototypeFunctionGetContext(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args)
{
if (!thisValue->isObject(&JSHTMLCanvasElement::s_info))
return throwError(exec, TypeError);
JSHTMLCanvasElement* castedThisObj = static_cast<JSHTMLCanvasElement*>(thisValue);
HTMLCanvasElement* imp = static_cast<HTMLCanvasElement*>(castedThisObj->impl());
const UString& contextId = args[0]->toString(exec);
KJS::JSValue* result = toJS(exec, WTF::getPtr(imp->getContext(contextId)));
return result;
}
示例4: getContext
JSValue JSHTMLCanvasElement::getContext(ExecState* exec)
{
HTMLCanvasElement* canvas = static_cast<HTMLCanvasElement*>(impl());
const UString& contextId = exec->argument(0).toString(exec)->value(exec);
RefPtr<CanvasContextAttributes> attrs;
#if ENABLE(WEBGL)
if (contextId == "experimental-webgl" || contextId == "webkit-3d") {
attrs = WebGLContextAttributes::create();
WebGLContextAttributes* webGLAttrs = static_cast<WebGLContextAttributes*>(attrs.get());
if (exec->argumentCount() > 1 && exec->argument(1).isObject()) {
JSObject* jsAttrs = exec->argument(1).getObject();
Identifier alpha(exec, "alpha");
if (jsAttrs->hasProperty(exec, alpha))
webGLAttrs->setAlpha(jsAttrs->get(exec, alpha).toBoolean(exec));
Identifier depth(exec, "depth");
if (jsAttrs->hasProperty(exec, depth))
webGLAttrs->setDepth(jsAttrs->get(exec, depth).toBoolean(exec));
Identifier stencil(exec, "stencil");
if (jsAttrs->hasProperty(exec, stencil))
webGLAttrs->setStencil(jsAttrs->get(exec, stencil).toBoolean(exec));
Identifier antialias(exec, "antialias");
if (jsAttrs->hasProperty(exec, antialias))
webGLAttrs->setAntialias(jsAttrs->get(exec, antialias).toBoolean(exec));
Identifier premultipliedAlpha(exec, "premultipliedAlpha");
if (jsAttrs->hasProperty(exec, premultipliedAlpha))
webGLAttrs->setPremultipliedAlpha(jsAttrs->get(exec, premultipliedAlpha).toBoolean(exec));
Identifier preserveDrawingBuffer(exec, "preserveDrawingBuffer");
if (jsAttrs->hasProperty(exec, preserveDrawingBuffer))
webGLAttrs->setPreserveDrawingBuffer(jsAttrs->get(exec, preserveDrawingBuffer).toBoolean(exec));
}
}
#endif
CanvasRenderingContext* context = canvas->getContext(ustringToString(contextId), attrs.get());
if (!context)
return jsNull();
JSValue jsValue = toJS(exec, globalObject(), WTF::getPtr(context));
#if ENABLE(WEBGL)
if (context->is3d() && InspectorInstrumentation::hasFrontends()) {
ScriptObject glContext(exec, jsValue.getObject());
ScriptObject wrapped = InspectorInstrumentation::wrapWebGLRenderingContextForInstrumentation(canvas->document(), glContext);
if (!wrapped.hasNoValue())
return wrapped.jsValue();
}
#endif
return jsValue;
}
示例5: callAsFunction
JSValue* JSHTMLCanvasElementPrototypeFunction::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args)
{
if (!thisObj->inherits(&JSHTMLCanvasElement::info))
return throwError(exec, TypeError);
HTMLCanvasElement* imp = static_cast<HTMLCanvasElement*>(static_cast<JSHTMLCanvasElement*>(thisObj)->impl());
switch (id) {
case JSHTMLCanvasElement::GetContextFuncNum: {
String contextId = args[0]->toString(exec);
KJS::JSValue* result = toJS(exec, WTF::getPtr(imp->getContext(contextId)));
return result;
}
}
return 0;
}
示例6: if
v8::Handle<v8::Value> V8HTMLCanvasElement::getContextCallback(const v8::Arguments& args)
{
INC_STATS("DOM.HTMLCanvasElement.context");
v8::Handle<v8::Object> holder = args.Holder();
HTMLCanvasElement* imp = V8HTMLCanvasElement::toNative(holder);
String contextId = toWebCoreString(args[0]);
RefPtr<CanvasContextAttributes> attrs;
#if ENABLE(3D_CANVAS)
if (contextId == "experimental-webgl" || contextId == "webkit-3d") {
attrs = WebGLContextAttributes::create();
WebGLContextAttributes* webGLAttrs = static_cast<WebGLContextAttributes*>(attrs.get());
if (args.Length() > 1 && args[1]->IsObject()) {
v8::Handle<v8::Object> jsAttrs = args[1]->ToObject();
v8::Handle<v8::String> alpha = v8::String::New("alpha");
if (jsAttrs->Has(alpha))
webGLAttrs->setAlpha(jsAttrs->Get(alpha)->BooleanValue());
v8::Handle<v8::String> depth = v8::String::New("depth");
if (jsAttrs->Has(depth))
webGLAttrs->setDepth(jsAttrs->Get(depth)->BooleanValue());
v8::Handle<v8::String> stencil = v8::String::New("stencil");
if (jsAttrs->Has(stencil))
webGLAttrs->setStencil(jsAttrs->Get(stencil)->BooleanValue());
v8::Handle<v8::String> antialias = v8::String::New("antialias");
if (jsAttrs->Has(antialias))
webGLAttrs->setAntialias(jsAttrs->Get(antialias)->BooleanValue());
v8::Handle<v8::String> premultipliedAlpha = v8::String::New("premultipliedAlpha");
if (jsAttrs->Has(premultipliedAlpha))
webGLAttrs->setPremultipliedAlpha(jsAttrs->Get(premultipliedAlpha)->BooleanValue());
}
}
#endif
CanvasRenderingContext* result = imp->getContext(contextId, attrs.get());
if (!result)
return v8::Null();
if (result->is2d())
return toV8(static_cast<CanvasRenderingContext2D*>(result));
#if ENABLE(3D_CANVAS)
else if (result->is3d())
return toV8(static_cast<WebGLRenderingContext*>(result));
#endif
ASSERT_NOT_REACHED();
return v8::Null();
}
示例7: StateHandler
void CocoDeviceWrapper::StateHandler(android_app* app, int32_t state)
{
CocoDeviceWrapper* t = (CocoDeviceWrapper*)app->userData;
switch(state)
{
case APP_CMD_INIT_WINDOW:
{
t->glwrap = new CocoDeviceOpenGLContext(app->window, t);
global = window = new HTMLWindow();
window->innerWidth = t->glwrap->GetScreen().width;
window->innerHeight = t->glwrap->GetScreen().height;
window->devicePixelRatio = t->glwrap->GetScreen().pixelRatio;
window->deviceRotation = 0.0f;
document = new HTMLDocument();
HTMLCanvasElement* canvas = document->createElement("canvas");
gl = (WebGLRenderingContext*)canvas->getContext("webgl");
gl->canvas->width = window->innerWidth;
gl->canvas->height = window->innerHeight;
engine = new GameEngine();
break;
}
case APP_CMD_WINDOW_REDRAW_NEEDED:
break;
case APP_CMD_TERM_WINDOW:
delete t->glwrap;
t->glwrap = nullptr;
break;
case APP_CMD_GAINED_FOCUS:
break;
case APP_CMD_LOST_FOCUS:
break;
case APP_CMD_STOP:
ANativeActivity_finish(app->activity);
break;
default:
break;
}
}
示例8: if
v8::Handle<v8::Value> V8HTMLCanvasElement::getContextCallback(const v8::Arguments& args)
{
INC_STATS("DOM.HTMLCanvasElement.context");
v8::Handle<v8::Object> holder = args.Holder();
HTMLCanvasElement* imp = V8HTMLCanvasElement::toNative(holder);
String contextId = toWebCoreString(args[0]);
RefPtr<CanvasContextAttributes> attrs;
#if ENABLE(WEBGL)
if (contextId == "experimental-webgl" || contextId == "webkit-3d") {
attrs = WebGLContextAttributes::create();
WebGLContextAttributes* webGLAttrs = static_cast<WebGLContextAttributes*>(attrs.get());
if (args.Length() > 1 && args[1]->IsObject()) {
v8::Handle<v8::Object> jsAttrs = args[1]->ToObject();
v8::Handle<v8::String> alpha = v8::String::New("alpha");
if (jsAttrs->Has(alpha))
webGLAttrs->setAlpha(jsAttrs->Get(alpha)->BooleanValue());
v8::Handle<v8::String> depth = v8::String::New("depth");
if (jsAttrs->Has(depth))
webGLAttrs->setDepth(jsAttrs->Get(depth)->BooleanValue());
v8::Handle<v8::String> stencil = v8::String::New("stencil");
if (jsAttrs->Has(stencil))
webGLAttrs->setStencil(jsAttrs->Get(stencil)->BooleanValue());
v8::Handle<v8::String> antialias = v8::String::New("antialias");
if (jsAttrs->Has(antialias))
webGLAttrs->setAntialias(jsAttrs->Get(antialias)->BooleanValue());
v8::Handle<v8::String> premultipliedAlpha = v8::String::New("premultipliedAlpha");
if (jsAttrs->Has(premultipliedAlpha))
webGLAttrs->setPremultipliedAlpha(jsAttrs->Get(premultipliedAlpha)->BooleanValue());
v8::Handle<v8::String> preserveDrawingBuffer = v8::String::New("preserveDrawingBuffer");
if (jsAttrs->Has(preserveDrawingBuffer))
webGLAttrs->setPreserveDrawingBuffer(jsAttrs->Get(preserveDrawingBuffer)->BooleanValue());
}
}
#endif
CanvasRenderingContext* result = imp->getContext(contextId, attrs.get());
if (!result)
return v8::Null(args.GetIsolate());
else if (result->is2d()) {
v8::Handle<v8::Value> v8Result = toV8(static_cast<CanvasRenderingContext2D*>(result), args.Holder(), args.GetIsolate());
if (InspectorInstrumentation::canvasAgentEnabled(imp->document())) {
ScriptState* scriptState = ScriptState::forContext(v8::Context::GetCurrent());
ScriptObject context(scriptState, v8::Handle<v8::Object>::Cast(v8Result));
ScriptObject wrapped = InspectorInstrumentation::wrapCanvas2DRenderingContextForInstrumentation(imp->document(), context);
if (!wrapped.hasNoValue())
return wrapped.v8Value();
}
return v8Result;
}
#if ENABLE(WEBGL)
else if (result->is3d()) {
// 3D canvas contexts can hold on to lots of GPU resources, and we want to take an
// opportunity to get rid of them as soon as possible when we navigate away from pages using
// them.
V8PerIsolateData* perIsolateData = V8PerIsolateData::from(args.GetIsolate());
perIsolateData->setShouldCollectGarbageSoon();
v8::Handle<v8::Value> v8Result = toV8(static_cast<WebGLRenderingContext*>(result), args.Holder(), args.GetIsolate());
if (InspectorInstrumentation::canvasAgentEnabled(imp->document())) {
ScriptState* scriptState = ScriptState::forContext(v8::Context::GetCurrent());
ScriptObject glContext(scriptState, v8::Handle<v8::Object>::Cast(v8Result));
ScriptObject wrapped = InspectorInstrumentation::wrapWebGLRenderingContextForInstrumentation(imp->document(), glContext);
if (!wrapped.hasNoValue())
return wrapped.v8Value();
}
return v8Result;
}
#endif
ASSERT_NOT_REACHED();
return v8::Null(args.GetIsolate());
}