Separate Simple Backend creation from initialization.
[chromium-blink-merge.git] / ui / gl / async_pixel_transfer_delegate_stub.cc
blobb085b1ee3eb63d7c68a58892c0a221f0579351bc
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;
14 namespace {
15 // Gets the address of the data from shared memory.
16 void* GetAddress(SharedMemory* shared_memory,
17 uint32 shm_size,
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;
27 } // namespace
29 namespace gfx {
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() {
45 return false;
48 AsyncPixelTransferDelegateStub::AsyncPixelTransferDelegateStub()
49 : texture_upload_count_(0) {
52 AsyncPixelTransferDelegateStub::~AsyncPixelTransferDelegateStub() {
55 AsyncPixelTransferState*
56 AsyncPixelTransferDelegateStub::CreateRawPixelTransferState(
57 GLuint texture_id,
58 const AsyncTexImage2DParams& define_params) {
59 return new AsyncTransferStateStub(texture_id);
62 bool AsyncPixelTransferDelegateStub::BindCompletedAsyncTransfers() {
63 // Everything is already bound.
64 return false;
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,
82 mem_params.shm_size,
83 mem_params.shm_data_offset,
84 mem_params.shm_data_size);
85 glTexImage2D(
86 tex_params.target,
87 tex_params.level,
88 tex_params.internal_format,
89 tex_params.width,
90 tex_params.height,
91 tex_params.border,
92 tex_params.format,
93 tex_params.type,
94 data);
95 // The texture is already fully bound so just call it now.
96 bind_callback.Run();
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,
104 mem_params.shm_size,
105 mem_params.shm_data_offset,
106 mem_params.shm_data_size);
107 DCHECK(transfer_state);
108 base::TimeTicks begin_time(base::TimeTicks::HighResNow());
109 glTexSubImage2D(
110 tex_params.target,
111 tex_params.level,
112 tex_params.xoffset,
113 tex_params.yoffset,
114 tex_params.width,
115 tex_params.height,
116 tex_params.format,
117 tex_params.type,
118 data);
119 texture_upload_count_++;
120 total_texture_upload_time_ += base::TimeTicks::HighResNow() - begin_time;
123 void AsyncPixelTransferDelegateStub::WaitForTransferCompletion(
124 AsyncPixelTransferState* state) {
125 // Already done.
128 uint32 AsyncPixelTransferDelegateStub::GetTextureUploadCount() {
129 return texture_upload_count_;
132 base::TimeDelta AsyncPixelTransferDelegateStub::GetTotalTextureUploadTime() {
133 return total_texture_upload_time_;
136 bool AsyncPixelTransferDelegateStub::ProcessMorePendingTransfers() {
137 return false;
140 bool AsyncPixelTransferDelegateStub::NeedsProcessMorePendingTransfers() {
141 return false;
144 } // namespace gfx