| 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 "cc/resources/resource_provider.h" | 11 #include "cc/resources/resource_provider.h" |
| 12 #include "content/renderer/gpu/frame_swap_message_queue.h" | 12 #include "content/renderer/gpu/frame_swap_message_queue.h" |
| 13 #include "gpu/command_buffer/client/gles2_interface.h" | 13 #include "gpu/command_buffer/client/gles2_interface.h" |
| 14 #include "third_party/khronos/GLES2/gl2.h" | 14 #include "third_party/khronos/GLES2/gl2.h" |
| 15 #include "third_party/khronos/GLES2/gl2ext.h" | 15 #include "third_party/khronos/GLES2/gl2ext.h" |
| 16 | 16 |
| 17 using cc::CompositorFrame; | 17 using cc::CompositorFrame; |
| 18 using cc::GLFrameData; | 18 using cc::GLFrameData; |
| 19 using cc::ResourceProvider; | 19 using cc::ResourceProvider; |
| 20 using gpu::Mailbox; | 20 using gpu::Mailbox; |
| 21 using gpu::gles2::GLES2Interface; | 21 using gpu::gles2::GLES2Interface; |
| 22 | 22 |
| 23 namespace content { | 23 namespace content { |
| 24 | 24 |
| 25 MailboxOutputSurface::MailboxOutputSurface( | 25 MailboxOutputSurface::MailboxOutputSurface( |
| 26 int32 routing_id, | 26 int32_t routing_id, |
| 27 uint32 output_surface_id, | 27 uint32_t output_surface_id, |
| 28 const scoped_refptr<ContextProviderCommandBuffer>& context_provider, | 28 const scoped_refptr<ContextProviderCommandBuffer>& context_provider, |
| 29 const scoped_refptr<ContextProviderCommandBuffer>& worker_context_provider, | 29 const scoped_refptr<ContextProviderCommandBuffer>& worker_context_provider, |
| 30 scoped_refptr<FrameSwapMessageQueue> swap_frame_message_queue, | 30 scoped_refptr<FrameSwapMessageQueue> swap_frame_message_queue, |
| 31 cc::ResourceFormat format) | 31 cc::ResourceFormat format) |
| 32 : CompositorOutputSurface(routing_id, | 32 : CompositorOutputSurface(routing_id, |
| 33 output_surface_id, | 33 output_surface_id, |
| 34 context_provider, | 34 context_provider, |
| 35 worker_context_provider, | 35 worker_context_provider, |
| 36 nullptr, | 36 nullptr, |
| 37 swap_frame_message_queue, | 37 swap_frame_message_queue, |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 if (!fbo_) | 145 if (!fbo_) |
| 146 gl->GenFramebuffers(1, &fbo_); | 146 gl->GenFramebuffers(1, &fbo_); |
| 147 gl->BindFramebuffer(GL_FRAMEBUFFER, fbo_); | 147 gl->BindFramebuffer(GL_FRAMEBUFFER, fbo_); |
| 148 gl->FramebufferTexture2D(GL_FRAMEBUFFER, | 148 gl->FramebufferTexture2D(GL_FRAMEBUFFER, |
| 149 GL_COLOR_ATTACHMENT0, | 149 GL_COLOR_ATTACHMENT0, |
| 150 GL_TEXTURE_2D, | 150 GL_TEXTURE_2D, |
| 151 current_backing_.texture_id, | 151 current_backing_.texture_id, |
| 152 0); | 152 0); |
| 153 } | 153 } |
| 154 | 154 |
| 155 void MailboxOutputSurface::OnSwapAck(uint32 output_surface_id, | 155 void MailboxOutputSurface::OnSwapAck(uint32_t output_surface_id, |
| 156 const cc::CompositorFrameAck& ack) { | 156 const cc::CompositorFrameAck& ack) { |
| 157 // Ignore message if it's a stale one coming from a different output surface | 157 // Ignore message if it's a stale one coming from a different output surface |
| 158 // (e.g. after a lost context). | 158 // (e.g. after a lost context). |
| 159 if (output_surface_id != output_surface_id_) { | 159 if (output_surface_id != output_surface_id_) { |
| 160 CompositorOutputSurface::OnSwapAck(output_surface_id, ack); | 160 CompositorOutputSurface::OnSwapAck(output_surface_id, ack); |
| 161 return; | 161 return; |
| 162 } | 162 } |
| 163 if (!ack.gl_frame_data->mailbox.IsZero()) { | 163 if (!ack.gl_frame_data->mailbox.IsZero()) { |
| 164 DCHECK(!ack.gl_frame_data->size.IsEmpty()); | 164 DCHECK(!ack.gl_frame_data->size.IsEmpty()); |
| 165 // The browser could be returning the oldest or any other pending texture | 165 // The browser could be returning the oldest or any other pending texture |
| (...skipping 16 matching lines...) Expand all Loading... |
| 182 } else { | 182 } else { |
| 183 context_provider_->ContextGL()->DeleteTextures(1, &it->texture_id); | 183 context_provider_->ContextGL()->DeleteTextures(1, &it->texture_id); |
| 184 } | 184 } |
| 185 | 185 |
| 186 pending_textures_.erase(it); | 186 pending_textures_.erase(it); |
| 187 } else { | 187 } else { |
| 188 DCHECK(!pending_textures_.empty()); | 188 DCHECK(!pending_textures_.empty()); |
| 189 // The browser always keeps one texture as the frontbuffer. | 189 // The browser always keeps one texture as the frontbuffer. |
| 190 // If it does not return a mailbox, it discarded the frontbuffer which is | 190 // If it does not return a mailbox, it discarded the frontbuffer which is |
| 191 // the oldest texture we sent. | 191 // the oldest texture we sent. |
| 192 uint32 texture_id = pending_textures_.front().texture_id; | 192 uint32_t texture_id = pending_textures_.front().texture_id; |
| 193 if (texture_id) | 193 if (texture_id) |
| 194 context_provider_->ContextGL()->DeleteTextures(1, &texture_id); | 194 context_provider_->ContextGL()->DeleteTextures(1, &texture_id); |
| 195 pending_textures_.pop_front(); | 195 pending_textures_.pop_front(); |
| 196 } | 196 } |
| 197 CompositorOutputSurface::OnSwapAck(output_surface_id, ack); | 197 CompositorOutputSurface::OnSwapAck(output_surface_id, ack); |
| 198 } | 198 } |
| 199 | 199 |
| 200 void MailboxOutputSurface::SwapBuffers(cc::CompositorFrame* frame) { | 200 void MailboxOutputSurface::SwapBuffers(cc::CompositorFrame* frame) { |
| 201 DCHECK(frame->gl_frame_data); | 201 DCHECK(frame->gl_frame_data); |
| 202 DCHECK(!surface_size_.IsEmpty()); | 202 DCHECK(!surface_size_.IsEmpty()); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 217 } | 217 } |
| 218 | 218 |
| 219 size_t MailboxOutputSurface::GetNumAcksPending() { | 219 size_t MailboxOutputSurface::GetNumAcksPending() { |
| 220 DCHECK(pending_textures_.size()); | 220 DCHECK(pending_textures_.size()); |
| 221 return pending_textures_.size() - 1; | 221 return pending_textures_.size() - 1; |
| 222 } | 222 } |
| 223 | 223 |
| 224 MailboxOutputSurface::TransferableFrame::TransferableFrame() : texture_id(0) {} | 224 MailboxOutputSurface::TransferableFrame::TransferableFrame() : texture_id(0) {} |
| 225 | 225 |
| 226 MailboxOutputSurface::TransferableFrame::TransferableFrame( | 226 MailboxOutputSurface::TransferableFrame::TransferableFrame( |
| 227 uint32 texture_id, | 227 uint32_t texture_id, |
| 228 const gpu::Mailbox& mailbox, | 228 const gpu::Mailbox& mailbox, |
| 229 const gfx::Size size) | 229 const gfx::Size size) |
| 230 : texture_id(texture_id), mailbox(mailbox), size(size) {} | 230 : texture_id(texture_id), mailbox(mailbox), size(size) {} |
| 231 | 231 |
| 232 } // namespace content | 232 } // namespace content |
| OLD | NEW |