Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: ui/gl/async_pixel_transfer_delegate_stub.cc

Issue 11428140: gpu: Add async pixel transfer interface, stub and tests. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fix bots. Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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.
4
5 #include "ui/gl/async_pixel_transfer_delegate_stub.h"
6
7 #include "base/shared_memory.h"
8 #include "build/build_config.h"
9 #include "ui/gl/gl_bindings.h"
10
11 using base::SharedMemory;
12 using base::SharedMemoryHandle;
13
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 // is 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;
26 }
27 } // namespace
28
29 namespace gfx {
30
31 scoped_ptr<AsyncPixelTransferDelegate>
32 AsyncPixelTransferDelegate::Create(gfx::GLContext* context) {
33 return AsyncPixelTransferDelegateStub::Create(context);
34 }
35
36 scoped_ptr<AsyncPixelTransferDelegate>
37 AsyncPixelTransferDelegateStub::Create(gfx::GLContext* context) {
38 return make_scoped_ptr(
39 static_cast<AsyncPixelTransferDelegate*>(
40 new AsyncPixelTransferDelegateStub()));
41 }
42
43 AsyncTransferStateStub::AsyncTransferStateStub(GLuint texture_id) {
44 static const AsyncTexImage2DParams zero_params = {0, 0, 0, 0, 0, 0, 0, 0};
45 late_bind_define_params_ = zero_params;
46 needs_late_bind_ = false;
47 }
48
49 AsyncTransferStateStub::~AsyncTransferStateStub() {
50 }
51
52 bool AsyncTransferStateStub::TransferIsInProgress() {
53 return false;
54 }
55
56 void AsyncTransferStateStub::BindTransfer(AsyncTexImage2DParams* out_params) {
57 DCHECK(out_params);
58 DCHECK(needs_late_bind_);
59 *out_params = late_bind_define_params_;
60 needs_late_bind_ = false;
61 }
62
63 AsyncPixelTransferDelegateStub::AsyncPixelTransferDelegateStub() {
64 }
65
66 AsyncPixelTransferDelegateStub::~AsyncPixelTransferDelegateStub() {
67 }
68
69 scoped_ptr<AsyncPixelTransferState>
70 AsyncPixelTransferDelegateStub::CreatePixelTransferState(
71 GLuint texture_id) {
72 return make_scoped_ptr(CreateRawPixelTransferState(texture_id));
73 }
74
75 AsyncPixelTransferState*
76 AsyncPixelTransferDelegateStub::CreateRawPixelTransferState(
77 GLuint texture_id) {
78 return static_cast<AsyncPixelTransferState*>(
79 new AsyncTransferStateStub(texture_id));
80 }
81
82 void AsyncPixelTransferDelegateStub::AsyncNotifyCompletion(
83 const base::Closure& task) {
84 task.Run();
85 }
86
87 void AsyncPixelTransferDelegateStub::AsyncTexImage2D(
88 AsyncPixelTransferState* transfer_state,
89 const AsyncTexImage2DParams& tex_params,
90 const AsyncMemoryParams& mem_params) {
91 // Save the define params to return later during deferred
92 // binding of the transfer texture.
93 DCHECK(transfer_state);
94 AsyncTransferStateStub* state =
95 static_cast<AsyncTransferStateStub*>(transfer_state);
96 // We don't actually need a late bind since this stub does
97 // everything synchronously, but this tries to be similar
98 // as an async implementation.
99 state->needs_late_bind_ = true;
100 state->late_bind_define_params_ = tex_params;
101 void* data = GetAddress(mem_params.shared_memory,
102 mem_params.shm_size,
103 mem_params.shm_data_offset,
104 mem_params.shm_data_size);
105 glTexImage2D(
106 tex_params.target,
107 tex_params.level,
108 tex_params.internal_format,
109 tex_params.width,
110 tex_params.height,
111 tex_params.border,
112 tex_params.format,
113 tex_params.type,
114 data);
115 }
116
117 void AsyncPixelTransferDelegateStub::AsyncTexSubImage2D(
118 AsyncPixelTransferState* transfer_state,
119 const AsyncTexSubImage2DParams& tex_params,
120 const AsyncMemoryParams& mem_params) {
121 void* data = GetAddress(mem_params.shared_memory,
122 mem_params.shm_size,
123 mem_params.shm_data_offset,
124 mem_params.shm_data_size);
125 DCHECK(transfer_state);
126 AsyncTransferStateStub* state =
127 static_cast<AsyncTransferStateStub*>(transfer_state);
128 DCHECK(!state->needs_late_bind_);
129 glTexSubImage2D(
130 tex_params.target,
131 tex_params.level,
132 tex_params.xoffset,
133 tex_params.yoffset,
134 tex_params.width,
135 tex_params.height,
136 tex_params.format,
137 tex_params.type,
138 data);
139 }
140 } // namespace gfx
141
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698