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/OffscreenCanvasRenderingContext2DOrWebGLRenderingC ontextOrWebGL2RenderingContext.h" | 7 #include "bindings/modules/v8/OffscreenCanvasRenderingContext2DOrWebGLRenderingC ontextOrWebGL2RenderingContext.h" |
8 #include "core/frame/ImageBitmap.h" | 8 #include "core/frame/ImageBitmap.h" |
9 #include "core/frame/Settings.h" | 9 #include "core/frame/Settings.h" |
10 #include "core/workers/WorkerGlobalScope.h" | 10 #include "core/workers/WorkerGlobalScope.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
46 | 46 |
47 void OffscreenCanvasRenderingContext2D::commit(ExceptionState& exceptionState) | 47 void OffscreenCanvasRenderingContext2D::commit(ExceptionState& exceptionState) |
48 { | 48 { |
49 if (getOffscreenCanvas()->getAssociatedCanvasId() < 0) { | 49 if (getOffscreenCanvas()->getAssociatedCanvasId() < 0) { |
50 // If an OffscreenCanvas has no associated canvas Id, it indicates that | 50 // If an OffscreenCanvas has no associated canvas Id, it indicates that |
51 // it is not an OffscreenCanvas created by transfering control from html | 51 // it is not an OffscreenCanvas created by transfering control from html |
52 // canvas. | 52 // canvas. |
53 exceptionState.throwDOMException(InvalidStateError, "Commit() was called on a context whose OffscreenCanvas is not associated with a canvas element."); | 53 exceptionState.throwDOMException(InvalidStateError, "Commit() was called on a context whose OffscreenCanvas is not associated with a canvas element."); |
54 return; | 54 return; |
55 } | 55 } |
56 getOffscreenCanvas()->getOrCreateFrameDispatcher()->dispatchFrame(nullptr); | 56 RefPtr<StaticBitmapImage> image = this->transferToStaticBitmapImage(); |
57 DCHECK(image->isTextureBacked() == this->isAccelerated()); | |
Justin Novosad
2016/09/22 19:27:39
Why this DCHECK? If for some reason this ever bec
xlai (Olivia)
2016/09/22 19:36:18
Done.
| |
58 getOffscreenCanvas()->getOrCreateFrameDispatcher()->dispatchFrame(image.rele ase()); | |
57 } | 59 } |
58 | 60 |
59 // BaseRenderingContext2D implementation | 61 // BaseRenderingContext2D implementation |
60 bool OffscreenCanvasRenderingContext2D::originClean() const | 62 bool OffscreenCanvasRenderingContext2D::originClean() const |
61 { | 63 { |
62 return getOffscreenCanvas()->originClean(); | 64 return getOffscreenCanvas()->originClean(); |
63 } | 65 } |
64 | 66 |
65 void OffscreenCanvasRenderingContext2D::setOriginTainted() | 67 void OffscreenCanvasRenderingContext2D::setOriginTainted() |
66 { | 68 { |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
117 | 119 |
118 if (m_needsMatrixClipRestore) { | 120 if (m_needsMatrixClipRestore) { |
119 restoreMatrixClipStack(m_imageBuffer->canvas()); | 121 restoreMatrixClipStack(m_imageBuffer->canvas()); |
120 nonConstThis->m_needsMatrixClipRestore = false; | 122 nonConstThis->m_needsMatrixClipRestore = false; |
121 } | 123 } |
122 } | 124 } |
123 | 125 |
124 return m_imageBuffer.get(); | 126 return m_imageBuffer.get(); |
125 } | 127 } |
126 | 128 |
127 ImageBitmap* OffscreenCanvasRenderingContext2D::transferToImageBitmap(ExceptionS tate& exceptionState) | 129 bool OffscreenCanvasRenderingContext2D::isAccelerated() const |
130 { | |
131 if (!hasImageBuffer()) | |
132 return false; | |
133 return m_imageBuffer->isAccelerated(); | |
134 } | |
135 | |
136 PassRefPtr<StaticBitmapImage> OffscreenCanvasRenderingContext2D::transferToStati cBitmapImage() | |
128 { | 137 { |
129 if (!imageBuffer()) | 138 if (!imageBuffer()) |
130 return nullptr; | 139 return nullptr; |
131 sk_sp<SkImage> skImage = m_imageBuffer->newSkImageSnapshot(PreferAcceleratio n, SnapshotReasonTransferToImageBitmap); | 140 sk_sp<SkImage> skImage = m_imageBuffer->newSkImageSnapshot(PreferAcceleratio n, SnapshotReasonTransferToImageBitmap); |
132 RefPtr<StaticBitmapImage> image = StaticBitmapImage::create(std::move(skImag e)); | 141 RefPtr<StaticBitmapImage> image = StaticBitmapImage::create(std::move(skImag e)); |
133 image->setOriginClean(this->originClean()); | 142 image->setOriginClean(this->originClean()); |
143 return image.release(); | |
144 } | |
145 | |
146 ImageBitmap* OffscreenCanvasRenderingContext2D::transferToImageBitmap(ExceptionS tate& exceptionState) | |
147 { | |
148 RefPtr<StaticBitmapImage> image = transferToStaticBitmapImage(); | |
149 if (!image) | |
150 return nullptr; | |
134 m_imageBuffer.reset(); // "Transfer" means no retained buffer | 151 m_imageBuffer.reset(); // "Transfer" means no retained buffer |
135 m_needsMatrixClipRestore = true; | 152 m_needsMatrixClipRestore = true; |
136 return ImageBitmap::create(image.release()); | 153 return ImageBitmap::create(image.release()); |
137 } | 154 } |
138 | 155 |
139 PassRefPtr<Image> OffscreenCanvasRenderingContext2D::getImage(AccelerationHint h int, SnapshotReason reason) const | 156 PassRefPtr<Image> OffscreenCanvasRenderingContext2D::getImage(AccelerationHint h int, SnapshotReason reason) const |
140 { | 157 { |
141 if (!imageBuffer()) | 158 if (!imageBuffer()) |
142 return nullptr; | 159 return nullptr; |
143 sk_sp<SkImage> skImage = m_imageBuffer->newSkImageSnapshot(hint, reason); | 160 sk_sp<SkImage> skImage = m_imageBuffer->newSkImageSnapshot(hint, reason); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
210 bool OffscreenCanvasRenderingContext2D::isContextLost() const | 227 bool OffscreenCanvasRenderingContext2D::isContextLost() const |
211 { | 228 { |
212 return false; | 229 return false; |
213 } | 230 } |
214 | 231 |
215 bool OffscreenCanvasRenderingContext2D::isPaintable() const | 232 bool OffscreenCanvasRenderingContext2D::isPaintable() const |
216 { | 233 { |
217 return this->imageBuffer(); | 234 return this->imageBuffer(); |
218 } | 235 } |
219 } | 236 } |
OLD | NEW |