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 19 matching lines...) Expand all Loading... |
30 CanvasRenderingContext* context = | 30 CanvasRenderingContext* context = |
31 canvas.getCanvasRenderingContext(type, attributes); | 31 canvas.getCanvasRenderingContext(type, attributes); |
32 if (context) { | 32 if (context) { |
33 context->setCanvasGetContextResult(result); | 33 context->setCanvasGetContextResult(result); |
34 } | 34 } |
35 } | 35 } |
36 | 36 |
37 OffscreenCanvas* HTMLCanvasElementModule::transferControlToOffscreen( | 37 OffscreenCanvas* HTMLCanvasElementModule::transferControlToOffscreen( |
38 HTMLCanvasElement& canvas, | 38 HTMLCanvasElement& canvas, |
39 ExceptionState& exceptionState) { | 39 ExceptionState& exceptionState) { |
40 if (!canvas.createSurfaceLayer()) { | 40 int canvasId = DOMNodeIds::idForNode(&canvas); |
| 41 if (!canvas.createSurfaceLayer(canvasId)) { |
41 exceptionState.throwDOMException( | 42 exceptionState.throwDOMException( |
42 V8Error, | 43 V8Error, |
43 "Offscreen canvas creation failed due to an internal timeout."); | 44 "Offscreen canvas creation failed due to an internal timeout."); |
44 return nullptr; | 45 return nullptr; |
45 } | 46 } |
46 | 47 |
47 return transferControlToOffscreenInternal(canvas, exceptionState); | 48 return transferControlToOffscreenInternal(canvas, canvasId, exceptionState); |
48 } | 49 } |
49 | 50 |
50 OffscreenCanvas* HTMLCanvasElementModule::transferControlToOffscreenInternal( | 51 OffscreenCanvas* HTMLCanvasElementModule::transferControlToOffscreenInternal( |
51 HTMLCanvasElement& canvas, | 52 HTMLCanvasElement& canvas, |
| 53 int canvasId, |
52 ExceptionState& exceptionState) { | 54 ExceptionState& exceptionState) { |
53 if (canvas.renderingContext()) { | 55 if (canvas.renderingContext()) { |
54 exceptionState.throwDOMException( | 56 exceptionState.throwDOMException( |
55 InvalidStateError, | 57 InvalidStateError, |
56 "Cannot transfer control from a canvas that has a rendering context."); | 58 "Cannot transfer control from a canvas that has a rendering context."); |
57 return nullptr; | 59 return nullptr; |
58 } | 60 } |
59 OffscreenCanvas* offscreenCanvas = | 61 OffscreenCanvas* offscreenCanvas = |
60 OffscreenCanvas::create(canvas.width(), canvas.height()); | 62 OffscreenCanvas::create(canvas.width(), canvas.height()); |
61 offscreenCanvas->setAssociatedCanvasId(DOMNodeIds::idForNode(&canvas)); | 63 offscreenCanvas->setAssociatedCanvasId(canvasId); |
62 | 64 |
63 CanvasSurfaceLayerBridge* bridge = canvas.surfaceLayerBridge(); | 65 CanvasSurfaceLayerBridge* bridge = canvas.surfaceLayerBridge(); |
64 if (bridge) { | 66 if (bridge) { |
65 // If a bridge exists, it means canvas.createSurfaceLayer() has been called | 67 // If a bridge exists, it means canvas.createSurfaceLayer() has been called |
66 // and its SurfaceId has been populated as well. | 68 // and its SurfaceId has been populated as well. |
67 offscreenCanvas->setSurfaceId( | 69 offscreenCanvas->setSurfaceId( |
68 bridge->getSurfaceId().frame_sink_id().client_id(), | 70 bridge->getSurfaceId().frame_sink_id().client_id(), |
69 bridge->getSurfaceId().frame_sink_id().sink_id(), | 71 bridge->getSurfaceId().frame_sink_id().sink_id(), |
70 bridge->getSurfaceId().local_frame_id().local_id(), | 72 bridge->getSurfaceId().local_frame_id().local_id(), |
71 bridge->getSurfaceId().local_frame_id().nonce()); | 73 bridge->getSurfaceId().local_frame_id().nonce()); |
72 } | 74 } |
73 return offscreenCanvas; | 75 return offscreenCanvas; |
74 } | 76 } |
75 } | 77 } |
OLD | NEW |