| OLD | NEW |
| 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 WebGraphicsContext3DCommandBufferImpl* context3D, | 23 WebGraphicsContext3DCommandBufferImpl* context3D, |
| 24 cc::SoftwareOutputDevice* software_device) | 24 cc::SoftwareOutputDevice* software_device) |
| 25 : CompositorOutputSurface(routing_id, context3D, software_device), | 25 : CompositorOutputSurface(routing_id, context3D, software_device, true), |
| 26 fbo_(0), | 26 fbo_(0), |
| 27 is_backbuffer_discarded_(false) { | 27 is_backbuffer_discarded_(false) { |
| 28 pending_textures_.push_back(TransferableFrame()); | 28 pending_textures_.push_back(TransferableFrame()); |
| 29 capabilities_.max_frames_pending = 1; | 29 capabilities_.max_frames_pending = 1; |
| 30 } | 30 } |
| 31 | 31 |
| 32 MailboxOutputSurface::~MailboxOutputSurface() { | 32 MailboxOutputSurface::~MailboxOutputSurface() { |
| 33 DiscardBackbuffer(); | 33 DiscardBackbuffer(); |
| 34 while (!pending_textures_.empty()) { | 34 while (!pending_textures_.empty()) { |
| 35 if (pending_textures_.front().texture_id) | 35 if (pending_textures_.front().texture_id) |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 DCHECK(current_backing_.texture_id); | 116 DCHECK(current_backing_.texture_id); |
| 117 | 117 |
| 118 if (!fbo_) | 118 if (!fbo_) |
| 119 fbo_ = context3d_->createFramebuffer(); | 119 fbo_ = context3d_->createFramebuffer(); |
| 120 context3d_->bindFramebuffer(GL_FRAMEBUFFER, fbo_); | 120 context3d_->bindFramebuffer(GL_FRAMEBUFFER, fbo_); |
| 121 context3d_->framebufferTexture2D( | 121 context3d_->framebufferTexture2D( |
| 122 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, | 122 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, |
| 123 current_backing_.texture_id, 0); | 123 current_backing_.texture_id, 0); |
| 124 } | 124 } |
| 125 | 125 |
| 126 void MailboxOutputSurface::SendFrameToParentCompositor( | |
| 127 cc::CompositorFrame* frame) { | |
| 128 frame->gl_frame_data.reset(new GLFrameData()); | |
| 129 | |
| 130 DCHECK(!surface_size_.IsEmpty()); | |
| 131 DCHECK(surface_size_ == current_backing_.size); | |
| 132 DCHECK(!current_backing_.mailbox.IsZero()); | |
| 133 | |
| 134 frame->gl_frame_data->mailbox = current_backing_.mailbox; | |
| 135 frame->gl_frame_data->size = current_backing_.size; | |
| 136 context3d_->flush(); | |
| 137 frame->gl_frame_data->sync_point = context3d_->insertSyncPoint(); | |
| 138 CompositorOutputSurface::SendFrameToParentCompositor(frame); | |
| 139 | |
| 140 pending_textures_.push_back(current_backing_); | |
| 141 current_backing_ = TransferableFrame(); | |
| 142 } | |
| 143 | |
| 144 void MailboxOutputSurface::OnSwapAck(const cc::CompositorFrameAck& ack) { | 126 void MailboxOutputSurface::OnSwapAck(const cc::CompositorFrameAck& ack) { |
| 145 if (!ack.gl_frame_data->mailbox.IsZero()) { | 127 if (!ack.gl_frame_data->mailbox.IsZero()) { |
| 146 DCHECK(!ack.gl_frame_data->size.IsEmpty()); | 128 DCHECK(!ack.gl_frame_data->size.IsEmpty()); |
| 147 // The browser could be returning the oldest or any other pending texture | 129 // The browser could be returning the oldest or any other pending texture |
| 148 // if it decided to skip a frame. | 130 // if it decided to skip a frame. |
| 149 std::deque<TransferableFrame>::iterator it; | 131 std::deque<TransferableFrame>::iterator it; |
| 150 for (it = pending_textures_.begin(); it != pending_textures_.end(); it++) { | 132 for (it = pending_textures_.begin(); it != pending_textures_.end(); it++) { |
| 151 DCHECK(!it->mailbox.IsZero()); | 133 DCHECK(!it->mailbox.IsZero()); |
| 152 if (!memcmp(it->mailbox.name, | 134 if (!memcmp(it->mailbox.name, |
| 153 ack.gl_frame_data->mailbox.name, | 135 ack.gl_frame_data->mailbox.name, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 172 // If it does not return a mailbox, it discarded the frontbuffer which is | 154 // If it does not return a mailbox, it discarded the frontbuffer which is |
| 173 // the oldest texture we sent. | 155 // the oldest texture we sent. |
| 174 uint32 texture_id = pending_textures_.front().texture_id; | 156 uint32 texture_id = pending_textures_.front().texture_id; |
| 175 if (texture_id) | 157 if (texture_id) |
| 176 context3d_->deleteTexture(texture_id); | 158 context3d_->deleteTexture(texture_id); |
| 177 pending_textures_.pop_front(); | 159 pending_textures_.pop_front(); |
| 178 } | 160 } |
| 179 CompositorOutputSurface::OnSwapAck(ack); | 161 CompositorOutputSurface::OnSwapAck(ack); |
| 180 } | 162 } |
| 181 | 163 |
| 182 void MailboxOutputSurface::SwapBuffers(const ui::LatencyInfo&) { | 164 void MailboxOutputSurface::SwapBuffers(cc::CompositorFrame* frame) { |
| 183 } | 165 DCHECK(frame->gl_frame_data); |
| 184 | 166 DCHECK(frame->gl_frame_data->sub_buffer_rect.size() == |
| 185 void MailboxOutputSurface::PostSubBuffer(gfx::Rect rect, | 167 frame->gl_frame_data->size) |
| 186 const ui::LatencyInfo&) { | |
| 187 NOTIMPLEMENTED() | |
| 188 << "Partial swap not supported with composite-to-mailbox yet."; | 168 << "Partial swap not supported with composite-to-mailbox yet."; |
| 189 | 169 |
| 190 // The browser only copies damage correctly for two buffers in use. | 170 DCHECK(!surface_size_.IsEmpty()); |
| 191 DCHECK(GetNumAcksPending() < 2); | 171 DCHECK(surface_size_ == current_backing_.size); |
| 172 DCHECK(frame->gl_frame_data->size == current_backing_.size); |
| 173 DCHECK(!current_backing_.mailbox.IsZero()); |
| 174 |
| 175 frame->gl_frame_data->mailbox = current_backing_.mailbox; |
| 176 context3d_->flush(); |
| 177 frame->gl_frame_data->sync_point = context3d_->insertSyncPoint(); |
| 178 CompositorOutputSurface::SwapBuffers(frame); |
| 179 |
| 180 pending_textures_.push_back(current_backing_); |
| 181 current_backing_ = TransferableFrame(); |
| 192 } | 182 } |
| 193 | 183 |
| 194 size_t MailboxOutputSurface::GetNumAcksPending() { | 184 size_t MailboxOutputSurface::GetNumAcksPending() { |
| 195 DCHECK(pending_textures_.size()); | 185 DCHECK(pending_textures_.size()); |
| 196 return pending_textures_.size() - 1; | 186 return pending_textures_.size() - 1; |
| 197 } | 187 } |
| 198 | 188 |
| 199 } // namespace content | 189 } // namespace content |
| OLD | NEW |