Chromium Code Reviews| 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 29 matching lines...) Expand all Loading... | |
| 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 == size_) { |
| 49 current_backing_ = texture; | 49 current_backing_ = texture; |
| 50 ConsumeTexture(texture); | |
| 51 returned_textures_.pop(); | 50 returned_textures_.pop(); |
| 52 break; | 51 break; |
| 53 } | 52 } |
| 54 | 53 |
| 55 ConsumeTexture(texture); | |
| 56 context3d_->deleteTexture(texture.texture_id); | 54 context3d_->deleteTexture(texture.texture_id); |
| 57 returned_textures_.pop(); | 55 returned_textures_.pop(); |
| 58 } | 56 } |
| 59 | 57 |
| 60 if (!current_backing_.texture_id) { | 58 if (!current_backing_.texture_id) { |
| 61 current_backing_.texture_id = context3d_->createTexture(); | 59 current_backing_.texture_id = context3d_->createTexture(); |
| 62 current_backing_.size = size_; | 60 current_backing_.size = size_; |
| 63 context3d_->genMailboxCHROMIUM(current_backing_.mailbox.name); | |
| 64 context3d_->bindTexture(GL_TEXTURE_2D, current_backing_.texture_id); | 61 context3d_->bindTexture(GL_TEXTURE_2D, current_backing_.texture_id); |
| 65 context3d_->texParameteri( | 62 context3d_->texParameteri( |
| 66 GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | 63 GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 67 context3d_->texParameteri( | 64 context3d_->texParameteri( |
| 68 GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | 65 GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 69 context3d_->texParameteri( | 66 context3d_->texParameteri( |
| 70 GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 67 GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 71 context3d_->texParameteri( | 68 context3d_->texParameteri( |
| 72 GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 69 GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 73 context3d_->texImage2D( | 70 context3d_->texImage2D( |
| 74 GL_TEXTURE_2D, 0, GL_RGBA, size_.width(), size_.height(), 0, | 71 GL_TEXTURE_2D, 0, GL_RGBA, size_.width(), size_.height(), 0, |
| 75 GL_RGBA, GL_UNSIGNED_BYTE, NULL); | 72 GL_RGBA, GL_UNSIGNED_BYTE, NULL); |
| 73 context3d_->genMailboxCHROMIUM(current_backing_.mailbox.name); | |
| 74 context3d_->produceTextureCHROMIUM( | |
| 75 GL_TEXTURE_2D, current_backing_.mailbox.name); | |
| 76 } | 76 } |
| 77 } | 77 } |
| 78 } | 78 } |
| 79 | 79 |
| 80 void MailboxOutputSurface::DiscardBackbuffer() { | 80 void MailboxOutputSurface::DiscardBackbuffer() { |
| 81 is_backbuffer_discarded_ = true; | 81 is_backbuffer_discarded_ = true; |
| 82 | 82 |
| 83 if (current_backing_.texture_id) { | 83 if (current_backing_.texture_id) { |
| 84 context3d_->deleteTexture(current_backing_.texture_id); | 84 context3d_->deleteTexture(current_backing_.texture_id); |
| 85 current_backing_ = TransferableFrame(); | 85 current_backing_ = TransferableFrame(); |
| 86 } | 86 } |
| 87 | 87 |
| 88 while (!returned_textures_.empty()) { | 88 while (!returned_textures_.empty()) { |
| 89 const TransferableFrame& frame = returned_textures_.front(); | 89 const TransferableFrame& frame = returned_textures_.front(); |
| 90 ConsumeTexture(frame); | |
| 91 context3d_->deleteTexture(frame.texture_id); | 90 context3d_->deleteTexture(frame.texture_id); |
| 92 returned_textures_.pop(); | 91 returned_textures_.pop(); |
| 93 } | 92 } |
| 94 | 93 |
| 95 if (fbo_) { | 94 if (fbo_) { |
| 96 context3d_->bindFramebuffer(GL_FRAMEBUFFER, fbo_); | 95 context3d_->bindFramebuffer(GL_FRAMEBUFFER, fbo_); |
| 97 context3d_->deleteFramebuffer(fbo_); | 96 context3d_->deleteFramebuffer(fbo_); |
| 98 fbo_ = 0; | 97 fbo_ = 0; |
| 99 } | 98 } |
| 100 } | 99 } |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 121 } | 120 } |
| 122 | 121 |
| 123 void MailboxOutputSurface::SendFrameToParentCompositor( | 122 void MailboxOutputSurface::SendFrameToParentCompositor( |
| 124 cc::CompositorFrame* frame) { | 123 cc::CompositorFrame* frame) { |
| 125 frame->gl_frame_data.reset(new GLFrameData()); | 124 frame->gl_frame_data.reset(new GLFrameData()); |
| 126 | 125 |
| 127 DCHECK(!size_.IsEmpty()); | 126 DCHECK(!size_.IsEmpty()); |
| 128 DCHECK(size_ == current_backing_.size); | 127 DCHECK(size_ == current_backing_.size); |
| 129 DCHECK(!current_backing_.mailbox.IsZero()); | 128 DCHECK(!current_backing_.mailbox.IsZero()); |
| 130 | 129 |
| 131 context3d_->framebufferTexture2D( | |
| 132 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0); | |
|
no sievers
2013/06/03 22:03:51
This was necessary for some Android driver that ha
| |
| 133 context3d_->bindFramebuffer(GL_FRAMEBUFFER, 0); | |
| 134 context3d_->bindTexture(GL_TEXTURE_2D, current_backing_.texture_id); | |
| 135 context3d_->produceTextureCHROMIUM( | |
| 136 GL_TEXTURE_2D, current_backing_.mailbox.name); | |
| 137 frame->gl_frame_data->mailbox = current_backing_.mailbox; | 130 frame->gl_frame_data->mailbox = current_backing_.mailbox; |
| 138 frame->gl_frame_data->size = current_backing_.size; | 131 frame->gl_frame_data->size = current_backing_.size; |
| 139 context3d_->flush(); | 132 context3d_->flush(); |
| 140 frame->gl_frame_data->sync_point = context3d_->insertSyncPoint(); | 133 frame->gl_frame_data->sync_point = context3d_->insertSyncPoint(); |
| 141 CompositorOutputSurface::SendFrameToParentCompositor(frame); | 134 CompositorOutputSurface::SendFrameToParentCompositor(frame); |
| 142 | 135 |
| 143 pending_textures_.push_back(current_backing_); | 136 pending_textures_.push_back(current_backing_); |
| 144 current_backing_ = TransferableFrame(); | 137 current_backing_ = TransferableFrame(); |
| 145 } | 138 } |
| 146 | 139 |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 158 DCHECK(it->size == ack.gl_frame_data->size); | 151 DCHECK(it->size == ack.gl_frame_data->size); |
| 159 break; | 152 break; |
| 160 } | 153 } |
| 161 } | 154 } |
| 162 DCHECK(it != pending_textures_.end()); | 155 DCHECK(it != pending_textures_.end()); |
| 163 it->sync_point = ack.gl_frame_data->sync_point; | 156 it->sync_point = ack.gl_frame_data->sync_point; |
| 164 | 157 |
| 165 if (!is_backbuffer_discarded_) { | 158 if (!is_backbuffer_discarded_) { |
| 166 returned_textures_.push(*it); | 159 returned_textures_.push(*it); |
| 167 } else { | 160 } else { |
| 168 ConsumeTexture(*it); | |
| 169 context3d_->deleteTexture(it->texture_id); | 161 context3d_->deleteTexture(it->texture_id); |
| 170 } | 162 } |
| 171 | 163 |
| 172 pending_textures_.erase(it); | 164 pending_textures_.erase(it); |
| 173 } else { | 165 } else { |
| 174 DCHECK(!pending_textures_.empty()); | 166 DCHECK(!pending_textures_.empty()); |
| 175 // The browser always keeps one texture as the frontbuffer. | 167 // The browser always keeps one texture as the frontbuffer. |
| 176 // If it does not return a mailbox, it discarded the frontbuffer which is | 168 // If it does not return a mailbox, it discarded the frontbuffer which is |
| 177 // the oldest texture we sent. | 169 // the oldest texture we sent. |
| 178 uint32 texture_id = pending_textures_.front().texture_id; | 170 uint32 texture_id = pending_textures_.front().texture_id; |
| 179 if (texture_id) | 171 if (texture_id) |
| 180 context3d_->deleteTexture(texture_id); | 172 context3d_->deleteTexture(texture_id); |
| 181 pending_textures_.pop_front(); | 173 pending_textures_.pop_front(); |
| 182 } | 174 } |
| 183 CompositorOutputSurface::OnSwapAck(ack); | 175 CompositorOutputSurface::OnSwapAck(ack); |
| 184 } | 176 } |
| 185 | 177 |
| 186 void MailboxOutputSurface::SwapBuffers(const ui::LatencyInfo&) { | 178 void MailboxOutputSurface::SwapBuffers(const ui::LatencyInfo&) { |
| 187 } | 179 } |
| 188 | 180 |
| 189 void MailboxOutputSurface::PostSubBuffer(gfx::Rect rect, | 181 void MailboxOutputSurface::PostSubBuffer(gfx::Rect rect, |
| 190 const ui::LatencyInfo&) { | 182 const ui::LatencyInfo&) { |
| 191 NOTIMPLEMENTED() | 183 NOTIMPLEMENTED() |
| 192 << "Partial swap not supported with composite-to-mailbox yet."; | 184 << "Partial swap not supported with composite-to-mailbox yet."; |
| 193 | 185 |
| 194 // The browser only copies damage correctly for two buffers in use. | 186 // The browser only copies damage correctly for two buffers in use. |
| 195 DCHECK(GetNumAcksPending() < 2); | 187 DCHECK(GetNumAcksPending() < 2); |
| 196 } | 188 } |
| 197 | 189 |
| 198 void MailboxOutputSurface::ConsumeTexture(const TransferableFrame& frame) { | |
| 199 DCHECK(!frame.mailbox.IsZero()); | |
| 200 if (frame.sync_point) | |
| 201 context3d_->waitSyncPoint(frame.sync_point); | |
| 202 | |
| 203 context3d_->bindTexture(GL_TEXTURE_2D, frame.texture_id); | |
| 204 context3d_->consumeTextureCHROMIUM(GL_TEXTURE_2D, frame.mailbox.name); | |
| 205 } | |
| 206 | |
| 207 size_t MailboxOutputSurface::GetNumAcksPending() { | 190 size_t MailboxOutputSurface::GetNumAcksPending() { |
| 208 DCHECK(pending_textures_.size()); | 191 DCHECK(pending_textures_.size()); |
| 209 return pending_textures_.size() - 1; | 192 return pending_textures_.size() - 1; |
| 210 } | 193 } |
| 211 | 194 |
| 212 } // namespace content | 195 } // namespace content |
| OLD | NEW |