1 | /* |
2 | * Copyright (C) 2015 Igalia S.L. |
3 | * |
4 | * Redistribution and use in source and binary forms, with or without |
5 | * modification, are permitted provided that the following conditions |
6 | * are met: |
7 | * 1. Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. |
9 | * 2. Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. |
12 | * |
13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' |
14 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
15 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS |
17 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
18 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
19 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
20 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
21 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
22 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
23 | * THE POSSIBILITY OF SUCH DAMAGE. |
24 | */ |
25 | |
26 | #include "config.h" |
27 | #include "TextureMapperPlatformLayerBuffer.h" |
28 | |
29 | #if USE(COORDINATED_GRAPHICS) |
30 | |
31 | #include "FloatRect.h" |
32 | #include "NotImplemented.h" |
33 | |
34 | namespace WebCore { |
35 | |
36 | TextureMapperPlatformLayerBuffer::TextureMapperPlatformLayerBuffer(RefPtr<BitmapTexture>&& texture, TextureMapperGL::Flags flags) |
37 | : m_texture(WTFMove(texture)) |
38 | , m_textureID(0) |
39 | , m_extraFlags(flags) |
40 | , m_hasManagedTexture(true) |
41 | { |
42 | } |
43 | |
44 | TextureMapperPlatformLayerBuffer::TextureMapperPlatformLayerBuffer(GLuint textureID, const IntSize& size, TextureMapperGL::Flags flags, GLint internalFormat) |
45 | : m_textureID(textureID) |
46 | , m_size(size) |
47 | , m_internalFormat(internalFormat) |
48 | , m_extraFlags(flags) |
49 | , m_hasManagedTexture(false) |
50 | { |
51 | } |
52 | |
53 | bool TextureMapperPlatformLayerBuffer::canReuseWithoutReset(const IntSize& size, GLint internalFormat) |
54 | { |
55 | return m_texture && (m_texture->size() == size) && (static_cast<BitmapTextureGL*>(m_texture.get())->internalFormat() == internalFormat || internalFormat == GL_DONT_CARE); |
56 | } |
57 | |
58 | std::unique_ptr<TextureMapperPlatformLayerBuffer> TextureMapperPlatformLayerBuffer::clone() |
59 | { |
60 | if (m_hasManagedTexture || !m_textureID) { |
61 | notImplemented(); |
62 | return nullptr; |
63 | } |
64 | auto texture = BitmapTextureGL::create(TextureMapperContextAttributes::get(), m_internalFormat); |
65 | texture->reset(m_size); |
66 | static_cast<BitmapTextureGL&>(texture.get()).copyFromExternalTexture(m_textureID); |
67 | return std::make_unique<TextureMapperPlatformLayerBuffer>(WTFMove(texture), m_extraFlags); |
68 | } |
69 | |
70 | void TextureMapperPlatformLayerBuffer::paintToTextureMapper(TextureMapper& textureMapper, const FloatRect& targetRect, const TransformationMatrix& modelViewMatrix, float opacity) |
71 | { |
72 | TextureMapperGL& texmapGL = static_cast<TextureMapperGL&>(textureMapper); |
73 | |
74 | if (m_hasManagedTexture) { |
75 | ASSERT(m_texture); |
76 | BitmapTextureGL* textureGL = static_cast<BitmapTextureGL*>(m_texture.get()); |
77 | texmapGL.drawTexture(textureGL->id(), m_extraFlags | textureGL->colorConvertFlags(), textureGL->size(), targetRect, modelViewMatrix, opacity); |
78 | return; |
79 | } |
80 | |
81 | if (m_extraFlags & TextureMapperGL::ShouldNotBlend) { |
82 | ASSERT(!m_texture); |
83 | if (m_holePunchClient) |
84 | m_holePunchClient->setVideoRectangle(enclosingIntRect(modelViewMatrix.mapRect(targetRect))); |
85 | texmapGL.drawSolidColor(targetRect, modelViewMatrix, Color(0, 0, 0, 0), false); |
86 | return; |
87 | } |
88 | |
89 | ASSERT(m_textureID); |
90 | texmapGL.drawTexture(m_textureID, m_extraFlags, m_size, targetRect, modelViewMatrix, opacity); |
91 | } |
92 | |
93 | } // namespace WebCore |
94 | |
95 | #endif // USE(COORDINATED_GRAPHICS) |
96 | |