18bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved.
28bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
38bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)// found in the LICENSE file.
48bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
50f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)#ifndef CC_TEST_TEST_CONTEXT_SUPPORT_H_
60f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)#define CC_TEST_TEST_CONTEXT_SUPPORT_H_
78bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
88bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#include <vector>
98bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
10a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "base/memory/weak_ptr.h"
118bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#include "gpu/command_buffer/client/context_support.h"
128bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
138bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)namespace cc {
148bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
158bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)class TestContextSupport : public gpu::ContextSupport {
168bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) public:
178bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  TestContextSupport();
188bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  virtual ~TestContextSupport();
198bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
208bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  // gpu::ContextSupport implementation.
218bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  virtual void SignalSyncPoint(uint32 sync_point,
228bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)                               const base::Closure& callback) OVERRIDE;
238bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  virtual void SignalQuery(uint32 query,
248bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)                           const base::Closure& callback) OVERRIDE;
25a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  virtual void SetSurfaceVisible(bool visible) OVERRIDE;
26a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  virtual void Swap() OVERRIDE;
275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual void PartialSwapBuffers(const gfx::Rect& sub_buffer) OVERRIDE;
28116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  virtual uint32 InsertFutureSyncPointCHROMIUM() OVERRIDE;
29116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  virtual void RetireSyncPointCHROMIUM(uint32 sync_point) OVERRIDE;
30a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  virtual void SetSwapBuffersCompleteCallback(
31a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      const base::Closure& callback) OVERRIDE;
32effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  virtual void ScheduleOverlayPlane(int plane_z_order,
33c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch                                    gfx::OverlayTransform plane_transform,
34effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch                                    unsigned overlay_texture_id,
35effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch                                    const gfx::Rect& display_bounds,
36effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch                                    const gfx::RectF& uv_rect) OVERRIDE;
378bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
388bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  void CallAllSyncPointCallbacks();
398bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
40a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  typedef base::Callback<void(bool visible)> SurfaceVisibleCallback;
41a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  void SetSurfaceVisibleCallback(
42a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      const SurfaceVisibleCallback& set_visible_callback);
43a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
44effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  typedef base::Callback<void(int plane_z_order,
45c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch                              gfx::OverlayTransform plane_transform,
46effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch                              unsigned overlay_texture_id,
47effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch                              const gfx::Rect& display_bounds,
48effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch                              const gfx::RectF& crop_rect)>
49effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch      ScheduleOverlayPlaneCallback;
50effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  void SetScheduleOverlayPlaneCallback(
51effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch      const ScheduleOverlayPlaneCallback& schedule_overlay_plane_callback);
52effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch
53a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  enum SwapType {
54a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    NO_SWAP,
55a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    SWAP,
56a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    PARTIAL_SWAP
57a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  };
58a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
59a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  SwapType last_swap_type() const { return last_swap_type_; }
60a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  gfx::Rect last_partial_swap_rect() const {
61a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    return last_partial_swap_rect_;
62a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  }
63a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
648bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) private:
65a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  void OnSwapBuffersComplete();
66a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
678bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  std::vector<base::Closure> sync_point_callbacks_;
68a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  SurfaceVisibleCallback set_visible_callback_;
69effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  ScheduleOverlayPlaneCallback schedule_overlay_plane_callback_;
70a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
71a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  base::Closure swap_buffers_complete_callback_;
72a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
73a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  SwapType last_swap_type_;
74a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  gfx::Rect last_partial_swap_rect_;
75a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
76a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  base::WeakPtrFactory<TestContextSupport> weak_ptr_factory_;
778bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
788bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(TestContextSupport);
798bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)};
808bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
818bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)}  // namespace cc
828bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
830f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)#endif  // CC_TEST_TEST_CONTEXT_SUPPORT_H_
84