1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef CHROME_BROWSER_VR_ELEMENTS_SHADOW_H_
6 #define CHROME_BROWSER_VR_ELEMENTS_SHADOW_H_
7 
8 #include "base/macros.h"
9 #include "chrome/browser/vr/elements/ui_element.h"
10 #include "chrome/browser/vr/renderers/base_quad_renderer.h"
11 #include "chrome/browser/vr/vr_ui_export.h"
12 #include "third_party/skia/include/core/SkColor.h"
13 
14 namespace vr {
15 
16 // A shadow is meant to be the ancestor of elements to which a shadow is to be
17 // applied. The shadow is applied across its padding.
18 // By default the direct child is used as the shadow caster. This behavior can
19 // be changed by manually setting a shadow caster.
20 class VR_UI_EXPORT Shadow : public UiElement {
21  public:
22   Shadow();
23   ~Shadow() override;
24 
25   void Render(UiElementRenderer* renderer,
26               const CameraModel& camera_model) const override;
27 
28   void LayOutContributingChildren() override;
set_intensity(float intensity)29   void set_intensity(float intensity) { intensity_ = intensity; }
set_shadow_caster(UiElement * shadow_caster)30   void set_shadow_caster(UiElement* shadow_caster) {
31     shadow_caster_ = shadow_caster;
32   }
33 
34   class Renderer : public BaseQuadRenderer {
35    public:
36     Renderer();
37     ~Renderer() override;
38 
39     void Draw(const gfx::Transform& model_view_proj_matrix,
40               const gfx::SizeF& element_size,
41               float x_padding,
42               float y_padding,
43               float y_offset,
44               SkColor color,
45               float opacity,
46               float corner_radius);
47 
48    private:
49     GLuint model_view_proj_matrix_handle_;
50     GLuint x_padding_handle_;
51     GLuint y_padding_handle_;
52     GLuint y_offset_handle_;
53     GLuint color_handle_;
54     GLuint opacity_handle_;
55     GLuint x_corner_radius_handle_;
56     GLuint y_corner_radius_handle_;
57 
58     DISALLOW_COPY_AND_ASSIGN(Renderer);
59   };
60 
61  private:
62   float depth_;
63   float intensity_ = 1.0f;
64   UiElement* shadow_caster_ = nullptr;
65   gfx::SizeF contributed_size_;
66 
67   DISALLOW_COPY_AND_ASSIGN(Shadow);
68 };
69 
70 }  // namespace vr
71 
72 #endif  // CHROME_BROWSER_VR_ELEMENTS_SHADOW_H_
73