summaryrefslogtreecommitdiffstats
path: root/cc/test/fake_output_surface.h
blob: a7a68bd9f0636af3c86387faa964088a0efd901d (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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
// Copyright 2012 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_TEST_FAKE_OUTPUT_SURFACE_H_
#define CC_TEST_FAKE_OUTPUT_SURFACE_H_

#include <stddef.h>

#include "base/callback.h"
#include "base/logging.h"
#include "base/time/time.h"
#include "cc/output/begin_frame_args.h"
#include "cc/output/compositor_frame.h"
#include "cc/output/managed_memory_policy.h"
#include "cc/output/output_surface.h"
#include "cc/output/software_output_device.h"
#include "cc/test/test_context_provider.h"
#include "cc/test/test_web_graphics_context_3d.h"

namespace cc {

class FakeOutputSurface : public OutputSurface {
 public:
  ~FakeOutputSurface() override;

  static scoped_ptr<FakeOutputSurface> Create3d() {
    return make_scoped_ptr(
        new FakeOutputSurface(TestContextProvider::Create(),
                              TestContextProvider::CreateWorker(), false));
  }

  static scoped_ptr<FakeOutputSurface> Create3d(
      scoped_refptr<ContextProvider> context_provider) {
    return make_scoped_ptr(new FakeOutputSurface(
        context_provider, TestContextProvider::CreateWorker(), false));
  }

  static scoped_ptr<FakeOutputSurface> Create3d(
      scoped_refptr<ContextProvider> context_provider,
      scoped_refptr<ContextProvider> worker_context_provider) {
    return make_scoped_ptr(new FakeOutputSurface(
        context_provider, worker_context_provider, false));
  }

  static scoped_ptr<FakeOutputSurface> Create3d(
      scoped_ptr<TestWebGraphicsContext3D> context) {
    return make_scoped_ptr(
        new FakeOutputSurface(TestContextProvider::Create(std::move(context)),
                              TestContextProvider::CreateWorker(), false));
  }

  static scoped_ptr<FakeOutputSurface> CreateSoftware(
      scoped_ptr<SoftwareOutputDevice> software_device) {
    return make_scoped_ptr(
        new FakeOutputSurface(std::move(software_device), false));
  }

  static scoped_ptr<FakeOutputSurface>
  Create3dWithResourcelessSoftwareSupport() {
    return make_scoped_ptr(new FakeOutputSurface(
        TestContextProvider::Create(),
        make_scoped_ptr(new SoftwareOutputDevice), false));
  }

  static scoped_ptr<FakeOutputSurface> CreateDelegating3d() {
    return make_scoped_ptr(
        new FakeOutputSurface(TestContextProvider::Create(),
                              TestContextProvider::CreateWorker(), true));
  }

  static scoped_ptr<FakeOutputSurface> CreateDelegating3d(
      scoped_refptr<TestContextProvider> context_provider) {
    return make_scoped_ptr(new FakeOutputSurface(
        context_provider, TestContextProvider::CreateWorker(), true));
  }

  static scoped_ptr<FakeOutputSurface> CreateDelegating3d(
      scoped_ptr<TestWebGraphicsContext3D> context) {
    return make_scoped_ptr(
        new FakeOutputSurface(TestContextProvider::Create(std::move(context)),
                              TestContextProvider::CreateWorker(), true));
  }

  static scoped_ptr<FakeOutputSurface> CreateDelegatingSoftware(
      scoped_ptr<SoftwareOutputDevice> software_device) {
    return make_scoped_ptr(
        new FakeOutputSurface(std::move(software_device), true));
  }

  static scoped_ptr<FakeOutputSurface> CreateNoRequireSyncPoint(
      scoped_ptr<TestWebGraphicsContext3D> context) {
    scoped_ptr<FakeOutputSurface> surface(Create3d(std::move(context)));
    surface->capabilities_.delegated_sync_points_required = false;
    return surface;
  }

  static scoped_ptr<FakeOutputSurface> CreateOffscreen(
      scoped_ptr<TestWebGraphicsContext3D> context) {
    scoped_ptr<FakeOutputSurface> surface(new FakeOutputSurface(
        TestContextProvider::Create(std::move(context)), false));
    surface->capabilities_.uses_default_gl_framebuffer = false;
    return surface;
  }

  void set_max_frames_pending(int max) {
    capabilities_.max_frames_pending = max;
  }

  CompositorFrame& last_sent_frame() { return last_sent_frame_; }
  size_t num_sent_frames() { return num_sent_frames_; }

  void SwapBuffers(CompositorFrame* frame) override;

  OutputSurfaceClient* client() { return client_; }
  bool BindToClient(OutputSurfaceClient* client) override;

  void set_framebuffer(unsigned framebuffer) { framebuffer_ = framebuffer; }
  void BindFramebuffer() override;

  void SetTreeActivationCallback(const base::Closure& callback);

  const TransferableResourceArray& resources_held_by_parent() {
    return resources_held_by_parent_;
  }

  void ReturnResource(unsigned id, CompositorFrameAck* ack);

  bool HasExternalStencilTest() const override;

  bool SurfaceIsSuspendForRecycle() const override;

  OverlayCandidateValidator* GetOverlayCandidateValidator() const override;
  void SetOverlayCandidateValidator(OverlayCandidateValidator* validator) {
    overlay_candidate_validator_ = validator;
  }

  void set_has_external_stencil_test(bool has_test) {
    has_external_stencil_test_ = has_test;
  }

  void set_suspended_for_recycle(bool suspended) {
    suspended_for_recycle_ = suspended;
  }

  void SetMemoryPolicyToSetAtBind(
      scoped_ptr<ManagedMemoryPolicy> memory_policy_to_set_at_bind);

  gfx::Rect last_swap_rect() const {
    return last_swap_rect_;
  }

 protected:
  FakeOutputSurface(
      scoped_refptr<ContextProvider> context_provider,
      bool delegated_rendering);

  FakeOutputSurface(scoped_refptr<ContextProvider> context_provider,
                    scoped_refptr<ContextProvider> worker_context_provider,
                    bool delegated_rendering);

  FakeOutputSurface(scoped_ptr<SoftwareOutputDevice> software_device,
                    bool delegated_rendering);

  FakeOutputSurface(
      scoped_refptr<ContextProvider> context_provider,
      scoped_ptr<SoftwareOutputDevice> software_device,
      bool delegated_rendering);

  OutputSurfaceClient* client_;
  CompositorFrame last_sent_frame_;
  size_t num_sent_frames_;
  bool has_external_stencil_test_;
  bool suspended_for_recycle_;
  unsigned framebuffer_;
  TransferableResourceArray resources_held_by_parent_;
  scoped_ptr<ManagedMemoryPolicy> memory_policy_to_set_at_bind_;
  OverlayCandidateValidator* overlay_candidate_validator_;
  gfx::Rect last_swap_rect_;
};

}  // namespace cc

#endif  // CC_TEST_FAKE_OUTPUT_SURFACE_H_