OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013, Google Inc. All rights reserved. | 2 * Copyright (c) 2013, Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 13 matching lines...) Expand all Loading... |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #include "platform/graphics/UnacceleratedImageBufferSurface.h" | 31 #include "platform/graphics/UnacceleratedImageBufferSurface.h" |
32 | 32 |
33 #include "platform/graphics/skia/SkiaUtils.h" | 33 #include "platform/graphics/skia/SkiaUtils.h" |
34 #include "third_party/skia/include/core/SkSurface.h" | |
35 #include "wtf/PassRefPtr.h" | 34 #include "wtf/PassRefPtr.h" |
36 | 35 |
37 namespace blink { | 36 namespace blink { |
38 | 37 |
39 UnacceleratedImageBufferSurface::UnacceleratedImageBufferSurface( | 38 UnacceleratedImageBufferSurface::UnacceleratedImageBufferSurface( |
40 const IntSize& size, | 39 const IntSize& size, |
41 OpacityMode opacityMode, | 40 OpacityMode opacityMode, |
42 ImageInitializationMode initializationMode, | 41 ImageInitializationMode initializationMode, |
43 sk_sp<SkColorSpace> colorSpace, | 42 sk_sp<SkColorSpace> colorSpace, |
44 SkColorType colorType) | 43 SkColorType colorType) |
45 : ImageBufferSurface(size, opacityMode, colorSpace, colorType) { | 44 : ImageBufferSurface(size, opacityMode, colorSpace, colorType) { |
46 SkAlphaType alphaType = | 45 SkAlphaType alphaType = |
47 (Opaque == opacityMode) ? kOpaque_SkAlphaType : kPremul_SkAlphaType; | 46 (Opaque == opacityMode) ? kOpaque_SkAlphaType : kPremul_SkAlphaType; |
48 SkImageInfo info = SkImageInfo::Make(size.width(), size.height(), colorType, | 47 SkImageInfo info = SkImageInfo::Make(size.width(), size.height(), colorType, |
49 alphaType, colorSpace); | 48 alphaType, colorSpace); |
50 SkSurfaceProps disableLCDProps(0, kUnknown_SkPixelGeometry); | 49 SkSurfaceProps disableLCDProps(0, kUnknown_SkPixelGeometry); |
51 m_surface = | 50 m_surface = PaintSurface::MakeRaster( |
52 SkSurface::MakeRaster(info, Opaque == opacityMode ? 0 : &disableLCDProps); | 51 info, Opaque == opacityMode ? 0 : &disableLCDProps); |
53 | |
54 if (!m_surface) | |
55 return; | |
56 | 52 |
57 // Always save an initial frame, to support resetting the top level matrix | 53 // Always save an initial frame, to support resetting the top level matrix |
58 // and clip. | 54 // and clip. |
59 m_canvas = WTF::wrapUnique(new PaintCanvas(m_surface->getCanvas())); | 55 if (m_surface) |
60 m_canvas->save(); | 56 m_surface->getCanvas()->save(); |
61 | 57 |
62 if (initializationMode == InitializeImagePixels) | 58 if (initializationMode == InitializeImagePixels) { |
63 clear(); | 59 if (m_surface) |
| 60 clear(); |
| 61 } |
64 } | 62 } |
65 | 63 |
66 UnacceleratedImageBufferSurface::~UnacceleratedImageBufferSurface() {} | 64 UnacceleratedImageBufferSurface::~UnacceleratedImageBufferSurface() {} |
67 | 65 |
68 PaintCanvas* UnacceleratedImageBufferSurface::canvas() { | 66 PaintCanvas* UnacceleratedImageBufferSurface::canvas() { |
69 return m_canvas.get(); | 67 return m_surface->getCanvas(); |
70 } | 68 } |
71 | 69 |
72 bool UnacceleratedImageBufferSurface::isValid() const { | 70 bool UnacceleratedImageBufferSurface::isValid() const { |
73 return m_surface; | 71 return m_surface; |
74 } | 72 } |
75 | 73 |
76 sk_sp<SkImage> UnacceleratedImageBufferSurface::newImageSnapshot( | 74 sk_sp<SkImage> UnacceleratedImageBufferSurface::newImageSnapshot( |
77 AccelerationHint, | 75 AccelerationHint, |
78 SnapshotReason) { | 76 SnapshotReason) { |
79 return m_surface->makeImageSnapshot(); | 77 return m_surface->makeImageSnapshot(); |
80 } | 78 } |
81 | 79 |
82 } // namespace blink | 80 } // namespace blink |
OLD | NEW |