OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/common/gpu/client/gpu_memory_buffer_impl_io_surface.h" | 5 #include "content/common/gpu/client/gpu_memory_buffer_impl_io_surface.h" |
6 | 6 |
7 #include "base/logging.h" | |
8 #include "ui/gl/gl_bindings.h" | 7 #include "ui/gl/gl_bindings.h" |
9 | 8 |
10 namespace content { | 9 namespace content { |
11 | 10 |
12 GpuMemoryBufferImplIOSurface::GpuMemoryBufferImplIOSurface( | 11 GpuMemoryBufferImplIOSurface::GpuMemoryBufferImplIOSurface( |
13 const gfx::Size& size, | 12 const gfx::Size& size, |
14 unsigned internalformat) | 13 unsigned internalformat, |
15 : GpuMemoryBufferImpl(size, internalformat) {} | 14 const DestructionCallback& callback, |
15 IOSurfaceRef io_surface) | |
16 : GpuMemoryBufferImpl(size, internalformat, callback), | |
17 io_surface_(io_surface) { | |
18 } | |
16 | 19 |
17 GpuMemoryBufferImplIOSurface::~GpuMemoryBufferImplIOSurface() {} | 20 GpuMemoryBufferImplIOSurface::~GpuMemoryBufferImplIOSurface() { |
21 } | |
22 | |
23 // static | |
24 scoped_ptr<GpuMemoryBufferImpl> GpuMemoryBufferImplIOSurface::CreateFromHandle( | |
25 const gfx::GpuMemoryBufferHandle& handle, | |
26 const gfx::Size& size, | |
27 unsigned internalformat, | |
28 const DestructionCallback& callback) { | |
29 DCHECK(IsFormatSupported(internalformat)); | |
30 | |
31 base::ScopedCFTypeRef<IOSurfaceRef> io_surface( | |
32 IOSurfaceLookup(handle.io_surface_id)); | |
33 if (!io_surface) | |
34 return scoped_ptr<GpuMemoryBufferImpl>(); | |
35 | |
36 return make_scoped_ptr<GpuMemoryBufferImpl>(new GpuMemoryBufferImplIOSurface( | |
37 size, internalformat, callback, io_surface.get())); | |
38 } | |
18 | 39 |
19 // static | 40 // static |
20 bool GpuMemoryBufferImplIOSurface::IsFormatSupported(unsigned internalformat) { | 41 bool GpuMemoryBufferImplIOSurface::IsFormatSupported(unsigned internalformat) { |
21 switch (internalformat) { | 42 switch (internalformat) { |
22 case GL_BGRA8_EXT: | 43 case GL_BGRA8_EXT: |
23 return true; | 44 return true; |
24 default: | 45 default: |
25 return false; | 46 return false; |
26 } | 47 } |
27 } | 48 } |
(...skipping 19 matching lines...) Expand all Loading... | |
47 uint32 GpuMemoryBufferImplIOSurface::PixelFormat(unsigned internalformat) { | 68 uint32 GpuMemoryBufferImplIOSurface::PixelFormat(unsigned internalformat) { |
48 switch (internalformat) { | 69 switch (internalformat) { |
49 case GL_BGRA8_EXT: | 70 case GL_BGRA8_EXT: |
50 return 'BGRA'; | 71 return 'BGRA'; |
51 default: | 72 default: |
52 NOTREACHED(); | 73 NOTREACHED(); |
53 return 0; | 74 return 0; |
54 } | 75 } |
55 } | 76 } |
56 | 77 |
57 bool GpuMemoryBufferImplIOSurface::InitializeFromHandle( | |
58 const 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"; | |
piman
2014/09/24 06:40:28
nit: do you want to keep this?
reveman
2014/09/24 07:10:54
I don't think this will ever fail unless there's s
| |
63 return false; | |
64 } | |
65 | |
66 return true; | |
67 } | |
68 | |
69 void* GpuMemoryBufferImplIOSurface::Map() { | 78 void* GpuMemoryBufferImplIOSurface::Map() { |
70 DCHECK(!mapped_); | 79 DCHECK(!mapped_); |
71 IOSurfaceLock(io_surface_, 0, NULL); | 80 IOSurfaceLock(io_surface_, 0, NULL); |
72 mapped_ = true; | 81 mapped_ = true; |
73 return IOSurfaceGetBaseAddress(io_surface_); | 82 return IOSurfaceGetBaseAddress(io_surface_); |
74 } | 83 } |
75 | 84 |
76 void GpuMemoryBufferImplIOSurface::Unmap() { | 85 void GpuMemoryBufferImplIOSurface::Unmap() { |
77 DCHECK(mapped_); | 86 DCHECK(mapped_); |
78 IOSurfaceUnlock(io_surface_, 0, NULL); | 87 IOSurfaceUnlock(io_surface_, 0, NULL); |
79 mapped_ = false; | 88 mapped_ = false; |
80 } | 89 } |
81 | 90 |
82 uint32 GpuMemoryBufferImplIOSurface::GetStride() const { | 91 uint32 GpuMemoryBufferImplIOSurface::GetStride() const { |
83 return IOSurfaceGetBytesPerRow(io_surface_); | 92 return IOSurfaceGetBytesPerRow(io_surface_); |
84 } | 93 } |
85 | 94 |
86 gfx::GpuMemoryBufferHandle GpuMemoryBufferImplIOSurface::GetHandle() const { | 95 gfx::GpuMemoryBufferHandle GpuMemoryBufferImplIOSurface::GetHandle() const { |
87 gfx::GpuMemoryBufferHandle handle; | 96 gfx::GpuMemoryBufferHandle handle; |
88 handle.type = gfx::IO_SURFACE_BUFFER; | 97 handle.type = gfx::IO_SURFACE_BUFFER; |
89 handle.io_surface_id = IOSurfaceGetID(io_surface_); | 98 handle.io_surface_id = IOSurfaceGetID(io_surface_); |
90 return handle; | 99 return handle; |
91 } | 100 } |
92 | 101 |
93 } // namespace content | 102 } // namespace content |
OLD | NEW |