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 ~AsyncPixelTransferDelegateSync() override
;
18 // Implement AsyncPixelTransferDelegate:
19 void AsyncTexImage2D(const AsyncTexImage2DParams
& tex_params
,
20 const AsyncMemoryParams
& mem_params
,
21 const base::Closure
& bind_callback
) override
;
22 void AsyncTexSubImage2D(const AsyncTexSubImage2DParams
& tex_params
,
23 const AsyncMemoryParams
& mem_params
) override
;
24 bool TransferIsInProgress() override
;
25 void WaitForTransferCompletion() override
;
28 // Safe to hold a raw pointer because SharedState is owned by the Manager
29 // which owns the Delegate.
30 AsyncPixelTransferManagerSync::SharedState
* shared_state_
;
32 DISALLOW_COPY_AND_ASSIGN(AsyncPixelTransferDelegateSync
);
35 AsyncPixelTransferDelegateSync::AsyncPixelTransferDelegateSync(
36 AsyncPixelTransferManagerSync::SharedState
* shared_state
)
37 : shared_state_(shared_state
) {}
39 AsyncPixelTransferDelegateSync::~AsyncPixelTransferDelegateSync() {}
41 void AsyncPixelTransferDelegateSync::AsyncTexImage2D(
42 const AsyncTexImage2DParams
& tex_params
,
43 const AsyncMemoryParams
& mem_params
,
44 const base::Closure
& bind_callback
) {
45 // Save the define params to return later during deferred
46 // binding of the transfer texture.
47 void* data
= mem_params
.GetDataAddress();
48 base::TimeTicks
begin_time(base::TimeTicks::Now());
52 tex_params
.internal_format
,
59 shared_state_
->texture_upload_count
++;
60 shared_state_
->total_texture_upload_time
+=
61 base::TimeTicks::Now() - begin_time
;
62 // The texture is already fully bound so just call it now.
66 void AsyncPixelTransferDelegateSync::AsyncTexSubImage2D(
67 const AsyncTexSubImage2DParams
& tex_params
,
68 const AsyncMemoryParams
& mem_params
) {
69 void* data
= mem_params
.GetDataAddress();
70 base::TimeTicks
begin_time(base::TimeTicks::Now());
81 shared_state_
->texture_upload_count
++;
82 shared_state_
->total_texture_upload_time
+=
83 base::TimeTicks::Now() - begin_time
;
86 bool AsyncPixelTransferDelegateSync::TransferIsInProgress() {
91 void AsyncPixelTransferDelegateSync::WaitForTransferCompletion() {
95 AsyncPixelTransferManagerSync::SharedState::SharedState()
96 : texture_upload_count(0) {}
98 AsyncPixelTransferManagerSync::SharedState::~SharedState() {}
100 AsyncPixelTransferManagerSync::AsyncPixelTransferManagerSync() {}
102 AsyncPixelTransferManagerSync::~AsyncPixelTransferManagerSync() {}
104 void AsyncPixelTransferManagerSync::BindCompletedAsyncTransfers() {
105 // Everything is already bound.
108 void AsyncPixelTransferManagerSync::AsyncNotifyCompletion(
109 const AsyncMemoryParams
& mem_params
,
110 AsyncPixelTransferCompletionObserver
* observer
) {
111 observer
->DidComplete(mem_params
);
114 uint32
AsyncPixelTransferManagerSync::GetTextureUploadCount() {
115 return shared_state_
.texture_upload_count
;
118 base::TimeDelta
AsyncPixelTransferManagerSync::GetTotalTextureUploadTime() {
119 return shared_state_
.total_texture_upload_time
;
122 void AsyncPixelTransferManagerSync::ProcessMorePendingTransfers() {
125 bool AsyncPixelTransferManagerSync::NeedsProcessMorePendingTransfers() {
129 void AsyncPixelTransferManagerSync::WaitAllAsyncTexImage2D() {
132 AsyncPixelTransferDelegate
*
133 AsyncPixelTransferManagerSync::CreatePixelTransferDelegateImpl(
134 gles2::TextureRef
* ref
,
135 const AsyncTexImage2DParams
& define_params
) {
136 return new AsyncPixelTransferDelegateSync(&shared_state_
);