Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "content/browser/compositor/buffered_output_surface.h" | |
| 6 | |
| 7 #include "content/common/gpu/client/context_provider_command_buffer.h" | |
| 8 #include "gpu/GLES2/gl2extchromium.h" | |
| 9 #include "gpu/command_buffer/client/gles2_interface.h" | |
| 10 | |
| 11 namespace content { | |
| 12 | |
| 13 BufferedOutputSurface::BufferedOutputSurface( | |
| 14 scoped_refptr<cc::ContextProvider> context_provider, | |
| 15 unsigned int internalformat) | |
| 16 : context_provider_(context_provider), | |
| 17 fbo_(0), | |
| 18 allocated_count_(0), | |
| 19 internalformat_(internalformat) { | |
| 20 } | |
| 21 | |
| 22 BufferedOutputSurface::~BufferedOutputSurface() { | |
| 23 FreeAllSurfaces(); | |
| 24 | |
| 25 gpu::gles2::GLES2Interface* gl = context_provider_->ContextGL(); | |
| 26 if (fbo_) | |
| 27 gl->DeleteFramebuffers(1, &fbo_); | |
| 28 } | |
| 29 | |
| 30 bool BufferedOutputSurface::Initialize() { | |
| 31 gpu::gles2::GLES2Interface* gl = context_provider_->ContextGL(); | |
| 32 gl->GenFramebuffers(1, &fbo_); | |
| 33 return fbo_ != 0; | |
| 34 } | |
| 35 | |
| 36 void BufferedOutputSurface::BindFramebuffer() { | |
| 37 gpu::gles2::GLES2Interface* gl = context_provider_->ContextGL(); | |
| 38 gl->BindFramebuffer(GL_FRAMEBUFFER, fbo_); | |
| 39 | |
| 40 if (!current_surface_.texture) { | |
| 41 current_surface_ = GetNextSurface(); | |
| 42 gl->FramebufferTexture2D(GL_FRAMEBUFFER, | |
| 43 GL_COLOR_ATTACHMENT0, | |
| 44 GL_TEXTURE_2D, | |
| 45 current_surface_.texture, | |
| 46 0); | |
| 47 } | |
| 48 } | |
| 49 | |
| 50 void BufferedOutputSurface::SwapBuffers() { | |
| 51 in_flight_surfaces_.push(current_surface_); | |
| 52 current_surface_.texture = 0; | |
| 53 current_surface_.image = 0; | |
| 54 } | |
| 55 | |
| 56 void BufferedOutputSurface::Reshape(const gfx::Size& size, float scale_factor) { | |
| 57 DCHECK(!current_surface_.texture); | |
| 58 if (size == size_) | |
| 59 return; | |
| 60 size_ = size; | |
| 61 | |
| 62 // TODO: add stencil buffer when needed. | |
| 63 gpu::gles2::GLES2Interface* gl = context_provider_->ContextGL(); | |
| 64 gl->BindFramebuffer(GL_FRAMEBUFFER, fbo_); | |
| 65 gl->FramebufferTexture2D( | |
| 66 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0); | |
| 67 | |
| 68 FreeAllSurfaces(); | |
| 69 } | |
| 70 | |
| 71 void BufferedOutputSurface::PageFlipComplete() { | |
| 72 if (in_flight_surfaces_.size() > 1) { | |
| 73 available_surfaces_.push_back(in_flight_surfaces_.front()); | |
| 74 in_flight_surfaces_.pop(); | |
| 75 } | |
| 76 } | |
| 77 | |
| 78 void BufferedOutputSurface::FreeAllSurfaces() { | |
| 79 FreeSurface(¤t_surface_); | |
| 80 while (!in_flight_surfaces_.empty()) { | |
| 81 FreeSurface(&in_flight_surfaces_.front()); | |
| 82 in_flight_surfaces_.pop(); | |
| 83 } | |
| 84 for (size_t i = 0; i < available_surfaces_.size(); i++) | |
| 85 FreeSurface(&available_surfaces_[i]); | |
| 86 available_surfaces_.clear(); | |
| 87 } | |
| 88 | |
| 89 void BufferedOutputSurface::FreeSurface(AllocatedSurface* surface) { | |
| 90 if (surface->texture) { | |
| 91 gpu::gles2::GLES2Interface* gl = context_provider_->ContextGL(); | |
| 92 gl->BindTexture(GL_TEXTURE_2D, surface->texture); | |
| 93 gl->ReleaseTexImage2DCHROMIUM(GL_TEXTURE_2D, surface->image); | |
| 94 gl->DeleteTextures(1, &surface->texture); | |
| 95 gl->DestroyImageCHROMIUM(surface->image); | |
| 96 surface->image = 0; | |
| 97 surface->texture = 0; | |
| 98 allocated_count_--; | |
| 99 } | |
| 100 } | |
| 101 | |
| 102 BufferedOutputSurface::AllocatedSurface | |
| 103 BufferedOutputSurface::GetNextSurface() { | |
| 104 if (!available_surfaces_.empty()) { | |
| 105 AllocatedSurface id = available_surfaces_.back(); | |
| 106 available_surfaces_.pop_back(); | |
| 107 return id; | |
| 108 } | |
| 109 | |
| 110 unsigned int texture; | |
|
piman
2014/09/12 21:58:29
nit: =0
If the context is lost, GenTextures may n
achaulk
2014/09/15 16:31:43
Done.
| |
| 111 gpu::gles2::GLES2Interface* gl = context_provider_->ContextGL(); | |
| 112 gl->GenTextures(1, &texture); | |
| 113 | |
| 114 // We don't want to allow anything more than triple buffering. | |
| 115 DCHECK_LT(allocated_count_, 4U); | |
| 116 | |
| 117 unsigned int id = context_provider_->ContextGL()->CreateImageCHROMIUM( | |
| 118 size_.width(), | |
| 119 size_.height(), | |
| 120 internalformat_, | |
| 121 GL_IMAGE_SCANOUT_CHROMIUM); | |
| 122 DCHECK(id); | |
|
piman
2014/09/12 21:58:30
nit: if the context is lost, id will be 0.
achaulk
2014/09/15 16:31:42
Done.
piman
2014/09/15 18:29:58
I still see the DCHECK in the new code.
Is the DC
achaulk
2014/09/15 18:41:24
Yeah, forgot to save the file after removing that
| |
| 123 allocated_count_++; | |
| 124 gl->BindTexture(GL_TEXTURE_2D, texture); | |
| 125 gl->BindTexImage2DCHROMIUM(GL_TEXTURE_2D, id); | |
| 126 return AllocatedSurface(texture, id); | |
| 127 } | |
| 128 | |
| 129 } // namespace content | |
| OLD | NEW |