| 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" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 } | 38 } |
| 39 } | 39 } |
| 40 | 40 |
| 41 void MailboxOutputSurface::EnsureBackbuffer() { | 41 void MailboxOutputSurface::EnsureBackbuffer() { |
| 42 is_backbuffer_discarded_ = false; | 42 is_backbuffer_discarded_ = false; |
| 43 | 43 |
| 44 if (!current_backing_.texture_id) { | 44 if (!current_backing_.texture_id) { |
| 45 // Find a texture of matching size to recycle. | 45 // Find a texture of matching size to recycle. |
| 46 while (!returned_textures_.empty()) { | 46 while (!returned_textures_.empty()) { |
| 47 TransferableFrame& texture = returned_textures_.front(); | 47 TransferableFrame& texture = returned_textures_.front(); |
| 48 if (texture.size == size_) { | 48 if (texture.size == surface_size_) { |
| 49 current_backing_ = texture; | 49 current_backing_ = texture; |
| 50 ConsumeTexture(texture); | 50 ConsumeTexture(texture); |
| 51 returned_textures_.pop(); | 51 returned_textures_.pop(); |
| 52 break; | 52 break; |
| 53 } | 53 } |
| 54 | 54 |
| 55 ConsumeTexture(texture); | 55 ConsumeTexture(texture); |
| 56 context3d_->deleteTexture(texture.texture_id); | 56 context3d_->deleteTexture(texture.texture_id); |
| 57 returned_textures_.pop(); | 57 returned_textures_.pop(); |
| 58 } | 58 } |
| 59 | 59 |
| 60 if (!current_backing_.texture_id) { | 60 if (!current_backing_.texture_id) { |
| 61 current_backing_.texture_id = context3d_->createTexture(); | 61 current_backing_.texture_id = context3d_->createTexture(); |
| 62 current_backing_.size = size_; | 62 current_backing_.size = surface_size_; |
| 63 context3d_->genMailboxCHROMIUM(current_backing_.mailbox.name); | 63 context3d_->genMailboxCHROMIUM(current_backing_.mailbox.name); |
| 64 context3d_->bindTexture(GL_TEXTURE_2D, current_backing_.texture_id); | 64 context3d_->bindTexture(GL_TEXTURE_2D, current_backing_.texture_id); |
| 65 context3d_->texParameteri( | 65 context3d_->texParameteri( |
| 66 GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | 66 GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 67 context3d_->texParameteri( | 67 context3d_->texParameteri( |
| 68 GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | 68 GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 69 context3d_->texParameteri( | 69 context3d_->texParameteri( |
| 70 GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 70 GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 71 context3d_->texParameteri( | 71 context3d_->texParameteri( |
| 72 GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 72 GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 73 context3d_->texImage2D( | 73 context3d_->texImage2D( |
| 74 GL_TEXTURE_2D, 0, GL_RGBA, size_.width(), size_.height(), 0, | 74 GL_TEXTURE_2D, 0, GL_RGBA, |
| 75 surface_size_.width(), surface_size_.height(), 0, |
| 75 GL_RGBA, GL_UNSIGNED_BYTE, NULL); | 76 GL_RGBA, GL_UNSIGNED_BYTE, NULL); |
| 76 } | 77 } |
| 77 } | 78 } |
| 78 } | 79 } |
| 79 | 80 |
| 80 void MailboxOutputSurface::DiscardBackbuffer() { | 81 void MailboxOutputSurface::DiscardBackbuffer() { |
| 81 is_backbuffer_discarded_ = true; | 82 is_backbuffer_discarded_ = true; |
| 82 | 83 |
| 83 if (current_backing_.texture_id) { | 84 if (current_backing_.texture_id) { |
| 84 context3d_->deleteTexture(current_backing_.texture_id); | 85 context3d_->deleteTexture(current_backing_.texture_id); |
| 85 current_backing_ = TransferableFrame(); | 86 current_backing_ = TransferableFrame(); |
| 86 } | 87 } |
| 87 | 88 |
| 88 while (!returned_textures_.empty()) { | 89 while (!returned_textures_.empty()) { |
| 89 const TransferableFrame& frame = returned_textures_.front(); | 90 const TransferableFrame& frame = returned_textures_.front(); |
| 90 ConsumeTexture(frame); | 91 ConsumeTexture(frame); |
| 91 context3d_->deleteTexture(frame.texture_id); | 92 context3d_->deleteTexture(frame.texture_id); |
| 92 returned_textures_.pop(); | 93 returned_textures_.pop(); |
| 93 } | 94 } |
| 94 | 95 |
| 95 if (fbo_) { | 96 if (fbo_) { |
| 96 context3d_->bindFramebuffer(GL_FRAMEBUFFER, fbo_); | 97 context3d_->bindFramebuffer(GL_FRAMEBUFFER, fbo_); |
| 97 context3d_->deleteFramebuffer(fbo_); | 98 context3d_->deleteFramebuffer(fbo_); |
| 98 fbo_ = 0; | 99 fbo_ = 0; |
| 99 } | 100 } |
| 100 } | 101 } |
| 101 | 102 |
| 102 void MailboxOutputSurface::Reshape(gfx::Size size, float scale_factor) { | 103 void MailboxOutputSurface::Reshape(gfx::Size size, float scale_factor) { |
| 103 if (size == size_) | 104 if (size == surface_size_) |
| 104 return; | 105 return; |
| 105 | 106 |
| 106 size_ = size; | 107 surface_size_ = size; |
| 108 device_scale_factor_ = scale_factor; |
| 107 DiscardBackbuffer(); | 109 DiscardBackbuffer(); |
| 108 EnsureBackbuffer(); | 110 EnsureBackbuffer(); |
| 109 } | 111 } |
| 110 | 112 |
| 111 void MailboxOutputSurface::BindFramebuffer() { | 113 void MailboxOutputSurface::BindFramebuffer() { |
| 112 EnsureBackbuffer(); | 114 EnsureBackbuffer(); |
| 113 DCHECK(current_backing_.texture_id); | 115 DCHECK(current_backing_.texture_id); |
| 114 | 116 |
| 115 if (!fbo_) | 117 if (!fbo_) |
| 116 fbo_ = context3d_->createFramebuffer(); | 118 fbo_ = context3d_->createFramebuffer(); |
| 117 context3d_->bindFramebuffer(GL_FRAMEBUFFER, fbo_); | 119 context3d_->bindFramebuffer(GL_FRAMEBUFFER, fbo_); |
| 118 context3d_->framebufferTexture2D( | 120 context3d_->framebufferTexture2D( |
| 119 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, | 121 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, |
| 120 current_backing_.texture_id, 0); | 122 current_backing_.texture_id, 0); |
| 121 } | 123 } |
| 122 | 124 |
| 123 void MailboxOutputSurface::SendFrameToParentCompositor( | 125 void MailboxOutputSurface::SendFrameToParentCompositor( |
| 124 cc::CompositorFrame* frame) { | 126 cc::CompositorFrame* frame) { |
| 125 frame->gl_frame_data.reset(new GLFrameData()); | 127 frame->gl_frame_data.reset(new GLFrameData()); |
| 126 | 128 |
| 127 DCHECK(!size_.IsEmpty()); | 129 DCHECK(!surface_size_.IsEmpty()); |
| 128 DCHECK(size_ == current_backing_.size); | 130 DCHECK(surface_size_ == current_backing_.size); |
| 129 DCHECK(!current_backing_.mailbox.IsZero()); | 131 DCHECK(!current_backing_.mailbox.IsZero()); |
| 130 | 132 |
| 131 context3d_->framebufferTexture2D( | 133 context3d_->framebufferTexture2D( |
| 132 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0); | 134 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0); |
| 133 context3d_->bindFramebuffer(GL_FRAMEBUFFER, 0); | 135 context3d_->bindFramebuffer(GL_FRAMEBUFFER, 0); |
| 134 context3d_->bindTexture(GL_TEXTURE_2D, current_backing_.texture_id); | 136 context3d_->bindTexture(GL_TEXTURE_2D, current_backing_.texture_id); |
| 135 context3d_->produceTextureCHROMIUM( | 137 context3d_->produceTextureCHROMIUM( |
| 136 GL_TEXTURE_2D, current_backing_.mailbox.name); | 138 GL_TEXTURE_2D, current_backing_.mailbox.name); |
| 137 frame->gl_frame_data->mailbox = current_backing_.mailbox; | 139 frame->gl_frame_data->mailbox = current_backing_.mailbox; |
| 138 frame->gl_frame_data->size = current_backing_.size; | 140 frame->gl_frame_data->size = current_backing_.size; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 context3d_->bindTexture(GL_TEXTURE_2D, frame.texture_id); | 205 context3d_->bindTexture(GL_TEXTURE_2D, frame.texture_id); |
| 204 context3d_->consumeTextureCHROMIUM(GL_TEXTURE_2D, frame.mailbox.name); | 206 context3d_->consumeTextureCHROMIUM(GL_TEXTURE_2D, frame.mailbox.name); |
| 205 } | 207 } |
| 206 | 208 |
| 207 size_t MailboxOutputSurface::GetNumAcksPending() { | 209 size_t MailboxOutputSurface::GetNumAcksPending() { |
| 208 DCHECK(pending_textures_.size()); | 210 DCHECK(pending_textures_.size()); |
| 209 return pending_textures_.size() - 1; | 211 return pending_textures_.size() - 1; |
| 210 } | 212 } |
| 211 | 213 |
| 212 } // namespace content | 214 } // namespace content |
| OLD | NEW |