| 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 "platform/NotImplemented.h" | 9 #include "platform/NotImplemented.h" |
| 10 #include "platform/graphics/ImageBuffer.h" |
| 11 #include "platform/graphics/StaticBitmapImage.h" |
| 9 #include "wtf/Assertions.h" | 12 #include "wtf/Assertions.h" |
| 10 | 13 |
| 11 #define UNIMPLEMENTED ASSERT_NOT_REACHED | 14 #define UNIMPLEMENTED ASSERT_NOT_REACHED |
| 12 | 15 |
| 13 namespace blink { | 16 namespace blink { |
| 14 | 17 |
| 15 OffscreenCanvasRenderingContext2D::~OffscreenCanvasRenderingContext2D() | 18 OffscreenCanvasRenderingContext2D::~OffscreenCanvasRenderingContext2D() |
| 16 { | 19 { |
| 17 } | 20 } |
| 18 | 21 |
| 19 OffscreenCanvasRenderingContext2D::OffscreenCanvasRenderingContext2D(OffscreenCa
nvas* canvas, const CanvasContextCreationAttributes& attrs) | 22 OffscreenCanvasRenderingContext2D::OffscreenCanvasRenderingContext2D(OffscreenCa
nvas* canvas, const CanvasContextCreationAttributes& attrs) |
| 20 : OffscreenCanvasRenderingContext(canvas) | 23 : OffscreenCanvasRenderingContext(canvas) |
| 21 , m_hasAlpha(attrs.alpha()) | 24 , m_hasAlpha(attrs.alpha()) |
| 22 { | 25 { |
| 23 } | 26 } |
| 24 | 27 |
| 25 DEFINE_TRACE(OffscreenCanvasRenderingContext2D) | 28 DEFINE_TRACE(OffscreenCanvasRenderingContext2D) |
| 26 { | 29 { |
| 27 OffscreenCanvasRenderingContext::trace(visitor); | 30 OffscreenCanvasRenderingContext::trace(visitor); |
| 28 BaseRenderingContext2D::trace(visitor); | 31 BaseRenderingContext2D::trace(visitor); |
| 29 } | 32 } |
| 30 | 33 |
| 31 // BaseRenderingContext2D implementation | 34 // BaseRenderingContext2D implementation |
| 32 bool OffscreenCanvasRenderingContext2D::originClean() const | 35 bool OffscreenCanvasRenderingContext2D::originClean() const |
| 33 { | 36 { |
| 34 notImplemented(); | 37 return m_originClean; |
| 35 return true; | |
| 36 } | 38 } |
| 37 | 39 |
| 38 void OffscreenCanvasRenderingContext2D::setOriginTainted() | 40 void OffscreenCanvasRenderingContext2D::setOriginTainted() |
| 39 { | 41 { |
| 40 notImplemented(); | 42 m_originClean = false; |
| 41 } | 43 } |
| 42 | 44 |
| 43 bool OffscreenCanvasRenderingContext2D::wouldTaintOrigin(CanvasImageSource* sour
ce) | 45 bool OffscreenCanvasRenderingContext2D::wouldTaintOrigin(CanvasImageSource* sour
ce) |
| 44 { | 46 { |
| 45 notImplemented(); | 47 notImplemented(); |
| 46 return false; | 48 return false; |
| 47 } | 49 } |
| 48 | 50 |
| 49 int OffscreenCanvasRenderingContext2D::width() const | 51 int OffscreenCanvasRenderingContext2D::width() const |
| 50 { | 52 { |
| 51 return offscreenCanvas()->height(); | 53 return offscreenCanvas()->height(); |
| 52 } | 54 } |
| 53 | 55 |
| 54 int OffscreenCanvasRenderingContext2D::height() const | 56 int OffscreenCanvasRenderingContext2D::height() const |
| 55 { | 57 { |
| 56 return offscreenCanvas()->width(); | 58 return offscreenCanvas()->width(); |
| 57 } | 59 } |
| 58 | 60 |
| 59 bool OffscreenCanvasRenderingContext2D::hasImageBuffer() const | 61 bool OffscreenCanvasRenderingContext2D::hasImageBuffer() const |
| 60 { | 62 { |
| 61 notImplemented(); | 63 return !!m_imageBuffer; |
| 62 return false; | |
| 63 } | 64 } |
| 64 | 65 |
| 65 ImageBuffer* OffscreenCanvasRenderingContext2D::imageBuffer() const | 66 ImageBuffer* OffscreenCanvasRenderingContext2D::imageBuffer() const |
| 66 { | 67 { |
| 67 notImplemented(); | 68 if (!m_imageBuffer) { |
| 68 return nullptr; | 69 OffscreenCanvasRenderingContext2D* nonConstThis = const_cast<OffscreenCa
nvasRenderingContext2D*>(this); |
| 70 nonConstThis->m_imageBuffer = ImageBuffer::create(IntSize(width(), heigh
t()), m_hasAlpha ? NonOpaque : Opaque, InitializeImagePixels); |
| 71 } |
| 72 |
| 73 return m_imageBuffer.get(); |
| 69 } | 74 } |
| 70 | 75 |
| 71 bool OffscreenCanvasRenderingContext2D::parseColorOrCurrentColor(Color&, const S
tring& colorString) const | 76 PassRefPtrWillBeRawPtr<ImageBitmap> OffscreenCanvasRenderingContext2D::transferT
oImageBitmap(ExceptionState& exceptionState) |
| 72 { | 77 { |
| 73 notImplemented(); | 78 RefPtr<SkImage> skImage = m_imageBuffer->newSkImageSnapshot(PreferNoAccelera
tion, SnapshotReasonUnknown); |
| 74 return false; | 79 RefPtr<StaticBitmapImage> image = StaticBitmapImage::create(skImage.release(
)); |
| 80 return ImageBitmap::create(image.release()); |
| 81 } |
| 82 |
| 83 bool OffscreenCanvasRenderingContext2D::parseColorOrCurrentColor(Color& color, c
onst String& colorString) const |
| 84 { |
| 85 return ::blink::parseColorOrCurrentColor(color, colorString, nullptr); |
| 75 } | 86 } |
| 76 | 87 |
| 77 SkCanvas* OffscreenCanvasRenderingContext2D::drawingCanvas() const | 88 SkCanvas* OffscreenCanvasRenderingContext2D::drawingCanvas() const |
| 78 { | 89 { |
| 79 notImplemented(); | 90 ImageBuffer* buffer = imageBuffer(); |
| 80 return nullptr; | 91 if (!buffer) |
| 92 return nullptr; |
| 93 return imageBuffer()->canvas(); |
| 81 } | 94 } |
| 82 | 95 |
| 83 SkCanvas* OffscreenCanvasRenderingContext2D::existingDrawingCanvas() const | 96 SkCanvas* OffscreenCanvasRenderingContext2D::existingDrawingCanvas() const |
| 84 { | 97 { |
| 85 notImplemented(); | 98 if (!m_imageBuffer) |
| 86 return nullptr; | 99 return nullptr; |
| 100 return m_imageBuffer->canvas(); |
| 87 } | 101 } |
| 88 | 102 |
| 89 void OffscreenCanvasRenderingContext2D::disableDeferral(DisableDeferralReason) | 103 void OffscreenCanvasRenderingContext2D::disableDeferral(DisableDeferralReason) |
| 90 { | 104 { } |
| 91 notImplemented(); | |
| 92 } | |
| 93 | 105 |
| 94 AffineTransform OffscreenCanvasRenderingContext2D::baseTransform() const | 106 AffineTransform OffscreenCanvasRenderingContext2D::baseTransform() const |
| 95 { | 107 { |
| 96 notImplemented(); | 108 if (!m_imageBuffer) |
| 97 return 0; | 109 return AffineTransform(); // identity |
| 110 return m_imageBuffer->baseTransform(); |
| 98 } | 111 } |
| 99 | 112 |
| 100 void OffscreenCanvasRenderingContext2D::didDraw(const SkIRect& dirtyRect) | 113 void OffscreenCanvasRenderingContext2D::didDraw(const SkIRect& dirtyRect) |
| 101 { | 114 { } |
| 102 notImplemented(); | |
| 103 } | |
| 104 | 115 |
| 105 bool OffscreenCanvasRenderingContext2D::stateHasFilter() | 116 bool OffscreenCanvasRenderingContext2D::stateHasFilter() |
| 106 { | 117 { |
| 107 notImplemented(); | 118 return state().hasFilter(nullptr, nullptr, IntSize(width(), height()), this)
; |
| 108 return false; | |
| 109 } | 119 } |
| 110 | 120 |
| 111 SkImageFilter* OffscreenCanvasRenderingContext2D::stateGetFilter() | 121 SkImageFilter* OffscreenCanvasRenderingContext2D::stateGetFilter() |
| 112 { | 122 { |
| 113 notImplemented(); | 123 return state().getFilter(nullptr, nullptr, IntSize(width(), height()), this)
; |
| 114 return nullptr; | |
| 115 } | 124 } |
| 116 | 125 |
| 117 void OffscreenCanvasRenderingContext2D::validateStateStack() | 126 void OffscreenCanvasRenderingContext2D::validateStateStack() |
| 118 { | 127 { |
| 119 notImplemented(); | 128 #if ENABLE(ASSERT) |
| 129 SkCanvas* skCanvas = existingDrawingCanvas(); |
| 130 if (skCanvas) { |
| 131 ASSERT(static_cast<size_t>(skCanvas->getSaveCount()) == m_stateStack.siz
e()); |
| 132 } |
| 133 #endif |
| 120 } | 134 } |
| 121 | 135 |
| 122 bool OffscreenCanvasRenderingContext2D::isContextLost() const | 136 bool OffscreenCanvasRenderingContext2D::isContextLost() const |
| 123 { | 137 { |
| 124 notImplemented(); | |
| 125 return false; | 138 return false; |
| 126 } | 139 } |
| 127 | 140 |
| 128 } | 141 } |
| OLD | NEW |