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/browser/compositor/buffer_queue.h" | 5 #include "content/browser/compositor/buffer_queue.h" |
6 | 6 |
7 #include "base/containers/adapters.h" | 7 #include "base/containers/adapters.h" |
| 8 #include "base/memory/ptr_util.h" |
8 #include "build/build_config.h" | 9 #include "build/build_config.h" |
9 #include "content/browser/compositor/gl_helper.h" | 10 #include "content/browser/compositor/gl_helper.h" |
10 #include "content/browser/compositor/image_transport_factory.h" | 11 #include "content/browser/compositor/image_transport_factory.h" |
11 #include "content/common/gpu/client/context_provider_command_buffer.h" | 12 #include "content/common/gpu/client/context_provider_command_buffer.h" |
12 #include "gpu/GLES2/gl2extchromium.h" | 13 #include "gpu/GLES2/gl2extchromium.h" |
13 #include "gpu/command_buffer/client/gles2_interface.h" | 14 #include "gpu/command_buffer/client/gles2_interface.h" |
14 #include "gpu/command_buffer/client/gpu_memory_buffer_manager.h" | 15 #include "gpu/command_buffer/client/gpu_memory_buffer_manager.h" |
15 #include "gpu/command_buffer/common/gpu_memory_buffer_support.h" | 16 #include "gpu/command_buffer/common/gpu_memory_buffer_support.h" |
16 #include "gpu/command_buffer/service/image_factory.h" | 17 #include "gpu/command_buffer/service/image_factory.h" |
17 #include "third_party/skia/include/core/SkRect.h" | 18 #include "third_party/skia/include/core/SkRect.h" |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 | 150 |
150 if (current_surface_) { | 151 if (current_surface_) { |
151 // If we have a texture bound, we will need to re-bind it. | 152 // If we have a texture bound, we will need to re-bind it. |
152 gpu::gles2::GLES2Interface* gl = context_provider_->ContextGL(); | 153 gpu::gles2::GLES2Interface* gl = context_provider_->ContextGL(); |
153 gl->BindFramebuffer(GL_FRAMEBUFFER, fbo_); | 154 gl->BindFramebuffer(GL_FRAMEBUFFER, fbo_); |
154 gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, | 155 gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, |
155 texture_target_, current_surface_->texture, 0); | 156 texture_target_, current_surface_->texture, 0); |
156 } | 157 } |
157 } | 158 } |
158 | 159 |
159 scoped_ptr<BufferQueue::AllocatedSurface> BufferQueue::RecreateBuffer( | 160 std::unique_ptr<BufferQueue::AllocatedSurface> BufferQueue::RecreateBuffer( |
160 scoped_ptr<AllocatedSurface> surface) { | 161 std::unique_ptr<AllocatedSurface> surface) { |
161 if (!surface) | 162 if (!surface) |
162 return nullptr; | 163 return nullptr; |
163 | 164 |
164 scoped_ptr<AllocatedSurface> new_surface(GetNextSurface()); | 165 std::unique_ptr<AllocatedSurface> new_surface(GetNextSurface()); |
165 if (!new_surface) | 166 if (!new_surface) |
166 return nullptr; | 167 return nullptr; |
167 | 168 |
168 new_surface->damage = surface->damage; | 169 new_surface->damage = surface->damage; |
169 | 170 |
170 // Copy the entire texture. | 171 // Copy the entire texture. |
171 CopyBufferDamage(new_surface->texture, surface->texture, gfx::Rect(), | 172 CopyBufferDamage(new_surface->texture, surface->texture, gfx::Rect(), |
172 gfx::Rect(size_)); | 173 gfx::Rect(size_)); |
173 return new_surface; | 174 return new_surface; |
174 } | 175 } |
(...skipping 22 matching lines...) Expand all Loading... |
197 | 198 |
198 gpu::gles2::GLES2Interface* gl = context_provider_->ContextGL(); | 199 gpu::gles2::GLES2Interface* gl = context_provider_->ContextGL(); |
199 gl->BindTexture(texture_target_, surface->texture); | 200 gl->BindTexture(texture_target_, surface->texture); |
200 gl->ReleaseTexImage2DCHROMIUM(texture_target_, surface->image); | 201 gl->ReleaseTexImage2DCHROMIUM(texture_target_, surface->image); |
201 gl->DeleteTextures(1, &surface->texture); | 202 gl->DeleteTextures(1, &surface->texture); |
202 gl->DestroyImageCHROMIUM(surface->image); | 203 gl->DestroyImageCHROMIUM(surface->image); |
203 surface->buffer.reset(); | 204 surface->buffer.reset(); |
204 allocated_count_--; | 205 allocated_count_--; |
205 } | 206 } |
206 | 207 |
207 scoped_ptr<BufferQueue::AllocatedSurface> BufferQueue::GetNextSurface() { | 208 std::unique_ptr<BufferQueue::AllocatedSurface> BufferQueue::GetNextSurface() { |
208 if (!available_surfaces_.empty()) { | 209 if (!available_surfaces_.empty()) { |
209 scoped_ptr<AllocatedSurface> surface = | 210 std::unique_ptr<AllocatedSurface> surface = |
210 std::move(available_surfaces_.back()); | 211 std::move(available_surfaces_.back()); |
211 available_surfaces_.pop_back(); | 212 available_surfaces_.pop_back(); |
212 return surface; | 213 return surface; |
213 } | 214 } |
214 | 215 |
215 unsigned int texture = 0; | 216 unsigned int texture = 0; |
216 gpu::gles2::GLES2Interface* gl = context_provider_->ContextGL(); | 217 gpu::gles2::GLES2Interface* gl = context_provider_->ContextGL(); |
217 gl->GenTextures(1, &texture); | 218 gl->GenTextures(1, &texture); |
218 if (!texture) | 219 if (!texture) |
219 return nullptr; | 220 return nullptr; |
220 | 221 |
221 // We don't want to allow anything more than triple buffering. | 222 // We don't want to allow anything more than triple buffering. |
222 DCHECK_LT(allocated_count_, 4U); | 223 DCHECK_LT(allocated_count_, 4U); |
223 | 224 |
224 scoped_ptr<gfx::GpuMemoryBuffer> buffer( | 225 std::unique_ptr<gfx::GpuMemoryBuffer> buffer( |
225 gpu_memory_buffer_manager_->AllocateGpuMemoryBuffer( | 226 gpu_memory_buffer_manager_->AllocateGpuMemoryBuffer( |
226 size_, gpu::DefaultBufferFormatForImageFormat(internal_format_), | 227 size_, gpu::DefaultBufferFormatForImageFormat(internal_format_), |
227 gfx::BufferUsage::SCANOUT, surface_id_)); | 228 gfx::BufferUsage::SCANOUT, surface_id_)); |
228 if (!buffer.get()) { | 229 if (!buffer.get()) { |
229 gl->DeleteTextures(1, &texture); | 230 gl->DeleteTextures(1, &texture); |
230 DLOG(ERROR) << "Failed to allocate GPU memory buffer"; | 231 DLOG(ERROR) << "Failed to allocate GPU memory buffer"; |
231 return nullptr; | 232 return nullptr; |
232 } | 233 } |
233 | 234 |
234 unsigned int id = gl->CreateImageCHROMIUM( | 235 unsigned int id = gl->CreateImageCHROMIUM( |
235 buffer->AsClientBuffer(), size_.width(), size_.height(), | 236 buffer->AsClientBuffer(), size_.width(), size_.height(), |
236 internal_format_); | 237 internal_format_); |
237 if (!id) { | 238 if (!id) { |
238 LOG(ERROR) << "Failed to allocate backing image surface"; | 239 LOG(ERROR) << "Failed to allocate backing image surface"; |
239 gl->DeleteTextures(1, &texture); | 240 gl->DeleteTextures(1, &texture); |
240 return nullptr; | 241 return nullptr; |
241 } | 242 } |
242 | 243 |
243 allocated_count_++; | 244 allocated_count_++; |
244 gl->BindTexture(texture_target_, texture); | 245 gl->BindTexture(texture_target_, texture); |
245 gl->BindTexImage2DCHROMIUM(texture_target_, id); | 246 gl->BindTexImage2DCHROMIUM(texture_target_, id); |
246 return make_scoped_ptr(new AllocatedSurface(this, std::move(buffer), texture, | 247 return base::WrapUnique(new AllocatedSurface(this, std::move(buffer), texture, |
247 id, gfx::Rect(size_))); | 248 id, gfx::Rect(size_))); |
248 } | 249 } |
249 | 250 |
250 BufferQueue::AllocatedSurface::AllocatedSurface( | 251 BufferQueue::AllocatedSurface::AllocatedSurface( |
251 BufferQueue* buffer_queue, | 252 BufferQueue* buffer_queue, |
252 scoped_ptr<gfx::GpuMemoryBuffer> buffer, | 253 std::unique_ptr<gfx::GpuMemoryBuffer> buffer, |
253 unsigned int texture, | 254 unsigned int texture, |
254 unsigned int image, | 255 unsigned int image, |
255 const gfx::Rect& rect) | 256 const gfx::Rect& rect) |
256 : buffer_queue(buffer_queue), | 257 : buffer_queue(buffer_queue), |
257 buffer(buffer.release()), | 258 buffer(buffer.release()), |
258 texture(texture), | 259 texture(texture), |
259 image(image), | 260 image(image), |
260 damage(rect) {} | 261 damage(rect) {} |
261 | 262 |
262 BufferQueue::AllocatedSurface::~AllocatedSurface() { | 263 BufferQueue::AllocatedSurface::~AllocatedSurface() { |
263 buffer_queue->FreeSurfaceResources(this); | 264 buffer_queue->FreeSurfaceResources(this); |
264 } | 265 } |
265 | 266 |
266 } // namespace content | 267 } // namespace content |
OLD | NEW |