summaryrefslogtreecommitdiffstats
path: root/gpu/command_buffer/service/gpu_processor.cc
blob: 845d5b6dcf74d5a751ee27b3b7464cb082b02fa2 (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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// 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 "gpu/command_buffer/service/gpu_processor.h"
#include "gpu/np_utils/np_browser.h"

using ::base::SharedMemory;
using np_utils::NPBrowser;

namespace command_buffer {

GPUProcessor::~GPUProcessor() {
}

namespace {
void InvokeProcessCommands(void* data) {
  static_cast<GPUProcessor*>(data)->ProcessCommands();
}
}  // namespace anonymous

void GPUProcessor::ProcessCommands() {
  if (command_buffer_->GetErrorStatus())
    return;

  parser_->set_put(command_buffer_->GetPutOffset());

  int commands_processed = 0;
  while (commands_processed < commands_per_update_ && !parser_->IsEmpty()) {
    command_buffer::parse_error::ParseError parse_error =
        parser_->ProcessCommand();
    switch (parse_error) {
      case command_buffer::parse_error::kParseUnknownCommand:
      case command_buffer::parse_error::kParseInvalidArguments:
        command_buffer_->SetParseError(parse_error);
        break;

      case command_buffer::parse_error::kParseInvalidSize:
      case command_buffer::parse_error::kParseOutOfBounds:
        command_buffer_->SetParseError(parse_error);
        command_buffer_->RaiseErrorStatus();
        return;
    }

    ++commands_processed;
  }

  command_buffer_->SetGetOffset(static_cast<int32>(parser_->get()));

  if (!parser_->IsEmpty()) {
    NPBrowser::get()->PluginThreadAsyncCall(npp_, InvokeProcessCommands, this);
  }
}

void *GPUProcessor::GetSharedMemoryAddress(int32 shm_id) {
  ::base::SharedMemory* shared_memory =
      command_buffer_->GetTransferBuffer(shm_id);
  if (!shared_memory)
    return NULL;

  if (!shared_memory->memory()) {
    if (!shared_memory->Map(shared_memory->max_size()))
      return NULL;
  }

  return shared_memory->memory();
}

// TODO(apatrick): Consolidate this with the above and return both the address
// and size.
size_t GPUProcessor::GetSharedMemorySize(int32 shm_id) {
  ::base::SharedMemory* shared_memory =
      command_buffer_->GetTransferBuffer(shm_id);
  if (!shared_memory)
    return 0;

  return shared_memory->max_size();
}

void GPUProcessor::set_token(int32 token) {
  command_buffer_->SetToken(token);
}

}  // namespace command_buffer