Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(102)

Side by Side Diff: content/common/gpu/client/gpu_memory_buffer_impl_surface_texture.cc

Issue 685983005: gpu: Associate all GpuMemoryBuffers with unique IDs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: one more ozone build fix Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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; 17 void GpuMemoryBufferDeleted(gfx::GpuMemoryBufferId id,
19 18 int client_id,
20 void GpuMemoryBufferDeleted(const gfx::GpuMemoryBufferHandle& handle,
21 uint32 sync_point) { 19 uint32 sync_point) {
22 GpuMemoryBufferFactoryHost::GetInstance()->DestroyGpuMemoryBuffer(handle, 20 GpuMemoryBufferFactoryHost::GetInstance()->DestroyGpuMemoryBuffer(
23 sync_point); 21 gfx::SURFACE_TEXTURE_BUFFER, id, client_id, sync_point);
24 } 22 }
25 23
26 void GpuMemoryBufferCreated( 24 void GpuMemoryBufferCreated(
27 const gfx::Size& size, 25 const gfx::Size& size,
28 gfx::GpuMemoryBuffer::Format format, 26 gfx::GpuMemoryBuffer::Format format,
27 int client_id,
29 const GpuMemoryBufferImpl::CreationCallback& callback, 28 const GpuMemoryBufferImpl::CreationCallback& callback,
30 const gfx::GpuMemoryBufferHandle& handle) { 29 const gfx::GpuMemoryBufferHandle& handle) {
31 DCHECK_EQ(gfx::SURFACE_TEXTURE_BUFFER, handle.type); 30 DCHECK_EQ(gfx::SURFACE_TEXTURE_BUFFER, handle.type);
32 31
33 callback.Run(GpuMemoryBufferImplSurfaceTexture::CreateFromHandle( 32 callback.Run(GpuMemoryBufferImplSurfaceTexture::CreateFromHandle(
34 handle, size, format, base::Bind(&GpuMemoryBufferDeleted, handle))); 33 handle,
34 size,
35 format,
36 base::Bind(&GpuMemoryBufferDeleted, handle.id, client_id)));
35 } 37 }
36 38
37 void GpuMemoryBufferCreatedForChildProcess( 39 void GpuMemoryBufferCreatedForChildProcess(
38 const GpuMemoryBufferImpl::AllocationCallback& callback, 40 const GpuMemoryBufferImpl::AllocationCallback& callback,
39 const gfx::GpuMemoryBufferHandle& handle) { 41 const gfx::GpuMemoryBufferHandle& handle) {
40 DCHECK_EQ(gfx::SURFACE_TEXTURE_BUFFER, handle.type); 42 DCHECK_EQ(gfx::SURFACE_TEXTURE_BUFFER, handle.type);
41 43
42 callback.Run(handle); 44 callback.Run(handle);
43 } 45 }
44 46
45 } // namespace 47 } // namespace
46 48
47 GpuMemoryBufferImplSurfaceTexture::GpuMemoryBufferImplSurfaceTexture( 49 GpuMemoryBufferImplSurfaceTexture::GpuMemoryBufferImplSurfaceTexture(
50 gfx::GpuMemoryBufferId id,
48 const gfx::Size& size, 51 const gfx::Size& size,
49 Format format, 52 Format format,
50 const DestructionCallback& callback, 53 const DestructionCallback& callback,
51 const gfx::GpuMemoryBufferId& id,
52 ANativeWindow* native_window) 54 ANativeWindow* native_window)
53 : GpuMemoryBufferImpl(size, format, callback), 55 : GpuMemoryBufferImpl(id, size, format, callback),
54 id_(id),
55 native_window_(native_window), 56 native_window_(native_window),
56 stride_(0u) { 57 stride_(0) {
57 } 58 }
58 59
59 GpuMemoryBufferImplSurfaceTexture::~GpuMemoryBufferImplSurfaceTexture() { 60 GpuMemoryBufferImplSurfaceTexture::~GpuMemoryBufferImplSurfaceTexture() {
60 ANativeWindow_release(native_window_); 61 ANativeWindow_release(native_window_);
61 } 62 }
62 63
63 // static 64 // static
64 void GpuMemoryBufferImplSurfaceTexture::Create( 65 void GpuMemoryBufferImplSurfaceTexture::Create(
66 gfx::GpuMemoryBufferId id,
65 const gfx::Size& size, 67 const gfx::Size& size,
66 Format format, 68 Format format,
67 int client_id, 69 int client_id,
68 const CreationCallback& callback) { 70 const CreationCallback& callback) {
69 gfx::GpuMemoryBufferHandle handle;
70 handle.global_id.primary_id = g_next_buffer_id.GetNext();
71 handle.global_id.secondary_id = client_id;
72 handle.type = gfx::SURFACE_TEXTURE_BUFFER;
73 GpuMemoryBufferFactoryHost::GetInstance()->CreateGpuMemoryBuffer( 71 GpuMemoryBufferFactoryHost::GetInstance()->CreateGpuMemoryBuffer(
74 handle, 72 gfx::SURFACE_TEXTURE_BUFFER,
73 id,
75 size, 74 size,
76 format, 75 format,
77 MAP, 76 MAP,
78 base::Bind(&GpuMemoryBufferCreated, size, format, callback)); 77 client_id,
78 base::Bind(&GpuMemoryBufferCreated, size, format, client_id, callback));
79 } 79 }
80 80
81 // static 81 // static
82 void GpuMemoryBufferImplSurfaceTexture::AllocateForChildProcess( 82 void GpuMemoryBufferImplSurfaceTexture::AllocateForChildProcess(
83 gfx::GpuMemoryBufferId id,
83 const gfx::Size& size, 84 const gfx::Size& size,
84 Format format, 85 Format format,
85 int child_client_id, 86 int child_client_id,
86 const AllocationCallback& callback) { 87 const AllocationCallback& callback) {
87 gfx::GpuMemoryBufferHandle handle;
88 handle.global_id.primary_id = g_next_buffer_id.GetNext();
89 handle.global_id.secondary_id = child_client_id;
90 handle.type = gfx::SURFACE_TEXTURE_BUFFER;
91 GpuMemoryBufferFactoryHost::GetInstance()->CreateGpuMemoryBuffer( 88 GpuMemoryBufferFactoryHost::GetInstance()->CreateGpuMemoryBuffer(
92 handle, 89 gfx::SURFACE_TEXTURE_BUFFER,
90 id,
93 size, 91 size,
94 format, 92 format,
95 MAP, 93 MAP,
94 child_client_id,
96 base::Bind(&GpuMemoryBufferCreatedForChildProcess, callback)); 95 base::Bind(&GpuMemoryBufferCreatedForChildProcess, callback));
97 } 96 }
98 97
99 // static 98 // static
100 scoped_ptr<GpuMemoryBufferImpl> 99 scoped_ptr<GpuMemoryBufferImpl>
101 GpuMemoryBufferImplSurfaceTexture::CreateFromHandle( 100 GpuMemoryBufferImplSurfaceTexture::CreateFromHandle(
102 const gfx::GpuMemoryBufferHandle& handle, 101 const gfx::GpuMemoryBufferHandle& handle,
103 const gfx::Size& size, 102 const gfx::Size& size,
104 Format format, 103 Format format,
105 const DestructionCallback& callback) { 104 const DestructionCallback& callback) {
106 DCHECK(IsFormatSupported(format)); 105 DCHECK(IsFormatSupported(format));
107 106
108 ANativeWindow* native_window = 107 ANativeWindow* native_window = SurfaceTextureManager::GetInstance()->
109 SurfaceTextureManager::GetInstance()->AcquireNativeWidget( 108 AcquireNativeWidgetForSurfaceTexture(handle.id);
110 handle.global_id.primary_id, handle.global_id.secondary_id);
111 if (!native_window) 109 if (!native_window)
112 return scoped_ptr<GpuMemoryBufferImpl>(); 110 return scoped_ptr<GpuMemoryBufferImpl>();
113 111
114 ANativeWindow_setBuffersGeometry( 112 ANativeWindow_setBuffersGeometry(
115 native_window, size.width(), size.height(), WindowFormat(format)); 113 native_window, size.width(), size.height(), WindowFormat(format));
116 114
117 return make_scoped_ptr<GpuMemoryBufferImpl>( 115 return make_scoped_ptr<GpuMemoryBufferImpl>(
118 new GpuMemoryBufferImplSurfaceTexture( 116 new GpuMemoryBufferImplSurfaceTexture(
119 size, format, callback, handle.global_id, native_window)); 117 handle.id, size, format, callback, native_window));
120 } 118 }
121 119
122 // static 120 // static
123 void GpuMemoryBufferImplSurfaceTexture::DeletedByChildProcess( 121 void GpuMemoryBufferImplSurfaceTexture::DeletedByChildProcess(
124 const gfx::GpuMemoryBufferId& id, 122 gfx::GpuMemoryBufferId id,
123 int child_client_id,
125 uint32_t sync_point) { 124 uint32_t sync_point) {
126 gfx::GpuMemoryBufferHandle handle; 125 GpuMemoryBufferFactoryHost::GetInstance()->DestroyGpuMemoryBuffer(
127 handle.type = gfx::SURFACE_TEXTURE_BUFFER; 126 gfx::SURFACE_TEXTURE_BUFFER, id, child_client_id, sync_point);
128 handle.global_id = id;
129 GpuMemoryBufferFactoryHost::GetInstance()->DestroyGpuMemoryBuffer(handle,
130 sync_point);
131 } 127 }
132 128
133 // static 129 // static
134 bool GpuMemoryBufferImplSurfaceTexture::IsFormatSupported(Format format) { 130 bool GpuMemoryBufferImplSurfaceTexture::IsFormatSupported(Format format) {
135 switch (format) { 131 switch (format) {
136 case RGBA_8888: 132 case RGBA_8888:
137 return true; 133 return true;
138 case RGBX_8888: 134 case RGBX_8888:
139 case BGRA_8888: 135 case BGRA_8888:
140 return false; 136 return false;
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 } 201 }
206 202
207 uint32 GpuMemoryBufferImplSurfaceTexture::GetStride() const { 203 uint32 GpuMemoryBufferImplSurfaceTexture::GetStride() const {
208 return stride_; 204 return stride_;
209 } 205 }
210 206
211 gfx::GpuMemoryBufferHandle GpuMemoryBufferImplSurfaceTexture::GetHandle() 207 gfx::GpuMemoryBufferHandle GpuMemoryBufferImplSurfaceTexture::GetHandle()
212 const { 208 const {
213 gfx::GpuMemoryBufferHandle handle; 209 gfx::GpuMemoryBufferHandle handle;
214 handle.type = gfx::SURFACE_TEXTURE_BUFFER; 210 handle.type = gfx::SURFACE_TEXTURE_BUFFER;
215 handle.global_id = id_; 211 handle.id = id_;
216 return handle; 212 return handle;
217 } 213 }
218 214
219 } // namespace content 215 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698