blob: 8a5ce8afa1799271306e7ea01399760ce222c313 [file] [log] [blame]
Chris Craik03188872015-02-02 18:39:33 -08001/*
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;
Chris Craik922d3a72015-02-13 17:47:21 -080024class SkShader;
Chris Craik03188872015-02-02 18:39:33 -080025
26namespace android {
27namespace uirenderer {
28
29class Caches;
Chris Craik117bdbc2015-02-05 10:12:38 -080030class Matrix4;
Chris Craik03188872015-02-02 18:39:33 -080031class RenderState;
32class Texture;
Chris Craik117bdbc2015-02-05 10:12:38 -080033class VertexBuffer;
Chris Craik922d3a72015-02-13 17:47:21 -080034struct Glop;
Chris Craik03188872015-02-02 18:39:33 -080035
Chris Craika6b52192015-02-27 17:43:02 -080036enum class TextureFillFlags {
37 kNone = 0,
38 kIsAlphaMaskTexture = 1 << 0,
39 kForceFilter = 1 << 1,
40};
41MAKE_FLAGS_ENUM(TextureFillFlags);
42
Chris Craik03188872015-02-02 18:39:33 -080043class GlopBuilder {
44 PREVENT_COPY_AND_ASSIGN(GlopBuilder);
45public:
46 GlopBuilder(RenderState& renderState, Caches& caches, Glop* outGlop);
Chris Craik2ab95d72015-02-06 15:25:51 -080047
Chris Craik03188872015-02-02 18:39:33 -080048 GlopBuilder& setMeshUnitQuad();
Chris Craikf27133d2015-02-19 09:51:53 -080049 GlopBuilder& setMeshTexturedUnitQuad(const UvMapper* uvMapper);
Chris Craik14100ac2015-02-24 13:46:29 -080050 GlopBuilder& setMeshTexturedUvQuad(const UvMapper* uvMapper, const Rect uvs);
Chris Craik117bdbc2015-02-05 10:12:38 -080051 GlopBuilder& setMeshVertexBuffer(const VertexBuffer& vertexBuffer, bool shadowInterp);
Chris Craikef250742015-02-25 17:16:16 -080052 GlopBuilder& setMeshIndexedQuads(Vertex* vertexData, int quadCount);
Chris Craika6b52192015-02-27 17:43:02 -080053 GlopBuilder& setMeshTexturedMesh(TextureVertex* vertexData, int elementCount); // TODO: use indexed quads
54 GlopBuilder& setMeshColoredTexturedMesh(ColorTextureVertex* vertexData, int elementCount); // TODO: use indexed quads
Chris Craikf27133d2015-02-19 09:51:53 -080055 GlopBuilder& setMeshTexturedIndexedQuads(TextureVertex* vertexData, int elementCount); // TODO: take quadCount
Chris Craik117bdbc2015-02-05 10:12:38 -080056
Chris Craik0519c812015-02-11 13:17:06 -080057 GlopBuilder& setFillPaint(const SkPaint& paint, float alphaScale);
Chris Craika6b52192015-02-27 17:43:02 -080058 GlopBuilder& setFillTexturePaint(Texture& texture, int textureFillFlags,
Chris Craik0519c812015-02-11 13:17:06 -080059 const SkPaint* paint, float alphaScale);
Chris Craik2bb8f562015-02-17 16:42:02 -080060 GlopBuilder& setFillPathTexturePaint(PathTexture& texture,
Chris Craik30036092015-02-12 10:41:39 -080061 const SkPaint& paint, float alphaScale);
Chris Craik2bb8f562015-02-17 16:42:02 -080062 GlopBuilder& setFillShadowTexturePaint(ShadowTexture& texture, int shadowColor,
63 const SkPaint& paint, float alphaScale);
64 GlopBuilder& setFillBlack();
65 GlopBuilder& setFillClear();
Chris Craikf27133d2015-02-19 09:51:53 -080066 GlopBuilder& setFillLayer(Texture& texture, const SkColorFilter* colorFilter,
67 float alpha, SkXfermode::Mode mode);
Chris Craik26bf3422015-02-26 16:28:17 -080068 GlopBuilder& setFillTextureLayer(Layer& layer, float alpha);
Chris Craik0519c812015-02-11 13:17:06 -080069
Chris Craikf27133d2015-02-19 09:51:53 -080070 GlopBuilder& setTransform(const Matrix4& ortho, const Matrix4& transform, bool fudgingOffset);
Chris Craik117bdbc2015-02-05 10:12:38 -080071
72 GlopBuilder& setModelViewMapUnitToRect(const Rect destination);
Chris Craik0519c812015-02-11 13:17:06 -080073 GlopBuilder& setModelViewMapUnitToRectSnap(const Rect destination);
Chris Craika6b52192015-02-27 17:43:02 -080074 GlopBuilder& setModelViewMapUnitToRectOptionalSnap(bool snap, const Rect& destination) {
Chris Craik26bf3422015-02-26 16:28:17 -080075 if (snap) {
76 return setModelViewMapUnitToRectSnap(destination);
77 } else {
78 return setModelViewMapUnitToRect(destination);
79 }
80 }
Chris Craik117bdbc2015-02-05 10:12:38 -080081 GlopBuilder& setModelViewOffsetRect(float offsetX, float offsetY, const Rect source);
Chris Craikf27133d2015-02-19 09:51:53 -080082 GlopBuilder& setModelViewOffsetRectSnap(float offsetX, float offsetY, const Rect source);
Chris Craika6b52192015-02-27 17:43:02 -080083 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 }
Chris Craik117bdbc2015-02-05 10:12:38 -080091
Chris Craik0519c812015-02-11 13:17:06 -080092 GlopBuilder& setRoundRectClipState(const RoundRectClipState* roundRectClipState);
93
Chris Craik03188872015-02-02 18:39:33 -080094 void build();
95private:
Chris Craik0519c812015-02-11 13:17:06 -080096 void setFill(int color, float alphaScale, SkXfermode::Mode mode,
97 const SkShader* shader, const SkColorFilter* colorFilter);
98
Chris Craik117bdbc2015-02-05 10:12:38 -080099 enum StageFlags {
100 kInitialStage = 0,
101 kMeshStage = 1 << 0,
102 kTransformStage = 1 << 1,
103 kModelViewStage = 1 << 2,
104 kFillStage = 1 << 3,
Chris Craik0519c812015-02-11 13:17:06 -0800105 kRoundRectClipStage = 1 << 4,
106 kAllStages = kMeshStage | kFillStage | kTransformStage | kModelViewStage | kRoundRectClipStage,
Chris Craik117bdbc2015-02-05 10:12:38 -0800107 } mStageFlags;
108
Chris Craik03188872015-02-02 18:39:33 -0800109 ProgramDescription mDescription;
110 RenderState& mRenderState;
111 Caches& mCaches;
Chris Craik922d3a72015-02-13 17:47:21 -0800112 const SkShader* mShader;
Chris Craik03188872015-02-02 18:39:33 -0800113 Glop* mOutGlop;
114};
115
116} /* namespace uirenderer */
117} /* namespace android */
118
119#endif // RENDERSTATE_GLOPBUILDER_H