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 depth_rb_(0), | |
| 19 allocated_count_(0), | |
| 20 internalformat_(internalformat) { | |
| 21 Initialize(); | |
| 22 } | |
| 23 | |
| 24 BufferedOutputSurface::~BufferedOutputSurface() { | |
| 25 FreeAllSurfaces(); | |
| 26 | |
| 27 gpu::gles2::GLES2Interface* gl = context_provider_->ContextGL(); | |
| 28 if (fbo_) | |
| 29 gl->DeleteFramebuffers(1, &fbo_); | |
| 30 if (depth_rb_) | |
| 31 gl->DeleteRenderbuffers(1, &depth_rb_); | |
|
piman
2014/09/11 20:25:29
We don't need a depth buffer for the compositor.
achaulk
2014/09/12 19:51:07
Done.
| |
| 32 } | |
| 33 | |
| 34 void BufferedOutputSurface::Initialize() { | |
| 35 gpu::gles2::GLES2Interface* gl = context_provider_->ContextGL(); | |
| 36 gl->GenFramebuffers(1, &fbo_); | |
| 37 gl->GenRenderbuffers(1, &depth_rb_); | |
| 38 DCHECK(fbo_); | |
| 39 DCHECK(depth_rb_); | |
|
piman
2014/09/11 20:25:28
Both these DCHECKs can fail in case of a lost cont
achaulk
2014/09/12 19:51:08
Done.
| |
| 40 } | |
| 41 | |
| 42 void BufferedOutputSurface::BindFramebuffer() { | |
| 43 gpu::gles2::GLES2Interface* gl = context_provider_->ContextGL(); | |
| 44 gl->BindFramebuffer(GL_FRAMEBUFFER, fbo_); | |
| 45 | |
| 46 if (!current_surface_.first) { | |
| 47 current_surface_ = GetNextSurface(); | |
| 48 gl->FramebufferTexture2D(GL_FRAMEBUFFER, | |
| 49 GL_COLOR_ATTACHMENT0, | |
| 50 GL_TEXTURE_2D, | |
| 51 current_surface_.second, | |
|
piman
2014/09/11 20:25:28
I'm confused. In BufferedOutputSurface::GetNextSur
achaulk
2014/09/12 19:51:08
Oh yes this should be first instead
| |
| 52 0); | |
| 53 } | |
| 54 } | |
| 55 | |
| 56 void BufferedOutputSurface::SwapBuffers() { | |
| 57 if (last_surface_.first) | |
| 58 in_flight_surfaces_.push(last_surface_); | |
|
piman
2014/09/11 20:25:28
in_flight_surfaces_ is confusing. It contains all
achaulk
2014/09/12 19:51:08
I don't really like having a dummy surface, but I
| |
| 59 last_surface_ = current_surface_; | |
| 60 current_surface_.first = 0; | |
| 61 current_surface_.second = 0; | |
| 62 } | |
| 63 | |
| 64 void BufferedOutputSurface::Reshape(const gfx::Size& size, float scale_factor) { | |
| 65 if (size == size_) | |
| 66 return; | |
| 67 size_ = size; | |
| 68 FreeAllSurfaces(); | |
|
piman
2014/09/11 20:25:28
Is it really ok to delete the surface that is curr
achaulk
2014/09/12 19:51:07
Yes. Only the GL-side structures will get torn dow
| |
| 69 | |
|
piman
2014/09/11 20:25:28
Can you add a DCHECK that current_surface_ is empt
achaulk
2014/09/12 19:51:08
Done.
| |
| 70 if (size_.width() == 0 || size_.height() == 0) | |
| 71 return; // Nothing to do. | |
|
piman
2014/09/11 20:25:29
You probably want to at least unbind the current a
achaulk
2014/09/12 19:51:08
Done.
| |
| 72 gpu::gles2::GLES2Interface* gl = context_provider_->ContextGL(); | |
| 73 gl->BindFramebuffer(GL_FRAMEBUFFER, fbo_); | |
| 74 gl->BindRenderbuffer(GL_RENDERBUFFER, depth_rb_); | |
| 75 gl->RenderbufferStorage( | |
| 76 GL_RENDERBUFFER, GL_DEPTH_COMPONENT24_OES, size_.width(), size_.height()); | |
| 77 gl->FramebufferRenderbuffer( | |
| 78 GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depth_rb_); | |
| 79 } | |
| 80 | |
| 81 void BufferedOutputSurface::PageFlipComplete() { | |
| 82 if (!in_flight_surfaces_.empty()) { | |
| 83 available_surfaces_.push_back(in_flight_surfaces_.front()); | |
| 84 in_flight_surfaces_.pop(); | |
| 85 } | |
| 86 } | |
| 87 | |
| 88 void BufferedOutputSurface::FreeAllSurfaces() { | |
| 89 FreeSurface(&last_surface_); | |
| 90 FreeSurface(¤t_surface_); | |
| 91 while (!in_flight_surfaces_.empty()) { | |
| 92 FreeSurface(&in_flight_surfaces_.front()); | |
| 93 in_flight_surfaces_.pop(); | |
| 94 } | |
| 95 for (size_t i = 0; i < available_surfaces_.size(); i++) | |
| 96 FreeSurface(&available_surfaces_[i]); | |
| 97 available_surfaces_.clear(); | |
| 98 } | |
| 99 | |
| 100 void BufferedOutputSurface::FreeSurface(AllocatedSurface* surface) { | |
| 101 if (surface->first) { | |
| 102 gpu::gles2::GLES2Interface* gl = context_provider_->ContextGL(); | |
| 103 gl->BindTexture(GL_TEXTURE_2D, surface->first); | |
| 104 gl->ReleaseTexImage2DCHROMIUM(GL_TEXTURE_2D, surface->second); | |
| 105 gl->DeleteTextures(1, &surface->first); | |
| 106 gl->DestroyImageCHROMIUM(surface->second); | |
| 107 surface->first = 0; | |
| 108 surface->second = 0; | |
| 109 allocated_count_--; | |
| 110 } | |
| 111 } | |
| 112 | |
| 113 BufferedOutputSurface::AllocatedSurface | |
| 114 BufferedOutputSurface::GetNextSurface() { | |
| 115 if (!available_surfaces_.empty()) { | |
| 116 AllocatedSurface id = available_surfaces_.back(); | |
| 117 available_surfaces_.pop_back(); | |
| 118 return id; | |
| 119 } | |
| 120 | |
| 121 unsigned int tex; | |
|
piman
2014/09/11 20:25:28
nit: texture
achaulk
2014/09/12 19:51:08
Done.
| |
| 122 gpu::gles2::GLES2Interface* gl = context_provider_->ContextGL(); | |
| 123 gl->GenTextures(1, &tex); | |
| 124 | |
| 125 // We don't want to allow anything more than triple buffering. | |
| 126 DCHECK_LT(allocated_count_, 4U); | |
| 127 | |
| 128 unsigned int id = context_provider_->ContextGL()->CreateImageCHROMIUM( | |
| 129 size_.width(), | |
| 130 size_.height(), | |
| 131 internalformat_, | |
| 132 GL_IMAGE_SCANOUT_CHROMIUM); | |
| 133 DCHECK(id); | |
| 134 allocated_count_++; | |
| 135 gl->BindTexture(GL_TEXTURE_2D, tex); | |
| 136 gl->BindTexImage2DCHROMIUM(GL_TEXTURE_2D, id); | |
| 137 return AllocatedSurface(tex, id); | |
| 138 } | |
| 139 | |
| 140 } // namespace content | |
| OLD | NEW |