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.
5 #include "gpu/command_buffer/service/async_pixel_transfer_manager_sync.h"
7 #include "gpu/command_buffer/service/async_pixel_transfer_delegate.h"
11 // Class which handles async pixel transfers synchronously.
12 class AsyncPixelTransferDelegateSync
: public AsyncPixelTransferDelegate
{
14 explicit AsyncPixelTransferDelegateSync(
15 AsyncPixelTransferManagerSync::SharedState
* shared_state
);
16 virtual ~AsyncPixelTransferDelegateSync();
18 // Implement AsyncPixelTransferDelegate:
19 virtual void AsyncTexImage2D(
20 const AsyncTexImage2DParams
& tex_params
,
21 const AsyncMemoryParams
& mem_params
,
22 const base::Closure
& bind_callback
) OVERRIDE
;
23 virtual void AsyncTexSubImage2D(
24 const AsyncTexSubImage2DParams
& tex_params
,
25 const AsyncMemoryParams
& mem_params
) OVERRIDE
;
26 virtual bool TransferIsInProgress() OVERRIDE
;
27 virtual void WaitForTransferCompletion() OVERRIDE
;
30 // Safe to hold a raw pointer because SharedState is owned by the Manager
31 // which owns the Delegate.
32 AsyncPixelTransferManagerSync::SharedState
* shared_state_
;
34 DISALLOW_COPY_AND_ASSIGN(AsyncPixelTransferDelegateSync
);
37 AsyncPixelTransferDelegateSync::AsyncPixelTransferDelegateSync(
38 AsyncPixelTransferManagerSync::SharedState
* shared_state
)
39 : shared_state_(shared_state
) {}
41 AsyncPixelTransferDelegateSync::~AsyncPixelTransferDelegateSync() {}
43 void AsyncPixelTransferDelegateSync::AsyncTexImage2D(
44 const AsyncTexImage2DParams
& tex_params
,
45 const AsyncMemoryParams
& mem_params
,
46 const base::Closure
& bind_callback
) {
47 // Save the define params to return later during deferred
48 // binding of the transfer texture.
49 void* data
= mem_params
.GetDataAddress();
50 base::TimeTicks
begin_time(base::TimeTicks::HighResNow());
54 tex_params
.internal_format
,
61 shared_state_
->texture_upload_count
++;
62 shared_state_
->total_texture_upload_time
+=
63 base::TimeTicks::HighResNow() - begin_time
;
64 // The texture is already fully bound so just call it now.
68 void AsyncPixelTransferDelegateSync::AsyncTexSubImage2D(
69 const AsyncTexSubImage2DParams
& tex_params
,
70 const AsyncMemoryParams
& mem_params
) {
71 void* data
= mem_params
.GetDataAddress();
72 base::TimeTicks
begin_time(base::TimeTicks::HighResNow());
83 shared_state_
->texture_upload_count
++;
84 shared_state_
->total_texture_upload_time
+=
85 base::TimeTicks::HighResNow() - begin_time
;
88 bool AsyncPixelTransferDelegateSync::TransferIsInProgress() {
93 void AsyncPixelTransferDelegateSync::WaitForTransferCompletion() {
97 AsyncPixelTransferManagerSync::SharedState::SharedState()
98 : texture_upload_count(0) {}
100 AsyncPixelTransferManagerSync::SharedState::~SharedState() {}
102 AsyncPixelTransferManagerSync::AsyncPixelTransferManagerSync() {}
104 AsyncPixelTransferManagerSync::~AsyncPixelTransferManagerSync() {}
106 void AsyncPixelTransferManagerSync::BindCompletedAsyncTransfers() {
107 // Everything is already bound.
110 void AsyncPixelTransferManagerSync::AsyncNotifyCompletion(
111 const AsyncMemoryParams
& mem_params
,
112 AsyncPixelTransferCompletionObserver
* observer
) {
113 observer
->DidComplete(mem_params
);
116 uint32
AsyncPixelTransferManagerSync::GetTextureUploadCount() {
117 return shared_state_
.texture_upload_count
;
120 base::TimeDelta
AsyncPixelTransferManagerSync::GetTotalTextureUploadTime() {
121 return shared_state_
.total_texture_upload_time
;
124 void AsyncPixelTransferManagerSync::ProcessMorePendingTransfers() {
127 bool AsyncPixelTransferManagerSync::NeedsProcessMorePendingTransfers() {
131 void AsyncPixelTransferManagerSync::WaitAllAsyncTexImage2D() {
134 AsyncPixelTransferDelegate
*
135 AsyncPixelTransferManagerSync::CreatePixelTransferDelegateImpl(
136 gles2::TextureRef
* ref
,
137 const AsyncTexImage2DParams
& define_params
) {
138 return new AsyncPixelTransferDelegateSync(&shared_state_
);