File: draw_polygon.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (80 lines) | stat: -rw-r--r-- 2,915 bytes parent folder | download | duplicates (11)
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
// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_VIZ_SERVICE_DISPLAY_DRAW_POLYGON_H_
#define COMPONENTS_VIZ_SERVICE_DISPLAY_DRAW_POLYGON_H_

#include <memory>
#include <vector>

#include "base/memory/raw_ptr.h"
#include "components/viz/service/viz_service_export.h"
#include "ui/gfx/geometry/point3_f.h"
#include "ui/gfx/geometry/quad_f.h"
#include "ui/gfx/geometry/rect_f.h"
#include "ui/gfx/geometry/transform.h"
#include "ui/gfx/geometry/vector3d_f.h"

namespace viz {
class DrawQuad;

class VIZ_SERVICE_EXPORT DrawPolygon {
 public:
  DrawPolygon();
  ~DrawPolygon();

  DrawPolygon(const DrawQuad* original_ref,
              const std::vector<gfx::Point3F>& in_points,
              const gfx::Vector3dF& normal,
              int draw_order_index = 0);
  DrawPolygon(const DrawQuad* original_ref,
              const gfx::RectF& visible_layer_rect,
              const gfx::Transform& transform,
              int draw_order_index = 0);

  void SplitPolygon(std::unique_ptr<DrawPolygon> polygon,
                    std::unique_ptr<DrawPolygon>* front,
                    std::unique_ptr<DrawPolygon>* back,
                    bool* is_coplanar) const;
  float SignedPointDistance(const gfx::Point3F& point) const;
  void ToQuads2D(std::vector<gfx::QuadF>* quads) const;
  void TransformToScreenSpace(const gfx::Transform& transform);
  void TransformToLayerSpace(const gfx::Transform& inverse_transform);

  const std::vector<gfx::Point3F>& points() const { return points_; }
  const gfx::Vector3dF& normal() const { return normal_; }
  const DrawQuad* original_ref() const { return original_ref_; }
  int order_index() const { return order_index_; }
  bool is_split() const { return is_split_; }
  std::unique_ptr<DrawPolygon> CreateCopy();

  // These are helper functions for testing.
  void RecomputeNormalForTesting();
  friend bool IsPlanarForTesting(const DrawPolygon& p);
  friend bool IsConvexForTesting(const DrawPolygon& p);

 private:
  void ApplyTransform(const gfx::Transform& transform);
  void ApplyTransformToNormal(const gfx::Transform& transform);

  void ConstructNormal();

  std::vector<gfx::Point3F> points_;
  // Normalized, necessitated by distance calculations and tests of coplanarity.
  gfx::Vector3dF normal_;
  // This is an index that can be used to test whether a quad comes before or
  // after another in document order, useful for tie-breaking when it comes
  // to coplanar surfaces.
  int order_index_;
  // The pointer to the original quad, which gives us all the drawing info
  // we need.
  // This DrawQuad is owned by the caller and its lifetime must be preserved
  // as long as this DrawPolygon is alive.
  raw_ptr<const DrawQuad> original_ref_;
  bool is_split_;
};

}  // namespace viz

#endif  // COMPONENTS_VIZ_SERVICE_DISPLAY_DRAW_POLYGON_H_