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