blob: cbdd0cd19b7b454dfe3969dcfd17095845444d52 [file] [log] [blame]
Chris Craik03188872015-02-02 18:39:33 -08001/*
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
23class SkPaint;
Chris Craik922d3a72015-02-13 17:47:21 -080024class SkShader;
Chris Craik03188872015-02-02 18:39:33 -080025
26namespace android {
27namespace uirenderer {
28
29class Caches;
Chris Craik117bdbc2015-02-05 10:12:38 -080030class Matrix4;
Chris Craik03188872015-02-02 18:39:33 -080031class RenderState;
32class Texture;
Chris Craik117bdbc2015-02-05 10:12:38 -080033class VertexBuffer;
Chris Craik922d3a72015-02-13 17:47:21 -080034struct Glop;
Chris Craik03188872015-02-02 18:39:33 -080035
36class GlopBuilder {
37 PREVENT_COPY_AND_ASSIGN(GlopBuilder);
38public:
39 GlopBuilder(RenderState& renderState, Caches& caches, Glop* outGlop);
Chris Craik2ab95d72015-02-06 15:25:51 -080040
Chris Craik03188872015-02-02 18:39:33 -080041 GlopBuilder& setMeshUnitQuad();
Chris Craikf27133d2015-02-19 09:51:53 -080042 GlopBuilder& setMeshTexturedUnitQuad(const UvMapper* uvMapper);
Chris Craik117bdbc2015-02-05 10:12:38 -080043 GlopBuilder& setMeshVertexBuffer(const VertexBuffer& vertexBuffer, bool shadowInterp);
Chris Craik2ab95d72015-02-06 15:25:51 -080044 GlopBuilder& setMeshIndexedQuads(void* vertexData, int quadCount);
Chris Craikf27133d2015-02-19 09:51:53 -080045 GlopBuilder& setMeshTexturedIndexedQuads(TextureVertex* vertexData, int elementCount); // TODO: take quadCount
Chris Craik117bdbc2015-02-05 10:12:38 -080046
Chris Craik0519c812015-02-11 13:17:06 -080047 GlopBuilder& setFillPaint(const SkPaint& paint, float alphaScale);
48 GlopBuilder& setFillTexturePaint(Texture& texture, bool isAlphaMaskTexture,
49 const SkPaint* paint, float alphaScale);
Chris Craik2bb8f562015-02-17 16:42:02 -080050 GlopBuilder& setFillPathTexturePaint(PathTexture& texture,
Chris Craik30036092015-02-12 10:41:39 -080051 const SkPaint& paint, float alphaScale);
Chris Craik2bb8f562015-02-17 16:42:02 -080052 GlopBuilder& setFillShadowTexturePaint(ShadowTexture& texture, int shadowColor,
53 const SkPaint& paint, float alphaScale);
54 GlopBuilder& setFillBlack();
55 GlopBuilder& setFillClear();
Chris Craikf27133d2015-02-19 09:51:53 -080056 GlopBuilder& setFillLayer(Texture& texture, const SkColorFilter* colorFilter,
57 float alpha, SkXfermode::Mode mode);
Chris Craik0519c812015-02-11 13:17:06 -080058
Chris Craikf27133d2015-02-19 09:51:53 -080059 GlopBuilder& setTransform(const Matrix4& ortho, const Matrix4& transform, bool fudgingOffset);
Chris Craik117bdbc2015-02-05 10:12:38 -080060
61 GlopBuilder& setModelViewMapUnitToRect(const Rect destination);
Chris Craik0519c812015-02-11 13:17:06 -080062 GlopBuilder& setModelViewMapUnitToRectSnap(const Rect destination);
Chris Craik117bdbc2015-02-05 10:12:38 -080063 GlopBuilder& setModelViewOffsetRect(float offsetX, float offsetY, const Rect source);
Chris Craikf27133d2015-02-19 09:51:53 -080064 GlopBuilder& setModelViewOffsetRectSnap(float offsetX, float offsetY, const Rect source);
Chris Craik117bdbc2015-02-05 10:12:38 -080065
Chris Craik0519c812015-02-11 13:17:06 -080066 GlopBuilder& setRoundRectClipState(const RoundRectClipState* roundRectClipState);
67
Chris Craik03188872015-02-02 18:39:33 -080068 void build();
69private:
Chris Craik0519c812015-02-11 13:17:06 -080070 void setFill(int color, float alphaScale, SkXfermode::Mode mode,
71 const SkShader* shader, const SkColorFilter* colorFilter);
72
Chris Craik117bdbc2015-02-05 10:12:38 -080073 enum StageFlags {
74 kInitialStage = 0,
75 kMeshStage = 1 << 0,
76 kTransformStage = 1 << 1,
77 kModelViewStage = 1 << 2,
78 kFillStage = 1 << 3,
Chris Craik0519c812015-02-11 13:17:06 -080079 kRoundRectClipStage = 1 << 4,
80 kAllStages = kMeshStage | kFillStage | kTransformStage | kModelViewStage | kRoundRectClipStage,
Chris Craik117bdbc2015-02-05 10:12:38 -080081 } mStageFlags;
82
Chris Craik03188872015-02-02 18:39:33 -080083 ProgramDescription mDescription;
84 RenderState& mRenderState;
85 Caches& mCaches;
Chris Craik922d3a72015-02-13 17:47:21 -080086 const SkShader* mShader;
Chris Craik03188872015-02-02 18:39:33 -080087 Glop* mOutGlop;
88};
89
90} /* namespace uirenderer */
91} /* namespace android */
92
93#endif // RENDERSTATE_GLOPBUILDER_H