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

Side by Side Diff: third_party/WebKit/Source/modules/offscreencanvas2d/OffscreenCanvasRenderingContext2D.cpp

Issue 2359723003: Implement OffscreenCanvas Accelerated 2D commit() (Closed)
Patch Set: fix Created 4 years, 2 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/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
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 getOffscreenCanvas()->getOrCreateFrameDispatcher()->dispatchFrame(std::move( image));
57 } 58 }
58 59
59 // BaseRenderingContext2D implementation 60 // BaseRenderingContext2D implementation
60 bool OffscreenCanvasRenderingContext2D::originClean() const 61 bool OffscreenCanvasRenderingContext2D::originClean() const
61 { 62 {
62 return getOffscreenCanvas()->originClean(); 63 return getOffscreenCanvas()->originClean();
63 } 64 }
64 65
65 void OffscreenCanvasRenderingContext2D::setOriginTainted() 66 void OffscreenCanvasRenderingContext2D::setOriginTainted()
66 { 67 {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 118
118 if (m_needsMatrixClipRestore) { 119 if (m_needsMatrixClipRestore) {
119 restoreMatrixClipStack(m_imageBuffer->canvas()); 120 restoreMatrixClipStack(m_imageBuffer->canvas());
120 nonConstThis->m_needsMatrixClipRestore = false; 121 nonConstThis->m_needsMatrixClipRestore = false;
121 } 122 }
122 } 123 }
123 124
124 return m_imageBuffer.get(); 125 return m_imageBuffer.get();
125 } 126 }
126 127
127 ImageBitmap* OffscreenCanvasRenderingContext2D::transferToImageBitmap(ExceptionS tate& exceptionState) 128 bool OffscreenCanvasRenderingContext2D::isAccelerated() const
xidachen 2016/09/22 19:42:33 Is there a reason to keep this function here, sinc
xlai (Olivia) 2016/09/22 19:53:51 Done.
129 {
130 if (!hasImageBuffer())
131 return false;
132 return m_imageBuffer->isAccelerated();
133 }
134
135 RefPtr<StaticBitmapImage> OffscreenCanvasRenderingContext2D::transferToStaticBit mapImage()
128 { 136 {
129 if (!imageBuffer()) 137 if (!imageBuffer())
130 return nullptr; 138 return nullptr;
131 sk_sp<SkImage> skImage = m_imageBuffer->newSkImageSnapshot(PreferAcceleratio n, SnapshotReasonTransferToImageBitmap); 139 sk_sp<SkImage> skImage = m_imageBuffer->newSkImageSnapshot(PreferAcceleratio n, SnapshotReasonTransferToImageBitmap);
132 RefPtr<StaticBitmapImage> image = StaticBitmapImage::create(std::move(skImag e)); 140 RefPtr<StaticBitmapImage> image = StaticBitmapImage::create(std::move(skImag e));
133 image->setOriginClean(this->originClean()); 141 image->setOriginClean(this->originClean());
142 return image;
143 }
144
145 ImageBitmap* OffscreenCanvasRenderingContext2D::transferToImageBitmap(ExceptionS tate& exceptionState)
146 {
147 RefPtr<StaticBitmapImage> image = transferToStaticBitmapImage();
148 if (!image)
149 return nullptr;
134 m_imageBuffer.reset(); // "Transfer" means no retained buffer 150 m_imageBuffer.reset(); // "Transfer" means no retained buffer
135 m_needsMatrixClipRestore = true; 151 m_needsMatrixClipRestore = true;
136 return ImageBitmap::create(image.release()); 152 return ImageBitmap::create(std::move(image));
137 } 153 }
138 154
139 PassRefPtr<Image> OffscreenCanvasRenderingContext2D::getImage(AccelerationHint h int, SnapshotReason reason) const 155 PassRefPtr<Image> OffscreenCanvasRenderingContext2D::getImage(AccelerationHint h int, SnapshotReason reason) const
140 { 156 {
141 if (!imageBuffer()) 157 if (!imageBuffer())
142 return nullptr; 158 return nullptr;
143 sk_sp<SkImage> skImage = m_imageBuffer->newSkImageSnapshot(hint, reason); 159 sk_sp<SkImage> skImage = m_imageBuffer->newSkImageSnapshot(hint, reason);
144 RefPtr<StaticBitmapImage> image = StaticBitmapImage::create(std::move(skImag e)); 160 RefPtr<StaticBitmapImage> image = StaticBitmapImage::create(std::move(skImag e));
145 return image; 161 return image;
146 } 162 }
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 bool OffscreenCanvasRenderingContext2D::isContextLost() const 226 bool OffscreenCanvasRenderingContext2D::isContextLost() const
211 { 227 {
212 return false; 228 return false;
213 } 229 }
214 230
215 bool OffscreenCanvasRenderingContext2D::isPaintable() const 231 bool OffscreenCanvasRenderingContext2D::isPaintable() const
216 { 232 {
217 return this->imageBuffer(); 233 return this->imageBuffer();
218 } 234 }
219 } 235 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698