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
:
29 GpuMemoryBufferImplIOSurface::GpuMemoryBufferImplIOSurface(
30 gfx::GpuMemoryBufferId id
,
31 const gfx::Size
& size
,
33 const DestructionCallback
& callback
,
34 IOSurfaceRef io_surface
,
36 : GpuMemoryBufferImpl(id
, size
, format
, callback
),
37 io_surface_(io_surface
),
38 lock_flags_(lock_flags
) {
41 GpuMemoryBufferImplIOSurface::~GpuMemoryBufferImplIOSurface() {
45 scoped_ptr
<GpuMemoryBufferImpl
> GpuMemoryBufferImplIOSurface::CreateFromHandle(
46 const gfx::GpuMemoryBufferHandle
& handle
,
47 const gfx::Size
& size
,
50 const DestructionCallback
& callback
) {
51 base::ScopedCFTypeRef
<IOSurfaceRef
> io_surface(
52 IOSurfaceManager::GetInstance()->AcquireIOSurface(handle
.id
));
56 return make_scoped_ptr
<GpuMemoryBufferImpl
>(
57 new GpuMemoryBufferImplIOSurface(handle
.id
, size
, format
, callback
,
58 io_surface
.release(), LockFlags(usage
)));
61 bool GpuMemoryBufferImplIOSurface::Map(void** data
) {
63 IOReturn status
= IOSurfaceLock(io_surface_
, lock_flags_
, NULL
);
64 DCHECK_NE(status
, kIOReturnCannotLock
);
66 *data
= IOSurfaceGetBaseAddress(io_surface_
);
70 void GpuMemoryBufferImplIOSurface::Unmap() {
72 IOSurfaceUnlock(io_surface_
, lock_flags_
, NULL
);
76 void GpuMemoryBufferImplIOSurface::GetStride(int* stride
) const {
77 *stride
= IOSurfaceGetBytesPerRow(io_surface_
);
80 gfx::GpuMemoryBufferHandle
GpuMemoryBufferImplIOSurface::GetHandle() const {
81 gfx::GpuMemoryBufferHandle handle
;
82 handle
.type
= gfx::IO_SURFACE_BUFFER
;
87 } // namespace content