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/imagebitmap/ImageBitmapRenderingContext.h" | 5 #include "modules/imagebitmap/ImageBitmapRenderingContext.h" |
6 | 6 |
7 #include "bindings/modules/v8/RenderingContext.h" | 7 #include "bindings/modules/v8/RenderingContext.h" |
8 #include "core/frame/ImageBitmap.h" | 8 #include "core/frame/ImageBitmap.h" |
9 #include "platform/graphics/GraphicsContext.h" | 9 #include "platform/graphics/GraphicsContext.h" |
10 #include "platform/graphics/StaticBitmapImage.h" | 10 #include "platform/graphics/StaticBitmapImage.h" |
(...skipping 26 matching lines...) Expand all Loading... |
37 if (imageBitmap->isNeutered()) { | 37 if (imageBitmap->isNeutered()) { |
38 exceptionState.throwDOMException(InvalidStateError, | 38 exceptionState.throwDOMException(InvalidStateError, |
39 "The input ImageBitmap has been detached"); | 39 "The input ImageBitmap has been detached"); |
40 return; | 40 return; |
41 } | 41 } |
42 | 42 |
43 m_image = imageBitmap->bitmapImage(); | 43 m_image = imageBitmap->bitmapImage(); |
44 if (!m_image) | 44 if (!m_image) |
45 return; | 45 return; |
46 | 46 |
47 sk_sp<SkImage> skImage = m_image->imageForCurrentFrame(); | 47 // TODO(ccameron): Determine the correct color behavior here. |
| 48 // ImageBitmapRenderingContext. |
| 49 // https://crbug.com/672306 |
| 50 sk_sp<SkImage> skImage = |
| 51 m_image->imageForCurrentFrame(ColorBehavior::transformToGlobalTarget()); |
48 if (skImage->isTextureBacked()) { | 52 if (skImage->isTextureBacked()) { |
49 // TODO(junov): crbug.com/585607 Eliminate this readback and use an | 53 // TODO(junov): crbug.com/585607 Eliminate this readback and use an |
50 // ExternalTextureLayer | 54 // ExternalTextureLayer |
51 sk_sp<SkSurface> surface = | 55 sk_sp<SkSurface> surface = |
52 SkSurface::MakeRasterN32Premul(skImage->width(), skImage->height()); | 56 SkSurface::MakeRasterN32Premul(skImage->width(), skImage->height()); |
53 if (!surface) { | 57 if (!surface) { |
54 // silent failure | 58 // silent failure |
55 m_image.clear(); | 59 m_image.clear(); |
56 return; | 60 return; |
57 } | 61 } |
58 surface->getCanvas()->drawImage(skImage, 0, 0); | 62 surface->getCanvas()->drawImage(skImage, 0, 0); |
59 m_image = StaticBitmapImage::create(surface->makeImageSnapshot()); | 63 m_image = StaticBitmapImage::create(surface->makeImageSnapshot()); |
60 } | 64 } |
61 canvas()->didDraw( | 65 canvas()->didDraw( |
62 FloatRect(FloatPoint(), FloatSize(m_image->width(), m_image->height()))); | 66 FloatRect(FloatPoint(), FloatSize(m_image->width(), m_image->height()))); |
63 imageBitmap->close(); | 67 imageBitmap->close(); |
64 } | 68 } |
65 | 69 |
66 bool ImageBitmapRenderingContext::paint(GraphicsContext& gc, const IntRect& r) { | 70 bool ImageBitmapRenderingContext::paint(GraphicsContext& gc, const IntRect& r) { |
67 if (!m_image) | 71 if (!m_image) |
68 return true; | 72 return true; |
69 | 73 |
70 // With impl-side painting, it is unsafe to use a gpu-backed SkImage | 74 // With impl-side painting, it is unsafe to use a gpu-backed SkImage |
71 ASSERT(!m_image->imageForCurrentFrame()->isTextureBacked()); | 75 DCHECK( |
| 76 !m_image->imageForCurrentFrame(ColorBehavior::transformToGlobalTarget()) |
| 77 ->isTextureBacked()); |
72 gc.drawImage(m_image.get(), r, nullptr, creationAttributes().alpha() | 78 gc.drawImage(m_image.get(), r, nullptr, creationAttributes().alpha() |
73 ? SkBlendMode::kSrcOver | 79 ? SkBlendMode::kSrcOver |
74 : SkBlendMode::kSrc); | 80 : SkBlendMode::kSrc); |
75 | 81 |
76 return true; | 82 return true; |
77 } | 83 } |
78 | 84 |
79 CanvasRenderingContext* ImageBitmapRenderingContext::Factory::create( | 85 CanvasRenderingContext* ImageBitmapRenderingContext::Factory::create( |
80 HTMLCanvasElement* canvas, | 86 HTMLCanvasElement* canvas, |
81 const CanvasContextCreationAttributes& attrs, | 87 const CanvasContextCreationAttributes& attrs, |
82 Document& document) { | 88 Document& document) { |
83 if (!RuntimeEnabledFeatures::experimentalCanvasFeaturesEnabled()) | 89 if (!RuntimeEnabledFeatures::experimentalCanvasFeaturesEnabled()) |
84 return nullptr; | 90 return nullptr; |
85 return new ImageBitmapRenderingContext(canvas, attrs, document); | 91 return new ImageBitmapRenderingContext(canvas, attrs, document); |
86 } | 92 } |
87 | 93 |
88 void ImageBitmapRenderingContext::stop() { | 94 void ImageBitmapRenderingContext::stop() { |
89 m_image.clear(); | 95 m_image.clear(); |
90 } | 96 } |
91 | 97 |
92 } // blink | 98 } // blink |
OLD | NEW |