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

Side by Side Diff: o3d/gpu_plugin/command_buffer.cc

Issue 234001: GPUProcessor uses O3D command buffer service to render to a window.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 2 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 | « o3d/gpu_plugin/command_buffer.h ('k') | o3d/gpu_plugin/command_buffer_mock.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "o3d/gpu_plugin/command_buffer.h" 5 #include "o3d/gpu_plugin/command_buffer.h"
6 6
7 namespace o3d { 7 namespace o3d {
8 namespace gpu_plugin { 8 namespace gpu_plugin {
9 9
10 CommandBuffer::CommandBuffer(NPP npp) 10 CommandBuffer::CommandBuffer(NPP npp)
11 : npp_(npp), 11 : npp_(npp),
12 size_(0), 12 size_(0),
13 get_offset_(0), 13 get_offset_(0),
14 put_offset_(0), 14 put_offset_(0),
15 token_(0), 15 token_(0),
16 error_(ERROR_NO_ERROR) { 16 parse_error_(0),
17 error_status_(false) {
17 // Element zero is always NULL. 18 // Element zero is always NULL.
18 registered_objects_.push_back(NPObjectPointer<NPObject>()); 19 registered_objects_.push_back(NPObjectPointer<NPObject>());
19 } 20 }
20 21
21 CommandBuffer::~CommandBuffer() { 22 CommandBuffer::~CommandBuffer() {
22 } 23 }
23 24
24 bool CommandBuffer::Initialize(int32 size) { 25 bool CommandBuffer::Initialize(int32 size) {
26 // Check the size will not overflow when it is converted from count of int32s
27 // to count of bytes.
28 int32 num_bytes = static_cast<int32>(size * sizeof(int32));
29 if (num_bytes / sizeof(int32) != size)
30 return false;
31
25 if (shared_memory_.Get()) 32 if (shared_memory_.Get())
26 return false; 33 return false;
27 34
28 NPObjectPointer<NPObject> window = NPObjectPointer<NPObject>::FromReturned( 35 NPObjectPointer<NPObject> window = NPObjectPointer<NPObject>::FromReturned(
29 NPBrowser::get()->GetWindowNPObject(npp_)); 36 NPBrowser::get()->GetWindowNPObject(npp_));
30 if (!window.Get()) 37 if (!window.Get())
31 return false; 38 return false;
32 39
33 NPObjectPointer<NPObject> chromium; 40 NPObjectPointer<NPObject> chromium;
34 if (!NPGetProperty(npp_, window, "chromium", &chromium)) { 41 if (!NPGetProperty(npp_, window, "chromium", &chromium)) {
35 return false; 42 return false;
36 } 43 }
37 44
38 NPObjectPointer<NPObject> system; 45 NPObjectPointer<NPObject> system;
39 if (!NPGetProperty(npp_, chromium, "system", &system)) { 46 if (!NPGetProperty(npp_, chromium, "system", &system)) {
40 return false; 47 return false;
41 } 48 }
42 49
43 NPObjectPointer<NPObject> result; 50 NPObjectPointer<NPObject> result;
44 if (!NPInvoke(npp_, system, "createSharedMemory", size, 51 if (!NPInvoke(npp_, system, "createSharedMemory", num_bytes,
45 &result)) { 52 &result)) {
46 return false; 53 return false;
47 } 54 }
48 55
49 // TODO(spatrick): validate NPClass before assuming a CHRSharedMemory is 56 // TODO(spatrick): validate NPClass before assuming a CHRSharedMemory is
50 // returned. 57 // returned.
51 shared_memory_ = NPObjectPointer<CHRSharedMemory>( 58 shared_memory_ = NPObjectPointer<CHRSharedMemory>(
52 static_cast<CHRSharedMemory*>(result.Get())); 59 static_cast<CHRSharedMemory*>(result.Get()));
53 if (!shared_memory_.Get()) 60 if (!shared_memory_.Get())
54 return false; 61 return false;
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 // to shrink when, for example, all objects are unregistered. Note that this 148 // to shrink when, for example, all objects are unregistered. Note that this
142 // loop never removes element zero, which is always NULL. 149 // loop never removes element zero, which is always NULL.
143 while (registered_objects_.size() > 1 && !registered_objects_.back().Get()) { 150 while (registered_objects_.size() > 1 && !registered_objects_.back().Get()) {
144 registered_objects_.pop_back(); 151 registered_objects_.pop_back();
145 unused_registered_object_elements_.erase( 152 unused_registered_object_elements_.erase(
146 static_cast<int32>(registered_objects_.size())); 153 static_cast<int32>(registered_objects_.size()));
147 } 154 }
148 } 155 }
149 156
150 NPObjectPointer<NPObject> CommandBuffer::GetRegisteredObject(int32 handle) { 157 NPObjectPointer<NPObject> CommandBuffer::GetRegisteredObject(int32 handle) {
151 DCHECK_GE(handle, 0); 158 if (handle < 0)
152 DCHECK_LT(static_cast<size_t>(handle), registered_objects_.size()); 159 return NPObjectPointer<NPObject>();
160
161 if (static_cast<size_t>(handle) >= registered_objects_.size())
162 return NPObjectPointer<NPObject>();
153 163
154 return registered_objects_[handle]; 164 return registered_objects_[handle];
155 } 165 }
156 166
157 int32 CommandBuffer::ResetError() { 167 int32 CommandBuffer::ResetParseError() {
158 int32 last_error = error_; 168 int32 last_error = parse_error_;
159 error_ = ERROR_NO_ERROR; 169 parse_error_ = 0;
160 return last_error; 170 return last_error;
161 } 171 }
162 172
163 } // namespace gpu_plugin 173 } // namespace gpu_plugin
164 } // namespace o3d 174 } // namespace o3d
OLDNEW
« no previous file with comments | « o3d/gpu_plugin/command_buffer.h ('k') | o3d/gpu_plugin/command_buffer_mock.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698