Home | History | Annotate | Download | only in test
      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 }
     23 
     24 void TestContextSupport::SignalQuery(uint32 query,
     25                                      const base::Closure& callback) {
     26   sync_point_callbacks_.push_back(callback);
     27 }
     28 
     29 void TestContextSupport::SetSurfaceVisible(bool visible) {
     30   if (!set_visible_callback_.is_null()) {
     31     set_visible_callback_.Run(visible);
     32   }
     33 }
     34 
     35 void TestContextSupport::SendManagedMemoryStats(
     36     const gpu::ManagedMemoryStats& stats) {}
     37 
     38 void TestContextSupport::CallAllSyncPointCallbacks() {
     39   for (size_t i = 0; i < sync_point_callbacks_.size(); ++i) {
     40     base::MessageLoop::current()->PostTask(
     41         FROM_HERE, sync_point_callbacks_[i]);
     42   }
     43   sync_point_callbacks_.clear();
     44 }
     45 
     46 void TestContextSupport::SetSurfaceVisibleCallback(
     47     const SurfaceVisibleCallback& set_visible_callback) {
     48   set_visible_callback_ = set_visible_callback;
     49 }
     50 
     51 void TestContextSupport::Swap() {
     52   last_swap_type_ = SWAP;
     53   base::MessageLoop::current()->PostTask(
     54       FROM_HERE, base::Bind(&TestContextSupport::OnSwapBuffersComplete,
     55                             weak_ptr_factory_.GetWeakPtr()));
     56   CallAllSyncPointCallbacks();
     57 }
     58 
     59 void TestContextSupport::PartialSwapBuffers(gfx::Rect sub_buffer) {
     60   last_swap_type_ = PARTIAL_SWAP;
     61   last_partial_swap_rect_ = sub_buffer;
     62   base::MessageLoop::current()->PostTask(
     63       FROM_HERE, base::Bind(&TestContextSupport::OnSwapBuffersComplete,
     64                             weak_ptr_factory_.GetWeakPtr()));
     65   CallAllSyncPointCallbacks();
     66 }
     67 
     68 void TestContextSupport::SetSwapBuffersCompleteCallback(
     69     const base::Closure& callback) {
     70   swap_buffers_complete_callback_ = callback;
     71 }
     72 
     73 void TestContextSupport::OnSwapBuffersComplete() {
     74   if (!swap_buffers_complete_callback_.is_null())
     75     swap_buffers_complete_callback_.Run();
     76 }
     77 
     78 }  // namespace cc
     79