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

Side by Side Diff: content/browser/compositor/buffer_queue.cc

Issue 516663003: Surfaceless OutputSurface implementation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix tests for new bind/init order Created 6 years, 3 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
(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/buffer_queue.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 BufferQueue::BufferQueue(scoped_refptr<cc::ContextProvider> context_provider,
14 unsigned int internalformat)
15 : context_provider_(context_provider),
16 fbo_(0),
17 allocated_count_(0),
18 internalformat_(internalformat) {
19 }
20
21 BufferQueue::~BufferQueue() {
22 FreeAllSurfaces();
23
24 gpu::gles2::GLES2Interface* gl = context_provider_->ContextGL();
25 if (fbo_)
26 gl->DeleteFramebuffers(1, &fbo_);
27 }
28
29 bool BufferQueue::Initialize() {
30 gpu::gles2::GLES2Interface* gl = context_provider_->ContextGL();
31 gl->GenFramebuffers(1, &fbo_);
32 return fbo_ != 0;
33 }
34
35 void BufferQueue::BindFramebuffer() {
36 gpu::gles2::GLES2Interface* gl = context_provider_->ContextGL();
37 gl->BindFramebuffer(GL_FRAMEBUFFER, fbo_);
38
39 if (!current_surface_.texture) {
40 current_surface_ = GetNextSurface();
41 gl->FramebufferTexture2D(GL_FRAMEBUFFER,
42 GL_COLOR_ATTACHMENT0,
43 GL_TEXTURE_2D,
44 current_surface_.texture,
45 0);
46 }
47 }
48
49 void BufferQueue::SwapBuffers() {
50 in_flight_surfaces_.push(current_surface_);
51 current_surface_.texture = 0;
52 current_surface_.image = 0;
53 }
54
55 void BufferQueue::Reshape(const gfx::Size& size, float scale_factor) {
56 DCHECK(!current_surface_.texture);
57 if (size == size_)
58 return;
59 size_ = size;
60
61 // TODO: add stencil buffer when needed.
62 gpu::gles2::GLES2Interface* gl = context_provider_->ContextGL();
63 gl->BindFramebuffer(GL_FRAMEBUFFER, fbo_);
64 gl->FramebufferTexture2D(
65 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0);
66
67 FreeAllSurfaces();
68 }
69
70 void BufferQueue::PageFlipComplete() {
71 if (in_flight_surfaces_.size() > 1) {
72 available_surfaces_.push_back(in_flight_surfaces_.front());
73 in_flight_surfaces_.pop();
74 }
75 }
76
77 void BufferQueue::FreeAllSurfaces() {
78 FreeSurface(&current_surface_);
79 while (!in_flight_surfaces_.empty()) {
80 FreeSurface(&in_flight_surfaces_.front());
81 in_flight_surfaces_.pop();
82 }
83 for (size_t i = 0; i < available_surfaces_.size(); i++)
84 FreeSurface(&available_surfaces_[i]);
85 available_surfaces_.clear();
86 }
87
88 void BufferQueue::FreeSurface(AllocatedSurface* surface) {
89 if (surface->texture) {
90 gpu::gles2::GLES2Interface* gl = context_provider_->ContextGL();
91 gl->BindTexture(GL_TEXTURE_2D, surface->texture);
92 gl->ReleaseTexImage2DCHROMIUM(GL_TEXTURE_2D, surface->image);
93 gl->DeleteTextures(1, &surface->texture);
94 gl->DestroyImageCHROMIUM(surface->image);
95 surface->image = 0;
96 surface->texture = 0;
97 allocated_count_--;
98 }
99 }
100
101 BufferQueue::AllocatedSurface BufferQueue::GetNextSurface() {
102 if (!available_surfaces_.empty()) {
103 AllocatedSurface id = available_surfaces_.back();
104 available_surfaces_.pop_back();
105 return id;
106 }
107
108 unsigned int texture = 0;
109 gpu::gles2::GLES2Interface* gl = context_provider_->ContextGL();
110 gl->GenTextures(1, &texture);
111 if (!texture)
112 return AllocatedSurface();
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 allocated_count_++;
123 gl->BindTexture(GL_TEXTURE_2D, texture);
124 gl->BindTexImage2DCHROMIUM(GL_TEXTURE_2D, id);
125 return AllocatedSurface(texture, id);
126 }
127
128 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/compositor/buffer_queue.h ('k') | content/browser/compositor/buffer_queue_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698