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 | */ |
Chris Craik | 5e00c7c | 2016-07-06 16:10:09 -0700 | [diff] [blame] | 16 | |
| 17 | #pragma once |
Chris Craik | 0318887 | 2015-02-02 18:39:33 -0800 | [diff] [blame] | 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 "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; |
Greg Daniel | 8cd3edf | 2017-01-09 14:15:41 -0500 | [diff] [blame] | 31 | class GlLayer; |
Chris Craik | 117bdbc | 2015-02-05 10:12:38 -0800 | [diff] [blame] | 32 | class Matrix4; |
Chris Craik | 5e00c7c | 2016-07-06 16:10:09 -0700 | [diff] [blame] | 33 | class Patch; |
Chris Craik | 0318887 | 2015-02-02 18:39:33 -0800 | [diff] [blame] | 34 | class RenderState; |
| 35 | class Texture; |
Chris Craik | 5e00c7c | 2016-07-06 16:10:09 -0700 | [diff] [blame] | 36 | class UvMapper; |
Chris Craik | 117bdbc | 2015-02-05 10:12:38 -0800 | [diff] [blame] | 37 | class VertexBuffer; |
Chris Craik | 5e00c7c | 2016-07-06 16:10:09 -0700 | [diff] [blame] | 38 | struct PathTexture; |
| 39 | struct ShadowTexture; |
Chris Craik | 0318887 | 2015-02-02 18:39:33 -0800 | [diff] [blame] | 40 | |
Chris Craik | 53e51e4 | 2015-06-01 10:35:35 -0700 | [diff] [blame] | 41 | namespace TextureFillFlags { |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame^] | 42 | enum { |
| 43 | None = 0, |
| 44 | IsAlphaMaskTexture = 1 << 0, |
| 45 | ForceFilter = 1 << 1, |
| 46 | }; |
Chris Craik | 53e51e4 | 2015-06-01 10:35:35 -0700 | [diff] [blame] | 47 | } |
Chris Craik | a6b5219 | 2015-02-27 17:43:02 -0800 | [diff] [blame] | 48 | |
Chris Craik | 0318887 | 2015-02-02 18:39:33 -0800 | [diff] [blame] | 49 | class GlopBuilder { |
| 50 | PREVENT_COPY_AND_ASSIGN(GlopBuilder); |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame^] | 51 | |
Chris Craik | 0318887 | 2015-02-02 18:39:33 -0800 | [diff] [blame] | 52 | public: |
| 53 | GlopBuilder(RenderState& renderState, Caches& caches, Glop* outGlop); |
Chris Craik | 2ab95d7 | 2015-02-06 15:25:51 -0800 | [diff] [blame] | 54 | |
Chris Craik | 8d2cf94 | 2015-11-02 14:52:21 -0800 | [diff] [blame] | 55 | GlopBuilder& setMeshTexturedIndexedVbo(GLuint vbo, GLsizei elementCount); |
Chris Craik | 0318887 | 2015-02-02 18:39:33 -0800 | [diff] [blame] | 56 | GlopBuilder& setMeshUnitQuad(); |
Chris Craik | f27133d | 2015-02-19 09:51:53 -0800 | [diff] [blame] | 57 | GlopBuilder& setMeshTexturedUnitQuad(const UvMapper* uvMapper); |
Chris Craik | 14100ac | 2015-02-24 13:46:29 -0800 | [diff] [blame] | 58 | GlopBuilder& setMeshTexturedUvQuad(const UvMapper* uvMapper, const Rect uvs); |
Chris Craik | 138c21f | 2016-04-28 16:59:42 -0700 | [diff] [blame] | 59 | GlopBuilder& setMeshVertexBuffer(const VertexBuffer& vertexBuffer); |
Chris Craik | ef25074 | 2015-02-25 17:16:16 -0800 | [diff] [blame] | 60 | GlopBuilder& setMeshIndexedQuads(Vertex* vertexData, int quadCount); |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame^] | 61 | GlopBuilder& setMeshColoredTexturedMesh(ColorTextureVertex* vertexData, |
| 62 | int elementCount); // TODO: use indexed quads |
| 63 | GlopBuilder& setMeshTexturedIndexedQuads(TextureVertex* vertexData, |
| 64 | int elementCount); // TODO: take quadCount |
Chris Craik | 0556d90 | 2015-03-03 09:54:14 -0800 | [diff] [blame] | 65 | GlopBuilder& setMeshPatchQuads(const Patch& patch); |
Chris Craik | 117bdbc | 2015-02-05 10:12:38 -0800 | [diff] [blame] | 66 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame^] | 67 | GlopBuilder& setFillPaint(const SkPaint& paint, float alphaScale, |
| 68 | bool shadowInterp = false); // TODO: avoid boolean with default |
Chris Craik | 53e51e4 | 2015-06-01 10:35:35 -0700 | [diff] [blame] | 69 | GlopBuilder& setFillTexturePaint(Texture& texture, const int textureFillFlags, |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame^] | 70 | const SkPaint* paint, float alphaScale); |
| 71 | GlopBuilder& setFillPathTexturePaint(PathTexture& texture, const SkPaint& paint, |
| 72 | float alphaScale); |
Chris Craik | 2bb8f56 | 2015-02-17 16:42:02 -0800 | [diff] [blame] | 73 | GlopBuilder& setFillShadowTexturePaint(ShadowTexture& texture, int shadowColor, |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame^] | 74 | const SkPaint& paint, float alphaScale); |
Chris Craik | 2bb8f56 | 2015-02-17 16:42:02 -0800 | [diff] [blame] | 75 | GlopBuilder& setFillBlack(); |
| 76 | GlopBuilder& setFillClear(); |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame^] | 77 | GlopBuilder& setFillLayer(Texture& texture, const SkColorFilter* colorFilter, float alpha, |
| 78 | SkBlendMode mode, Blend::ModeOrderSwap modeUsage); |
Greg Daniel | 8cd3edf | 2017-01-09 14:15:41 -0500 | [diff] [blame] | 79 | GlopBuilder& setFillTextureLayer(GlLayer& layer, float alpha); |
sergeyv | 2a38c42 | 2016-10-25 15:21:50 -0700 | [diff] [blame] | 80 | // TODO: setFillLayer normally forces its own wrap & filter mode, |
| 81 | // which isn't always correct. |
John Reck | 7bf96a0 | 2017-06-28 11:08:07 -0700 | [diff] [blame] | 82 | GlopBuilder& setFillExternalTexture(Texture& texture, Matrix4& textureTransform, |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame^] | 83 | bool requiresFilter); |
Chris Craik | 0519c81 | 2015-02-11 13:17:06 -0800 | [diff] [blame] | 84 | |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 85 | GlopBuilder& setTransform(const Matrix4& canvas, const int transformFlags); |
Chris Craik | 117bdbc | 2015-02-05 10:12:38 -0800 | [diff] [blame] | 86 | |
| 87 | GlopBuilder& setModelViewMapUnitToRect(const Rect destination); |
Chris Craik | 0519c81 | 2015-02-11 13:17:06 -0800 | [diff] [blame] | 88 | GlopBuilder& setModelViewMapUnitToRectSnap(const Rect destination); |
Chris Craik | a6b5219 | 2015-02-27 17:43:02 -0800 | [diff] [blame] | 89 | GlopBuilder& setModelViewMapUnitToRectOptionalSnap(bool snap, const Rect& destination) { |
Chris Craik | 26bf342 | 2015-02-26 16:28:17 -0800 | [diff] [blame] | 90 | if (snap) { |
| 91 | return setModelViewMapUnitToRectSnap(destination); |
| 92 | } else { |
| 93 | return setModelViewMapUnitToRect(destination); |
| 94 | } |
| 95 | } |
Chris Craik | 117bdbc | 2015-02-05 10:12:38 -0800 | [diff] [blame] | 96 | GlopBuilder& setModelViewOffsetRect(float offsetX, float offsetY, const Rect source); |
Chris Craik | f27133d | 2015-02-19 09:51:53 -0800 | [diff] [blame] | 97 | GlopBuilder& setModelViewOffsetRectSnap(float offsetX, float offsetY, const Rect source); |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame^] | 98 | GlopBuilder& setModelViewOffsetRectOptionalSnap(bool snap, float offsetX, float offsetY, |
| 99 | const Rect& source) { |
Chris Craik | a6b5219 | 2015-02-27 17:43:02 -0800 | [diff] [blame] | 100 | if (snap) { |
| 101 | return setModelViewOffsetRectSnap(offsetX, offsetY, source); |
| 102 | } else { |
| 103 | return setModelViewOffsetRect(offsetX, offsetY, source); |
| 104 | } |
| 105 | } |
Chris Craik | f09ff5a | 2015-12-08 17:21:58 -0800 | [diff] [blame] | 106 | GlopBuilder& setModelViewIdentityEmptyBounds() { |
| 107 | // pass empty rect since not needed for damage / snap |
| 108 | return setModelViewOffsetRect(0, 0, Rect()); |
| 109 | } |
Chris Craik | 117bdbc | 2015-02-05 10:12:38 -0800 | [diff] [blame] | 110 | |
Chris Craik | 0519c81 | 2015-02-11 13:17:06 -0800 | [diff] [blame] | 111 | GlopBuilder& setRoundRectClipState(const RoundRectClipState* roundRectClipState); |
| 112 | |
Romain Guy | 253f2c2 | 2016-09-28 17:34:42 -0700 | [diff] [blame] | 113 | GlopBuilder& setGammaCorrection(bool enabled); |
| 114 | |
Chris Craik | 0318887 | 2015-02-02 18:39:33 -0800 | [diff] [blame] | 115 | void build(); |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 116 | |
| 117 | static void dump(const Glop& glop); |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame^] | 118 | |
Chris Craik | 0318887 | 2015-02-02 18:39:33 -0800 | [diff] [blame] | 119 | private: |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame^] | 120 | void setFill(int color, float alphaScale, SkBlendMode mode, Blend::ModeOrderSwap modeUsage, |
| 121 | const SkShader* shader, const SkColorFilter* colorFilter); |
Chris Craik | 0519c81 | 2015-02-11 13:17:06 -0800 | [diff] [blame] | 122 | |
Chris Craik | 117bdbc | 2015-02-05 10:12:38 -0800 | [diff] [blame] | 123 | enum StageFlags { |
| 124 | kInitialStage = 0, |
| 125 | kMeshStage = 1 << 0, |
| 126 | kTransformStage = 1 << 1, |
| 127 | kModelViewStage = 1 << 2, |
| 128 | kFillStage = 1 << 3, |
Chris Craik | 0519c81 | 2015-02-11 13:17:06 -0800 | [diff] [blame] | 129 | kRoundRectClipStage = 1 << 4, |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame^] | 130 | kAllStages = |
| 131 | kMeshStage | kFillStage | kTransformStage | kModelViewStage | kRoundRectClipStage, |
Chris Craik | 117bdbc | 2015-02-05 10:12:38 -0800 | [diff] [blame] | 132 | } mStageFlags; |
| 133 | |
Chris Craik | 0318887 | 2015-02-02 18:39:33 -0800 | [diff] [blame] | 134 | ProgramDescription mDescription; |
| 135 | RenderState& mRenderState; |
| 136 | Caches& mCaches; |
Chris Craik | 922d3a7 | 2015-02-13 17:47:21 -0800 | [diff] [blame] | 137 | const SkShader* mShader; |
Chris Craik | 0318887 | 2015-02-02 18:39:33 -0800 | [diff] [blame] | 138 | Glop* mOutGlop; |
| 139 | }; |
| 140 | |
| 141 | } /* namespace uirenderer */ |
| 142 | } /* namespace android */ |