base/threading: remove ScopedTracker placed for experiments
[chromium-blink-merge.git] / content / common / gpu / client / gpu_memory_buffer_impl_io_surface.cc
blobf16125bfa181f8e5bd51abfe54c0d48b3d453511
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/common/gpu/client/gpu_memory_buffer_impl_io_surface.h"
7 #include "base/logging.h"
8 #include "content/common/mac/io_surface_manager.h"
10 namespace content {
11 namespace {
13 uint32_t LockFlags(gfx::BufferUsage usage) {
14 switch (usage) {
15 case gfx::BufferUsage::MAP:
16 return kIOSurfaceLockAvoidSync;
17 case gfx::BufferUsage::PERSISTENT_MAP:
18 return 0;
19 case gfx::BufferUsage::SCANOUT:
20 return 0;
22 NOTREACHED();
23 return 0;
26 } // namespace
28 GpuMemoryBufferImplIOSurface::GpuMemoryBufferImplIOSurface(
29 gfx::GpuMemoryBufferId id,
30 const gfx::Size& size,
31 gfx::BufferFormat format,
32 const DestructionCallback& callback,
33 IOSurfaceRef io_surface,
34 uint32_t lock_flags)
35 : GpuMemoryBufferImpl(id, size, format, callback),
36 io_surface_(io_surface),
37 lock_flags_(lock_flags) {}
39 GpuMemoryBufferImplIOSurface::~GpuMemoryBufferImplIOSurface() {
42 // static
43 scoped_ptr<GpuMemoryBufferImpl> GpuMemoryBufferImplIOSurface::CreateFromHandle(
44 const gfx::GpuMemoryBufferHandle& handle,
45 const gfx::Size& size,
46 gfx::BufferFormat format,
47 gfx::BufferUsage usage,
48 const DestructionCallback& callback) {
49 base::ScopedCFTypeRef<IOSurfaceRef> io_surface(
50 IOSurfaceManager::GetInstance()->AcquireIOSurface(handle.id));
51 if (!io_surface)
52 return nullptr;
54 return make_scoped_ptr<GpuMemoryBufferImpl>(
55 new GpuMemoryBufferImplIOSurface(handle.id, size, format, callback,
56 io_surface.release(), LockFlags(usage)));
59 bool GpuMemoryBufferImplIOSurface::Map(void** data) {
60 DCHECK(!mapped_);
61 IOReturn status = IOSurfaceLock(io_surface_, lock_flags_, NULL);
62 DCHECK_NE(status, kIOReturnCannotLock);
63 mapped_ = true;
64 *data = IOSurfaceGetBaseAddress(io_surface_);
65 return true;
68 void GpuMemoryBufferImplIOSurface::Unmap() {
69 DCHECK(mapped_);
70 IOSurfaceUnlock(io_surface_, lock_flags_, NULL);
71 mapped_ = false;
74 void GpuMemoryBufferImplIOSurface::GetStride(int* stride) const {
75 *stride = IOSurfaceGetBytesPerRow(io_surface_);
78 gfx::GpuMemoryBufferHandle GpuMemoryBufferImplIOSurface::GetHandle() const {
79 gfx::GpuMemoryBufferHandle handle;
80 handle.type = gfx::IO_SURFACE_BUFFER;
81 handle.id = id_;
82 return handle;
85 } // namespace content