Chris Craik | 0318887 | 2015-02-02 18:39:33 -0800 | [diff] [blame] | 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" |
Chris Craik | 182952f | 2015-03-09 14:17:29 -0700 | [diff] [blame] | 21 | #include "renderstate/Blend.h" |
Chris Craik | 0318887 | 2015-02-02 18:39:33 -0800 | [diff] [blame] | 22 | #include "utils/Macros.h" |
| 23 | |
| 24 | class SkPaint; |
Chris Craik | 922d3a7 | 2015-02-13 17:47:21 -0800 | [diff] [blame] | 25 | class SkShader; |
Chris Craik | 0318887 | 2015-02-02 18:39:33 -0800 | [diff] [blame] | 26 | |
| 27 | namespace android { |
| 28 | namespace uirenderer { |
| 29 | |
| 30 | class Caches; |
Chris Craik | 117bdbc | 2015-02-05 10:12:38 -0800 | [diff] [blame] | 31 | class Matrix4; |
Chris Craik | 0318887 | 2015-02-02 18:39:33 -0800 | [diff] [blame] | 32 | class RenderState; |
| 33 | class Texture; |
Chris Craik | 117bdbc | 2015-02-05 10:12:38 -0800 | [diff] [blame] | 34 | class VertexBuffer; |
Chris Craik | 922d3a7 | 2015-02-13 17:47:21 -0800 | [diff] [blame] | 35 | struct Glop; |
Chris Craik | 0318887 | 2015-02-02 18:39:33 -0800 | [diff] [blame] | 36 | |
Chris Craik | a6b5219 | 2015-02-27 17:43:02 -0800 | [diff] [blame] | 37 | enum class TextureFillFlags { |
| 38 | kNone = 0, |
| 39 | kIsAlphaMaskTexture = 1 << 0, |
| 40 | kForceFilter = 1 << 1, |
| 41 | }; |
| 42 | MAKE_FLAGS_ENUM(TextureFillFlags); |
| 43 | |
Chris Craik | 0318887 | 2015-02-02 18:39:33 -0800 | [diff] [blame] | 44 | class GlopBuilder { |
| 45 | PREVENT_COPY_AND_ASSIGN(GlopBuilder); |
| 46 | public: |
| 47 | GlopBuilder(RenderState& renderState, Caches& caches, Glop* outGlop); |
Chris Craik | 2ab95d7 | 2015-02-06 15:25:51 -0800 | [diff] [blame] | 48 | |
Chris Craik | 0318887 | 2015-02-02 18:39:33 -0800 | [diff] [blame] | 49 | GlopBuilder& setMeshUnitQuad(); |
Chris Craik | f27133d | 2015-02-19 09:51:53 -0800 | [diff] [blame] | 50 | GlopBuilder& setMeshTexturedUnitQuad(const UvMapper* uvMapper); |
Chris Craik | 14100ac | 2015-02-24 13:46:29 -0800 | [diff] [blame] | 51 | GlopBuilder& setMeshTexturedUvQuad(const UvMapper* uvMapper, const Rect uvs); |
Chris Craik | 117bdbc | 2015-02-05 10:12:38 -0800 | [diff] [blame] | 52 | GlopBuilder& setMeshVertexBuffer(const VertexBuffer& vertexBuffer, bool shadowInterp); |
Chris Craik | ef25074 | 2015-02-25 17:16:16 -0800 | [diff] [blame] | 53 | GlopBuilder& setMeshIndexedQuads(Vertex* vertexData, int quadCount); |
Chris Craik | a6b5219 | 2015-02-27 17:43:02 -0800 | [diff] [blame] | 54 | GlopBuilder& setMeshTexturedMesh(TextureVertex* vertexData, int elementCount); // TODO: use indexed quads |
| 55 | GlopBuilder& setMeshColoredTexturedMesh(ColorTextureVertex* vertexData, int elementCount); // TODO: use indexed quads |
Chris Craik | f27133d | 2015-02-19 09:51:53 -0800 | [diff] [blame] | 56 | GlopBuilder& setMeshTexturedIndexedQuads(TextureVertex* vertexData, int elementCount); // TODO: take quadCount |
Chris Craik | 0556d90 | 2015-03-03 09:54:14 -0800 | [diff] [blame] | 57 | GlopBuilder& setMeshPatchQuads(const Patch& patch); |
Chris Craik | 117bdbc | 2015-02-05 10:12:38 -0800 | [diff] [blame] | 58 | |
Chris Craik | 0519c81 | 2015-02-11 13:17:06 -0800 | [diff] [blame] | 59 | GlopBuilder& setFillPaint(const SkPaint& paint, float alphaScale); |
Chris Craik | a6b5219 | 2015-02-27 17:43:02 -0800 | [diff] [blame] | 60 | GlopBuilder& setFillTexturePaint(Texture& texture, int textureFillFlags, |
Chris Craik | 0519c81 | 2015-02-11 13:17:06 -0800 | [diff] [blame] | 61 | const SkPaint* paint, float alphaScale); |
Chris Craik | 2bb8f56 | 2015-02-17 16:42:02 -0800 | [diff] [blame] | 62 | GlopBuilder& setFillPathTexturePaint(PathTexture& texture, |
Chris Craik | 3003609 | 2015-02-12 10:41:39 -0800 | [diff] [blame] | 63 | const SkPaint& paint, float alphaScale); |
Chris Craik | 2bb8f56 | 2015-02-17 16:42:02 -0800 | [diff] [blame] | 64 | GlopBuilder& setFillShadowTexturePaint(ShadowTexture& texture, int shadowColor, |
| 65 | const SkPaint& paint, float alphaScale); |
| 66 | GlopBuilder& setFillBlack(); |
| 67 | GlopBuilder& setFillClear(); |
Chris Craik | f27133d | 2015-02-19 09:51:53 -0800 | [diff] [blame] | 68 | GlopBuilder& setFillLayer(Texture& texture, const SkColorFilter* colorFilter, |
Chris Craik | 182952f | 2015-03-09 14:17:29 -0700 | [diff] [blame] | 69 | float alpha, SkXfermode::Mode mode, Blend::ModeOrderSwap modeUsage); |
Chris Craik | 26bf342 | 2015-02-26 16:28:17 -0800 | [diff] [blame] | 70 | GlopBuilder& setFillTextureLayer(Layer& layer, float alpha); |
Chris Craik | 0519c81 | 2015-02-11 13:17:06 -0800 | [diff] [blame] | 71 | |
Chris Craik | f27133d | 2015-02-19 09:51:53 -0800 | [diff] [blame] | 72 | GlopBuilder& setTransform(const Matrix4& ortho, const Matrix4& transform, bool fudgingOffset); |
Chris Craik | 117bdbc | 2015-02-05 10:12:38 -0800 | [diff] [blame] | 73 | |
| 74 | GlopBuilder& setModelViewMapUnitToRect(const Rect destination); |
Chris Craik | 0519c81 | 2015-02-11 13:17:06 -0800 | [diff] [blame] | 75 | GlopBuilder& setModelViewMapUnitToRectSnap(const Rect destination); |
Chris Craik | a6b5219 | 2015-02-27 17:43:02 -0800 | [diff] [blame] | 76 | GlopBuilder& setModelViewMapUnitToRectOptionalSnap(bool snap, const Rect& destination) { |
Chris Craik | 26bf342 | 2015-02-26 16:28:17 -0800 | [diff] [blame] | 77 | if (snap) { |
| 78 | return setModelViewMapUnitToRectSnap(destination); |
| 79 | } else { |
| 80 | return setModelViewMapUnitToRect(destination); |
| 81 | } |
| 82 | } |
Chris Craik | 117bdbc | 2015-02-05 10:12:38 -0800 | [diff] [blame] | 83 | GlopBuilder& setModelViewOffsetRect(float offsetX, float offsetY, const Rect source); |
Chris Craik | f27133d | 2015-02-19 09:51:53 -0800 | [diff] [blame] | 84 | GlopBuilder& setModelViewOffsetRectSnap(float offsetX, float offsetY, const Rect source); |
Chris Craik | a6b5219 | 2015-02-27 17:43:02 -0800 | [diff] [blame] | 85 | GlopBuilder& setModelViewOffsetRectOptionalSnap(bool snap, |
| 86 | float offsetX, float offsetY, const Rect& source) { |
| 87 | if (snap) { |
| 88 | return setModelViewOffsetRectSnap(offsetX, offsetY, source); |
| 89 | } else { |
| 90 | return setModelViewOffsetRect(offsetX, offsetY, source); |
| 91 | } |
| 92 | } |
Chris Craik | 117bdbc | 2015-02-05 10:12:38 -0800 | [diff] [blame] | 93 | |
Chris Craik | 0519c81 | 2015-02-11 13:17:06 -0800 | [diff] [blame] | 94 | GlopBuilder& setRoundRectClipState(const RoundRectClipState* roundRectClipState); |
| 95 | |
Chris Craik | 0318887 | 2015-02-02 18:39:33 -0800 | [diff] [blame] | 96 | void build(); |
| 97 | private: |
Chris Craik | 182952f | 2015-03-09 14:17:29 -0700 | [diff] [blame] | 98 | void setFill(int color, float alphaScale, |
| 99 | SkXfermode::Mode mode, Blend::ModeOrderSwap modeUsage, |
Chris Craik | 0519c81 | 2015-02-11 13:17:06 -0800 | [diff] [blame] | 100 | const SkShader* shader, const SkColorFilter* colorFilter); |
| 101 | |
Chris Craik | 117bdbc | 2015-02-05 10:12:38 -0800 | [diff] [blame] | 102 | enum StageFlags { |
| 103 | kInitialStage = 0, |
| 104 | kMeshStage = 1 << 0, |
| 105 | kTransformStage = 1 << 1, |
| 106 | kModelViewStage = 1 << 2, |
| 107 | kFillStage = 1 << 3, |
Chris Craik | 0519c81 | 2015-02-11 13:17:06 -0800 | [diff] [blame] | 108 | kRoundRectClipStage = 1 << 4, |
| 109 | kAllStages = kMeshStage | kFillStage | kTransformStage | kModelViewStage | kRoundRectClipStage, |
Chris Craik | 117bdbc | 2015-02-05 10:12:38 -0800 | [diff] [blame] | 110 | } mStageFlags; |
| 111 | |
Chris Craik | 0318887 | 2015-02-02 18:39:33 -0800 | [diff] [blame] | 112 | ProgramDescription mDescription; |
| 113 | RenderState& mRenderState; |
| 114 | Caches& mCaches; |
Chris Craik | 922d3a7 | 2015-02-13 17:47:21 -0800 | [diff] [blame] | 115 | const SkShader* mShader; |
Chris Craik | 0318887 | 2015-02-02 18:39:33 -0800 | [diff] [blame] | 116 | Glop* mOutGlop; |
| 117 | }; |
| 118 | |
| 119 | } /* namespace uirenderer */ |
| 120 | } /* namespace android */ |
| 121 | |
| 122 | #endif // RENDERSTATE_GLOPBUILDER_H |