OLD | NEW |
---|---|
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/offscreencanvas2d/OffscreenCanvasRenderingContext2D.h" | 5 #include "modules/offscreencanvas2d/OffscreenCanvasRenderingContext2D.h" |
6 | 6 |
7 #include "bindings/modules/v8/UnionTypesModules.h" | 7 #include "bindings/modules/v8/UnionTypesModules.h" |
8 #include "core/frame/ImageBitmap.h" | |
8 #include "platform/NotImplemented.h" | 9 #include "platform/NotImplemented.h" |
10 #include "platform/graphics/ImageBuffer.h" | |
11 #include "platform/graphics/StaticBitmapImage.h" | |
9 #include "wtf/Assertions.h" | 12 #include "wtf/Assertions.h" |
10 | 13 |
11 #define UNIMPLEMENTED ASSERT_NOT_REACHED | 14 #define UNIMPLEMENTED ASSERT_NOT_REACHED |
12 | 15 |
13 namespace blink { | 16 namespace blink { |
14 | 17 |
15 OffscreenCanvasRenderingContext2D::~OffscreenCanvasRenderingContext2D() | 18 OffscreenCanvasRenderingContext2D::~OffscreenCanvasRenderingContext2D() |
16 { | 19 { |
17 } | 20 } |
18 | 21 |
19 OffscreenCanvasRenderingContext2D::OffscreenCanvasRenderingContext2D(OffscreenCa nvas* canvas, const CanvasContextCreationAttributes& attrs) | 22 OffscreenCanvasRenderingContext2D::OffscreenCanvasRenderingContext2D(OffscreenCa nvas* canvas, const CanvasContextCreationAttributes& attrs) |
20 : OffscreenCanvasRenderingContext(canvas) | 23 : OffscreenCanvasRenderingContext(canvas) |
21 , m_hasAlpha(attrs.alpha()) | 24 , m_hasAlpha(attrs.alpha()) |
22 { | 25 { |
23 } | 26 } |
24 | 27 |
25 DEFINE_TRACE(OffscreenCanvasRenderingContext2D) | 28 DEFINE_TRACE(OffscreenCanvasRenderingContext2D) |
26 { | 29 { |
27 OffscreenCanvasRenderingContext::trace(visitor); | 30 OffscreenCanvasRenderingContext::trace(visitor); |
28 BaseRenderingContext2D::trace(visitor); | 31 BaseRenderingContext2D::trace(visitor); |
29 } | 32 } |
30 | 33 |
31 // BaseRenderingContext2D implementation | 34 // BaseRenderingContext2D implementation |
32 bool OffscreenCanvasRenderingContext2D::originClean() const | 35 bool OffscreenCanvasRenderingContext2D::originClean() const |
33 { | 36 { |
34 notImplemented(); | 37 return m_originClean; |
35 return true; | |
36 } | 38 } |
37 | 39 |
38 void OffscreenCanvasRenderingContext2D::setOriginTainted() | 40 void OffscreenCanvasRenderingContext2D::setOriginTainted() |
39 { | 41 { |
40 notImplemented(); | 42 m_originClean = false; |
41 } | 43 } |
42 | 44 |
43 bool OffscreenCanvasRenderingContext2D::wouldTaintOrigin(CanvasImageSource* sour ce) | 45 bool OffscreenCanvasRenderingContext2D::wouldTaintOrigin(CanvasImageSource* sour ce) |
44 { | 46 { |
45 notImplemented(); | 47 notImplemented(); |
46 return false; | 48 return false; |
47 } | 49 } |
48 | 50 |
49 int OffscreenCanvasRenderingContext2D::width() const | 51 int OffscreenCanvasRenderingContext2D::width() const |
50 { | 52 { |
53 return offscreenCanvas()->width(); | |
54 } | |
55 | |
56 int OffscreenCanvasRenderingContext2D::height() const | |
57 { | |
51 return offscreenCanvas()->height(); | 58 return offscreenCanvas()->height(); |
52 } | 59 } |
53 | 60 |
54 int OffscreenCanvasRenderingContext2D::height() const | |
55 { | |
56 return offscreenCanvas()->width(); | |
57 } | |
58 | |
59 bool OffscreenCanvasRenderingContext2D::hasImageBuffer() const | 61 bool OffscreenCanvasRenderingContext2D::hasImageBuffer() const |
60 { | 62 { |
61 notImplemented(); | 63 return !!m_imageBuffer; |
62 return false; | |
63 } | 64 } |
64 | 65 |
65 ImageBuffer* OffscreenCanvasRenderingContext2D::imageBuffer() const | 66 ImageBuffer* OffscreenCanvasRenderingContext2D::imageBuffer() const |
66 { | 67 { |
67 notImplemented(); | 68 if (!m_imageBuffer) { |
68 return nullptr; | 69 OffscreenCanvasRenderingContext2D* nonConstThis = const_cast<OffscreenCa nvasRenderingContext2D*>(this); |
70 nonConstThis->m_imageBuffer = ImageBuffer::create(IntSize(width(), heigh t()), m_hasAlpha ? NonOpaque : Opaque, InitializeImagePixels); | |
71 // TODO: crbug.com/593349 Restore matrix and clip state on the new Image Buffer. | |
72 } | |
73 | |
74 return m_imageBuffer.get(); | |
69 } | 75 } |
70 | 76 |
71 bool OffscreenCanvasRenderingContext2D::parseColorOrCurrentColor(Color&, const S tring& colorString) const | 77 PassRefPtrWillBeRawPtr<ImageBitmap> OffscreenCanvasRenderingContext2D::transferT oImageBitmap(ExceptionState& exceptionState) |
72 { | 78 { |
73 notImplemented(); | 79 if (!imageBuffer()) |
74 return false; | 80 return nullptr; |
81 RefPtr<SkImage> skImage = m_imageBuffer->newSkImageSnapshot(PreferNoAccelera tion, SnapshotReasonUnknown); | |
Stephen White
2016/03/09 18:54:07
Add a reference to a bug for making OffscreenCanva
| |
82 RefPtr<StaticBitmapImage> image = StaticBitmapImage::create(skImage.release( )); | |
83 m_imageBuffer.clear(); // "Transfer" means no retained buffer | |
84 return ImageBitmap::create(image.release()); | |
85 } | |
86 | |
87 bool OffscreenCanvasRenderingContext2D::parseColorOrCurrentColor(Color& color, c onst String& colorString) const | |
88 { | |
89 return ::blink::parseColorOrCurrentColor(color, colorString, nullptr); | |
75 } | 90 } |
76 | 91 |
77 SkCanvas* OffscreenCanvasRenderingContext2D::drawingCanvas() const | 92 SkCanvas* OffscreenCanvasRenderingContext2D::drawingCanvas() const |
78 { | 93 { |
79 notImplemented(); | 94 ImageBuffer* buffer = imageBuffer(); |
80 return nullptr; | 95 if (!buffer) |
96 return nullptr; | |
97 return imageBuffer()->canvas(); | |
81 } | 98 } |
82 | 99 |
83 SkCanvas* OffscreenCanvasRenderingContext2D::existingDrawingCanvas() const | 100 SkCanvas* OffscreenCanvasRenderingContext2D::existingDrawingCanvas() const |
84 { | 101 { |
85 notImplemented(); | 102 if (!m_imageBuffer) |
86 return nullptr; | 103 return nullptr; |
104 return m_imageBuffer->canvas(); | |
87 } | 105 } |
88 | 106 |
89 void OffscreenCanvasRenderingContext2D::disableDeferral(DisableDeferralReason) | 107 void OffscreenCanvasRenderingContext2D::disableDeferral(DisableDeferralReason) |
90 { | 108 { } |
91 notImplemented(); | |
92 } | |
93 | 109 |
94 AffineTransform OffscreenCanvasRenderingContext2D::baseTransform() const | 110 AffineTransform OffscreenCanvasRenderingContext2D::baseTransform() const |
95 { | 111 { |
96 notImplemented(); | 112 if (!m_imageBuffer) |
97 return 0; | 113 return AffineTransform(); // identity |
114 return m_imageBuffer->baseTransform(); | |
98 } | 115 } |
99 | 116 |
100 void OffscreenCanvasRenderingContext2D::didDraw(const SkIRect& dirtyRect) | 117 void OffscreenCanvasRenderingContext2D::didDraw(const SkIRect& dirtyRect) |
101 { | 118 { } |
102 notImplemented(); | |
103 } | |
104 | 119 |
105 bool OffscreenCanvasRenderingContext2D::stateHasFilter() | 120 bool OffscreenCanvasRenderingContext2D::stateHasFilter() |
106 { | 121 { |
107 notImplemented(); | 122 // TODO: make hasFilter accept nullptr |
Stephen White
2016/03/09 18:54:07
Add a bug reference here?
| |
123 // return state().hasFilter(nullptr, nullptr, IntSize(width(), height()), th is); | |
108 return false; | 124 return false; |
109 } | 125 } |
110 | 126 |
111 SkImageFilter* OffscreenCanvasRenderingContext2D::stateGetFilter() | 127 SkImageFilter* OffscreenCanvasRenderingContext2D::stateGetFilter() |
112 { | 128 { |
113 notImplemented(); | 129 // TODO: make getFilter accept nullptr |
130 // return state().getFilter(nullptr, nullptr, IntSize(width(), height()), th is); | |
114 return nullptr; | 131 return nullptr; |
115 } | 132 } |
116 | 133 |
117 void OffscreenCanvasRenderingContext2D::validateStateStack() | 134 void OffscreenCanvasRenderingContext2D::validateStateStack() |
118 { | 135 { |
119 notImplemented(); | 136 #if ENABLE(ASSERT) |
137 SkCanvas* skCanvas = existingDrawingCanvas(); | |
138 if (skCanvas) { | |
139 ASSERT(static_cast<size_t>(skCanvas->getSaveCount()) == m_stateStack.siz e()); | |
140 } | |
141 #endif | |
120 } | 142 } |
121 | 143 |
122 bool OffscreenCanvasRenderingContext2D::isContextLost() const | 144 bool OffscreenCanvasRenderingContext2D::isContextLost() const |
123 { | 145 { |
124 notImplemented(); | |
125 return false; | 146 return false; |
126 } | 147 } |
127 | 148 |
128 } | 149 } |
OLD | NEW |