blob: e7d18615fd2818c265918bd2fa337ea261e0a9ec [file] [log] [blame]
Vishnu Nair16efdbf2019-12-10 11:55:42 -08001/*
2 * Copyright 2019 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
17#pragma once
18
19#include <math/vec4.h>
20#include <ui/Rect.h>
21
22namespace android {
23namespace renderengine {
24
25class Mesh;
26
27namespace gl {
28
29/**
30 * The shadow geometry logic and vertex generation code has been ported from skia shadow
31 * fast path OpenGL implementation to draw shadows around rects and rounded rects including
32 * circles.
33 *
34 * path: skia/src/gpu/GrRenderTargetContext.cpp GrRenderTargetContext::drawFastShadow
35 *
36 * Modifications made:
37 * - Switched to using std lib math functions
38 * - Fall off function is implemented in vertex shader rather than a shadow texture
39 * - Removed transformations applied on the caster rect since the caster will be in local
40 * coordinate space and will be transformed by the vertex shader.
41 */
42
43enum RRectType {
44 kFill_RRectType,
45 kStroke_RRectType,
46 kOverstroke_RRectType,
47};
48
49struct Geometry {
50 vec4 fColor;
51 float fOuterRadius;
52 float fUmbraInset;
53 float fInnerRadius;
54 float fBlurRadius;
55 FloatRect fDevBounds;
56 RRectType fType;
57 bool fIsCircle;
58 bool fIsStroked;
59};
60
61std::unique_ptr<Geometry> getSpotShadowGeometry(const FloatRect& casterRect,
62 float casterCornerRadius, float casterZ,
63 bool casterIsTranslucent, const vec4& spotColor,
64 const vec3& lightPosition, float lightRadius);
65
66std::unique_ptr<Geometry> getAmbientShadowGeometry(const FloatRect& casterRect,
67 float casterCornerRadius, float casterZ,
68 bool casterIsTranslucent,
69 const vec4& ambientColor);
70
71int getVertexCountForGeometry(const Geometry& shadowGeometry);
72
73int getIndexCountForGeometry(const Geometry& shadowGeometry);
74
75void fillVerticesForGeometry(const Geometry& shadowGeometry, int vertexCount,
76 Mesh::VertexArray<vec2> position, Mesh::VertexArray<vec4> shadowColor,
77 Mesh::VertexArray<vec3> shadowParams);
78
79void fillIndicesForGeometry(const Geometry& shadowGeometry, int indexCount,
80 int startingVertexOffset, uint16_t* indices);
81
82} // namespace gl
83} // namespace renderengine
84} // namespace android