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