summaryrefslogtreecommitdiff
path: root/chromium/gpu/command_buffer/service/gpu_control_service.cc
blob: d368ff92149d177c74b5861eae92430fdcf87083 (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
// Copyright 2013 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_control_service.h"

#include "gpu/command_buffer/client/gpu_memory_buffer_factory.h"
#include "gpu/command_buffer/service/gpu_memory_buffer_manager.h"

namespace gpu {

GpuControlService::GpuControlService(
    GpuMemoryBufferManagerInterface* gpu_memory_buffer_manager,
    GpuMemoryBufferFactory* gpu_memory_buffer_factory)
    : gpu_memory_buffer_manager_(gpu_memory_buffer_manager),
      gpu_memory_buffer_factory_(gpu_memory_buffer_factory) {
}

GpuControlService::~GpuControlService() {
}

gfx::GpuMemoryBuffer* GpuControlService::CreateGpuMemoryBuffer(
    size_t width,
    size_t height,
    unsigned internalformat,
    int32* id) {
  *id = -1;

  CHECK(gpu_memory_buffer_factory_) << "No GPU memory buffer factory provided";
  linked_ptr<gfx::GpuMemoryBuffer> buffer = make_linked_ptr(
      gpu_memory_buffer_factory_->CreateGpuMemoryBuffer(width,
                                                        height,
                                                        internalformat));
  if (!buffer.get())
    return NULL;

  static int32 next_id = 1;
  *id = next_id++;

  if (!RegisterGpuMemoryBuffer(*id,
                               buffer->GetHandle(),
                               width,
                               height,
                               internalformat)) {
    *id = -1;
    return NULL;
  }

  gpu_memory_buffers_[*id] = buffer;
  return buffer.get();
}

void GpuControlService::DestroyGpuMemoryBuffer(int32 id) {
  GpuMemoryBufferMap::iterator it = gpu_memory_buffers_.find(id);
  if (it != gpu_memory_buffers_.end())
    gpu_memory_buffers_.erase(it);

  gpu_memory_buffer_manager_->DestroyGpuMemoryBuffer(id);
}

bool GpuControlService::RegisterGpuMemoryBuffer(
    int32 id,
    gfx::GpuMemoryBufferHandle buffer,
    size_t width,
    size_t height,
    unsigned internalformat) {
  return gpu_memory_buffer_manager_->RegisterGpuMemoryBuffer(id,
                                                             buffer,
                                                             width,
                                                             height,
                                                             internalformat);
}

}  // namespace gpu