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/html/ImageData.h" | 10 #include "core/html/ImageData.h" |
10 #include "core/html/canvas/CanvasAsyncBlobCreator.h" | 11 #include "core/html/canvas/CanvasAsyncBlobCreator.h" |
11 #include "core/html/canvas/CanvasContextCreationAttributes.h" | 12 #include "core/html/canvas/CanvasContextCreationAttributes.h" |
12 #include "core/html/canvas/CanvasRenderingContext.h" | 13 #include "core/html/canvas/CanvasRenderingContext.h" |
13 #include "core/html/canvas/CanvasRenderingContextFactory.h" | 14 #include "core/html/canvas/CanvasRenderingContextFactory.h" |
14 #include "platform/graphics/Image.h" | 15 #include "platform/graphics/Image.h" |
15 #include "platform/graphics/ImageBuffer.h" | 16 #include "platform/graphics/ImageBuffer.h" |
16 #include "platform/graphics/OffscreenCanvasFrameDispatcherImpl.h" | 17 #include "platform/graphics/OffscreenCanvasFrameDispatcherImpl.h" |
17 #include "platform/graphics/StaticBitmapImage.h" | 18 #include "platform/graphics/StaticBitmapImage.h" |
18 #include "platform/image-encoders/ImageEncoderUtils.h" | 19 #include "platform/image-encoders/ImageEncoderUtils.h" |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 } | 105 } |
105 RefPtr<Image> image = m_context->getImage(hint, reason); | 106 RefPtr<Image> image = m_context->getImage(hint, reason); |
106 if (!image) { | 107 if (!image) { |
107 *status = InvalidSourceImageStatus; | 108 *status = InvalidSourceImageStatus; |
108 } else { | 109 } else { |
109 *status = NormalSourceImageStatus; | 110 *status = NormalSourceImageStatus; |
110 } | 111 } |
111 return image.release(); | 112 return image.release(); |
112 } | 113 } |
113 | 114 |
| 115 IntSize OffscreenCanvas::bitmapSourceSize() const { |
| 116 return m_size; |
| 117 } |
| 118 |
| 119 ScriptPromise OffscreenCanvas::createImageBitmap( |
| 120 ScriptState* scriptState, |
| 121 EventTarget&, |
| 122 Optional<IntRect> cropRect, |
| 123 const ImageBitmapOptions& options, |
| 124 ExceptionState& exceptionState) { |
| 125 if ((cropRect && |
| 126 !ImageBitmap::isSourceSizeValid(cropRect->width(), cropRect->height(), |
| 127 exceptionState)) || |
| 128 !ImageBitmap::isSourceSizeValid(bitmapSourceSize().width(), |
| 129 bitmapSourceSize().height(), |
| 130 exceptionState)) |
| 131 return ScriptPromise(); |
| 132 if (!ImageBitmap::isResizeOptionValid(options, exceptionState)) |
| 133 return ScriptPromise(); |
| 134 return ImageBitmapSource::fulfillImageBitmap( |
| 135 scriptState, |
| 136 isPaintable() ? ImageBitmap::create(this, cropRect, options) : nullptr); |
| 137 } |
| 138 |
114 bool OffscreenCanvas::isOpaque() const { | 139 bool OffscreenCanvas::isOpaque() const { |
115 if (!m_context) | 140 if (!m_context) |
116 return false; | 141 return false; |
117 return !m_context->creationAttributes().hasAlpha(); | 142 return !m_context->creationAttributes().hasAlpha(); |
118 } | 143 } |
119 | 144 |
120 CanvasRenderingContext* OffscreenCanvas::getCanvasRenderingContext( | 145 CanvasRenderingContext* OffscreenCanvas::getCanvasRenderingContext( |
121 ScriptState* scriptState, | 146 ScriptState* scriptState, |
122 const String& id, | 147 const String& id, |
123 const CanvasContextCreationAttributes& attributes) { | 148 const CanvasContextCreationAttributes& attributes) { |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 return resolver->promise(); | 268 return resolver->promise(); |
244 } | 269 } |
245 | 270 |
246 DEFINE_TRACE(OffscreenCanvas) { | 271 DEFINE_TRACE(OffscreenCanvas) { |
247 visitor->trace(m_context); | 272 visitor->trace(m_context); |
248 visitor->trace(m_executionContext); | 273 visitor->trace(m_executionContext); |
249 EventTargetWithInlineData::trace(visitor); | 274 EventTargetWithInlineData::trace(visitor); |
250 } | 275 } |
251 | 276 |
252 } // namespace blink | 277 } // namespace blink |
OLD | NEW |