Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / cc / test / test_context_support.cc
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "cc/test/test_context_support.h"
6
7 #include "base/bind.h"
8 #include "base/message_loop/message_loop.h"
9
10 namespace cc {
11
12 TestContextSupport::TestContextSupport()
13     : last_swap_type_(NO_SWAP),
14       weak_ptr_factory_(this) {
15 }
16
17 TestContextSupport::~TestContextSupport() {}
18
19 void TestContextSupport::SignalSyncPoint(uint32 sync_point,
20                                          const base::Closure& callback) {
21   sync_point_callbacks_.push_back(callback);
22   base::MessageLoop::current()->PostTask(
23       FROM_HERE,
24       base::Bind(&TestContextSupport::CallAllSyncPointCallbacks,
25                  weak_ptr_factory_.GetWeakPtr()));
26 }
27
28 void TestContextSupport::SignalQuery(uint32 query,
29                                      const base::Closure& callback) {
30   sync_point_callbacks_.push_back(callback);
31   base::MessageLoop::current()->PostTask(
32       FROM_HERE,
33       base::Bind(&TestContextSupport::CallAllSyncPointCallbacks,
34                  weak_ptr_factory_.GetWeakPtr()));
35 }
36
37 void TestContextSupport::SetSurfaceVisible(bool visible) {
38   if (!set_visible_callback_.is_null()) {
39     set_visible_callback_.Run(visible);
40   }
41 }
42
43 void TestContextSupport::SendManagedMemoryStats(
44     const gpu::ManagedMemoryStats& stats) {}
45
46 void TestContextSupport::CallAllSyncPointCallbacks() {
47   for (size_t i = 0; i < sync_point_callbacks_.size(); ++i) {
48     base::MessageLoop::current()->PostTask(
49         FROM_HERE, sync_point_callbacks_[i]);
50   }
51   sync_point_callbacks_.clear();
52 }
53
54 void TestContextSupport::SetSurfaceVisibleCallback(
55     const SurfaceVisibleCallback& set_visible_callback) {
56   set_visible_callback_ = set_visible_callback;
57 }
58
59 void TestContextSupport::SetScheduleOverlayPlaneCallback(
60     const ScheduleOverlayPlaneCallback& schedule_overlay_plane_callback) {
61   schedule_overlay_plane_callback_ = schedule_overlay_plane_callback;
62 }
63
64 void TestContextSupport::Swap() {
65   last_swap_type_ = SWAP;
66   base::MessageLoop::current()->PostTask(
67       FROM_HERE, base::Bind(&TestContextSupport::OnSwapBuffersComplete,
68                             weak_ptr_factory_.GetWeakPtr()));
69 }
70
71 void TestContextSupport::PartialSwapBuffers(const gfx::Rect& sub_buffer) {
72   last_swap_type_ = PARTIAL_SWAP;
73   last_partial_swap_rect_ = sub_buffer;
74   base::MessageLoop::current()->PostTask(
75       FROM_HERE, base::Bind(&TestContextSupport::OnSwapBuffersComplete,
76                             weak_ptr_factory_.GetWeakPtr()));
77 }
78
79 void TestContextSupport::ScheduleOverlayPlane(
80     int plane_z_order,
81     gfx::OverlayTransform plane_transform,
82     unsigned overlay_texture_id,
83     const gfx::Rect& display_bounds,
84     const gfx::RectF& uv_rect) {
85   if (!schedule_overlay_plane_callback_.is_null()) {
86     schedule_overlay_plane_callback_.Run(plane_z_order,
87                                          plane_transform,
88                                          overlay_texture_id,
89                                          display_bounds,
90                                          uv_rect);
91   }
92 }
93
94 void TestContextSupport::SetSwapBuffersCompleteCallback(
95     const base::Closure& callback) {
96   swap_buffers_complete_callback_ = callback;
97 }
98
99 void TestContextSupport::OnSwapBuffersComplete() {
100   if (!swap_buffers_complete_callback_.is_null())
101     swap_buffers_complete_callback_.Run();
102 }
103
104 }  // namespace cc