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

Side by Side Diff: content/renderer/gpu/mailbox_output_surface.cc

Issue 19331002: Associate an id with the output surface to handle lost contexts (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix android, tests Created 7 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « content/renderer/gpu/mailbox_output_surface.h ('k') | content/renderer/render_widget.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/renderer/gpu/mailbox_output_surface.h" 5 #include "content/renderer/gpu/mailbox_output_surface.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "cc/output/compositor_frame.h" 8 #include "cc/output/compositor_frame.h"
9 #include "cc/output/compositor_frame_ack.h" 9 #include "cc/output/compositor_frame_ack.h"
10 #include "cc/output/gl_frame_data.h" 10 #include "cc/output/gl_frame_data.h"
11 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h" 11 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h"
12 #include "third_party/khronos/GLES2/gl2.h" 12 #include "third_party/khronos/GLES2/gl2.h"
13 #include "third_party/khronos/GLES2/gl2ext.h" 13 #include "third_party/khronos/GLES2/gl2ext.h"
14 14
15 using cc::CompositorFrame; 15 using cc::CompositorFrame;
16 using cc::GLFrameData; 16 using cc::GLFrameData;
17 using gpu::Mailbox; 17 using gpu::Mailbox;
18 18
19 namespace content { 19 namespace content {
20 20
21 MailboxOutputSurface::MailboxOutputSurface( 21 MailboxOutputSurface::MailboxOutputSurface(
22 int32 routing_id, 22 int32 routing_id,
23 uint32 output_surface_id,
23 WebGraphicsContext3DCommandBufferImpl* context3D, 24 WebGraphicsContext3DCommandBufferImpl* context3D,
24 cc::SoftwareOutputDevice* software_device) 25 cc::SoftwareOutputDevice* software_device)
25 : CompositorOutputSurface(routing_id, context3D, software_device, true), 26 : CompositorOutputSurface(routing_id,
27 output_surface_id,
28 context3D,
29 software_device,
30 true),
26 fbo_(0), 31 fbo_(0),
27 is_backbuffer_discarded_(false) { 32 is_backbuffer_discarded_(false) {
28 pending_textures_.push_back(TransferableFrame()); 33 pending_textures_.push_back(TransferableFrame());
29 capabilities_.max_frames_pending = 1; 34 capabilities_.max_frames_pending = 1;
30 } 35 }
31 36
32 MailboxOutputSurface::~MailboxOutputSurface() { 37 MailboxOutputSurface::~MailboxOutputSurface() {
33 DiscardBackbuffer(); 38 DiscardBackbuffer();
34 while (!pending_textures_.empty()) { 39 while (!pending_textures_.empty()) {
35 if (pending_textures_.front().texture_id) 40 if (pending_textures_.front().texture_id)
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 DCHECK(current_backing_.texture_id); 121 DCHECK(current_backing_.texture_id);
117 122
118 if (!fbo_) 123 if (!fbo_)
119 fbo_ = context3d_->createFramebuffer(); 124 fbo_ = context3d_->createFramebuffer();
120 context3d_->bindFramebuffer(GL_FRAMEBUFFER, fbo_); 125 context3d_->bindFramebuffer(GL_FRAMEBUFFER, fbo_);
121 context3d_->framebufferTexture2D( 126 context3d_->framebufferTexture2D(
122 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 127 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
123 current_backing_.texture_id, 0); 128 current_backing_.texture_id, 0);
124 } 129 }
125 130
126 void MailboxOutputSurface::OnSwapAck(const cc::CompositorFrameAck& ack) { 131 void MailboxOutputSurface::OnSwapAck(uint32 output_surface_id,
132 const cc::CompositorFrameAck& ack) {
133 // Ignore message if it's a stale one coming from a different output surface
134 // (e.g. after a lost context).
135 if (output_surface_id != output_surface_id_) {
136 CompositorOutputSurface::OnSwapAck(output_surface_id, ack);
137 return;
138 }
127 if (!ack.gl_frame_data->mailbox.IsZero()) { 139 if (!ack.gl_frame_data->mailbox.IsZero()) {
128 DCHECK(!ack.gl_frame_data->size.IsEmpty()); 140 DCHECK(!ack.gl_frame_data->size.IsEmpty());
129 // The browser could be returning the oldest or any other pending texture 141 // The browser could be returning the oldest or any other pending texture
130 // if it decided to skip a frame. 142 // if it decided to skip a frame.
131 std::deque<TransferableFrame>::iterator it; 143 std::deque<TransferableFrame>::iterator it;
132 for (it = pending_textures_.begin(); it != pending_textures_.end(); it++) { 144 for (it = pending_textures_.begin(); it != pending_textures_.end(); it++) {
133 DCHECK(!it->mailbox.IsZero()); 145 DCHECK(!it->mailbox.IsZero());
134 if (!memcmp(it->mailbox.name, 146 if (!memcmp(it->mailbox.name,
135 ack.gl_frame_data->mailbox.name, 147 ack.gl_frame_data->mailbox.name,
136 sizeof(it->mailbox.name))) { 148 sizeof(it->mailbox.name))) {
(...skipping 14 matching lines...) Expand all
151 } else { 163 } else {
152 DCHECK(!pending_textures_.empty()); 164 DCHECK(!pending_textures_.empty());
153 // The browser always keeps one texture as the frontbuffer. 165 // The browser always keeps one texture as the frontbuffer.
154 // If it does not return a mailbox, it discarded the frontbuffer which is 166 // If it does not return a mailbox, it discarded the frontbuffer which is
155 // the oldest texture we sent. 167 // the oldest texture we sent.
156 uint32 texture_id = pending_textures_.front().texture_id; 168 uint32 texture_id = pending_textures_.front().texture_id;
157 if (texture_id) 169 if (texture_id)
158 context3d_->deleteTexture(texture_id); 170 context3d_->deleteTexture(texture_id);
159 pending_textures_.pop_front(); 171 pending_textures_.pop_front();
160 } 172 }
161 CompositorOutputSurface::OnSwapAck(ack); 173 CompositorOutputSurface::OnSwapAck(output_surface_id, ack);
162 } 174 }
163 175
164 void MailboxOutputSurface::SwapBuffers(cc::CompositorFrame* frame) { 176 void MailboxOutputSurface::SwapBuffers(cc::CompositorFrame* frame) {
165 DCHECK(frame->gl_frame_data); 177 DCHECK(frame->gl_frame_data);
166 DCHECK(!surface_size_.IsEmpty()); 178 DCHECK(!surface_size_.IsEmpty());
167 DCHECK(surface_size_ == current_backing_.size); 179 DCHECK(surface_size_ == current_backing_.size);
168 DCHECK(frame->gl_frame_data->size == current_backing_.size); 180 DCHECK(frame->gl_frame_data->size == current_backing_.size);
169 DCHECK(!current_backing_.mailbox.IsZero()); 181 DCHECK(!current_backing_.mailbox.IsZero());
170 182
171 frame->gl_frame_data->mailbox = current_backing_.mailbox; 183 frame->gl_frame_data->mailbox = current_backing_.mailbox;
172 context3d_->flush(); 184 context3d_->flush();
173 frame->gl_frame_data->sync_point = context3d_->insertSyncPoint(); 185 frame->gl_frame_data->sync_point = context3d_->insertSyncPoint();
174 CompositorOutputSurface::SwapBuffers(frame); 186 CompositorOutputSurface::SwapBuffers(frame);
175 187
176 pending_textures_.push_back(current_backing_); 188 pending_textures_.push_back(current_backing_);
177 current_backing_ = TransferableFrame(); 189 current_backing_ = TransferableFrame();
178 } 190 }
179 191
180 size_t MailboxOutputSurface::GetNumAcksPending() { 192 size_t MailboxOutputSurface::GetNumAcksPending() {
181 DCHECK(pending_textures_.size()); 193 DCHECK(pending_textures_.size());
182 return pending_textures_.size() - 1; 194 return pending_textures_.size() - 1;
183 } 195 }
184 196
185 } // namespace content 197 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/gpu/mailbox_output_surface.h ('k') | content/renderer/render_widget.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698