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 if (current_backing_.sync_point) | 50 if (current_backing_.sync_point) |
51 context3d_->waitSyncPoint(current_backing_.sync_point); | 51 context3d_->waitSyncPoint(current_backing_.sync_point); |
52 returned_textures_.pop(); | 52 returned_textures_.pop(); |
53 break; | 53 break; |
54 } | 54 } |
55 | 55 |
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_->bindTexture(GL_TEXTURE_2D, current_backing_.texture_id); | 63 context3d_->bindTexture(GL_TEXTURE_2D, current_backing_.texture_id); |
64 context3d_->texParameteri( | 64 context3d_->texParameteri( |
65 GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | 65 GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
66 context3d_->texParameteri( | 66 context3d_->texParameteri( |
67 GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | 67 GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
68 context3d_->texParameteri( | 68 context3d_->texParameteri( |
69 GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 69 GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
70 context3d_->texParameteri( | 70 context3d_->texParameteri( |
71 GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 71 GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
72 context3d_->texImage2D( | 72 context3d_->texImage2D( |
73 GL_TEXTURE_2D, 0, GL_RGBA, size_.width(), size_.height(), 0, | 73 GL_TEXTURE_2D, 0, GL_RGBA, |
| 74 surface_size_.width(), surface_size_.height(), 0, |
74 GL_RGBA, GL_UNSIGNED_BYTE, NULL); | 75 GL_RGBA, GL_UNSIGNED_BYTE, NULL); |
75 context3d_->genMailboxCHROMIUM(current_backing_.mailbox.name); | 76 context3d_->genMailboxCHROMIUM(current_backing_.mailbox.name); |
76 context3d_->produceTextureCHROMIUM( | 77 context3d_->produceTextureCHROMIUM( |
77 GL_TEXTURE_2D, current_backing_.mailbox.name); | 78 GL_TEXTURE_2D, current_backing_.mailbox.name); |
78 } | 79 } |
79 } | 80 } |
80 } | 81 } |
81 | 82 |
82 void MailboxOutputSurface::DiscardBackbuffer() { | 83 void MailboxOutputSurface::DiscardBackbuffer() { |
83 is_backbuffer_discarded_ = true; | 84 is_backbuffer_discarded_ = true; |
(...skipping 10 matching lines...) Expand all Loading... |
94 } | 95 } |
95 | 96 |
96 if (fbo_) { | 97 if (fbo_) { |
97 context3d_->bindFramebuffer(GL_FRAMEBUFFER, fbo_); | 98 context3d_->bindFramebuffer(GL_FRAMEBUFFER, fbo_); |
98 context3d_->deleteFramebuffer(fbo_); | 99 context3d_->deleteFramebuffer(fbo_); |
99 fbo_ = 0; | 100 fbo_ = 0; |
100 } | 101 } |
101 } | 102 } |
102 | 103 |
103 void MailboxOutputSurface::Reshape(gfx::Size size, float scale_factor) { | 104 void MailboxOutputSurface::Reshape(gfx::Size size, float scale_factor) { |
104 if (size == size_) | 105 if (size == surface_size_) |
105 return; | 106 return; |
106 | 107 |
107 size_ = size; | 108 surface_size_ = size; |
| 109 device_scale_factor_ = scale_factor; |
108 DiscardBackbuffer(); | 110 DiscardBackbuffer(); |
109 EnsureBackbuffer(); | 111 EnsureBackbuffer(); |
110 } | 112 } |
111 | 113 |
112 void MailboxOutputSurface::BindFramebuffer() { | 114 void MailboxOutputSurface::BindFramebuffer() { |
113 EnsureBackbuffer(); | 115 EnsureBackbuffer(); |
114 DCHECK(current_backing_.texture_id); | 116 DCHECK(current_backing_.texture_id); |
115 | 117 |
116 if (!fbo_) | 118 if (!fbo_) |
117 fbo_ = context3d_->createFramebuffer(); | 119 fbo_ = context3d_->createFramebuffer(); |
118 context3d_->bindFramebuffer(GL_FRAMEBUFFER, fbo_); | 120 context3d_->bindFramebuffer(GL_FRAMEBUFFER, fbo_); |
119 context3d_->framebufferTexture2D( | 121 context3d_->framebufferTexture2D( |
120 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, | 122 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, |
121 current_backing_.texture_id, 0); | 123 current_backing_.texture_id, 0); |
122 } | 124 } |
123 | 125 |
124 void MailboxOutputSurface::SendFrameToParentCompositor( | 126 void MailboxOutputSurface::SendFrameToParentCompositor( |
125 cc::CompositorFrame* frame) { | 127 cc::CompositorFrame* frame) { |
126 frame->gl_frame_data.reset(new GLFrameData()); | 128 frame->gl_frame_data.reset(new GLFrameData()); |
127 | 129 |
128 DCHECK(!size_.IsEmpty()); | 130 DCHECK(!surface_size_.IsEmpty()); |
129 DCHECK(size_ == current_backing_.size); | 131 DCHECK(surface_size_ == current_backing_.size); |
130 DCHECK(!current_backing_.mailbox.IsZero()); | 132 DCHECK(!current_backing_.mailbox.IsZero()); |
131 | 133 |
132 frame->gl_frame_data->mailbox = current_backing_.mailbox; | 134 frame->gl_frame_data->mailbox = current_backing_.mailbox; |
133 frame->gl_frame_data->size = current_backing_.size; | 135 frame->gl_frame_data->size = current_backing_.size; |
134 context3d_->flush(); | 136 context3d_->flush(); |
135 frame->gl_frame_data->sync_point = context3d_->insertSyncPoint(); | 137 frame->gl_frame_data->sync_point = context3d_->insertSyncPoint(); |
136 CompositorOutputSurface::SendFrameToParentCompositor(frame); | 138 CompositorOutputSurface::SendFrameToParentCompositor(frame); |
137 | 139 |
138 pending_textures_.push_back(current_backing_); | 140 pending_textures_.push_back(current_backing_); |
139 current_backing_ = TransferableFrame(); | 141 current_backing_ = TransferableFrame(); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 // The browser only copies damage correctly for two buffers in use. | 190 // The browser only copies damage correctly for two buffers in use. |
189 DCHECK(GetNumAcksPending() < 2); | 191 DCHECK(GetNumAcksPending() < 2); |
190 } | 192 } |
191 | 193 |
192 size_t MailboxOutputSurface::GetNumAcksPending() { | 194 size_t MailboxOutputSurface::GetNumAcksPending() { |
193 DCHECK(pending_textures_.size()); | 195 DCHECK(pending_textures_.size()); |
194 return pending_textures_.size() - 1; | 196 return pending_textures_.size() - 1; |
195 } | 197 } |
196 | 198 |
197 } // namespace content | 199 } // namespace content |
OLD | NEW |