GlopBuilder.h revision 26bf34200e40a0fa8c66366559aa016380cd8c6f
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 36class GlopBuilder { 37 PREVENT_COPY_AND_ASSIGN(GlopBuilder); 38public: 39 GlopBuilder(RenderState& renderState, Caches& caches, Glop* outGlop); 40 41 GlopBuilder& setMeshUnitQuad(); 42 GlopBuilder& setMeshTexturedUnitQuad(const UvMapper* uvMapper); 43 GlopBuilder& setMeshTexturedUvQuad(const UvMapper* uvMapper, const Rect uvs); 44 GlopBuilder& setMeshVertexBuffer(const VertexBuffer& vertexBuffer, bool shadowInterp); 45 GlopBuilder& setMeshIndexedQuads(Vertex* vertexData, int quadCount); 46 GlopBuilder& setMeshColoredTexturedMesh(ColorTextureVertex* vertexData, int elementCount); 47 GlopBuilder& setMeshTexturedIndexedQuads(TextureVertex* vertexData, int elementCount); // TODO: take quadCount 48 49 GlopBuilder& setFillPaint(const SkPaint& paint, float alphaScale); 50 GlopBuilder& setFillTexturePaint(Texture& texture, bool isAlphaMaskTexture, 51 const SkPaint* paint, float alphaScale); 52 GlopBuilder& setFillPathTexturePaint(PathTexture& texture, 53 const SkPaint& paint, float alphaScale); 54 GlopBuilder& setFillShadowTexturePaint(ShadowTexture& texture, int shadowColor, 55 const SkPaint& paint, float alphaScale); 56 GlopBuilder& setFillBlack(); 57 GlopBuilder& setFillClear(); 58 GlopBuilder& setFillLayer(Texture& texture, const SkColorFilter* colorFilter, 59 float alpha, SkXfermode::Mode mode); 60 GlopBuilder& setFillTextureLayer(Layer& layer, float alpha); 61 62 GlopBuilder& setTransform(const Matrix4& ortho, const Matrix4& transform, bool fudgingOffset); 63 64 GlopBuilder& setModelViewMapUnitToRect(const Rect destination); 65 GlopBuilder& setModelViewMapUnitToRectSnap(const Rect destination); 66 GlopBuilder& setModelViewMapUnitToRectOptionalSnap(bool snap, const Rect destination) { 67 if (snap) { 68 return setModelViewMapUnitToRectSnap(destination); 69 } else { 70 return setModelViewMapUnitToRect(destination); 71 } 72 } 73 GlopBuilder& setModelViewOffsetRect(float offsetX, float offsetY, const Rect source); 74 GlopBuilder& setModelViewOffsetRectSnap(float offsetX, float offsetY, const Rect source); 75 76 GlopBuilder& setRoundRectClipState(const RoundRectClipState* roundRectClipState); 77 78 void build(); 79private: 80 void setFill(int color, float alphaScale, SkXfermode::Mode mode, 81 const SkShader* shader, const SkColorFilter* colorFilter); 82 83 enum StageFlags { 84 kInitialStage = 0, 85 kMeshStage = 1 << 0, 86 kTransformStage = 1 << 1, 87 kModelViewStage = 1 << 2, 88 kFillStage = 1 << 3, 89 kRoundRectClipStage = 1 << 4, 90 kAllStages = kMeshStage | kFillStage | kTransformStage | kModelViewStage | kRoundRectClipStage, 91 } mStageFlags; 92 93 ProgramDescription mDescription; 94 RenderState& mRenderState; 95 Caches& mCaches; 96 const SkShader* mShader; 97 Glop* mOutGlop; 98}; 99 100} /* namespace uirenderer */ 101} /* namespace android */ 102 103#endif // RENDERSTATE_GLOPBUILDER_H 104