GlopBuilder.h revision 15c3f19a445b8df575911a16e8a6dba755a084b5
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 "Glop.h" 20#include "OpenGLRenderer.h" 21#include "Program.h" 22#include "renderstate/Blend.h" 23#include "utils/Macros.h" 24 25class SkPaint; 26class SkShader; 27 28namespace android { 29namespace uirenderer { 30 31class Caches; 32class Matrix4; 33class RenderState; 34class Texture; 35class VertexBuffer; 36 37namespace TextureFillFlags { 38 enum { 39 None = 0, 40 IsAlphaMaskTexture = 1 << 0, 41 ForceFilter = 1 << 1, 42 }; 43} 44 45class GlopBuilder { 46 PREVENT_COPY_AND_ASSIGN(GlopBuilder); 47public: 48 GlopBuilder(RenderState& renderState, Caches& caches, Glop* outGlop); 49 50 GlopBuilder& setMeshTexturedIndexedVbo(GLuint vbo, GLsizei elementCount); 51 GlopBuilder& setMeshUnitQuad(); 52 GlopBuilder& setMeshTexturedUnitQuad(const UvMapper* uvMapper); 53 GlopBuilder& setMeshTexturedUvQuad(const UvMapper* uvMapper, const Rect uvs); 54 GlopBuilder& setMeshVertexBuffer(const VertexBuffer& vertexBuffer, bool shadowInterp); 55 GlopBuilder& setMeshIndexedQuads(Vertex* vertexData, int quadCount); 56 GlopBuilder& setMeshTexturedMesh(TextureVertex* vertexData, int elementCount); // TODO: delete 57 GlopBuilder& setMeshColoredTexturedMesh(ColorTextureVertex* vertexData, int elementCount); // TODO: use indexed quads 58 GlopBuilder& setMeshTexturedIndexedQuads(TextureVertex* vertexData, int elementCount); // TODO: take quadCount 59 GlopBuilder& setMeshPatchQuads(const Patch& patch); 60 61 GlopBuilder& setFillPaint(const SkPaint& paint, float alphaScale); 62 GlopBuilder& setFillTexturePaint(Texture& texture, const int textureFillFlags, 63 const SkPaint* paint, float alphaScale); 64 GlopBuilder& setFillPathTexturePaint(PathTexture& texture, 65 const SkPaint& paint, float alphaScale); 66 GlopBuilder& setFillShadowTexturePaint(ShadowTexture& texture, int shadowColor, 67 const SkPaint& paint, float alphaScale); 68 GlopBuilder& setFillBlack(); 69 GlopBuilder& setFillClear(); 70 GlopBuilder& setFillLayer(Texture& texture, const SkColorFilter* colorFilter, 71 float alpha, SkXfermode::Mode mode, Blend::ModeOrderSwap modeUsage); 72 GlopBuilder& setFillTextureLayer(Layer& layer, float alpha); 73 74 GlopBuilder& setTransform(const Snapshot& snapshot, const int transformFlags) { 75 return setTransform(*snapshot.transform, transformFlags); 76 } 77 GlopBuilder& setTransform(const Matrix4& canvas, const int transformFlags); 78 79 GlopBuilder& setModelViewMapUnitToRect(const Rect destination); 80 GlopBuilder& setModelViewMapUnitToRectSnap(const Rect destination); 81 GlopBuilder& setModelViewMapUnitToRectOptionalSnap(bool snap, const Rect& destination) { 82 if (snap) { 83 return setModelViewMapUnitToRectSnap(destination); 84 } else { 85 return setModelViewMapUnitToRect(destination); 86 } 87 } 88 GlopBuilder& setModelViewOffsetRect(float offsetX, float offsetY, const Rect source); 89 GlopBuilder& setModelViewOffsetRectSnap(float offsetX, float offsetY, const Rect source); 90 GlopBuilder& setModelViewOffsetRectOptionalSnap(bool snap, 91 float offsetX, float offsetY, const Rect& source) { 92 if (snap) { 93 return setModelViewOffsetRectSnap(offsetX, offsetY, source); 94 } else { 95 return setModelViewOffsetRect(offsetX, offsetY, source); 96 } 97 } 98 99 GlopBuilder& setRoundRectClipState(const RoundRectClipState* roundRectClipState); 100 101 void build(); 102 103 static void dump(const Glop& glop); 104private: 105 void setFill(int color, float alphaScale, 106 SkXfermode::Mode mode, Blend::ModeOrderSwap modeUsage, 107 const SkShader* shader, const SkColorFilter* colorFilter); 108 109 enum StageFlags { 110 kInitialStage = 0, 111 kMeshStage = 1 << 0, 112 kTransformStage = 1 << 1, 113 kModelViewStage = 1 << 2, 114 kFillStage = 1 << 3, 115 kRoundRectClipStage = 1 << 4, 116 kAllStages = kMeshStage | kFillStage | kTransformStage | kModelViewStage | kRoundRectClipStage, 117 } mStageFlags; 118 119 ProgramDescription mDescription; 120 RenderState& mRenderState; 121 Caches& mCaches; 122 const SkShader* mShader; 123 Glop* mOutGlop; 124}; 125 126} /* namespace uirenderer */ 127} /* namespace android */ 128 129#endif // RENDERSTATE_GLOPBUILDER_H 130