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