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/atomic_sequence_num.h" | |
8 #include "base/bind.h" | 7 #include "base/bind.h" |
9 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
10 #include "base/logging.h" | 9 #include "base/logging.h" |
11 #include "content/common/android/surface_texture_manager.h" | 10 #include "content/common/android/surface_texture_manager.h" |
12 #include "content/common/gpu/client/gpu_memory_buffer_factory_host.h" | 11 #include "content/common/gpu/client/gpu_memory_buffer_factory_host.h" |
13 #include "ui/gl/gl_bindings.h" | 12 #include "ui/gl/gl_bindings.h" |
14 | 13 |
15 namespace content { | 14 namespace content { |
16 namespace { | 15 namespace { |
17 | 16 |
18 base::StaticAtomicSequenceNumber g_next_buffer_id; | |
19 | |
20 void Noop() { | 17 void Noop() { |
21 } | 18 } |
22 | 19 |
23 void GpuMemoryBufferCreated( | 20 void GpuMemoryBufferCreated( |
24 const gfx::Size& size, | 21 const gfx::Size& size, |
25 gfx::GpuMemoryBuffer::Format format, | 22 gfx::GpuMemoryBuffer::Format format, |
26 const GpuMemoryBufferImpl::CreationCallback& callback, | 23 const GpuMemoryBufferImpl::CreationCallback& callback, |
27 const gfx::GpuMemoryBufferHandle& handle) { | 24 const gfx::GpuMemoryBufferHandle& handle) { |
28 DCHECK_EQ(gfx::SURFACE_TEXTURE_BUFFER, handle.type); | 25 DCHECK_EQ(gfx::SURFACE_TEXTURE_BUFFER, handle.type); |
29 | 26 |
30 callback.Run(GpuMemoryBufferImplSurfaceTexture::CreateFromHandle( | 27 callback.Run(GpuMemoryBufferImplSurfaceTexture::CreateFromHandle( |
31 handle, size, format, base::Bind(&Noop))); | 28 handle, size, format, base::Bind(&Noop))); |
32 } | 29 } |
33 | 30 |
34 void GpuMemoryBufferCreatedForChildProcess( | 31 void GpuMemoryBufferCreatedForChildProcess( |
35 const GpuMemoryBufferImpl::AllocationCallback& callback, | 32 const GpuMemoryBufferImpl::AllocationCallback& callback, |
36 const gfx::GpuMemoryBufferHandle& handle) { | 33 const gfx::GpuMemoryBufferHandle& handle) { |
37 DCHECK_EQ(gfx::SURFACE_TEXTURE_BUFFER, handle.type); | 34 DCHECK_EQ(gfx::SURFACE_TEXTURE_BUFFER, handle.type); |
38 | 35 |
39 callback.Run(handle); | 36 callback.Run(handle); |
40 } | 37 } |
41 | 38 |
42 } // namespace | 39 } // namespace |
43 | 40 |
44 GpuMemoryBufferImplSurfaceTexture::GpuMemoryBufferImplSurfaceTexture( | 41 GpuMemoryBufferImplSurfaceTexture::GpuMemoryBufferImplSurfaceTexture( |
| 42 gfx::GpuMemoryBufferId id, |
45 const gfx::Size& size, | 43 const gfx::Size& size, |
46 Format format, | 44 Format format, |
47 const DestructionCallback& callback, | 45 const DestructionCallback& callback, |
48 const gfx::GpuMemoryBufferId& id, | 46 const gfx::GpuMemoryBufferId& id, |
49 ANativeWindow* native_window) | 47 ANativeWindow* native_window) |
50 : GpuMemoryBufferImpl(size, format, callback), | 48 : GpuMemoryBufferImpl(id, size, format, callback), |
51 id_(id), | |
52 native_window_(native_window), | 49 native_window_(native_window), |
53 stride_(0u) { | 50 stride_(0u) { |
54 } | 51 } |
55 | 52 |
56 GpuMemoryBufferImplSurfaceTexture::~GpuMemoryBufferImplSurfaceTexture() { | 53 GpuMemoryBufferImplSurfaceTexture::~GpuMemoryBufferImplSurfaceTexture() { |
57 ANativeWindow_release(native_window_); | 54 ANativeWindow_release(native_window_); |
58 } | 55 } |
59 | 56 |
60 // static | 57 // static |
61 void GpuMemoryBufferImplSurfaceTexture::Create( | 58 void GpuMemoryBufferImplSurfaceTexture::Create( |
| 59 gfx::GpuMemoryBufferId id, |
62 const gfx::Size& size, | 60 const gfx::Size& size, |
63 Format format, | 61 Format format, |
64 int client_id, | 62 int client_id, |
65 const CreationCallback& callback) { | 63 const CreationCallback& callback) { |
66 gfx::GpuMemoryBufferHandle handle; | |
67 handle.global_id.primary_id = g_next_buffer_id.GetNext(); | |
68 handle.global_id.secondary_id = client_id; | |
69 handle.type = gfx::SURFACE_TEXTURE_BUFFER; | |
70 GpuMemoryBufferFactoryHost::GetInstance()->CreateGpuMemoryBuffer( | 64 GpuMemoryBufferFactoryHost::GetInstance()->CreateGpuMemoryBuffer( |
71 handle, | 65 gfx::SURFACE_TEXTURE_BUFFER, |
| 66 id, |
72 size, | 67 size, |
73 format, | 68 format, |
74 MAP, | 69 MAP, |
| 70 client_id, |
75 base::Bind(&GpuMemoryBufferCreated, size, format, callback)); | 71 base::Bind(&GpuMemoryBufferCreated, size, format, callback)); |
76 } | 72 } |
77 | 73 |
78 // static | 74 // static |
79 void GpuMemoryBufferImplSurfaceTexture::AllocateForChildProcess( | 75 void GpuMemoryBufferImplSurfaceTexture::AllocateForChildProcess( |
80 const gfx::Size& size, | 76 gfx::GpuMemoryBufferId id, |
81 Format format, | 77 Format format, |
82 int child_client_id, | 78 int child_client_id, |
83 const AllocationCallback& callback) { | 79 const AllocationCallback& callback) { |
84 gfx::GpuMemoryBufferHandle handle; | |
85 handle.global_id.primary_id = g_next_buffer_id.GetNext(); | |
86 handle.global_id.secondary_id = child_client_id; | |
87 handle.type = gfx::SURFACE_TEXTURE_BUFFER; | |
88 GpuMemoryBufferFactoryHost::GetInstance()->CreateGpuMemoryBuffer( | 80 GpuMemoryBufferFactoryHost::GetInstance()->CreateGpuMemoryBuffer( |
89 handle, | 81 gfx::SURFACE_TEXTURE_BUFFER, |
| 82 id, |
90 size, | 83 size, |
91 format, | 84 format, |
92 MAP, | 85 MAP, |
| 86 child_client_id, |
93 base::Bind(&GpuMemoryBufferCreatedForChildProcess, callback)); | 87 base::Bind(&GpuMemoryBufferCreatedForChildProcess, callback)); |
94 } | 88 } |
95 | 89 |
96 // static | 90 // static |
97 scoped_ptr<GpuMemoryBufferImpl> | 91 scoped_ptr<GpuMemoryBufferImpl> |
98 GpuMemoryBufferImplSurfaceTexture::CreateFromHandle( | 92 GpuMemoryBufferImplSurfaceTexture::CreateFromHandle( |
99 const gfx::GpuMemoryBufferHandle& handle, | 93 const gfx::GpuMemoryBufferHandle& handle, |
100 const gfx::Size& size, | 94 const gfx::Size& size, |
101 Format format, | 95 Format format, |
102 const DestructionCallback& callback) { | 96 const DestructionCallback& callback) { |
103 DCHECK(IsFormatSupported(format)); | 97 DCHECK(IsFormatSupported(format)); |
104 | 98 |
105 ANativeWindow* native_window = | 99 ANativeWindow* native_window = |
106 SurfaceTextureManager::GetInstance()->AcquireNativeWidget( | 100 SurfaceTextureManager::GetInstance()->AcquireNativeWidget(handle.id); |
107 handle.global_id.primary_id, handle.global_id.secondary_id); | |
108 if (!native_window) | 101 if (!native_window) |
109 return scoped_ptr<GpuMemoryBufferImpl>(); | 102 return scoped_ptr<GpuMemoryBufferImpl>(); |
110 | 103 |
111 ANativeWindow_setBuffersGeometry( | 104 ANativeWindow_setBuffersGeometry( |
112 native_window, size.width(), size.height(), WindowFormat(format)); | 105 native_window, size.width(), size.height(), WindowFormat(format)); |
113 | 106 |
114 return make_scoped_ptr<GpuMemoryBufferImpl>( | 107 return make_scoped_ptr<GpuMemoryBufferImpl>( |
115 new GpuMemoryBufferImplSurfaceTexture( | 108 new GpuMemoryBufferImplSurfaceTexture( |
116 size, format, callback, handle.global_id, native_window)); | 109 id, size, format, callback, native_window)); |
117 } | 110 } |
118 | 111 |
119 // static | 112 // static |
120 bool GpuMemoryBufferImplSurfaceTexture::IsFormatSupported(Format format) { | 113 bool GpuMemoryBufferImplSurfaceTexture::IsFormatSupported(Format format) { |
121 switch (format) { | 114 switch (format) { |
122 case RGBA_8888: | 115 case RGBA_8888: |
123 return true; | 116 return true; |
124 case RGBX_8888: | 117 case RGBX_8888: |
125 case BGRA_8888: | 118 case BGRA_8888: |
126 return false; | 119 return false; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 } | 184 } |
192 | 185 |
193 uint32 GpuMemoryBufferImplSurfaceTexture::GetStride() const { | 186 uint32 GpuMemoryBufferImplSurfaceTexture::GetStride() const { |
194 return stride_; | 187 return stride_; |
195 } | 188 } |
196 | 189 |
197 gfx::GpuMemoryBufferHandle GpuMemoryBufferImplSurfaceTexture::GetHandle() | 190 gfx::GpuMemoryBufferHandle GpuMemoryBufferImplSurfaceTexture::GetHandle() |
198 const { | 191 const { |
199 gfx::GpuMemoryBufferHandle handle; | 192 gfx::GpuMemoryBufferHandle handle; |
200 handle.type = gfx::SURFACE_TEXTURE_BUFFER; | 193 handle.type = gfx::SURFACE_TEXTURE_BUFFER; |
201 handle.global_id = id_; | 194 handle.id = id_; |
202 return handle; | 195 return handle; |
203 } | 196 } |
204 | 197 |
205 } // namespace content | 198 } // namespace content |
OLD | NEW |