summaryrefslogtreecommitdiffstats
path: root/content/browser/in_process_io_surface_manager_mac.cc
blob: ca387859d46d3b47eda8418949d5d74edafcec4e (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
// Copyright 2015 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 "content/browser/in_process_io_surface_manager_mac.h"

#include "base/logging.h"

namespace content {

// static
InProcessIOSurfaceManager* InProcessIOSurfaceManager::GetInstance() {
  return Singleton<InProcessIOSurfaceManager,
                   LeakySingletonTraits<InProcessIOSurfaceManager>>::get();
}

bool InProcessIOSurfaceManager::RegisterIOSurface(int io_surface_id,
                                                  int client_id,
                                                  IOSurfaceRef io_surface) {
  base::AutoLock lock(lock_);

  DCHECK(io_surfaces_.find(io_surface_id) == io_surfaces_.end());
  io_surfaces_.add(io_surface_id,
                   make_scoped_ptr(new base::mac::ScopedMachSendRight(
                       IOSurfaceCreateMachPort(io_surface))));
  return true;
}

void InProcessIOSurfaceManager::UnregisterIOSurface(int io_surface_id,
                                                    int client_id) {
  base::AutoLock lock(lock_);

  DCHECK(io_surfaces_.find(io_surface_id) != io_surfaces_.end());
  io_surfaces_.erase(io_surface_id);
}

IOSurfaceRef InProcessIOSurfaceManager::AcquireIOSurface(int io_surface_id) {
  base::AutoLock lock(lock_);

  DCHECK(io_surfaces_.find(io_surface_id) != io_surfaces_.end());
  return IOSurfaceLookupFromMachPort(io_surfaces_.get(io_surface_id)->get());
}

InProcessIOSurfaceManager::InProcessIOSurfaceManager() {
}

InProcessIOSurfaceManager::~InProcessIOSurfaceManager() {
}

}  // namespace content