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