summaryrefslogtreecommitdiffstats
path: root/cc/test/test_context_support.cc
blob: a2bedc0835219e3f6193d8bda6087e5b83d11a3a (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
// Copyright 2013 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.

#include "cc/test/test_context_support.h"

#include "base/bind.h"
#include "base/message_loop/message_loop.h"

namespace cc {

TestContextSupport::TestContextSupport()
    : last_swap_type_(NO_SWAP),
      weak_ptr_factory_(this) {
}

TestContextSupport::~TestContextSupport() {}

void TestContextSupport::SignalSyncPoint(uint32 sync_point,
                                         const base::Closure& callback) {
  sync_point_callbacks_.push_back(callback);
  base::MessageLoop::current()->PostTask(
      FROM_HERE,
      base::Bind(&TestContextSupport::CallAllSyncPointCallbacks,
                 weak_ptr_factory_.GetWeakPtr()));
}

void TestContextSupport::SignalQuery(uint32 query,
                                     const base::Closure& callback) {
  sync_point_callbacks_.push_back(callback);
  base::MessageLoop::current()->PostTask(
      FROM_HERE,
      base::Bind(&TestContextSupport::CallAllSyncPointCallbacks,
                 weak_ptr_factory_.GetWeakPtr()));
}

void TestContextSupport::SetSurfaceVisible(bool visible) {
  if (!set_visible_callback_.is_null()) {
    set_visible_callback_.Run(visible);
  }
}

void TestContextSupport::CallAllSyncPointCallbacks() {
  for (size_t i = 0; i < sync_point_callbacks_.size(); ++i) {
    base::MessageLoop::current()->PostTask(
        FROM_HERE, sync_point_callbacks_[i]);
  }
  sync_point_callbacks_.clear();
}

void TestContextSupport::SetSurfaceVisibleCallback(
    const SurfaceVisibleCallback& set_visible_callback) {
  set_visible_callback_ = set_visible_callback;
}

void TestContextSupport::SetScheduleOverlayPlaneCallback(
    const ScheduleOverlayPlaneCallback& schedule_overlay_plane_callback) {
  schedule_overlay_plane_callback_ = schedule_overlay_plane_callback;
}

void TestContextSupport::Swap() {
  last_swap_type_ = SWAP;
  base::MessageLoop::current()->PostTask(
      FROM_HERE, base::Bind(&TestContextSupport::OnSwapBuffersComplete,
                            weak_ptr_factory_.GetWeakPtr()));
}

uint32 TestContextSupport::InsertFutureSyncPointCHROMIUM() {
  NOTIMPLEMENTED();
  return 0;
}

void TestContextSupport::RetireSyncPointCHROMIUM(uint32 sync_point) {
  NOTIMPLEMENTED();
}

void TestContextSupport::PartialSwapBuffers(const gfx::Rect& sub_buffer) {
  last_swap_type_ = PARTIAL_SWAP;
  last_partial_swap_rect_ = sub_buffer;
  base::MessageLoop::current()->PostTask(
      FROM_HERE, base::Bind(&TestContextSupport::OnSwapBuffersComplete,
                            weak_ptr_factory_.GetWeakPtr()));
}

void TestContextSupport::ScheduleOverlayPlane(
    int plane_z_order,
    gfx::OverlayTransform plane_transform,
    unsigned overlay_texture_id,
    const gfx::Rect& display_bounds,
    const gfx::RectF& uv_rect) {
  if (!schedule_overlay_plane_callback_.is_null()) {
    schedule_overlay_plane_callback_.Run(plane_z_order,
                                         plane_transform,
                                         overlay_texture_id,
                                         display_bounds,
                                         uv_rect);
  }
}

void TestContextSupport::SetSwapBuffersCompleteCallback(
    const base::Closure& callback) {
  swap_buffers_complete_callback_ = callback;
}

void TestContextSupport::OnSwapBuffersComplete() {
  if (!swap_buffers_complete_callback_.is_null())
    swap_buffers_complete_callback_.Run();
}

}  // namespace cc