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