Chromium Code Reviews| 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/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
| 8 #include "base/logging.h" | 10 #include "base/logging.h" |
| 9 #include "content/common/android/surface_texture_lookup.h" | 11 #include "content/common/android/surface_texture_manager.h" |
| 12 #include "content/common/gpu/client/gpu_memory_buffer_factory_host.h" | |
| 10 #include "ui/gl/gl_bindings.h" | 13 #include "ui/gl/gl_bindings.h" |
| 11 | 14 |
| 12 namespace content { | 15 namespace content { |
| 16 namespace { | |
| 17 | |
| 18 base::StaticAtomicSequenceNumber g_next_buffer_id; | |
| 19 | |
| 20 void Noop() { | |
| 21 } | |
| 22 | |
| 23 void GpuMemoryBufferCreated( | |
| 24 const gfx::Size& size, | |
| 25 unsigned internalformat, | |
| 26 const GpuMemoryBufferImpl::CreationCallback& callback, | |
| 27 const gfx::GpuMemoryBufferHandle& handle) { | |
| 28 DCHECK_EQ(gfx::SURFACE_TEXTURE_BUFFER, handle.type); | |
| 29 | |
| 30 callback.Run(GpuMemoryBufferImplSurfaceTexture::CreateFromHandle( | |
| 31 handle, size, internalformat, base::Bind(&Noop))); | |
| 32 } | |
| 33 | |
| 34 void GpuMemoryBufferCreatedForChildProcess( | |
| 35 const GpuMemoryBufferImpl::AllocationCallback& callback, | |
| 36 const gfx::GpuMemoryBufferHandle& handle) { | |
| 37 DCHECK_EQ(gfx::SURFACE_TEXTURE_BUFFER, handle.type); | |
| 38 | |
| 39 callback.Run(handle); | |
| 40 } | |
| 41 | |
| 42 } // namespace | |
| 13 | 43 |
| 14 GpuMemoryBufferImplSurfaceTexture::GpuMemoryBufferImplSurfaceTexture( | 44 GpuMemoryBufferImplSurfaceTexture::GpuMemoryBufferImplSurfaceTexture( |
| 15 const gfx::Size& size, | 45 const gfx::Size& size, |
| 16 unsigned internalformat, | 46 unsigned internalformat, |
| 17 const DestructionCallback& callback, | 47 const DestructionCallback& callback, |
| 18 const gfx::SurfaceTextureId& surface_texture_id, | 48 const gfx::GpuMemoryBufferId& id, |
| 19 ANativeWindow* native_window) | 49 ANativeWindow* native_window) |
| 20 : GpuMemoryBufferImpl(size, internalformat, callback), | 50 : GpuMemoryBufferImpl(size, internalformat, callback), |
| 21 surface_texture_id_(surface_texture_id), | 51 id_(id), |
| 22 native_window_(native_window), | 52 native_window_(native_window), |
| 23 stride_(0u) { | 53 stride_(0u) { |
| 24 } | 54 } |
| 25 | 55 |
| 26 GpuMemoryBufferImplSurfaceTexture::~GpuMemoryBufferImplSurfaceTexture() { | 56 GpuMemoryBufferImplSurfaceTexture::~GpuMemoryBufferImplSurfaceTexture() { |
| 27 ANativeWindow_release(native_window_); | 57 ANativeWindow_release(native_window_); |
| 28 } | 58 } |
| 29 | 59 |
| 30 // static | 60 // static |
| 61 void GpuMemoryBufferImplSurfaceTexture::Create( | |
| 62 const gfx::Size& size, | |
| 63 unsigned internalformat, | |
| 64 unsigned usage, | |
| 65 int client_id, | |
| 66 const CreationCallback& callback) { | |
| 67 gfx::GpuMemoryBufferHandle handle; | |
| 68 handle.global_id.primary_id = g_next_buffer_id.GetNext(); | |
| 69 handle.global_id.secondary_id = client_id; | |
|
no sievers
2014/10/06 22:28:27
Can we avoid using the very opaque identifiers pri
reveman
2014/10/07 01:00:21
gfx::GpuMemoryBufferId needs to live in ui/gfx and
| |
| 70 handle.type = gfx::SURFACE_TEXTURE_BUFFER; | |
| 71 GpuMemoryBufferFactoryHost::GetInstance()->CreateGpuMemoryBuffer( | |
| 72 handle, | |
| 73 size, | |
| 74 internalformat, | |
| 75 usage, | |
| 76 base::Bind(&GpuMemoryBufferCreated, size, internalformat, callback)); | |
| 77 } | |
| 78 | |
| 79 // static | |
| 80 void GpuMemoryBufferImplSurfaceTexture::AllocateForChildProcess( | |
| 81 const gfx::Size& size, | |
| 82 unsigned internalformat, | |
| 83 unsigned usage, | |
| 84 int child_client_id, | |
| 85 const AllocationCallback& callback) { | |
| 86 gfx::GpuMemoryBufferHandle handle; | |
| 87 handle.global_id.primary_id = g_next_buffer_id.GetNext(); | |
| 88 handle.global_id.secondary_id = child_client_id; | |
| 89 handle.type = gfx::SURFACE_TEXTURE_BUFFER; | |
| 90 GpuMemoryBufferFactoryHost::GetInstance()->CreateGpuMemoryBuffer( | |
| 91 handle, | |
| 92 size, | |
| 93 internalformat, | |
| 94 usage, | |
| 95 base::Bind(&GpuMemoryBufferCreatedForChildProcess, callback)); | |
| 96 } | |
| 97 | |
| 98 // static | |
| 31 scoped_ptr<GpuMemoryBufferImpl> | 99 scoped_ptr<GpuMemoryBufferImpl> |
| 32 GpuMemoryBufferImplSurfaceTexture::CreateFromHandle( | 100 GpuMemoryBufferImplSurfaceTexture::CreateFromHandle( |
| 33 const gfx::GpuMemoryBufferHandle& handle, | 101 const gfx::GpuMemoryBufferHandle& handle, |
| 34 const gfx::Size& size, | 102 const gfx::Size& size, |
| 35 unsigned internalformat, | 103 unsigned internalformat, |
| 36 const DestructionCallback& callback) { | 104 const DestructionCallback& callback) { |
| 37 DCHECK(IsFormatSupported(internalformat)); | 105 DCHECK(IsFormatSupported(internalformat)); |
| 38 | 106 |
| 39 ANativeWindow* native_window = | 107 ANativeWindow* native_window = |
| 40 SurfaceTextureLookup::GetInstance()->AcquireNativeWidget( | 108 SurfaceTextureManager::GetInstance()->AcquireNativeWidget( |
| 41 handle.surface_texture_id.primary_id, | 109 handle.global_id.primary_id, handle.global_id.secondary_id); |
| 42 handle.surface_texture_id.secondary_id); | |
| 43 if (!native_window) | 110 if (!native_window) |
| 44 return scoped_ptr<GpuMemoryBufferImpl>(); | 111 return scoped_ptr<GpuMemoryBufferImpl>(); |
| 45 | 112 |
| 46 ANativeWindow_setBuffersGeometry( | 113 ANativeWindow_setBuffersGeometry( |
| 47 native_window, size.width(), size.height(), WindowFormat(internalformat)); | 114 native_window, size.width(), size.height(), WindowFormat(internalformat)); |
| 48 | 115 |
| 49 return make_scoped_ptr<GpuMemoryBufferImpl>( | 116 return make_scoped_ptr<GpuMemoryBufferImpl>( |
| 50 new GpuMemoryBufferImplSurfaceTexture(size, | 117 new GpuMemoryBufferImplSurfaceTexture( |
| 51 internalformat, | 118 size, internalformat, callback, handle.global_id, native_window)); |
| 52 callback, | |
| 53 handle.surface_texture_id, | |
| 54 native_window)); | |
| 55 } | 119 } |
| 56 | 120 |
| 57 // static | 121 // static |
| 58 bool GpuMemoryBufferImplSurfaceTexture::IsFormatSupported( | 122 bool GpuMemoryBufferImplSurfaceTexture::IsFormatSupported( |
| 59 unsigned internalformat) { | 123 unsigned internalformat) { |
| 60 switch (internalformat) { | 124 switch (internalformat) { |
| 61 case GL_RGBA8_OES: | 125 case GL_RGBA8_OES: |
| 62 return true; | 126 return true; |
| 63 default: | 127 default: |
| 64 return false; | 128 return false; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 118 ANativeWindow_unlockAndPost(native_window_); | 182 ANativeWindow_unlockAndPost(native_window_); |
| 119 mapped_ = false; | 183 mapped_ = false; |
| 120 } | 184 } |
| 121 | 185 |
| 122 uint32 GpuMemoryBufferImplSurfaceTexture::GetStride() const { return stride_; } | 186 uint32 GpuMemoryBufferImplSurfaceTexture::GetStride() const { return stride_; } |
| 123 | 187 |
| 124 gfx::GpuMemoryBufferHandle GpuMemoryBufferImplSurfaceTexture::GetHandle() | 188 gfx::GpuMemoryBufferHandle GpuMemoryBufferImplSurfaceTexture::GetHandle() |
| 125 const { | 189 const { |
| 126 gfx::GpuMemoryBufferHandle handle; | 190 gfx::GpuMemoryBufferHandle handle; |
| 127 handle.type = gfx::SURFACE_TEXTURE_BUFFER; | 191 handle.type = gfx::SURFACE_TEXTURE_BUFFER; |
| 128 handle.surface_texture_id = surface_texture_id_; | 192 handle.global_id = id_; |
| 129 return handle; | 193 return handle; |
| 130 } | 194 } |
| 131 | 195 |
| 132 } // namespace content | 196 } // namespace content |
| OLD | NEW |