[SyncFS] Build indexes from FileTracker entries on disk.
[chromium-blink-merge.git] / content / common / gpu / client / gpu_memory_buffer_impl_io_surface.cc
blob06cb7ed9bdc3064c4c05294a5b875b0aef1259b6
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"
10 namespace content {
12 GpuMemoryBufferImplIOSurface::GpuMemoryBufferImplIOSurface(
13 const gfx::Size& size,
14 unsigned internalformat)
15 : GpuMemoryBufferImpl(size, internalformat) {}
17 GpuMemoryBufferImplIOSurface::~GpuMemoryBufferImplIOSurface() {}
19 // static
20 bool GpuMemoryBufferImplIOSurface::IsFormatSupported(unsigned internalformat) {
21 switch (internalformat) {
22 case GL_BGRA8_EXT:
23 return true;
24 default:
25 return false;
29 // static
30 bool GpuMemoryBufferImplIOSurface::IsUsageSupported(unsigned usage) {
31 switch (usage) {
32 case GL_IMAGE_MAP_CHROMIUM:
33 return true;
34 default:
35 return false;
39 // static
40 bool GpuMemoryBufferImplIOSurface::IsConfigurationSupported(
41 unsigned internalformat,
42 unsigned usage) {
43 return IsFormatSupported(internalformat) && IsUsageSupported(usage);
46 // static
47 uint32 GpuMemoryBufferImplIOSurface::PixelFormat(unsigned internalformat) {
48 switch (internalformat) {
49 case GL_BGRA8_EXT:
50 return 'BGRA';
51 default:
52 NOTREACHED();
53 return 0;
57 bool GpuMemoryBufferImplIOSurface::InitializeFromHandle(
58 gfx::GpuMemoryBufferHandle handle) {
59 DCHECK(IsFormatSupported(internalformat_));
60 io_surface_.reset(IOSurfaceLookup(handle.io_surface_id));
61 if (!io_surface_) {
62 VLOG(1) << "IOSurface lookup failed";
63 return false;
66 return true;
69 void* GpuMemoryBufferImplIOSurface::Map() {
70 DCHECK(!mapped_);
71 IOSurfaceLock(io_surface_, 0, NULL);
72 mapped_ = true;
73 return IOSurfaceGetBaseAddress(io_surface_);
76 void GpuMemoryBufferImplIOSurface::Unmap() {
77 DCHECK(mapped_);
78 IOSurfaceUnlock(io_surface_, 0, NULL);
79 mapped_ = false;
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_);
90 return handle;
93 } // namespace content