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

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

Issue 634083002: gpu: Compositor management of GpuMemoryBuffer instances. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@cc-pre-chromium-image-refactor
Patch Set: rebase Created 6 years, 2 months 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" 7 #include "base/atomic_sequence_num.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/debug/trace_event.h" 9 #include "base/debug/trace_event.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "content/common/android/surface_texture_manager.h" 11 #include "content/common/android/surface_texture_manager.h"
12 #include "content/common/gpu/client/gpu_memory_buffer_factory_host.h" 12 #include "content/common/gpu/client/gpu_memory_buffer_factory_host.h"
13 #include "ui/gl/gl_bindings.h" 13 #include "ui/gl/gl_bindings.h"
14 14
15 namespace content { 15 namespace content {
16 namespace { 16 namespace {
17 17
18 base::StaticAtomicSequenceNumber g_next_buffer_id; 18 base::StaticAtomicSequenceNumber g_next_buffer_id;
19 19
20 void Noop() { 20 void Noop() {
21 } 21 }
22 22
23 void GpuMemoryBufferCreated( 23 void GpuMemoryBufferCreated(
24 const gfx::Size& size, 24 const gfx::Size& size,
25 unsigned internalformat, 25 gfx::GpuMemoryBuffer::Format format,
26 const GpuMemoryBufferImpl::CreationCallback& callback, 26 const GpuMemoryBufferImpl::CreationCallback& callback,
27 const gfx::GpuMemoryBufferHandle& handle) { 27 const gfx::GpuMemoryBufferHandle& handle) {
28 DCHECK_EQ(gfx::SURFACE_TEXTURE_BUFFER, handle.type); 28 DCHECK_EQ(gfx::SURFACE_TEXTURE_BUFFER, handle.type);
29 29
30 callback.Run(GpuMemoryBufferImplSurfaceTexture::CreateFromHandle( 30 callback.Run(GpuMemoryBufferImplSurfaceTexture::CreateFromHandle(
31 handle, size, internalformat, base::Bind(&Noop))); 31 handle, size, format, base::Bind(&Noop)));
32 } 32 }
33 33
34 void GpuMemoryBufferCreatedForChildProcess( 34 void GpuMemoryBufferCreatedForChildProcess(
35 const GpuMemoryBufferImpl::AllocationCallback& callback, 35 const GpuMemoryBufferImpl::AllocationCallback& callback,
36 const gfx::GpuMemoryBufferHandle& handle) { 36 const gfx::GpuMemoryBufferHandle& handle) {
37 DCHECK_EQ(gfx::SURFACE_TEXTURE_BUFFER, handle.type); 37 DCHECK_EQ(gfx::SURFACE_TEXTURE_BUFFER, handle.type);
38 38
39 callback.Run(handle); 39 callback.Run(handle);
40 } 40 }
41 41
42 } // namespace 42 } // namespace
43 43
44 GpuMemoryBufferImplSurfaceTexture::GpuMemoryBufferImplSurfaceTexture( 44 GpuMemoryBufferImplSurfaceTexture::GpuMemoryBufferImplSurfaceTexture(
45 const gfx::Size& size, 45 const gfx::Size& size,
46 unsigned internalformat, 46 Format format,
47 const DestructionCallback& callback, 47 const DestructionCallback& callback,
48 const gfx::GpuMemoryBufferId& id, 48 const gfx::GpuMemoryBufferId& id,
49 ANativeWindow* native_window) 49 ANativeWindow* native_window)
50 : GpuMemoryBufferImpl(size, internalformat, callback), 50 : GpuMemoryBufferImpl(size, format, callback),
51 id_(id), 51 id_(id),
52 native_window_(native_window), 52 native_window_(native_window),
53 stride_(0u) { 53 stride_(0u) {
54 } 54 }
55 55
56 GpuMemoryBufferImplSurfaceTexture::~GpuMemoryBufferImplSurfaceTexture() { 56 GpuMemoryBufferImplSurfaceTexture::~GpuMemoryBufferImplSurfaceTexture() {
57 ANativeWindow_release(native_window_); 57 ANativeWindow_release(native_window_);
58 } 58 }
59 59
60 // static 60 // static
61 void GpuMemoryBufferImplSurfaceTexture::Create( 61 void GpuMemoryBufferImplSurfaceTexture::Create(
62 const gfx::Size& size, 62 const gfx::Size& size,
63 unsigned internalformat, 63 Format format,
64 unsigned usage,
65 int client_id, 64 int client_id,
66 const CreationCallback& callback) { 65 const CreationCallback& callback) {
67 gfx::GpuMemoryBufferHandle handle; 66 gfx::GpuMemoryBufferHandle handle;
68 handle.global_id.primary_id = g_next_buffer_id.GetNext(); 67 handle.global_id.primary_id = g_next_buffer_id.GetNext();
69 handle.global_id.secondary_id = client_id; 68 handle.global_id.secondary_id = client_id;
70 handle.type = gfx::SURFACE_TEXTURE_BUFFER; 69 handle.type = gfx::SURFACE_TEXTURE_BUFFER;
71 GpuMemoryBufferFactoryHost::GetInstance()->CreateGpuMemoryBuffer( 70 GpuMemoryBufferFactoryHost::GetInstance()->CreateGpuMemoryBuffer(
72 handle, 71 handle,
73 size, 72 size,
74 internalformat, 73 format,
75 usage, 74 MAP,
76 base::Bind(&GpuMemoryBufferCreated, size, internalformat, callback)); 75 base::Bind(&GpuMemoryBufferCreated, size, format, callback));
77 } 76 }
78 77
79 // static 78 // static
80 void GpuMemoryBufferImplSurfaceTexture::AllocateForChildProcess( 79 void GpuMemoryBufferImplSurfaceTexture::AllocateForChildProcess(
81 const gfx::Size& size, 80 const gfx::Size& size,
82 unsigned internalformat, 81 Format format,
83 unsigned usage,
84 int child_client_id, 82 int child_client_id,
85 const AllocationCallback& callback) { 83 const AllocationCallback& callback) {
86 gfx::GpuMemoryBufferHandle handle; 84 gfx::GpuMemoryBufferHandle handle;
87 handle.global_id.primary_id = g_next_buffer_id.GetNext(); 85 handle.global_id.primary_id = g_next_buffer_id.GetNext();
88 handle.global_id.secondary_id = child_client_id; 86 handle.global_id.secondary_id = child_client_id;
89 handle.type = gfx::SURFACE_TEXTURE_BUFFER; 87 handle.type = gfx::SURFACE_TEXTURE_BUFFER;
90 GpuMemoryBufferFactoryHost::GetInstance()->CreateGpuMemoryBuffer( 88 GpuMemoryBufferFactoryHost::GetInstance()->CreateGpuMemoryBuffer(
91 handle, 89 handle,
92 size, 90 size,
93 internalformat, 91 format,
94 usage, 92 MAP,
95 base::Bind(&GpuMemoryBufferCreatedForChildProcess, callback)); 93 base::Bind(&GpuMemoryBufferCreatedForChildProcess, callback));
96 } 94 }
97 95
98 // static 96 // static
99 scoped_ptr<GpuMemoryBufferImpl> 97 scoped_ptr<GpuMemoryBufferImpl>
100 GpuMemoryBufferImplSurfaceTexture::CreateFromHandle( 98 GpuMemoryBufferImplSurfaceTexture::CreateFromHandle(
101 const gfx::GpuMemoryBufferHandle& handle, 99 const gfx::GpuMemoryBufferHandle& handle,
102 const gfx::Size& size, 100 const gfx::Size& size,
103 unsigned internalformat, 101 Format format,
104 const DestructionCallback& callback) { 102 const DestructionCallback& callback) {
105 DCHECK(IsFormatSupported(internalformat)); 103 DCHECK(IsFormatSupported(format));
106 104
107 ANativeWindow* native_window = 105 ANativeWindow* native_window =
108 SurfaceTextureManager::GetInstance()->AcquireNativeWidget( 106 SurfaceTextureManager::GetInstance()->AcquireNativeWidget(
109 handle.global_id.primary_id, handle.global_id.secondary_id); 107 handle.global_id.primary_id, handle.global_id.secondary_id);
110 if (!native_window) 108 if (!native_window)
111 return scoped_ptr<GpuMemoryBufferImpl>(); 109 return scoped_ptr<GpuMemoryBufferImpl>();
112 110
113 ANativeWindow_setBuffersGeometry( 111 ANativeWindow_setBuffersGeometry(
114 native_window, size.width(), size.height(), WindowFormat(internalformat)); 112 native_window, size.width(), size.height(), WindowFormat(format));
115 113
116 return make_scoped_ptr<GpuMemoryBufferImpl>( 114 return make_scoped_ptr<GpuMemoryBufferImpl>(
117 new GpuMemoryBufferImplSurfaceTexture( 115 new GpuMemoryBufferImplSurfaceTexture(
118 size, internalformat, callback, handle.global_id, native_window)); 116 size, format, callback, handle.global_id, native_window));
119 } 117 }
120 118
121 // static 119 // static
122 bool GpuMemoryBufferImplSurfaceTexture::IsFormatSupported( 120 bool GpuMemoryBufferImplSurfaceTexture::IsFormatSupported(Format format) {
123 unsigned internalformat) { 121 switch (format) {
124 switch (internalformat) { 122 case RGBA_8888:
125 case GL_RGBA8_OES:
126 return true; 123 return true;
127 default: 124 case RGBX_8888:
125 case BGRA_8888:
128 return false; 126 return false;
129 } 127 }
128
129 NOTREACHED();
130 return false;
130 } 131 }
131 132
132 // static 133 // static
133 bool GpuMemoryBufferImplSurfaceTexture::IsUsageSupported(unsigned usage) { 134 bool GpuMemoryBufferImplSurfaceTexture::IsUsageSupported(Usage usage) {
134 switch (usage) { 135 switch (usage) {
135 case GL_IMAGE_MAP_CHROMIUM: 136 case MAP:
136 return true; 137 return true;
137 default: 138 case SCANOUT:
138 return false; 139 return false;
139 } 140 }
141
142 NOTREACHED();
143 return false;
140 } 144 }
141 145
142 // static 146 // static
143 bool GpuMemoryBufferImplSurfaceTexture::IsConfigurationSupported( 147 bool GpuMemoryBufferImplSurfaceTexture::IsConfigurationSupported(Format format,
144 unsigned internalformat, 148 Usage usage) {
145 unsigned usage) { 149 return IsFormatSupported(format) && IsUsageSupported(usage);
146 return IsFormatSupported(internalformat) && IsUsageSupported(usage);
147 } 150 }
148 151
149 // static 152 // static
150 int GpuMemoryBufferImplSurfaceTexture::WindowFormat(unsigned internalformat) { 153 int GpuMemoryBufferImplSurfaceTexture::WindowFormat(Format format) {
151 switch (internalformat) { 154 switch (format) {
152 case GL_RGBA8_OES: 155 case RGBA_8888:
153 return WINDOW_FORMAT_RGBA_8888; 156 return WINDOW_FORMAT_RGBA_8888;
154 default: 157 case RGBX_8888:
158 case BGRA_8888:
155 NOTREACHED(); 159 NOTREACHED();
156 return 0; 160 return 0;
157 } 161 }
162
163 NOTREACHED();
164 return 0;
158 } 165 }
159 166
160 void* GpuMemoryBufferImplSurfaceTexture::Map() { 167 void* GpuMemoryBufferImplSurfaceTexture::Map() {
161 TRACE_EVENT0("gpu", "GpuMemoryBufferImplSurfaceTexture::Map"); 168 TRACE_EVENT0("gpu", "GpuMemoryBufferImplSurfaceTexture::Map");
162 169
163 DCHECK(!mapped_); 170 DCHECK(!mapped_);
164 DCHECK(native_window_); 171 DCHECK(native_window_);
165 ANativeWindow_Buffer buffer; 172 ANativeWindow_Buffer buffer;
166 int status = ANativeWindow_lock(native_window_, &buffer, NULL); 173 int status = ANativeWindow_lock(native_window_, &buffer, NULL);
167 if (status) { 174 if (status) {
168 VLOG(1) << "ANativeWindow_lock failed with error code: " << status; 175 VLOG(1) << "ANativeWindow_lock failed with error code: " << status;
169 return NULL; 176 return NULL;
170 } 177 }
171 178
172 DCHECK_LE(size_.width(), buffer.stride); 179 DCHECK_LE(size_.width(), buffer.stride);
173 stride_ = buffer.stride * BytesPerPixel(internalformat_); 180 stride_ = buffer.stride * BytesPerPixel(format_);
174 mapped_ = true; 181 mapped_ = true;
175 return buffer.bits; 182 return buffer.bits;
176 } 183 }
177 184
178 void GpuMemoryBufferImplSurfaceTexture::Unmap() { 185 void GpuMemoryBufferImplSurfaceTexture::Unmap() {
179 TRACE_EVENT0("gpu", "GpuMemoryBufferImplSurfaceTexture::Unmap"); 186 TRACE_EVENT0("gpu", "GpuMemoryBufferImplSurfaceTexture::Unmap");
180 187
181 DCHECK(mapped_); 188 DCHECK(mapped_);
182 ANativeWindow_unlockAndPost(native_window_); 189 ANativeWindow_unlockAndPost(native_window_);
183 mapped_ = false; 190 mapped_ = false;
184 } 191 }
185 192
186 uint32 GpuMemoryBufferImplSurfaceTexture::GetStride() const { return stride_; } 193 uint32 GpuMemoryBufferImplSurfaceTexture::GetStride() const {
194 return stride_;
195 }
187 196
188 gfx::GpuMemoryBufferHandle GpuMemoryBufferImplSurfaceTexture::GetHandle() 197 gfx::GpuMemoryBufferHandle GpuMemoryBufferImplSurfaceTexture::GetHandle()
189 const { 198 const {
190 gfx::GpuMemoryBufferHandle handle; 199 gfx::GpuMemoryBufferHandle handle;
191 handle.type = gfx::SURFACE_TEXTURE_BUFFER; 200 handle.type = gfx::SURFACE_TEXTURE_BUFFER;
192 handle.global_id = id_; 201 handle.global_id = id_;
193 return handle; 202 return handle;
194 } 203 }
195 204
196 } // namespace content 205 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698