Performance histograms for extension content verification
[chromium-blink-merge.git] / gpu / command_buffer / service / async_pixel_transfer_manager_sync.cc
blobcd7d087730f408dc76ae5a3d5a93eeecb3734ee3
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"
9 namespace gpu {
11 // Class which handles async pixel transfers synchronously.
12 class AsyncPixelTransferDelegateSync : public AsyncPixelTransferDelegate {
13 public:
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;
29 private:
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());
51 glTexImage2D(
52 tex_params.target,
53 tex_params.level,
54 tex_params.internal_format,
55 tex_params.width,
56 tex_params.height,
57 tex_params.border,
58 tex_params.format,
59 tex_params.type,
60 data);
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.
65 bind_callback.Run();
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());
73 glTexSubImage2D(
74 tex_params.target,
75 tex_params.level,
76 tex_params.xoffset,
77 tex_params.yoffset,
78 tex_params.width,
79 tex_params.height,
80 tex_params.format,
81 tex_params.type,
82 data);
83 shared_state_->texture_upload_count++;
84 shared_state_->total_texture_upload_time +=
85 base::TimeTicks::HighResNow() - begin_time;
88 bool AsyncPixelTransferDelegateSync::TransferIsInProgress() {
89 // Already done.
90 return false;
93 void AsyncPixelTransferDelegateSync::WaitForTransferCompletion() {
94 // Already done.
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() {
128 return false;
131 void AsyncPixelTransferManagerSync::WaitAllAsyncTexImage2D() {
134 AsyncPixelTransferDelegate*
135 AsyncPixelTransferManagerSync::CreatePixelTransferDelegateImpl(
136 gles2::TextureRef* ref,
137 const AsyncTexImage2DParams& define_params) {
138 return new AsyncPixelTransferDelegateSync(&shared_state_);
141 } // namespace gpu