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 17 matching lines...) Expand all Loading... |
28 { | 28 { |
29 if (!imageBitmap) { | 29 if (!imageBitmap) { |
30 m_image.release(); | 30 m_image.release(); |
31 return; | 31 return; |
32 } | 32 } |
33 | 33 |
34 m_image = imageBitmap->bitmapImage(); | 34 m_image = imageBitmap->bitmapImage(); |
35 if (!m_image) | 35 if (!m_image) |
36 return; | 36 return; |
37 | 37 |
38 RefPtr<SkImage> skImage = m_image->imageForCurrentFrame(); | 38 sk_sp<SkImage> skImage = m_image->imageForCurrentFrame(); |
39 if (skImage->isTextureBacked()) { | 39 if (skImage->isTextureBacked()) { |
40 // TODO(junov): crbug.com/585607 Eliminate this readback and use an Exte
rnalTextureLayer | 40 // TODO(junov): crbug.com/585607 Eliminate this readback and use an Exte
rnalTextureLayer |
41 sk_sp<SkSurface> surface = SkSurface::MakeRasterN32Premul(skImage->width
(), skImage->height()); | 41 sk_sp<SkSurface> surface = SkSurface::MakeRasterN32Premul(skImage->width
(), skImage->height()); |
42 if (!surface) { | 42 if (!surface) { |
43 // silent failure | 43 // silent failure |
44 m_image.clear(); | 44 m_image.clear(); |
45 return; | 45 return; |
46 } | 46 } |
47 surface->getCanvas()->drawImage(skImage.get(), 0, 0); | 47 surface->getCanvas()->drawImage(skImage, 0, 0); |
48 m_image = StaticBitmapImage::create(fromSkSp(surface->makeImageSnapshot(
))); | 48 m_image = StaticBitmapImage::create(surface->makeImageSnapshot()); |
49 } | 49 } |
50 canvas()->didDraw(FloatRect(FloatPoint(), FloatSize(m_image->width(), m_imag
e->height()))); | 50 canvas()->didDraw(FloatRect(FloatPoint(), FloatSize(m_image->width(), m_imag
e->height()))); |
51 } | 51 } |
52 | 52 |
53 bool ImageBitmapRenderingContext::paint(GraphicsContext& gc, const IntRect& r) | 53 bool ImageBitmapRenderingContext::paint(GraphicsContext& gc, const IntRect& r) |
54 { | 54 { |
55 if (!m_image) | 55 if (!m_image) |
56 return true; | 56 return true; |
57 | 57 |
58 // With impl-side painting, it is unsafe to use a gpu-backed SkImage | 58 // With impl-side painting, it is unsafe to use a gpu-backed SkImage |
59 ASSERT(!m_image->imageForCurrentFrame()->isTextureBacked()); | 59 ASSERT(!m_image->imageForCurrentFrame()->isTextureBacked()); |
60 gc.drawImage(m_image.get(), r, nullptr, creationAttributes().alpha() ? SkXfe
rmode::kSrcOver_Mode : SkXfermode::kSrc_Mode); | 60 gc.drawImage(m_image.get(), r, nullptr, creationAttributes().alpha() ? SkXfe
rmode::kSrcOver_Mode : SkXfermode::kSrc_Mode); |
61 | 61 |
62 return true; | 62 return true; |
63 } | 63 } |
64 | 64 |
65 CanvasRenderingContext* ImageBitmapRenderingContext::Factory::create(HTMLCanvasE
lement* canvas, const CanvasContextCreationAttributes& attrs, Document& document
) | 65 CanvasRenderingContext* ImageBitmapRenderingContext::Factory::create(HTMLCanvasE
lement* canvas, const CanvasContextCreationAttributes& attrs, Document& document
) |
66 { | 66 { |
67 if (!RuntimeEnabledFeatures::experimentalCanvasFeaturesEnabled()) | 67 if (!RuntimeEnabledFeatures::experimentalCanvasFeaturesEnabled()) |
68 return nullptr; | 68 return nullptr; |
69 return new ImageBitmapRenderingContext(canvas, attrs, document); | 69 return new ImageBitmapRenderingContext(canvas, attrs, document); |
70 } | 70 } |
71 | 71 |
72 void ImageBitmapRenderingContext::stop() | 72 void ImageBitmapRenderingContext::stop() |
73 { | 73 { |
74 m_image.clear(); | 74 m_image.clear(); |
75 } | 75 } |
76 | 76 |
77 } // blink | 77 } // blink |
OLD | NEW |