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

Side by Side Diff: gpu/pgl/command_buffer_pepper.cc

Issue 6883179: Rework FlushSync to return early if commands have been processed since the last update (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: style Created 9 years, 8 months 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 | Annotate | Revision Log
« no previous file with comments | « gpu/pgl/command_buffer_pepper.h ('k') | gpu/pgl/pgl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2011 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 "gpu/pgl/command_buffer_pepper.h"
6
7 #include "gpu/command_buffer/common/logging.h"
8
9 using base::SharedMemory;
10 using gpu::Buffer;
11 using gpu::CommandBuffer;
12
13 CommandBufferPepper::CommandBufferPepper(NPP npp,
14 NPDevice* device,
15 NPDeviceContext3D* context)
16 : npp_(npp),
17 device_(device),
18 context_(context) {
19 }
20
21 CommandBufferPepper::~CommandBufferPepper() {
22 }
23
24 // Not implemented in CommandBufferPepper.
25 bool CommandBufferPepper::Initialize(int32 size) {
26 GPU_NOTREACHED();
27 return false;
28 }
29
30 bool CommandBufferPepper::Initialize(base::SharedMemory* buffer, int32 size) {
31 GPU_NOTREACHED();
32 return false;
33 }
34
35 Buffer CommandBufferPepper::GetRingBuffer() {
36 Buffer buffer;
37 #if defined(ENABLE_NEW_NPDEVICE_API)
38 NPDeviceBuffer np_buffer;
39 device_->mapBuffer(npp_,
40 context_,
41 NP3DCommandBufferId,
42 &np_buffer);
43 buffer.ptr = np_buffer.ptr;
44 buffer.size = np_buffer.size;
45 #else
46 buffer.ptr = context_->commandBuffer;
47 buffer.size = context_->commandBufferSize * sizeof(int32);
48 #endif
49 return buffer;
50 }
51
52 CommandBuffer::State CommandBufferPepper::GetState() {
53 #if defined(ENABLE_NEW_NPDEVICE_API)
54 int32 output_attribs[] = {
55 NP3DAttrib_CommandBufferSize, 0,
56 NP3DAttrib_GetOffset, 0,
57 NP3DAttrib_PutOffset, 0,
58 NP3DAttrib_Token, 0,
59 NPAttrib_Error, 0,
60 NPAttrib_End
61 };
62 device_->synchronizeContext(npp_,
63 context_,
64 NPDeviceSynchronizationMode_Immediate,
65 NULL,
66 output_attribs,
67 NULL,
68 NULL);
69
70 CommandBuffer::State state;
71 state.num_entries = output_attribs[1];
72 state.get_offset = output_attribs[3];
73 state.put_offset = output_attribs[5];
74 state.token = output_attribs[7];
75 state.error = static_cast<gpu::error::Error>(
76 output_attribs[9]);
77
78 return state;
79 #else
80 context_->waitForProgress = false;
81
82 if (NPERR_NO_ERROR != device_->flushContext(npp_, context_, NULL, NULL))
83 context_->error = NPDeviceContext3DError_GenericError;
84
85 context_->waitForProgress = true;
86
87 return ConvertState();
88 #endif // ENABLE_NEW_NPDEVICE_API
89 }
90
91 void CommandBufferPepper::Flush(int32 put_offset) {
92 FlushSync(put_offset);
93 }
94
95 CommandBuffer::State CommandBufferPepper::FlushSync(int32 put_offset) {
96 #if defined(ENABLE_NEW_NPDEVICE_API)
97 int32 input_attribs[] = {
98 NP3DAttrib_PutOffset, put_offset,
99 NPAttrib_End
100 };
101 int32 output_attribs[] = {
102 NP3DAttrib_CommandBufferSize, 0,
103 NP3DAttrib_GetOffset, 0,
104 NP3DAttrib_PutOffset, 0,
105 NP3DAttrib_Token, 0,
106 NPAttrib_Error, 0,
107 NPAttrib_End
108 };
109 device_->synchronizeContext(npp_,
110 context_,
111 NPDeviceSynchronizationMode_Flush,
112 input_attribs,
113 output_attribs,
114 NULL,
115 NULL);
116
117 CommandBuffer::State state;
118 state.num_entries = output_attribs[1];
119 state.get_offset = output_attribs[3];
120 state.put_offset = output_attribs[5];
121 state.token = output_attribs[7];
122 state.error = static_cast<gpu::error::Error>(
123 output_attribs[9]);
124
125 return state;
126 #else
127 context_->waitForProgress = true;
128 context_->putOffset = put_offset;
129
130 if (NPERR_NO_ERROR != device_->flushContext(npp_, context_, NULL, NULL))
131 context_->error = NPDeviceContext3DError_GenericError;
132
133 return ConvertState();
134 #endif // ENABLE_NEW_NPDEVICE_API
135 }
136
137 void CommandBufferPepper::SetGetOffset(int32 get_offset) {
138 // Not implemented by proxy.
139 GPU_NOTREACHED();
140 }
141
142 int32 CommandBufferPepper::CreateTransferBuffer(size_t size, int32 id_request) {
143 int32_t id;
144 if (NPERR_NO_ERROR != device_->createBuffer(npp_, context_, size, &id))
145 return -1;
146
147 return static_cast<int32>(id);
148 }
149
150 int32 CommandBufferPepper::RegisterTransferBuffer(
151 base::SharedMemory* shared_memory,
152 size_t size,
153 int32 id_request) {
154 // Not implemented by proxy.
155 GPU_NOTREACHED();
156 return -1;
157 }
158
159 void CommandBufferPepper::DestroyTransferBuffer(int32 id) {
160 device_->destroyBuffer(npp_, context_, id);
161 }
162
163 Buffer CommandBufferPepper::GetTransferBuffer(int32 id) {
164 NPDeviceBuffer np_buffer;
165 if (NPERR_NO_ERROR != device_->mapBuffer(npp_, context_, id, &np_buffer))
166 return Buffer();
167
168 Buffer buffer;
169 buffer.ptr = np_buffer.ptr;
170 buffer.size = np_buffer.size;
171 return buffer;
172 }
173
174 void CommandBufferPepper::SetToken(int32 token) {
175 // Not implemented by proxy.
176 GPU_NOTREACHED();
177 }
178
179 void CommandBufferPepper::SetParseError(
180 gpu::error::Error error) {
181 // Not implemented by proxy.
182 GPU_NOTREACHED();
183 }
184
185 gpu::error::Error CommandBufferPepper::GetCachedError() {
186 int32_t attrib_list[] = {
187 NPAttrib_Error, 0,
188 NPAttrib_End
189 };
190 device_->synchronizeContext(npp_,
191 context_,
192 NPDeviceSynchronizationMode_Cached,
193 NULL,
194 attrib_list,
195 NULL,
196 NULL);
197 return static_cast<gpu::error::Error>(attrib_list[1]);
198 }
199
200 CommandBuffer::State CommandBufferPepper::ConvertState() {
201 CommandBuffer::State state;
202 state.num_entries = context_->commandBufferSize;
203 state.get_offset = context_->getOffset;
204 state.put_offset = context_->putOffset;
205 state.token = context_->token;
206 state.error = static_cast<gpu::error::Error>(
207 context_->error);
208 return state;
209 }
OLDNEW
« no previous file with comments | « gpu/pgl/command_buffer_pepper.h ('k') | gpu/pgl/pgl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698