| Index: third_party/WebKit/Source/modules/csspaint/CSSPaintDefinition.cpp
|
| diff --git a/third_party/WebKit/Source/modules/csspaint/CSSPaintDefinition.cpp b/third_party/WebKit/Source/modules/csspaint/CSSPaintDefinition.cpp
|
| index 29507cdb68e9ea6b037d5d3b35fa9200f20a3a01..85b4a2e275b0c003226ef3d26a8ddb09d89e73db 100644
|
| --- a/third_party/WebKit/Source/modules/csspaint/CSSPaintDefinition.cpp
|
| +++ b/third_party/WebKit/Source/modules/csspaint/CSSPaintDefinition.cpp
|
| @@ -5,9 +5,41 @@
|
| #include "modules/csspaint/CSSPaintDefinition.h"
|
|
|
| #include "bindings/core/v8/ScriptState.h"
|
| +#include "bindings/core/v8/V8Binding.h"
|
| +#include "core/dom/ExecutionContext.h"
|
| +#include "core/frame/ConsoleTypes.h"
|
| +#include "core/inspector/ConsoleMessage.h"
|
| +#include "modules/csspaint/Geometry.h"
|
| +#include "modules/csspaint/PaintRenderingContext2D.h"
|
| +#include "platform/ScriptForbiddenScope.h"
|
| +#include "platform/graphics/ImageBuffer.h"
|
| +#include "platform/graphics/PaintGeneratedImage.h"
|
| +#include "platform/graphics/RecordingImageBufferSurface.h"
|
| +#include "platform/graphics/UnacceleratedImageBufferSurface.h"
|
|
|
| namespace blink {
|
|
|
| +namespace {
|
| +
|
| +class UnacceleratedSurfaceFactory : public RecordingImageBufferFallbackSurfaceFactory {
|
| +public:
|
| + virtual PassOwnPtr<ImageBufferSurface> createSurface(const IntSize& size, OpacityMode opacityMode)
|
| + {
|
| + // ASSERT_NOT_REACHED();
|
| + // return nullptr;
|
| + return adoptPtr(new UnacceleratedImageBufferSurface(size, opacityMode));
|
| + }
|
| +
|
| + virtual ~UnacceleratedSurfaceFactory() { }
|
| +};
|
| +
|
| +static void clearHandle(const v8::WeakCallbackInfo<ScopedPersistent<v8::Object>>& data)
|
| +{
|
| + data.GetParameter()->clear();
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| RawPtr<CSSPaintDefinition> CSSPaintDefinition::create(ScriptState* scriptState, v8::Local<v8::Function> constructor, v8::Local<v8::Function> paint)
|
| {
|
| return new CSSPaintDefinition(scriptState, constructor, paint);
|
| @@ -24,4 +56,64 @@ CSSPaintDefinition::~CSSPaintDefinition()
|
| {
|
| }
|
|
|
| +PassRefPtr<Image> CSSPaintDefinition::paint(const IntSize& size)
|
| +{
|
| + v8::Isolate* isolate = m_scriptState->isolate();
|
| +
|
| + ScriptState::Scope scope(m_scriptState.get());
|
| + v8::MicrotasksScope microtasksScope(isolate, v8::MicrotasksScope::kRunMicrotasks);
|
| +
|
| + v8::Local<v8::Object> instance = m_instance.newLocal(m_scriptState->isolate());
|
| + if (isUndefinedOrNull(instance))
|
| + return nullptr;
|
| +
|
| + PaintRenderingContext2D* renderingContext = PaintRenderingContext2D::create(
|
| + ImageBuffer::create(adoptPtr(new RecordingImageBufferSurface(size, adoptPtr(new UnacceleratedSurfaceFactory())))));
|
| + Geometry* geom = Geometry::create(size);
|
| +
|
| + v8::Local<v8::Value> argv[] = {
|
| + toV8(renderingContext, m_scriptState->context()->Global(), isolate),
|
| + toV8(geom, m_scriptState->context()->Global(), isolate)
|
| + };
|
| +
|
| + v8::Local<v8::Function> paint = m_paint.newLocal(isolate);
|
| +
|
| + ScriptForbiddenScope::AllowUserAgentScript allowScripting;
|
| + v8::TryCatch block(isolate);
|
| +
|
| + V8ScriptRunner::callFunction(paint, m_scriptState->getExecutionContext(), instance, 2, argv, isolate);
|
| +
|
| + if (block.HasCaught()) {
|
| + block.ReThrow();
|
| + return nullptr;
|
| + }
|
| +
|
| + return PaintGeneratedImage::create(renderingContext->imageBuffer()->getPicture(), size);
|
| +}
|
| +
|
| +v8::Local<v8::Object> CSSPaintDefinition::paintInstance()
|
| +{
|
| + v8::Isolate* isolate = m_scriptState->isolate();
|
| +
|
| + ScriptState::Scope scope(m_scriptState.get());
|
| + v8::MicrotasksScope microtasksScope(isolate, v8::MicrotasksScope::kDoNotRunMicrotasks);
|
| +
|
| + if (m_instance.isEmpty()) {
|
| + v8::Local<v8::Function> constructor = m_constructor.newLocal(isolate);
|
| + ASSERT(!isUndefinedOrNull(constructor));
|
| +
|
| + v8::Local<v8::Object> paintInstance;
|
| + if (!constructor->NewInstance(m_scriptState->context()).ToLocal(&paintInstance)) {
|
| + m_scriptState->getExecutionContext()->addConsoleMessage(ConsoleMessage::create(JSMessageSource, ErrorMessageLevel, "Failed to create instance of class."));
|
| + } else {
|
| + m_instance.set(isolate, paintInstance);
|
| + m_instance.setWeak(&m_instance, clearHandle);
|
| + }
|
| +
|
| + return paintInstance;
|
| + }
|
| +
|
| + return m_instance.newLocal(isolate);
|
| +}
|
| +
|
| } // namespace blink
|
|
|