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"
11 GpuMemoryBufferImplIOSurface::GpuMemoryBufferImplIOSurface(
12 gfx::GpuMemoryBufferId id
,
13 const gfx::Size
& size
,
15 const DestructionCallback
& callback
,
16 IOSurfaceRef io_surface
)
17 : GpuMemoryBufferImpl(id
, size
, format
, callback
), io_surface_(io_surface
) {
20 GpuMemoryBufferImplIOSurface::~GpuMemoryBufferImplIOSurface() {
24 scoped_ptr
<GpuMemoryBufferImpl
> GpuMemoryBufferImplIOSurface::CreateFromHandle(
25 const gfx::GpuMemoryBufferHandle
& handle
,
26 const gfx::Size
& size
,
28 const DestructionCallback
& callback
) {
29 base::ScopedCFTypeRef
<IOSurfaceRef
> io_surface(
30 IOSurfaceLookup(handle
.io_surface_id
));
32 return scoped_ptr
<GpuMemoryBufferImpl
>();
34 return make_scoped_ptr
<GpuMemoryBufferImpl
>(new GpuMemoryBufferImplIOSurface(
35 handle
.id
, size
, format
, callback
, io_surface
.release()));
38 bool GpuMemoryBufferImplIOSurface::Map(void** data
) {
40 IOSurfaceLock(io_surface_
, 0, NULL
);
42 *data
= IOSurfaceGetBaseAddress(io_surface_
);
46 void GpuMemoryBufferImplIOSurface::Unmap() {
48 IOSurfaceUnlock(io_surface_
, 0, NULL
);
52 void GpuMemoryBufferImplIOSurface::GetStride(int* stride
) const {
53 *stride
= IOSurfaceGetBytesPerRow(io_surface_
);
56 gfx::GpuMemoryBufferHandle
GpuMemoryBufferImplIOSurface::GetHandle() const {
57 gfx::GpuMemoryBufferHandle handle
;
58 handle
.type
= gfx::IO_SURFACE_BUFFER
;
60 handle
.io_surface_id
= IOSurfaceGetID(io_surface_
);
64 } // namespace content