File: ui_element_renderer.h

package info (click to toggle)
chromium 138.0.7204.157-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 6,071,864 kB
  • sloc: cpp: 34,936,859; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,967; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (91 lines) | stat: -rw-r--r-- 2,837 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// Copyright 2016 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_VR_UI_ELEMENT_RENDERER_H_
#define CHROME_BROWSER_VR_UI_ELEMENT_RENDERER_H_

#include <memory>
#include <vector>

#include "base/memory/raw_ptr.h"
#include "chrome/browser/vr/elements/corner_radii.h"
#include "chrome/browser/vr/macros.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/gfx/geometry/rect_f.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/geometry/size_f.h"
#include "ui/gfx/geometry/transform.h"

namespace gfx {
class RectF;
class SizeF;
class Transform;
}  // namespace gfx

namespace vr {

class BaseRenderer;
class GridRenderer;
class RadialGradientQuadRenderer;
class TexturedQuadRenderer;

// An instance of this class is passed to UiElements by the UiRenderer in order
// to issue the GL commands for drawing the frame. In some ways, this class is a
// bit of unnecessary abstraction, but by having all the renderers owned by a
// single class, we gain several benefits. For one, we know when the shader
// programs are being changed and this lets us do batching (see the textured
// quad renderer). It also is a central point of contact that can let all
// renderers know to recreate their state in the event of a GL context
// loss/recreation.
class UiElementRenderer {
 public:
  UiElementRenderer();

  UiElementRenderer(const UiElementRenderer&) = delete;
  UiElementRenderer& operator=(const UiElementRenderer&) = delete;

  VIRTUAL_FOR_MOCKS ~UiElementRenderer();

  VIRTUAL_FOR_MOCKS void DrawTexturedQuad(
      int texture_data_handle,
      int overlay_texture_data_handle,
      const gfx::Transform& model_view_proj_matrix,
      const gfx::RectF& clip_rect,
      float opacity,
      const gfx::SizeF& element_size,
      float corner_radius,
      bool blend);
  VIRTUAL_FOR_MOCKS void DrawRadialGradientQuad(
      const gfx::Transform& model_view_proj_matrix,
      const SkColor edge_color,
      const SkColor center_color,
      const gfx::RectF& clip_rect,
      float opacity,
      const gfx::SizeF& element_size,
      const CornerRadii& radii);
  VIRTUAL_FOR_MOCKS void DrawGradientGridQuad(
      const gfx::Transform& model_view_proj_matrix,
      const SkColor grid_color,
      int gridline_count,
      float opacity);

  void Flush();

 protected:
  explicit UiElementRenderer(bool use_gl);

 private:
  void Init();
  void FlushIfNecessary(BaseRenderer* renderer);

  raw_ptr<BaseRenderer> last_renderer_ = nullptr;

  std::unique_ptr<TexturedQuadRenderer> textured_quad_renderer_;
  std::unique_ptr<RadialGradientQuadRenderer> radial_gradient_quad_renderer_;
  std::unique_ptr<GridRenderer> gradient_grid_renderer_;
};

}  // namespace vr

#endif  // CHROME_BROWSER_VR_UI_ELEMENT_RENDERER_H_