summaryrefslogtreecommitdiffstats
path: root/o3d/gpu_plugin/command_buffer.cc
blob: ca2d6915a41bfe16597f19f9b9a676889e8f6ee8 (plain)
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
// 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() {
  if (shared_memory_) {
    NPBrowser::get()->UnmapSharedMemory(npp_, shared_memory_);
  }
}

bool CommandBuffer::Initialize(int32 size) {
  if (buffer_object_.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;
  }

  if (!NPInvoke(npp_, system, "createSharedMemory", size,
                &buffer_object_)) {
    return false;
  }

  shared_memory_ = NPBrowser::get()->MapSharedMemory(
      npp_, buffer_object_.Get(), size, false);
  if (!shared_memory_) {
    buffer_object_ = NPObjectPointer<NPObject>();
    return false;
  }

  return true;
}

NPObjectPointer<NPObject> CommandBuffer::GetBuffer() {
  return buffer_object_;
}

void CommandBuffer::SetPutOffset(int32 offset) {
}

int32 CommandBuffer::GetGetOffset() {
  return 0;
}

}  // namespace gpu_plugin
}  // namespace o3d