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 "core/frame/ImageBitmap.h" | 7 #include "core/frame/ImageBitmap.h" |
8 #include "platform/graphics/GraphicsContext.h" | 8 #include "platform/graphics/GraphicsContext.h" |
9 #include "platform/graphics/StaticBitmapImage.h" | 9 #include "platform/graphics/StaticBitmapImage.h" |
10 #include "third_party/skia/include/core/SkImage.h" | 10 #include "third_party/skia/include/core/SkImage.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 // TODO(junov): crbug.com/585607 Eliminate this readback and use an Exte
rnalTextureLayer | 30 // TODO(junov): crbug.com/585607 Eliminate this readback and use an Exte
rnalTextureLayer |
31 RefPtr<SkSurface> surface = adoptRef(SkSurface::NewRasterN32Premul(skIma
ge->width(), skImage->height())); | 31 RefPtr<SkSurface> surface = adoptRef(SkSurface::NewRasterN32Premul(skIma
ge->width(), skImage->height())); |
32 if (!surface) { | 32 if (!surface) { |
33 // silent failure | 33 // silent failure |
34 m_image.clear(); | 34 m_image.clear(); |
35 return; | 35 return; |
36 } | 36 } |
37 surface->getCanvas()->drawImage(skImage.get(), 0, 0); | 37 surface->getCanvas()->drawImage(skImage.get(), 0, 0); |
38 m_image = StaticBitmapImage::create(adoptRef(surface->newImageSnapshot()
)); | 38 m_image = StaticBitmapImage::create(adoptRef(surface->newImageSnapshot()
)); |
39 } | 39 } |
40 canvas()->didDraw(FloatRect(FloatPoint(), FloatSize(m_image->width(), m_imag
e->height()))); | 40 canvas()->didDraw(FloatRect(FloatPoint(), FloatSize(m_image->defaultConcrete
ObjectSizeWidth(), m_image->defaultConcreteObjectSizeHeight()))); |
41 } | 41 } |
42 | 42 |
43 bool ImageBitmapRenderingContext::paint(GraphicsContext& gc, const IntRect& r) | 43 bool ImageBitmapRenderingContext::paint(GraphicsContext& gc, const IntRect& r) |
44 { | 44 { |
45 if (!m_image) | 45 if (!m_image) |
46 return true; | 46 return true; |
47 | 47 |
48 // With impl-side painting, it is unsafe to use a gpu-backed SkImage | 48 // With impl-side painting, it is unsafe to use a gpu-backed SkImage |
49 ASSERT(!m_image->imageForCurrentFrame()->isTextureBacked()); | 49 ASSERT(!m_image->imageForCurrentFrame()->isTextureBacked()); |
50 gc.drawImage(m_image.get(), r, m_hasAlpha ? SkXfermode::kSrcOver_Mode : SkXf
ermode::kSrc_Mode); | 50 gc.drawImage(m_image.get(), r, m_hasAlpha ? SkXfermode::kSrcOver_Mode : SkXf
ermode::kSrc_Mode); |
51 | 51 |
52 return true; | 52 return true; |
53 } | 53 } |
54 | 54 |
55 PassOwnPtrWillBeRawPtr<CanvasRenderingContext> ImageBitmapRenderingContext::Fact
ory::create(HTMLCanvasElement* canvas, const CanvasContextCreationAttributes& at
trs, Document& document) | 55 PassOwnPtrWillBeRawPtr<CanvasRenderingContext> ImageBitmapRenderingContext::Fact
ory::create(HTMLCanvasElement* canvas, const CanvasContextCreationAttributes& at
trs, Document& document) |
56 { | 56 { |
57 if (!RuntimeEnabledFeatures::experimentalCanvasFeaturesEnabled()) | 57 if (!RuntimeEnabledFeatures::experimentalCanvasFeaturesEnabled()) |
58 return nullptr; | 58 return nullptr; |
59 return adoptPtrWillBeNoop(new ImageBitmapRenderingContext(canvas, attrs, doc
ument)); | 59 return adoptPtrWillBeNoop(new ImageBitmapRenderingContext(canvas, attrs, doc
ument)); |
60 } | 60 } |
61 | 61 |
62 void ImageBitmapRenderingContext::stop() | 62 void ImageBitmapRenderingContext::stop() |
63 { | 63 { |
64 m_image.clear(); | 64 m_image.clear(); |
65 } | 65 } |
66 | 66 |
67 } // blink | 67 } // blink |
OLD | NEW |