GlopBuilder.h revision a6b52198b9e73a4b7f80103116feeace74433246
1/*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16#ifndef RENDERSTATE_GLOPBUILDER_H
17#define RENDERSTATE_GLOPBUILDER_H
18
19#include "OpenGLRenderer.h"
20#include "Program.h"
21#include "utils/Macros.h"
22
23class SkPaint;
24class SkShader;
25
26namespace android {
27namespace uirenderer {
28
29class Caches;
30class Matrix4;
31class RenderState;
32class Texture;
33class VertexBuffer;
34struct Glop;
35
36enum class TextureFillFlags {
37    kNone = 0,
38    kIsAlphaMaskTexture = 1 << 0,
39    kForceFilter = 1 << 1,
40};
41MAKE_FLAGS_ENUM(TextureFillFlags);
42
43class GlopBuilder {
44    PREVENT_COPY_AND_ASSIGN(GlopBuilder);
45public:
46    GlopBuilder(RenderState& renderState, Caches& caches, Glop* outGlop);
47
48    GlopBuilder& setMeshUnitQuad();
49    GlopBuilder& setMeshTexturedUnitQuad(const UvMapper* uvMapper);
50    GlopBuilder& setMeshTexturedUvQuad(const UvMapper* uvMapper, const Rect uvs);
51    GlopBuilder& setMeshVertexBuffer(const VertexBuffer& vertexBuffer, bool shadowInterp);
52    GlopBuilder& setMeshIndexedQuads(Vertex* vertexData, int quadCount);
53    GlopBuilder& setMeshTexturedMesh(TextureVertex* vertexData, int elementCount); // TODO: use indexed quads
54    GlopBuilder& setMeshColoredTexturedMesh(ColorTextureVertex* vertexData, int elementCount); // TODO: use indexed quads
55    GlopBuilder& setMeshTexturedIndexedQuads(TextureVertex* vertexData, int elementCount); // TODO: take quadCount
56
57    GlopBuilder& setFillPaint(const SkPaint& paint, float alphaScale);
58    GlopBuilder& setFillTexturePaint(Texture& texture, int textureFillFlags,
59            const SkPaint* paint, float alphaScale);
60    GlopBuilder& setFillPathTexturePaint(PathTexture& texture,
61            const SkPaint& paint, float alphaScale);
62    GlopBuilder& setFillShadowTexturePaint(ShadowTexture& texture, int shadowColor,
63            const SkPaint& paint, float alphaScale);
64    GlopBuilder& setFillBlack();
65    GlopBuilder& setFillClear();
66    GlopBuilder& setFillLayer(Texture& texture, const SkColorFilter* colorFilter,
67            float alpha, SkXfermode::Mode mode);
68    GlopBuilder& setFillTextureLayer(Layer& layer, float alpha);
69
70    GlopBuilder& setTransform(const Matrix4& ortho, const Matrix4& transform, bool fudgingOffset);
71
72    GlopBuilder& setModelViewMapUnitToRect(const Rect destination);
73    GlopBuilder& setModelViewMapUnitToRectSnap(const Rect destination);
74    GlopBuilder& setModelViewMapUnitToRectOptionalSnap(bool snap, const Rect& destination) {
75        if (snap) {
76            return setModelViewMapUnitToRectSnap(destination);
77        } else {
78            return setModelViewMapUnitToRect(destination);
79        }
80    }
81    GlopBuilder& setModelViewOffsetRect(float offsetX, float offsetY, const Rect source);
82    GlopBuilder& setModelViewOffsetRectSnap(float offsetX, float offsetY, const Rect source);
83    GlopBuilder& setModelViewOffsetRectOptionalSnap(bool snap,
84            float offsetX, float offsetY, const Rect& source) {
85        if (snap) {
86            return setModelViewOffsetRectSnap(offsetX, offsetY, source);
87        } else {
88            return setModelViewOffsetRect(offsetX, offsetY, source);
89        }
90    }
91
92    GlopBuilder& setRoundRectClipState(const RoundRectClipState* roundRectClipState);
93
94    void build();
95private:
96    void setFill(int color, float alphaScale, SkXfermode::Mode mode,
97            const SkShader* shader, const SkColorFilter* colorFilter);
98
99    enum StageFlags {
100        kInitialStage = 0,
101        kMeshStage = 1 << 0,
102        kTransformStage = 1 << 1,
103        kModelViewStage = 1 << 2,
104        kFillStage = 1 << 3,
105        kRoundRectClipStage = 1 << 4,
106        kAllStages = kMeshStage | kFillStage | kTransformStage | kModelViewStage | kRoundRectClipStage,
107    } mStageFlags;
108
109    ProgramDescription mDescription;
110    RenderState& mRenderState;
111    Caches& mCaches;
112    const SkShader* mShader;
113    Glop* mOutGlop;
114};
115
116} /* namespace uirenderer */
117} /* namespace android */
118
119#endif // RENDERSTATE_GLOPBUILDER_H
120