1/*
2 Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
3 Copyright (C) 2014 Igalia S.L.
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19 */
20
21#ifndef BitmapTextureGL_h
22#define BitmapTextureGL_h
23
24#if USE(TEXTURE_MAPPER_GL)
25
26#include "BitmapTexture.h"
27#include "ClipStack.h"
28#include "FilterOperation.h"
29#include "IntSize.h"
30#include "TextureMapperContextAttributes.h"
31#include "TextureMapperGL.h"
32#include "TextureMapperGLHeaders.h"
33
34namespace WebCore {
35
36class TextureMapper;
37class TextureMapperGL;
38class FilterOperation;
39
40class BitmapTextureGL : public BitmapTexture {
41public:
42 static Ref<BitmapTexture> create(const TextureMapperContextAttributes& contextAttributes, const Flags flags = NoFlag, GLint internalFormat = GL_DONT_CARE)
43 {
44 return adoptRef(*new BitmapTextureGL(contextAttributes, flags, internalFormat));
45 }
46
47 virtual ~BitmapTextureGL();
48
49 IntSize size() const override;
50 bool isValid() const override;
51 void didReset() override;
52 void bindAsSurface();
53 void initializeStencil();
54 void initializeDepthBuffer();
55 virtual uint32_t id() const { return m_id; }
56 uint32_t textureTarget() const { return GL_TEXTURE_2D; }
57 IntSize textureSize() const { return m_textureSize; }
58 void updateContents(Image*, const IntRect&, const IntPoint&) override;
59 void updateContents(const void*, const IntRect& target, const IntPoint& sourceOffset, int bytesPerLine) override;
60 bool isBackedByOpenGL() const override { return true; }
61
62 RefPtr<BitmapTexture> applyFilters(TextureMapper&, const FilterOperations&) override;
63 struct FilterInfo {
64 RefPtr<FilterOperation> filter;
65 unsigned pass;
66 RefPtr<BitmapTexture> contentTexture;
67
68 FilterInfo(RefPtr<FilterOperation>&& f = nullptr, unsigned p = 0, RefPtr<BitmapTexture>&& t = nullptr)
69 : filter(WTFMove(f))
70 , pass(p)
71 , contentTexture(WTFMove(t))
72 { }
73 };
74 const FilterInfo* filterInfo() const { return &m_filterInfo; }
75 ClipStack& clipStack() { return m_clipStack; }
76
77 GLint internalFormat() const { return m_internalFormat; }
78
79 void copyFromExternalTexture(GLuint textureID);
80
81 TextureMapperGL::Flags colorConvertFlags() const { return m_colorConvertFlags; }
82
83private:
84 BitmapTextureGL(const TextureMapperContextAttributes&, const Flags, GLint internalFormat);
85
86 GLuint m_id { 0 };
87 IntSize m_textureSize;
88 IntRect m_dirtyRect;
89 GLuint m_fbo { 0 };
90 GLuint m_rbo { 0 };
91 GLuint m_depthBufferObject { 0 };
92 bool m_shouldClear { true };
93 ClipStack m_clipStack;
94 TextureMapperContextAttributes m_contextAttributes;
95 TextureMapperGL::Flags m_colorConvertFlags { TextureMapperGL::NoFlag };
96
97 void clearIfNeeded();
98 void createFboIfNeeded();
99
100 FilterInfo m_filterInfo;
101
102 GLint m_internalFormat;
103 GLenum m_format;
104 GLenum m_type {
105#if OS(DARWIN)
106 GL_UNSIGNED_INT_8_8_8_8_REV
107#else
108 GL_UNSIGNED_BYTE
109#endif
110 };
111};
112
113BitmapTextureGL* toBitmapTextureGL(BitmapTexture*);
114
115}
116
117#endif // USE(TEXTURE_MAPPER_GL)
118
119#endif // BitmapTextureGL_h
120