1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
|
/*
Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#pragma once
#if USE(TEXTURE_MAPPER)
#include "BitmapTexturePool.h"
#include "ClipStack.h"
#include "Color.h"
#include "FilterOperation.h"
#include "IntRect.h"
#include "IntSize.h"
#include "TextureMapperGLHeaders.h"
#include "TextureMapperGPUBuffer.h"
#include "TransformationMatrix.h"
#include <array>
#include <wtf/OptionSet.h>
#include <wtf/TZoneMalloc.h>
#include <wtf/Vector.h>
// TextureMapper is a mechanism that enables hardware acceleration of CSS animations (accelerated compositing) without
// a need for a platform specific scene-graph library like CoreAnimation.
typedef void *EGLImage;
namespace WebCore {
class ClipPath;
class TextureMapperGLData;
class TextureMapperGPUBuffer;
class TextureMapperShaderProgram;
class FilterOperations;
class FloatRoundedRect;
enum class TextureMapperFlags : uint16_t;
class TextureMapper {
WTF_MAKE_TZONE_ALLOCATED(TextureMapper);
public:
enum class WrapMode : uint8_t {
Stretch,
Repeat
};
WEBCORE_EXPORT static std::unique_ptr<TextureMapper> create();
TextureMapper();
WEBCORE_EXPORT ~TextureMapper();
enum class AllEdgesExposed : bool { No, Yes };
enum class FlipY : bool { No, Yes };
WEBCORE_EXPORT void drawBorder(const Color&, float borderWidth, const FloatRect&, const TransformationMatrix&);
void drawNumber(int number, const Color&, const FloatPoint&, const TransformationMatrix&);
WEBCORE_EXPORT void drawTexture(const BitmapTexture&, const FloatRect& target, const TransformationMatrix& modelViewMatrix = TransformationMatrix(), float opacity = 1.0f, AllEdgesExposed = AllEdgesExposed::Yes);
void drawTexture(GLuint texture, OptionSet<TextureMapperFlags>, const FloatRect& targetRect, const TransformationMatrix& modelViewMatrix, float opacity, AllEdgesExposed = AllEdgesExposed::Yes);
void drawTexturePlanarYUV(const std::array<GLuint, 3>& textures, const std::array<GLfloat, 16>& yuvToRgbMatrix, OptionSet<TextureMapperFlags>, const FloatRect& targetRect, const TransformationMatrix& modelViewMatrix, float opacity, std::optional<GLuint> alphaPlane, AllEdgesExposed = AllEdgesExposed::Yes);
void drawTextureSemiPlanarYUV(const std::array<GLuint, 2>& textures, bool uvReversed, const std::array<GLfloat, 16>& yuvToRgbMatrix, OptionSet<TextureMapperFlags>, const FloatRect& targetRect, const TransformationMatrix& modelViewMatrix, float opacity, AllEdgesExposed = AllEdgesExposed::Yes);
void drawTexturePackedYUV(GLuint texture, const std::array<GLfloat, 16>& yuvToRgbMatrix, OptionSet<TextureMapperFlags>, const FloatRect& targetRect, const TransformationMatrix& modelViewMatrix, float opacity, AllEdgesExposed = AllEdgesExposed::Yes);
void drawTextureExternalOES(GLuint texture, OptionSet<TextureMapperFlags>, const FloatRect&, const TransformationMatrix& modelViewMatrix, float opacity);
void drawSolidColor(const FloatRect&, const TransformationMatrix&, const Color&, bool);
void clearColor(const Color&);
// makes a surface the target for the following drawTexture calls.
void bindSurface(BitmapTexture* surface);
BitmapTexture* currentSurface();
void beginClip(const TransformationMatrix&, const FloatRoundedRect&);
void beginClip(const TransformationMatrix&, const ClipPath&);
WEBCORE_EXPORT void beginPainting(FlipY = FlipY::No, BitmapTexture* = nullptr);
WEBCORE_EXPORT void endPainting();
void endClip();
IntRect clipBounds();
IntSize maxTextureSize() const;
void setDepthRange(double zNear, double zFar);
std::pair<double, double> depthRange() const;
void setMaskMode(bool m) { m_isMaskMode = m; }
void setWrapMode(WrapMode m) { m_wrapMode = m; }
void setPatternTransform(const TransformationMatrix& p) { m_patternTransform = p; }
RefPtr<BitmapTexture> applyFilters(RefPtr<BitmapTexture>&, const FilterOperations&, bool defersLastPass);
WEBCORE_EXPORT Ref<BitmapTexture> acquireTextureFromPool(const IntSize&, OptionSet<BitmapTexture::Flags>);
#if USE(GBM)
WEBCORE_EXPORT Ref<BitmapTexture> createTextureForImage(EGLImage, OptionSet<BitmapTexture::Flags>);
#endif
#if USE(GRAPHICS_LAYER_WC)
WEBCORE_EXPORT void releaseUnusedTexturesNow();
#endif
Ref<TextureMapperGPUBuffer> acquireBufferFromPool(size_t, TextureMapperGPUBuffer::Type);
private:
bool isInMaskMode() const { return m_isMaskMode; }
const TransformationMatrix& patternTransform() const { return m_patternTransform; }
enum class Direction { X, Y };
RefPtr<BitmapTexture> applyFilter(RefPtr<BitmapTexture>&, const Ref<const FilterOperation>&, bool defersLastPass);
RefPtr<BitmapTexture> applyBlurFilter(RefPtr<BitmapTexture>&, const BlurFilterOperation&);
RefPtr<BitmapTexture> applyDropShadowFilter(RefPtr<BitmapTexture>&, const DropShadowFilterOperation&);
RefPtr<BitmapTexture> applySinglePassFilter(RefPtr<BitmapTexture>&, const Ref<const FilterOperation>&, bool shouldDefer);
void drawTextureCopy(const BitmapTexture& sourceTexture, const FloatRect& sourceRect, const FloatRect& targetRect);
void drawBlurred(const BitmapTexture& sourceTexture, const FloatRect&, float radius, Direction, bool alphaBlur = false);
void drawTexturedQuadWithProgram(TextureMapperShaderProgram&, uint32_t texture, OptionSet<TextureMapperFlags>, const FloatRect&, const TransformationMatrix& modelViewMatrix, float opacity);
void drawTexturedQuadWithProgram(TextureMapperShaderProgram&, const Vector<std::pair<GLuint, GLuint> >& texturesAndSamplers, OptionSet<TextureMapperFlags>, const FloatRect&, const TransformationMatrix& modelViewMatrix, float opacity);
void draw(const FloatRect&, const TransformationMatrix& modelViewMatrix, TextureMapperShaderProgram&, GLenum drawingMode, OptionSet<TextureMapperFlags>);
void drawUnitRect(TextureMapperShaderProgram&, GLenum drawingMode);
void drawEdgeTriangles(TextureMapperShaderProgram&);
bool beginScissorClip(const TransformationMatrix&, const FloatRect&);
bool beginRoundedRectClip(const TransformationMatrix&, const FloatRoundedRect&);
void bindDefaultSurface();
ClipStack& clipStack();
TextureMapperGLData& data() const { return *m_data; }
void updateProjectionMatrix();
BitmapTexturePool m_texturePool;
bool m_isMaskMode { false };
TransformationMatrix m_patternTransform;
WrapMode m_wrapMode { WrapMode::Stretch };
TextureMapperGLData* m_data;
ClipStack m_clipStack;
};
} // namespace WebCore
#endif // USE(TEXTURE_MAPPER)
|