| 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/offscreencanvas2d/OffscreenCanvasRenderingContext2D.h" | 5 #include "modules/offscreencanvas2d/OffscreenCanvasRenderingContext2D.h" |
| 6 | 6 |
| 7 #include "bindings/modules/v8/UnionTypesModules.h" | 7 #include "bindings/modules/v8/UnionTypesModules.h" |
| 8 #include "core/frame/ImageBitmap.h" | 8 #include "core/frame/ImageBitmap.h" |
| 9 #include "platform/graphics/ImageBuffer.h" | 9 #include "platform/graphics/ImageBuffer.h" |
| 10 #include "platform/graphics/StaticBitmapImage.h" | 10 #include "platform/graphics/StaticBitmapImage.h" |
| 11 #include "wtf/Assertions.h" | 11 #include "wtf/Assertions.h" |
| 12 | 12 |
| 13 #define UNIMPLEMENTED ASSERT_NOT_REACHED | 13 #define UNIMPLEMENTED ASSERT_NOT_REACHED |
| 14 | 14 |
| 15 namespace blink { | 15 namespace blink { |
| 16 | 16 |
| 17 OffscreenCanvasRenderingContext2D::~OffscreenCanvasRenderingContext2D() | 17 OffscreenCanvasRenderingContext2D::~OffscreenCanvasRenderingContext2D() |
| 18 { | 18 { |
| 19 } | 19 } |
| 20 | 20 |
| 21 OffscreenCanvasRenderingContext2D::OffscreenCanvasRenderingContext2D(OffscreenCa
nvas* canvas, const CanvasContextCreationAttributes& attrs) | 21 OffscreenCanvasRenderingContext2D::OffscreenCanvasRenderingContext2D(OffscreenCa
nvas* canvas, const CanvasContextCreationAttributes& attrs) |
| 22 : OffscreenCanvasRenderingContext(canvas) | 22 : OffscreenCanvasRenderingContext(canvas) |
| 23 , m_hasAlpha(attrs.alpha()) | 23 , m_hasAlpha(attrs.alpha()) |
| 24 { | 24 { |
| 25 } | 25 } |
| 26 | 26 |
| 27 DEFINE_TRACE(OffscreenCanvasRenderingContext2D) | 27 DEFINE_TRACE(OffscreenCanvasRenderingContext2D) |
| 28 { | 28 { |
| 29 visitor->trace(m_executionContext); |
| 29 OffscreenCanvasRenderingContext::trace(visitor); | 30 OffscreenCanvasRenderingContext::trace(visitor); |
| 30 BaseRenderingContext2D::trace(visitor); | 31 BaseRenderingContext2D::trace(visitor); |
| 31 } | 32 } |
| 32 | 33 |
| 33 // BaseRenderingContext2D implementation | 34 // BaseRenderingContext2D implementation |
| 34 bool OffscreenCanvasRenderingContext2D::originClean() const | 35 bool OffscreenCanvasRenderingContext2D::originClean() const |
| 35 { | 36 { |
| 36 return m_originClean; | 37 return m_originClean; |
| 37 } | 38 } |
| 38 | 39 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 return nullptr; | 81 return nullptr; |
| 81 // TODO: crbug.com/593514 Add support for GPU rendering | 82 // TODO: crbug.com/593514 Add support for GPU rendering |
| 82 RefPtr<SkImage> skImage = m_imageBuffer->newSkImageSnapshot(PreferNoAccelera
tion, SnapshotReasonUnknown); | 83 RefPtr<SkImage> skImage = m_imageBuffer->newSkImageSnapshot(PreferNoAccelera
tion, SnapshotReasonUnknown); |
| 83 RefPtr<StaticBitmapImage> image = StaticBitmapImage::create(skImage.release(
)); | 84 RefPtr<StaticBitmapImage> image = StaticBitmapImage::create(skImage.release(
)); |
| 84 m_imageBuffer.clear(); // "Transfer" means no retained buffer | 85 m_imageBuffer.clear(); // "Transfer" means no retained buffer |
| 85 return ImageBitmap::create(image.release()); | 86 return ImageBitmap::create(image.release()); |
| 86 } | 87 } |
| 87 | 88 |
| 88 bool OffscreenCanvasRenderingContext2D::parseColorOrCurrentColor(Color& color, c
onst String& colorString) const | 89 bool OffscreenCanvasRenderingContext2D::parseColorOrCurrentColor(Color& color, c
onst String& colorString) const |
| 89 { | 90 { |
| 91 if (!m_executionContext) |
| 92 const_cast<OffscreenCanvasRenderingContext2D*>(this)->m_executionContext
= ScriptState::current(v8::Isolate::GetCurrent())->getExecutionContext(); |
| 93 |
| 94 DCHECK(m_executionContext); |
| 95 if (m_executionContext->isWorkerGlobalScope()) { |
| 96 return ::blink::parseColorOrCurrentColor(color, colorString, nullptr, m_
executionContext->localCssValuePool()); |
| 97 } |
| 98 |
| 90 return ::blink::parseColorOrCurrentColor(color, colorString, nullptr); | 99 return ::blink::parseColorOrCurrentColor(color, colorString, nullptr); |
| 91 } | 100 } |
| 92 | 101 |
| 93 SkCanvas* OffscreenCanvasRenderingContext2D::drawingCanvas() const | 102 SkCanvas* OffscreenCanvasRenderingContext2D::drawingCanvas() const |
| 94 { | 103 { |
| 95 ImageBuffer* buffer = imageBuffer(); | 104 ImageBuffer* buffer = imageBuffer(); |
| 96 if (!buffer) | 105 if (!buffer) |
| 97 return nullptr; | 106 return nullptr; |
| 98 return imageBuffer()->canvas(); | 107 return imageBuffer()->canvas(); |
| 99 } | 108 } |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 } | 150 } |
| 142 #endif | 151 #endif |
| 143 } | 152 } |
| 144 | 153 |
| 145 bool OffscreenCanvasRenderingContext2D::isContextLost() const | 154 bool OffscreenCanvasRenderingContext2D::isContextLost() const |
| 146 { | 155 { |
| 147 return false; | 156 return false; |
| 148 } | 157 } |
| 149 | 158 |
| 150 } | 159 } |
| OLD | NEW |