summaryrefslogtreecommitdiffstats
path: root/chromium/cc/layers/surface_layer_impl.h
blob: 97b1f6ce9d0c8bd48734ff3fe8fedb405f104e3c (plain)
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
92
93
94
95
96
97
98
99
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CC_LAYERS_SURFACE_LAYER_IMPL_H_
#define CC_LAYERS_SURFACE_LAYER_IMPL_H_

#include <memory>

#include "base/bind.h"
#include "base/memory/ptr_util.h"
#include "cc/cc_export.h"
#include "cc/layers/layer_impl.h"
#include "components/viz/common/quads/surface_draw_quad.h"
#include "components/viz/common/surfaces/surface_id.h"
#include "components/viz/common/surfaces/surface_info.h"
#include "components/viz/common/surfaces/surface_range.h"

namespace cc {

// This must match SurfaceLayer::UpdateSubmissionStateCB.
using UpdateSubmissionStateCB = base::RepeatingCallback<void(bool is_visible)>;

class CC_EXPORT SurfaceLayerImpl : public LayerImpl {
 public:
  static std::unique_ptr<SurfaceLayerImpl> Create(
      LayerTreeImpl* tree_impl,
      int id,
      UpdateSubmissionStateCB update_submission_state_callback) {
    return base::WrapUnique(new SurfaceLayerImpl(
        tree_impl, id, std::move(update_submission_state_callback)));
  }

  static std::unique_ptr<SurfaceLayerImpl> Create(LayerTreeImpl* tree_impl,
                                                  int id) {
    return base::WrapUnique(
        new SurfaceLayerImpl(tree_impl, id, base::BindRepeating([](bool) {})));
  }

  SurfaceLayerImpl(const SurfaceLayerImpl&) = delete;
  ~SurfaceLayerImpl() override;

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

  void SetRange(const viz::SurfaceRange& surface_range,
                base::Optional<uint32_t> deadline_in_frames);
  const viz::SurfaceRange& range() const { return surface_range_; }

  base::Optional<uint32_t> deadline_in_frames() const {
    return deadline_in_frames_;
  }

  void SetStretchContentToFillBounds(bool stretch_content);
  bool stretch_content_to_fill_bounds() const {
    return stretch_content_to_fill_bounds_;
  }

  void SetSurfaceHitTestable(bool surface_hit_testable);
  bool surface_hit_testable() const { return surface_hit_testable_; }

  void SetHasPointerEventsNone(bool has_pointer_events_none);
  bool has_pointer_events_none() const { return has_pointer_events_none_; }

  void SetIsReflection(bool is_reflection);
  bool is_reflection() const { return is_reflection_; }

  // LayerImpl overrides.
  std::unique_ptr<LayerImpl> CreateLayerImpl(LayerTreeImpl* tree_impl) override;
  void PushPropertiesTo(LayerImpl* layer) override;
  bool WillDraw(DrawMode draw_mode,
                viz::ClientResourceProvider* resource_provider) override;
  void AppendQuads(viz::RenderPass* render_pass,
                   AppendQuadsData* append_quads_data) override;
  bool is_surface_layer() const override;
  gfx::Rect GetEnclosingRectInTargetSpace() const override;

 protected:
  SurfaceLayerImpl(LayerTreeImpl* tree_impl, int id, UpdateSubmissionStateCB);

 private:
  void GetDebugBorderProperties(SkColor* color, float* width) const override;
  void AppendRainbowDebugBorder(viz::RenderPass* render_pass);
  void AsValueInto(base::trace_event::TracedValue* dict) const override;
  const char* LayerTypeAsString() const override;

  UpdateSubmissionStateCB update_submission_state_callback_;
  viz::SurfaceRange surface_range_;
  base::Optional<uint32_t> deadline_in_frames_;

  bool stretch_content_to_fill_bounds_ = false;
  bool surface_hit_testable_ = false;
  bool has_pointer_events_none_ = false;
  bool is_reflection_ = false;
  bool will_draw_ = false;
};

}  // namespace cc

#endif  // CC_LAYERS_SURFACE_LAYER_IMPL_H_