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 #include "ui/gl/async_pixel_transfer_delegate_stub.h"
7 #include "base/memory/shared_memory.h"
8 #include "build/build_config.h"
9 #include "ui/gl/gl_bindings.h"
11 using base::SharedMemory
;
12 using base::SharedMemoryHandle
;
15 // Gets the address of the data from shared memory.
16 void* GetAddress(SharedMemory
* shared_memory
,
18 uint32 shm_data_offset
,
19 uint32 shm_data_size
) {
20 // Memory bounds have already been validated, so there
21 // are just DCHECKS here.
22 DCHECK(shared_memory
);
23 DCHECK(shared_memory
->memory());
24 DCHECK_LE(shm_data_offset
+ shm_data_size
, shm_size
);
25 return static_cast<int8
*>(shared_memory
->memory()) + shm_data_offset
;
31 scoped_ptr
<AsyncPixelTransferDelegate
>
32 AsyncPixelTransferDelegateStub::Create(gfx::GLContext
* context
) {
33 return make_scoped_ptr(
34 static_cast<AsyncPixelTransferDelegate
*>(
35 new AsyncPixelTransferDelegateStub()));
38 AsyncTransferStateStub::AsyncTransferStateStub(GLuint texture_id
) {
41 AsyncTransferStateStub::~AsyncTransferStateStub() {
44 bool AsyncTransferStateStub::TransferIsInProgress() {
48 AsyncPixelTransferDelegateStub::AsyncPixelTransferDelegateStub()
49 : texture_upload_count_(0) {
52 AsyncPixelTransferDelegateStub::~AsyncPixelTransferDelegateStub() {
55 AsyncPixelTransferState
*
56 AsyncPixelTransferDelegateStub::CreateRawPixelTransferState(
58 const AsyncTexImage2DParams
& define_params
) {
59 return new AsyncTransferStateStub(texture_id
);
62 bool AsyncPixelTransferDelegateStub::BindCompletedAsyncTransfers() {
63 // Everything is already bound.
67 void AsyncPixelTransferDelegateStub::AsyncNotifyCompletion(
68 const AsyncMemoryParams
& mem_params
,
69 const CompletionCallback
& callback
) {
70 callback
.Run(mem_params
);
73 void AsyncPixelTransferDelegateStub::AsyncTexImage2D(
74 AsyncPixelTransferState
* transfer_state
,
75 const AsyncTexImage2DParams
& tex_params
,
76 const AsyncMemoryParams
& mem_params
,
77 const base::Closure
& bind_callback
) {
78 // Save the define params to return later during deferred
79 // binding of the transfer texture.
80 DCHECK(transfer_state
);
81 void* data
= GetAddress(mem_params
.shared_memory
,
83 mem_params
.shm_data_offset
,
84 mem_params
.shm_data_size
);
88 tex_params
.internal_format
,
95 // The texture is already fully bound so just call it now.
99 void AsyncPixelTransferDelegateStub::AsyncTexSubImage2D(
100 AsyncPixelTransferState
* transfer_state
,
101 const AsyncTexSubImage2DParams
& tex_params
,
102 const AsyncMemoryParams
& mem_params
) {
103 void* data
= GetAddress(mem_params
.shared_memory
,
105 mem_params
.shm_data_offset
,
106 mem_params
.shm_data_size
);
107 DCHECK(transfer_state
);
108 base::TimeTicks
begin_time(base::TimeTicks::HighResNow());
119 texture_upload_count_
++;
120 total_texture_upload_time_
+= base::TimeTicks::HighResNow() - begin_time
;
123 void AsyncPixelTransferDelegateStub::WaitForTransferCompletion(
124 AsyncPixelTransferState
* state
) {
128 uint32
AsyncPixelTransferDelegateStub::GetTextureUploadCount() {
129 return texture_upload_count_
;
132 base::TimeDelta
AsyncPixelTransferDelegateStub::GetTotalTextureUploadTime() {
133 return total_texture_upload_time_
;
136 bool AsyncPixelTransferDelegateStub::ProcessMorePendingTransfers() {
140 bool AsyncPixelTransferDelegateStub::NeedsProcessMorePendingTransfers() {