OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_surface_texture.h" | 5 #include "content/common/gpu/client/gpu_memory_buffer_impl_surface_texture.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/trace_event/trace_event.h" | 8 #include "base/trace_event/trace_event.h" |
9 #include "content/common/android/surface_texture_manager.h" | 9 #include "content/common/android/surface_texture_manager.h" |
| 10 #include "content/common/gpu/gpu_memory_buffer_factory_surface_texture.h" |
10 #include "ui/gfx/buffer_format_util.h" | 11 #include "ui/gfx/buffer_format_util.h" |
11 #include "ui/gl/gl_bindings.h" | 12 #include "ui/gl/gl_bindings.h" |
12 | 13 |
13 namespace content { | 14 namespace content { |
14 namespace { | 15 namespace { |
15 | 16 |
16 int WindowFormat(gfx::BufferFormat format) { | 17 int WindowFormat(gfx::BufferFormat format) { |
17 switch (format) { | 18 switch (format) { |
18 case gfx::BufferFormat::RGBA_8888: | 19 case gfx::BufferFormat::RGBA_8888: |
19 return WINDOW_FORMAT_RGBA_8888; | 20 return WINDOW_FORMAT_RGBA_8888; |
(...skipping 10 matching lines...) Expand all Loading... |
30 case gfx::BufferFormat::YUV_420_BIPLANAR: | 31 case gfx::BufferFormat::YUV_420_BIPLANAR: |
31 case gfx::BufferFormat::UYVY_422: | 32 case gfx::BufferFormat::UYVY_422: |
32 NOTREACHED(); | 33 NOTREACHED(); |
33 return 0; | 34 return 0; |
34 } | 35 } |
35 | 36 |
36 NOTREACHED(); | 37 NOTREACHED(); |
37 return 0; | 38 return 0; |
38 } | 39 } |
39 | 40 |
| 41 void FreeSurfaceTextureForTesting(gfx::GpuMemoryBufferId id) { |
| 42 SurfaceTextureManager::GetInstance()->UnregisterSurfaceTexture(id.id, 0); |
| 43 } |
| 44 |
40 } // namespace | 45 } // namespace |
41 | 46 |
42 GpuMemoryBufferImplSurfaceTexture::GpuMemoryBufferImplSurfaceTexture( | 47 GpuMemoryBufferImplSurfaceTexture::GpuMemoryBufferImplSurfaceTexture( |
43 gfx::GpuMemoryBufferId id, | 48 gfx::GpuMemoryBufferId id, |
44 const gfx::Size& size, | 49 const gfx::Size& size, |
45 gfx::BufferFormat format, | 50 gfx::BufferFormat format, |
46 const DestructionCallback& callback, | 51 const DestructionCallback& callback, |
47 ANativeWindow* native_window) | 52 ANativeWindow* native_window) |
48 : GpuMemoryBufferImpl(id, size, format, callback), | 53 : GpuMemoryBufferImpl(id, size, format, callback), |
49 native_window_(native_window), | 54 native_window_(native_window), |
50 stride_(0) {} | 55 stride_(0) {} |
51 | 56 |
52 GpuMemoryBufferImplSurfaceTexture::~GpuMemoryBufferImplSurfaceTexture() { | 57 GpuMemoryBufferImplSurfaceTexture::~GpuMemoryBufferImplSurfaceTexture() { |
53 ANativeWindow_release(native_window_); | 58 ANativeWindow_release(native_window_); |
54 } | 59 } |
55 | 60 |
56 // static | 61 // static |
57 scoped_ptr<GpuMemoryBufferImpl> | 62 scoped_ptr<GpuMemoryBufferImplSurfaceTexture> |
58 GpuMemoryBufferImplSurfaceTexture::CreateFromHandle( | 63 GpuMemoryBufferImplSurfaceTexture::CreateFromHandle( |
59 const gfx::GpuMemoryBufferHandle& handle, | 64 const gfx::GpuMemoryBufferHandle& handle, |
60 const gfx::Size& size, | 65 const gfx::Size& size, |
61 gfx::BufferFormat format, | 66 gfx::BufferFormat format, |
62 const DestructionCallback& callback) { | 67 const DestructionCallback& callback) { |
63 ANativeWindow* native_window = | 68 ANativeWindow* native_window = |
64 SurfaceTextureManager::GetInstance() | 69 SurfaceTextureManager::GetInstance() |
65 ->AcquireNativeWidgetForSurfaceTexture(handle.id.id); | 70 ->AcquireNativeWidgetForSurfaceTexture(handle.id.id); |
66 if (!native_window) | 71 if (!native_window) |
67 return scoped_ptr<GpuMemoryBufferImpl>(); | 72 return nullptr; |
68 | 73 |
69 ANativeWindow_setBuffersGeometry( | 74 ANativeWindow_setBuffersGeometry( |
70 native_window, size.width(), size.height(), WindowFormat(format)); | 75 native_window, size.width(), size.height(), WindowFormat(format)); |
71 | 76 |
72 return make_scoped_ptr<GpuMemoryBufferImpl>( | 77 return make_scoped_ptr(new GpuMemoryBufferImplSurfaceTexture( |
73 new GpuMemoryBufferImplSurfaceTexture( | 78 handle.id, size, format, callback, native_window)); |
74 handle.id, size, format, callback, native_window)); | 79 } |
| 80 |
| 81 // static |
| 82 bool GpuMemoryBufferImplSurfaceTexture::IsConfigurationSupported( |
| 83 gfx::BufferFormat format, |
| 84 gfx::BufferUsage usage) { |
| 85 return GpuMemoryBufferFactorySurfaceTexture:: |
| 86 IsGpuMemoryBufferConfigurationSupported(format, usage); |
| 87 } |
| 88 |
| 89 // static |
| 90 base::Closure GpuMemoryBufferImplSurfaceTexture::AllocateForTesting( |
| 91 const gfx::Size& size, |
| 92 gfx::BufferFormat format, |
| 93 gfx::BufferUsage usage, |
| 94 gfx::GpuMemoryBufferHandle* handle) { |
| 95 scoped_refptr<gfx::SurfaceTexture> surface_texture = |
| 96 gfx::SurfaceTexture::Create(0); |
| 97 DCHECK(surface_texture); |
| 98 gfx::GpuMemoryBufferId kBufferId(1); |
| 99 SurfaceTextureManager::GetInstance()->RegisterSurfaceTexture( |
| 100 kBufferId.id, 0, surface_texture.get()); |
| 101 handle->type = gfx::SURFACE_TEXTURE_BUFFER; |
| 102 handle->id = kBufferId; |
| 103 return base::Bind(&FreeSurfaceTextureForTesting, kBufferId); |
75 } | 104 } |
76 | 105 |
77 bool GpuMemoryBufferImplSurfaceTexture::Map(void** data) { | 106 bool GpuMemoryBufferImplSurfaceTexture::Map(void** data) { |
78 TRACE_EVENT0("gpu", "GpuMemoryBufferImplSurfaceTexture::Map"); | 107 TRACE_EVENT0("gpu", "GpuMemoryBufferImplSurfaceTexture::Map"); |
79 | 108 |
80 DCHECK(!mapped_); | 109 DCHECK(!mapped_); |
81 DCHECK(native_window_); | 110 DCHECK(native_window_); |
82 ANativeWindow_Buffer buffer; | 111 ANativeWindow_Buffer buffer; |
83 int status = ANativeWindow_lock(native_window_, &buffer, NULL); | 112 int status = ANativeWindow_lock(native_window_, &buffer, NULL); |
84 if (status) { | 113 if (status) { |
(...skipping 22 matching lines...) Expand all Loading... |
107 | 136 |
108 gfx::GpuMemoryBufferHandle GpuMemoryBufferImplSurfaceTexture::GetHandle() | 137 gfx::GpuMemoryBufferHandle GpuMemoryBufferImplSurfaceTexture::GetHandle() |
109 const { | 138 const { |
110 gfx::GpuMemoryBufferHandle handle; | 139 gfx::GpuMemoryBufferHandle handle; |
111 handle.type = gfx::SURFACE_TEXTURE_BUFFER; | 140 handle.type = gfx::SURFACE_TEXTURE_BUFFER; |
112 handle.id = id_; | 141 handle.id = id_; |
113 return handle; | 142 return handle; |
114 } | 143 } |
115 | 144 |
116 } // namespace content | 145 } // namespace content |
OLD | NEW |