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"
13 uint32_t LockFlags(gfx::GpuMemoryBuffer::Usage usage
) {
15 case gfx::GpuMemoryBuffer::MAP
:
16 return kIOSurfaceLockAvoidSync
;
17 case gfx::GpuMemoryBuffer::PERSISTENT_MAP
:
19 case gfx::GpuMemoryBuffer::SCANOUT
:
28 GpuMemoryBufferImplIOSurface::GpuMemoryBufferImplIOSurface(
29 gfx::GpuMemoryBufferId id
,
30 const gfx::Size
& size
,
32 const DestructionCallback
& callback
,
33 IOSurfaceRef io_surface
,
35 : GpuMemoryBufferImpl(id
, size
, format
, callback
),
36 io_surface_(io_surface
),
37 lock_flags_(lock_flags
) {
40 GpuMemoryBufferImplIOSurface::~GpuMemoryBufferImplIOSurface() {
44 scoped_ptr
<GpuMemoryBufferImpl
> GpuMemoryBufferImplIOSurface::CreateFromHandle(
45 const gfx::GpuMemoryBufferHandle
& handle
,
46 const gfx::Size
& size
,
49 const DestructionCallback
& callback
) {
50 base::ScopedCFTypeRef
<IOSurfaceRef
> io_surface(
51 IOSurfaceManager::GetInstance()->AcquireIOSurface(handle
.id
));
55 return make_scoped_ptr
<GpuMemoryBufferImpl
>(
56 new GpuMemoryBufferImplIOSurface(handle
.id
, size
, format
, callback
,
57 io_surface
.release(), LockFlags(usage
)));
60 bool GpuMemoryBufferImplIOSurface::Map(void** data
) {
62 IOReturn status
= IOSurfaceLock(io_surface_
, lock_flags_
, NULL
);
63 DCHECK_NE(status
, kIOReturnCannotLock
);
65 *data
= IOSurfaceGetBaseAddress(io_surface_
);
69 void GpuMemoryBufferImplIOSurface::Unmap() {
71 IOSurfaceUnlock(io_surface_
, lock_flags_
, NULL
);
75 void GpuMemoryBufferImplIOSurface::GetStride(int* stride
) const {
76 *stride
= IOSurfaceGetBytesPerRow(io_surface_
);
79 gfx::GpuMemoryBufferHandle
GpuMemoryBufferImplIOSurface::GetHandle() const {
80 gfx::GpuMemoryBufferHandle handle
;
81 handle
.type
= gfx::IO_SURFACE_BUFFER
;
86 } // namespace content