OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "modules/csspaint/CSSPaintImageGeneratorImpl.h" |
| 6 |
| 7 #include "core/dom/Document.h" |
| 8 #include "core/frame/LocalDOMWindow.h" |
| 9 #include "modules/csspaint/CSSPaintDefinition.h" |
| 10 #include "modules/csspaint/PaintWorklet.h" |
| 11 #include "modules/csspaint/WindowPaintWorklet.h" |
| 12 #include "platform/graphics/Image.h" |
| 13 |
| 14 namespace blink { |
| 15 |
| 16 PassRefPtrWillBeRawPtr<CSSPaintImageGenerator> CSSPaintImageGeneratorImpl::creat
e(const String& name, Document& document, Observer* observer) |
| 17 { |
| 18 // TODO(ikilpatrick): lazy create worklet global scope. |
| 19 LocalDOMWindow* domWindow = document.domWindow(); |
| 20 PaintWorklet* paintWorklet = WindowPaintWorklet::from(*domWindow).paintWorkl
et(&document); |
| 21 |
| 22 CSSPaintDefinition* paintDefinition = paintWorklet->findDefinition(name); |
| 23 RefPtrWillBeRawPtr<CSSPaintImageGeneratorImpl> generator; |
| 24 if (!paintDefinition) { |
| 25 generator = adoptRefWillBeNoop(new CSSPaintImageGeneratorImpl(observer))
; |
| 26 paintWorklet->addPendingGenerator(name, generator); |
| 27 } else { |
| 28 generator = adoptRefWillBeNoop(new CSSPaintImageGeneratorImpl(paintDefin
ition)); |
| 29 } |
| 30 |
| 31 return generator.release(); |
| 32 } |
| 33 |
| 34 CSSPaintImageGeneratorImpl::CSSPaintImageGeneratorImpl(PassRefPtrWillBeRawPtr<CS
SPaintDefinition> definition) |
| 35 : m_definition(definition) |
| 36 { |
| 37 } |
| 38 |
| 39 CSSPaintImageGeneratorImpl::CSSPaintImageGeneratorImpl(Observer* observer) |
| 40 : m_observer(observer) |
| 41 { |
| 42 } |
| 43 |
| 44 void CSSPaintImageGeneratorImpl::setDefinition(PassRefPtrWillBeRawPtr<CSSPaintDe
finition> definition) |
| 45 { |
| 46 ASSERT(!m_definition); |
| 47 m_definition = definition; |
| 48 |
| 49 ASSERT(m_observer); |
| 50 m_observer->ready(); |
| 51 } |
| 52 |
| 53 PassRefPtr<Image> CSSPaintImageGeneratorImpl::paint(const IntSize& size) |
| 54 { |
| 55 return m_definition ? m_definition->paint(size) : nullptr; |
| 56 } |
| 57 |
| 58 DEFINE_TRACE(CSSPaintImageGeneratorImpl) |
| 59 { |
| 60 visitor->trace(m_definition); |
| 61 CSSPaintImageGenerator::trace(visitor); |
| 62 } |
| 63 |
| 64 } // namespace blink |
OLD | NEW |