1 // Copyright (c) 2012 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.
5 // Helper classes for implementing gpu client side unit tests.
7 #ifndef GPU_COMMAND_BUFFER_CLIENT_CLIENT_TEST_HELPER_H_
8 #define GPU_COMMAND_BUFFER_CLIENT_CLIENT_TEST_HELPER_H_
10 #include "base/compiler_specific.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "gpu/command_buffer/client/gpu_control.h"
13 #include "gpu/command_buffer/common/cmd_buffer_common.h"
14 #include "gpu/command_buffer/common/gpu_memory_allocation.h"
15 #include "gpu/command_buffer/service/command_buffer_service.h"
16 #include "testing/gmock/include/gmock/gmock.h"
17 #include "testing/gtest/include/gtest/gtest.h"
21 class CommandBufferHelper
;
23 class MockCommandBufferBase
: public CommandBufferServiceBase
{
25 static const int32 kTransferBufferBaseId
= 0x123;
26 static const int32 kMaxTransferBuffers
= 32;
28 MockCommandBufferBase();
29 ~MockCommandBufferBase() override
;
31 bool Initialize() override
;
32 State
GetLastState() override
;
33 int32
GetLastToken() override
;
34 void WaitForTokenInRange(int32 start
, int32 end
) override
;
35 void WaitForGetOffsetInRange(int32 start
, int32 end
) override
;
36 void SetGetBuffer(int transfer_buffer_id
) override
;
37 void SetGetOffset(int32 get_offset
) override
;
38 scoped_refptr
<gpu::Buffer
> CreateTransferBuffer(size_t size
,
40 scoped_refptr
<gpu::Buffer
> GetTransferBuffer(int32 id
) override
;
41 void SetToken(int32 token
) override
;
42 void SetParseError(error::Error error
) override
;
43 void SetContextLostReason(error::ContextLostReason reason
) override
;
44 int32
GetPutOffset() override
;
46 // Get's the Id of the next transfer buffer that will be returned
47 // by CreateTransferBuffer. This is useful for testing expected ids.
48 int32
GetNextFreeTransferBufferId();
50 void FlushHelper(int32 put_offset
);
51 void DestroyTransferBufferHelper(int32 id
);
53 virtual void OnFlush() = 0;
56 scoped_refptr
<Buffer
> transfer_buffer_buffers_
[kMaxTransferBuffers
];
57 CommandBufferEntry
* ring_buffer_
;
58 scoped_refptr
<Buffer
> ring_buffer_buffer_
;
63 class MockClientCommandBuffer
: public MockCommandBufferBase
{
65 MockClientCommandBuffer();
66 ~MockClientCommandBuffer() override
;
68 // This is so we can use all the gmock functions when Flush is called.
69 MOCK_METHOD0(OnFlush
, void());
70 MOCK_METHOD1(DestroyTransferBuffer
, void(int32 id
));
72 void Flush(int32 put_offset
) override
;
73 void OrderingBarrier(int32 put_offset
) override
;
75 void DelegateToFake();
78 class MockClientCommandBufferMockFlush
: public MockClientCommandBuffer
{
80 MockClientCommandBufferMockFlush();
81 virtual ~MockClientCommandBufferMockFlush();
83 MOCK_METHOD1(Flush
, void(int32 put_offset
));
84 MOCK_METHOD1(OrderingBarrier
, void(int32 put_offset
));
86 void DelegateToFake();
89 class MockClientGpuControl
: public GpuControl
{
91 MockClientGpuControl();
92 virtual ~MockClientGpuControl();
94 MOCK_METHOD0(GetCapabilities
, Capabilities());
95 MOCK_METHOD4(CreateImage
,
96 int32(ClientBuffer buffer
,
99 unsigned internalformat
));
100 MOCK_METHOD1(DestroyImage
, void(int32 id
));
101 MOCK_METHOD4(CreateGpuMemoryBufferImage
,
104 unsigned internalformat
,
106 MOCK_METHOD0(InsertSyncPoint
, uint32());
107 MOCK_METHOD0(InsertFutureSyncPoint
, uint32());
108 MOCK_METHOD1(RetireSyncPoint
, void(uint32 id
));
109 MOCK_METHOD2(SignalSyncPoint
, void(uint32 id
, const base::Closure
& callback
));
110 MOCK_METHOD2(SignalQuery
, void(uint32 query
, const base::Closure
& callback
));
111 MOCK_METHOD1(SetSurfaceVisible
, void(bool visible
));
112 MOCK_METHOD1(CreateStreamTexture
, uint32(uint32
));
113 MOCK_METHOD1(SetLock
, void(base::Lock
*));
114 MOCK_METHOD0(IsGpuChannelLost
, bool());
117 DISALLOW_COPY_AND_ASSIGN(MockClientGpuControl
);
122 #endif // GPU_COMMAND_BUFFER_CLIENT_CLIENT_TEST_HELPER_H_