OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "core/offscreencanvas/OffscreenCanvas.h" | 5 #include "core/offscreencanvas/OffscreenCanvas.h" |
6 | 6 |
7 #include "core/dom/ExceptionCode.h" | 7 #include "core/dom/ExceptionCode.h" |
8 #include "core/fileapi/Blob.h" | 8 #include "core/fileapi/Blob.h" |
9 #include "core/frame/ImageBitmap.h" | 9 #include "core/frame/ImageBitmap.h" |
10 #include "core/html/ImageData.h" | 10 #include "core/html/ImageData.h" |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 m_frameDispatcher = WTF::wrapUnique(new OffscreenCanvasFrameDispatcherImpl( | 229 m_frameDispatcher = WTF::wrapUnique(new OffscreenCanvasFrameDispatcherImpl( |
230 this, m_clientId, m_sinkId, m_placeholderCanvasId, m_size.width(), | 230 this, m_clientId, m_sinkId, m_placeholderCanvasId, m_size.width(), |
231 m_size.height())); | 231 m_size.height())); |
232 } | 232 } |
233 return m_frameDispatcher.get(); | 233 return m_frameDispatcher.get(); |
234 } | 234 } |
235 | 235 |
236 ScriptPromise OffscreenCanvas::commit(RefPtr<StaticBitmapImage> image, | 236 ScriptPromise OffscreenCanvas::commit(RefPtr<StaticBitmapImage> image, |
237 bool isWebGLSoftwareRendering, | 237 bool isWebGLSoftwareRendering, |
238 ScriptState* scriptState) { | 238 ScriptState* scriptState) { |
| 239 getOrCreateFrameDispatcher()->setNeedsBeginFrame(true); |
239 if (m_commitPromiseResolver) { | 240 if (m_commitPromiseResolver) { |
240 if (image) { | 241 if (image) { |
241 m_overdrawFrame = std::move(image); | 242 m_overdrawFrame = std::move(image); |
242 m_overdrawFrameIsWebGLSoftwareRendering = isWebGLSoftwareRendering; | 243 m_overdrawFrameIsWebGLSoftwareRendering = isWebGLSoftwareRendering; |
243 } | 244 } |
244 } else { | 245 } else { |
245 m_overdrawFrame = nullptr; | 246 m_overdrawFrame = nullptr; |
246 m_commitPromiseResolver = ScriptPromiseResolver::create(scriptState); | 247 m_commitPromiseResolver = ScriptPromiseResolver::create(scriptState); |
247 m_commitPromiseResolver->keepAliveWhilePending(); | 248 m_commitPromiseResolver->keepAliveWhilePending(); |
248 doCommit(std::move(image), isWebGLSoftwareRendering); | 249 doCommit(std::move(image), isWebGLSoftwareRendering); |
(...skipping 10 matching lines...) Expand all Loading... |
259 | 260 |
260 void OffscreenCanvas::beginFrame() { | 261 void OffscreenCanvas::beginFrame() { |
261 if (m_overdrawFrame) { | 262 if (m_overdrawFrame) { |
262 // if we have an overdraw backlog, push the frame from the backlog | 263 // if we have an overdraw backlog, push the frame from the backlog |
263 // first and save the promise resolution for later. | 264 // first and save the promise resolution for later. |
264 doCommit(std::move(m_overdrawFrame), | 265 doCommit(std::move(m_overdrawFrame), |
265 m_overdrawFrameIsWebGLSoftwareRendering); | 266 m_overdrawFrameIsWebGLSoftwareRendering); |
266 } else if (m_commitPromiseResolver) { | 267 } else if (m_commitPromiseResolver) { |
267 m_commitPromiseResolver->resolve(); | 268 m_commitPromiseResolver->resolve(); |
268 m_commitPromiseResolver.clear(); | 269 m_commitPromiseResolver.clear(); |
| 270 // We need to tell parent frame to stop sending signals on begin frame to |
| 271 // avoid overhead once we resolve the promise. |
| 272 // In the case of overdraw frame (if block), we still need to wait for one |
| 273 // more frame time to resolve the existing promise. |
| 274 getOrCreateFrameDispatcher()->setNeedsBeginFrame(false); |
269 } | 275 } |
270 } | 276 } |
271 | 277 |
272 ScriptPromise OffscreenCanvas::convertToBlob(ScriptState* scriptState, | 278 ScriptPromise OffscreenCanvas::convertToBlob(ScriptState* scriptState, |
273 const ImageEncodeOptions& options, | 279 const ImageEncodeOptions& options, |
274 ExceptionState& exceptionState) { | 280 ExceptionState& exceptionState) { |
275 if (this->isNeutered()) { | 281 if (this->isNeutered()) { |
276 exceptionState.throwDOMException(InvalidStateError, | 282 exceptionState.throwDOMException(InvalidStateError, |
277 "OffscreenCanvas object is detached."); | 283 "OffscreenCanvas object is detached."); |
278 return exceptionState.reject(scriptState); | 284 return exceptionState.reject(scriptState); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 } | 325 } |
320 | 326 |
321 DEFINE_TRACE(OffscreenCanvas) { | 327 DEFINE_TRACE(OffscreenCanvas) { |
322 visitor->trace(m_context); | 328 visitor->trace(m_context); |
323 visitor->trace(m_executionContext); | 329 visitor->trace(m_executionContext); |
324 visitor->trace(m_commitPromiseResolver); | 330 visitor->trace(m_commitPromiseResolver); |
325 EventTargetWithInlineData::trace(visitor); | 331 EventTargetWithInlineData::trace(visitor); |
326 } | 332 } |
327 | 333 |
328 } // namespace blink | 334 } // namespace blink |
OLD | NEW |