blob: 74d4889dfdc46f1d18500d74b9cd10762c53ba83 [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 Craik0556d902015-03-03 09:54:14 -080056 GlopBuilder& setMeshPatchQuads(const Patch& patch);
Chris Craik117bdbc2015-02-05 10:12:38 -080057
Chris Craik0519c812015-02-11 13:17:06 -080058 GlopBuilder& setFillPaint(const SkPaint& paint, float alphaScale);
Chris Craika6b52192015-02-27 17:43:02 -080059 GlopBuilder& setFillTexturePaint(Texture& texture, int textureFillFlags,
Chris Craik0519c812015-02-11 13:17:06 -080060 const SkPaint* paint, float alphaScale);
Chris Craik2bb8f562015-02-17 16:42:02 -080061 GlopBuilder& setFillPathTexturePaint(PathTexture& texture,
Chris Craik30036092015-02-12 10:41:39 -080062 const SkPaint& paint, float alphaScale);
Chris Craik2bb8f562015-02-17 16:42:02 -080063 GlopBuilder& setFillShadowTexturePaint(ShadowTexture& texture, int shadowColor,
64 const SkPaint& paint, float alphaScale);
65 GlopBuilder& setFillBlack();
66 GlopBuilder& setFillClear();
Chris Craikf27133d2015-02-19 09:51:53 -080067 GlopBuilder& setFillLayer(Texture& texture, const SkColorFilter* colorFilter,
68 float alpha, SkXfermode::Mode mode);
Chris Craik26bf3422015-02-26 16:28:17 -080069 GlopBuilder& setFillTextureLayer(Layer& layer, float alpha);
Chris Craik0519c812015-02-11 13:17:06 -080070
Chris Craikf27133d2015-02-19 09:51:53 -080071 GlopBuilder& setTransform(const Matrix4& ortho, const Matrix4& transform, bool fudgingOffset);
Chris Craik117bdbc2015-02-05 10:12:38 -080072
73 GlopBuilder& setModelViewMapUnitToRect(const Rect destination);
Chris Craik0519c812015-02-11 13:17:06 -080074 GlopBuilder& setModelViewMapUnitToRectSnap(const Rect destination);
Chris Craika6b52192015-02-27 17:43:02 -080075 GlopBuilder& setModelViewMapUnitToRectOptionalSnap(bool snap, const Rect& destination) {
Chris Craik26bf3422015-02-26 16:28:17 -080076 if (snap) {
77 return setModelViewMapUnitToRectSnap(destination);
78 } else {
79 return setModelViewMapUnitToRect(destination);
80 }
81 }
Chris Craik117bdbc2015-02-05 10:12:38 -080082 GlopBuilder& setModelViewOffsetRect(float offsetX, float offsetY, const Rect source);
Chris Craikf27133d2015-02-19 09:51:53 -080083 GlopBuilder& setModelViewOffsetRectSnap(float offsetX, float offsetY, const Rect source);
Chris Craika6b52192015-02-27 17:43:02 -080084 GlopBuilder& setModelViewOffsetRectOptionalSnap(bool snap,
85 float offsetX, float offsetY, const Rect& source) {
86 if (snap) {
87 return setModelViewOffsetRectSnap(offsetX, offsetY, source);
88 } else {
89 return setModelViewOffsetRect(offsetX, offsetY, source);
90 }
91 }
Chris Craik117bdbc2015-02-05 10:12:38 -080092
Chris Craik0519c812015-02-11 13:17:06 -080093 GlopBuilder& setRoundRectClipState(const RoundRectClipState* roundRectClipState);
94
Chris Craik03188872015-02-02 18:39:33 -080095 void build();
96private:
Chris Craik0519c812015-02-11 13:17:06 -080097 void setFill(int color, float alphaScale, SkXfermode::Mode mode,
98 const SkShader* shader, const SkColorFilter* colorFilter);
99
Chris Craik117bdbc2015-02-05 10:12:38 -0800100 enum StageFlags {
101 kInitialStage = 0,
102 kMeshStage = 1 << 0,
103 kTransformStage = 1 << 1,
104 kModelViewStage = 1 << 2,
105 kFillStage = 1 << 3,
Chris Craik0519c812015-02-11 13:17:06 -0800106 kRoundRectClipStage = 1 << 4,
107 kAllStages = kMeshStage | kFillStage | kTransformStage | kModelViewStage | kRoundRectClipStage,
Chris Craik117bdbc2015-02-05 10:12:38 -0800108 } mStageFlags;
109
Chris Craik03188872015-02-02 18:39:33 -0800110 ProgramDescription mDescription;
111 RenderState& mRenderState;
112 Caches& mCaches;
Chris Craik922d3a72015-02-13 17:47:21 -0800113 const SkShader* mShader;
Chris Craik03188872015-02-02 18:39:33 -0800114 Glop* mOutGlop;
115};
116
117} /* namespace uirenderer */
118} /* namespace android */
119
120#endif // RENDERSTATE_GLOPBUILDER_H