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 "ui/gl/gl_bindings.h"
12 GpuMemoryBufferImplIOSurface::GpuMemoryBufferImplIOSurface(
13 const gfx::Size
& size
,
14 unsigned internalformat
)
15 : GpuMemoryBufferImpl(size
, internalformat
) {}
17 GpuMemoryBufferImplIOSurface::~GpuMemoryBufferImplIOSurface() {}
20 bool GpuMemoryBufferImplIOSurface::IsFormatSupported(unsigned internalformat
) {
21 switch (internalformat
) {
30 bool GpuMemoryBufferImplIOSurface::IsUsageSupported(unsigned usage
) {
32 case GL_IMAGE_MAP_CHROMIUM
:
40 bool GpuMemoryBufferImplIOSurface::IsConfigurationSupported(
41 unsigned internalformat
,
43 return IsFormatSupported(internalformat
) && IsUsageSupported(usage
);
47 uint32
GpuMemoryBufferImplIOSurface::PixelFormat(unsigned internalformat
) {
48 switch (internalformat
) {
57 bool GpuMemoryBufferImplIOSurface::InitializeFromHandle(
58 gfx::GpuMemoryBufferHandle handle
) {
59 DCHECK(IsFormatSupported(internalformat_
));
60 io_surface_
.reset(IOSurfaceLookup(handle
.io_surface_id
));
62 VLOG(1) << "IOSurface lookup failed";
69 void* GpuMemoryBufferImplIOSurface::Map() {
71 IOSurfaceLock(io_surface_
, 0, NULL
);
73 return IOSurfaceGetBaseAddress(io_surface_
);
76 void GpuMemoryBufferImplIOSurface::Unmap() {
78 IOSurfaceUnlock(io_surface_
, 0, NULL
);
82 uint32
GpuMemoryBufferImplIOSurface::GetStride() const {
83 return IOSurfaceGetBytesPerRow(io_surface_
);
86 gfx::GpuMemoryBufferHandle
GpuMemoryBufferImplIOSurface::GetHandle() const {
87 gfx::GpuMemoryBufferHandle handle
;
88 handle
.type
= gfx::IO_SURFACE_BUFFER
;
89 handle
.io_surface_id
= IOSurfaceGetID(io_surface_
);
93 } // namespace content