1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "o3d/gpu_plugin/command_buffer.h"
namespace o3d {
namespace gpu_plugin {
CommandBuffer::CommandBuffer(NPP npp) : npp_(npp) {
}
CommandBuffer::~CommandBuffer() {
}
bool CommandBuffer::Initialize(int32 size) {
if (shared_memory_.Get())
return false;
NPObjectPointer<NPObject> window = NPObjectPointer<NPObject>::FromReturned(
NPBrowser::get()->GetWindowNPObject(npp_));
if (!window.Get())
return false;
NPObjectPointer<NPObject> chromium;
if (!NPGetProperty(npp_, window, "chromium", &chromium)) {
return false;
}
NPObjectPointer<NPObject> system;
if (!NPGetProperty(npp_, chromium, "system", &system)) {
return false;
}
NPObjectPointer<NPObject> result;
if (!NPInvoke(npp_, system, "createSharedMemory", size,
&result)) {
return false;
}
// TODO(spatrick): validate NPClass before assuming a CHRSHaredMemory is
// returned.
shared_memory_ = NPObjectPointer<CHRSharedMemory>(
static_cast<CHRSharedMemory*>(result.Get()));
if (!shared_memory_.Get())
return false;
bool mapped;
if (!NPInvoke(npp_, shared_memory_, "map", &mapped) || !mapped) {
shared_memory_ = NPObjectPointer<CHRSharedMemory>();
return false;
}
return true;
}
NPObjectPointer<NPObject> CommandBuffer::GetSharedMemory() {
return shared_memory_;
}
void CommandBuffer::SetPutOffset(int32 offset) {
}
int32 CommandBuffer::GetGetOffset() {
return 0;
}
} // namespace gpu_plugin
} // namespace o3d
|