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