| 1 | /* |
| 2 | Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) |
| 3 | Copyright (C) 2015 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 TextureMapperGL_h |
| 22 | #define TextureMapperGL_h |
| 23 | |
| 24 | #if USE(TEXTURE_MAPPER_GL) |
| 25 | |
| 26 | #include "ClipStack.h" |
| 27 | #include "FilterOperation.h" |
| 28 | #include "IntSize.h" |
| 29 | #include "TextureMapper.h" |
| 30 | #include "TextureMapperContextAttributes.h" |
| 31 | #include "TextureMapperGLHeaders.h" |
| 32 | #include "TransformationMatrix.h" |
| 33 | |
| 34 | namespace WebCore { |
| 35 | |
| 36 | class TextureMapperGLData; |
| 37 | class TextureMapperShaderProgram; |
| 38 | class FilterOperation; |
| 39 | |
| 40 | // An OpenGL-ES2 implementation of TextureMapper. |
| 41 | class TextureMapperGL : public TextureMapper { |
| 42 | public: |
| 43 | TextureMapperGL(); |
| 44 | virtual ~TextureMapperGL(); |
| 45 | |
| 46 | enum Flag { |
| 47 | NoFlag = 0x00, |
| 48 | ShouldBlend = 0x01, |
| 49 | ShouldFlipTexture = 0x02, |
| 50 | ShouldUseARBTextureRect = 0x04, |
| 51 | ShouldAntialias = 0x08, |
| 52 | ShouldRotateTexture90 = 0x10, |
| 53 | ShouldRotateTexture180 = 0x20, |
| 54 | ShouldRotateTexture270 = 0x40, |
| 55 | ShouldConvertTextureBGRAToRGBA = 0x80, |
| 56 | ShouldConvertTextureARGBToRGBA = 0x100, |
| 57 | ShouldNotBlend = 0x200 |
| 58 | }; |
| 59 | |
| 60 | typedef int Flags; |
| 61 | |
| 62 | // TextureMapper implementation |
| 63 | void drawBorder(const Color&, float borderWidth, const FloatRect&, const TransformationMatrix&) override; |
| 64 | void drawNumber(int number, const Color&, const FloatPoint&, const TransformationMatrix&) override; |
| 65 | void drawTexture(const BitmapTexture&, const FloatRect&, const TransformationMatrix&, float opacity, unsigned exposedEdges) override; |
| 66 | virtual void drawTexture(GLuint texture, Flags, const IntSize& textureSize, const FloatRect& targetRect, const TransformationMatrix& modelViewMatrix, float opacity, unsigned exposedEdges = AllEdges); |
| 67 | void drawSolidColor(const FloatRect&, const TransformationMatrix&, const Color&, bool) override; |
| 68 | void clearColor(const Color&) override; |
| 69 | |
| 70 | void bindSurface(BitmapTexture* surface) override; |
| 71 | BitmapTexture* currentSurface(); |
| 72 | void beginClip(const TransformationMatrix&, const FloatRect&) override; |
| 73 | void beginPainting(PaintFlags = 0) override; |
| 74 | void endPainting() override; |
| 75 | void endClip() override; |
| 76 | IntRect clipBounds() override; |
| 77 | IntSize maxTextureSize() const override { return IntSize(2000, 2000); } |
| 78 | Ref<BitmapTexture> createTexture() override { return createTexture(GL_DONT_CARE); } |
| 79 | Ref<BitmapTexture> createTexture(GLint internalFormat) override; |
| 80 | |
| 81 | void drawFiltered(const BitmapTexture& sourceTexture, const BitmapTexture* contentTexture, const FilterOperation&, int pass); |
| 82 | |
| 83 | void setEnableEdgeDistanceAntialiasing(bool enabled) { m_enableEdgeDistanceAntialiasing = enabled; } |
| 84 | |
| 85 | private: |
| 86 | void drawTexturedQuadWithProgram(TextureMapperShaderProgram&, uint32_t texture, Flags, const IntSize&, const FloatRect&, const TransformationMatrix& modelViewMatrix, float opacity); |
| 87 | void draw(const FloatRect&, const TransformationMatrix& modelViewMatrix, TextureMapperShaderProgram&, GLenum drawingMode, Flags); |
| 88 | |
| 89 | void drawUnitRect(TextureMapperShaderProgram&, GLenum drawingMode); |
| 90 | void drawEdgeTriangles(TextureMapperShaderProgram&); |
| 91 | |
| 92 | bool beginScissorClip(const TransformationMatrix&, const FloatRect&); |
| 93 | void bindDefaultSurface(); |
| 94 | ClipStack& clipStack(); |
| 95 | inline TextureMapperGLData& data() { return *m_data; } |
| 96 | |
| 97 | TextureMapperContextAttributes m_contextAttributes; |
| 98 | TextureMapperGLData* m_data; |
| 99 | ClipStack m_clipStack; |
| 100 | bool m_enableEdgeDistanceAntialiasing; |
| 101 | }; |
| 102 | |
| 103 | } // namespace WebCore |
| 104 | |
| 105 | #endif // USE(TEXTURE_MAPPER_GL) |
| 106 | |
| 107 | #endif // TextureMapperGL_h |
| 108 | |