Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(568)

Side by Side Diff: third_party/WebKit/Source/modules/csspaint/CSSPaintDefinition.cpp

Issue 1834843002: [WIP] Plumbing for paint Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "modules/csspaint/CSSPaintDefinition.h" 5 #include "modules/csspaint/CSSPaintDefinition.h"
6 6
7 #include "bindings/core/v8/ScriptState.h" 7 #include "bindings/core/v8/ScriptState.h"
8 #include "bindings/core/v8/V8Binding.h"
9 #include "core/dom/ExecutionContext.h"
10 #include "core/frame/ConsoleTypes.h"
11 #include "core/inspector/ConsoleMessage.h"
12 #include "modules/csspaint/Geometry.h"
13 #include "modules/csspaint/PaintRenderingContext2D.h"
14 #include "platform/ScriptForbiddenScope.h"
15 #include "platform/graphics/ImageBuffer.h"
16 #include "platform/graphics/PaintGeneratedImage.h"
17 #include "platform/graphics/RecordingImageBufferSurface.h"
18 #include "platform/graphics/UnacceleratedImageBufferSurface.h"
8 19
9 namespace blink { 20 namespace blink {
10 21
22 namespace {
23
24 class UnacceleratedSurfaceFactory : public RecordingImageBufferFallbackSurfaceFa ctory {
25 public:
26 virtual PassOwnPtr<ImageBufferSurface> createSurface(const IntSize& size, Op acityMode opacityMode)
27 {
28 // ASSERT_NOT_REACHED();
29 // return nullptr;
30 return adoptPtr(new UnacceleratedImageBufferSurface(size, opacityMode));
31 }
32
33 virtual ~UnacceleratedSurfaceFactory() { }
34 };
35
36 static void clearHandle(const v8::WeakCallbackInfo<ScopedPersistent<v8::Object>> & data)
37 {
38 data.GetParameter()->clear();
39 }
40
41 } // namespace
42
11 RawPtr<CSSPaintDefinition> CSSPaintDefinition::create(ScriptState* scriptState, v8::Local<v8::Function> constructor, v8::Local<v8::Function> paint) 43 RawPtr<CSSPaintDefinition> CSSPaintDefinition::create(ScriptState* scriptState, v8::Local<v8::Function> constructor, v8::Local<v8::Function> paint)
12 { 44 {
13 return new CSSPaintDefinition(scriptState, constructor, paint); 45 return new CSSPaintDefinition(scriptState, constructor, paint);
14 } 46 }
15 47
16 CSSPaintDefinition::CSSPaintDefinition(ScriptState* scriptState, v8::Local<v8::F unction> constructor, v8::Local<v8::Function> paint) 48 CSSPaintDefinition::CSSPaintDefinition(ScriptState* scriptState, v8::Local<v8::F unction> constructor, v8::Local<v8::Function> paint)
17 : m_scriptState(scriptState) 49 : m_scriptState(scriptState)
18 , m_constructor(scriptState->isolate(), constructor) 50 , m_constructor(scriptState->isolate(), constructor)
19 , m_paint(scriptState->isolate(), paint) 51 , m_paint(scriptState->isolate(), paint)
20 { 52 {
21 } 53 }
22 54
23 CSSPaintDefinition::~CSSPaintDefinition() 55 CSSPaintDefinition::~CSSPaintDefinition()
24 { 56 {
25 } 57 }
26 58
59 PassRefPtr<Image> CSSPaintDefinition::paint(const IntSize& size)
60 {
61 v8::Isolate* isolate = m_scriptState->isolate();
62
63 ScriptState::Scope scope(m_scriptState.get());
64 v8::MicrotasksScope microtasksScope(isolate, v8::MicrotasksScope::kRunMicrot asks);
65
66 v8::Local<v8::Object> instance = m_instance.newLocal(m_scriptState->isolate( ));
67 if (isUndefinedOrNull(instance))
68 return nullptr;
69
70 PaintRenderingContext2D* renderingContext = PaintRenderingContext2D::create(
71 ImageBuffer::create(adoptPtr(new RecordingImageBufferSurface(size, adopt Ptr(new UnacceleratedSurfaceFactory())))));
72 Geometry* geom = Geometry::create(size);
73
74 v8::Local<v8::Value> argv[] = {
75 toV8(renderingContext, m_scriptState->context()->Global(), isolate),
76 toV8(geom, m_scriptState->context()->Global(), isolate)
77 };
78
79 v8::Local<v8::Function> paint = m_paint.newLocal(isolate);
80
81 ScriptForbiddenScope::AllowUserAgentScript allowScripting;
82 v8::TryCatch block(isolate);
83
84 V8ScriptRunner::callFunction(paint, m_scriptState->getExecutionContext(), in stance, 2, argv, isolate);
85
86 if (block.HasCaught()) {
87 block.ReThrow();
88 return nullptr;
89 }
90
91 return PaintGeneratedImage::create(renderingContext->imageBuffer()->getPictu re(), size);
92 }
93
94 v8::Local<v8::Object> CSSPaintDefinition::paintInstance()
95 {
96 v8::Isolate* isolate = m_scriptState->isolate();
97
98 ScriptState::Scope scope(m_scriptState.get());
99 v8::MicrotasksScope microtasksScope(isolate, v8::MicrotasksScope::kDoNotRunM icrotasks);
100
101 if (m_instance.isEmpty()) {
102 v8::Local<v8::Function> constructor = m_constructor.newLocal(isolate);
103 ASSERT(!isUndefinedOrNull(constructor));
104
105 v8::Local<v8::Object> paintInstance;
106 if (!constructor->NewInstance(m_scriptState->context()).ToLocal(&paintIn stance)) {
107 m_scriptState->getExecutionContext()->addConsoleMessage(ConsoleMessa ge::create(JSMessageSource, ErrorMessageLevel, "Failed to create instance of cla ss."));
108 } else {
109 m_instance.set(isolate, paintInstance);
110 m_instance.setWeak(&m_instance, clearHandle);
111 }
112
113 return paintInstance;
114 }
115
116 return m_instance.newLocal(isolate);
117 }
118
27 } // namespace blink 119 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698