| 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/canvas/HTMLCanvasElementModule.h" | 5 #include "modules/canvas/HTMLCanvasElementModule.h" |
| 6 | 6 |
| 7 #include "core/dom/DOMNodeIds.h" | 7 #include "core/dom/DOMNodeIds.h" |
| 8 #include "core/html/canvas/CanvasContextCreationAttributes.h" | 8 #include "core/html/canvas/CanvasContextCreationAttributes.h" |
| 9 #include "core/html/canvas/CanvasRenderingContext.h" | 9 #include "core/html/canvas/CanvasRenderingContext.h" |
| 10 #include "core/offscreencanvas/OffscreenCanvas.h" | 10 #include "core/offscreencanvas/OffscreenCanvas.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 OffscreenCanvas* HTMLCanvasElementModule::transferControlToOffscreen( | 37 OffscreenCanvas* HTMLCanvasElementModule::transferControlToOffscreen( |
| 38 HTMLCanvasElement& canvas, | 38 HTMLCanvasElement& canvas, |
| 39 ExceptionState& exceptionState) { | 39 ExceptionState& exceptionState) { |
| 40 if (canvas.surfaceLayerBridge()) { | 40 if (canvas.surfaceLayerBridge()) { |
| 41 exceptionState.throwDOMException( | 41 exceptionState.throwDOMException( |
| 42 InvalidStateError, | 42 InvalidStateError, |
| 43 "Cannot transfer control from a canvas for more than one time."); | 43 "Cannot transfer control from a canvas for more than one time."); |
| 44 return nullptr; | 44 return nullptr; |
| 45 } | 45 } |
| 46 | 46 |
| 47 if (!canvas.createSurfaceLayer()) { | 47 canvas.createLayer(); |
| 48 exceptionState.throwDOMException( | |
| 49 V8Error, | |
| 50 "Offscreen canvas creation failed due to an internal timeout."); | |
| 51 return nullptr; | |
| 52 } | |
| 53 | 48 |
| 54 return transferControlToOffscreenInternal(canvas, exceptionState); | 49 return transferControlToOffscreenInternal(canvas, exceptionState); |
| 55 } | 50 } |
| 56 | 51 |
| 57 OffscreenCanvas* HTMLCanvasElementModule::transferControlToOffscreenInternal( | 52 OffscreenCanvas* HTMLCanvasElementModule::transferControlToOffscreenInternal( |
| 58 HTMLCanvasElement& canvas, | 53 HTMLCanvasElement& canvas, |
| 59 ExceptionState& exceptionState) { | 54 ExceptionState& exceptionState) { |
| 60 if (canvas.renderingContext()) { | 55 if (canvas.renderingContext()) { |
| 61 exceptionState.throwDOMException( | 56 exceptionState.throwDOMException( |
| 62 InvalidStateError, | 57 InvalidStateError, |
| 63 "Cannot transfer control from a canvas that has a rendering context."); | 58 "Cannot transfer control from a canvas that has a rendering context."); |
| 64 return nullptr; | 59 return nullptr; |
| 65 } | 60 } |
| 66 OffscreenCanvas* offscreenCanvas = | 61 OffscreenCanvas* offscreenCanvas = |
| 67 OffscreenCanvas::create(canvas.width(), canvas.height()); | 62 OffscreenCanvas::create(canvas.width(), canvas.height()); |
| 68 | 63 |
| 69 int canvasId = DOMNodeIds::idForNode(&canvas); | 64 int canvasId = DOMNodeIds::idForNode(&canvas); |
| 70 offscreenCanvas->setPlaceholderCanvasId(canvasId); | 65 offscreenCanvas->setPlaceholderCanvasId(canvasId); |
| 71 canvas.registerPlaceholder(canvasId); | 66 canvas.registerPlaceholder(canvasId); |
| 72 | 67 |
| 73 CanvasSurfaceLayerBridge* bridge = canvas.surfaceLayerBridge(); | 68 CanvasSurfaceLayerBridge* bridge = canvas.surfaceLayerBridge(); |
| 74 if (bridge) { | 69 if (bridge) { |
| 75 // If a bridge exists, it means canvas.createSurfaceLayer() has been called | 70 offscreenCanvas->setFrameSinkId(bridge->getFrameSinkId().client_id(), |
| 76 // and its SurfaceId has been populated as well. | 71 bridge->getFrameSinkId().sink_id()); |
| 77 offscreenCanvas->setSurfaceId( | |
| 78 bridge->getSurfaceId().frame_sink_id().client_id(), | |
| 79 bridge->getSurfaceId().frame_sink_id().sink_id(), | |
| 80 bridge->getSurfaceId().local_frame_id().local_id(), | |
| 81 bridge->getSurfaceId() | |
| 82 .local_frame_id() | |
| 83 .nonce() | |
| 84 .GetHighForSerialization(), | |
| 85 bridge->getSurfaceId() | |
| 86 .local_frame_id() | |
| 87 .nonce() | |
| 88 .GetLowForSerialization()); | |
| 89 } | 72 } |
| 90 return offscreenCanvas; | 73 return offscreenCanvas; |
| 91 } | 74 } |
| 92 } | 75 } |
| OLD | NEW |