OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/browser/compositor/reflector_impl.h" | 5 #include "content/browser/compositor/reflector_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "content/browser/compositor/browser_compositor_output_surface.h" | 9 #include "content/browser/compositor/browser_compositor_output_surface.h" |
10 #include "content/browser/compositor/owned_mailbox.h" | 10 #include "content/browser/compositor/owned_mailbox.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 FROM_HERE, | 31 FROM_HERE, |
32 base::Bind( | 32 base::Bind( |
33 &ReflectorImpl::InitOnImplThread, this, main.mailbox->holder())); | 33 &ReflectorImpl::InitOnImplThread, this, main.mailbox->holder())); |
34 } | 34 } |
35 | 35 |
36 ReflectorImpl::MainThreadData::MainThreadData( | 36 ReflectorImpl::MainThreadData::MainThreadData( |
37 ui::Compositor* mirrored_compositor, | 37 ui::Compositor* mirrored_compositor, |
38 ui::Layer* mirroring_layer) | 38 ui::Layer* mirroring_layer) |
39 : needs_set_mailbox(true), | 39 : needs_set_mailbox(true), |
40 mirrored_compositor(mirrored_compositor), | 40 mirrored_compositor(mirrored_compositor), |
41 mirroring_layer(mirroring_layer) {} | 41 mirroring_layer(mirroring_layer), |
| 42 flip_texture(false) { |
| 43 } |
42 | 44 |
43 ReflectorImpl::MainThreadData::~MainThreadData() {} | 45 ReflectorImpl::MainThreadData::~MainThreadData() {} |
44 | 46 |
45 ReflectorImpl::ImplThreadData::ImplThreadData( | 47 ReflectorImpl::ImplThreadData::ImplThreadData( |
46 IDMap<BrowserCompositorOutputSurface>* output_surface_map) | 48 IDMap<BrowserCompositorOutputSurface>* output_surface_map) |
47 : output_surface_map(output_surface_map), | 49 : output_surface_map(output_surface_map), |
48 output_surface(NULL), | 50 output_surface(NULL), |
49 texture_id(0) {} | 51 texture_id(0) {} |
50 | 52 |
51 ReflectorImpl::ImplThreadData::~ImplThreadData() {} | 53 ReflectorImpl::ImplThreadData::~ImplThreadData() {} |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 output_surface->context_provider()->BindToCurrentThread(); | 188 output_surface->context_provider()->BindToCurrentThread(); |
187 impl.gl_helper.reset( | 189 impl.gl_helper.reset( |
188 new GLHelper(output_surface->context_provider()->ContextGL(), | 190 new GLHelper(output_surface->context_provider()->ContextGL(), |
189 output_surface->context_provider()->ContextSupport())); | 191 output_surface->context_provider()->ContextSupport())); |
190 impl.texture_id = impl.gl_helper->ConsumeMailboxToTexture( | 192 impl.texture_id = impl.gl_helper->ConsumeMailboxToTexture( |
191 mailbox_holder.mailbox, mailbox_holder.sync_point); | 193 mailbox_holder.mailbox, mailbox_holder.sync_point); |
192 impl.gl_helper->ResizeTexture(impl.texture_id, output_surface->SurfaceSize()); | 194 impl.gl_helper->ResizeTexture(impl.texture_id, output_surface->SurfaceSize()); |
193 impl.gl_helper->Flush(); | 195 impl.gl_helper->Flush(); |
194 output_surface->SetReflector(this); | 196 output_surface->SetReflector(this); |
195 // The texture doesn't have the data, so invokes full redraw now. | 197 // The texture doesn't have the data, so invokes full redraw now. |
| 198 bool flip_texture = !output_surface->capabilities().flipped_output_surface; |
196 main_message_loop_->PostTask( | 199 main_message_loop_->PostTask( |
197 FROM_HERE, | 200 FROM_HERE, base::Bind(&ReflectorImpl::FullRedrawContentOnMainThread, |
198 base::Bind(&ReflectorImpl::FullRedrawContentOnMainThread, | 201 scoped_refptr<ReflectorImpl>(this), flip_texture)); |
199 scoped_refptr<ReflectorImpl>(this))); | |
200 } | 202 } |
201 | 203 |
202 void ReflectorImpl::UpdateTextureSizeOnMainThread(gfx::Size size) { | 204 void ReflectorImpl::UpdateTextureSizeOnMainThread(gfx::Size size) { |
203 MainThreadData& main = GetMain(); | 205 MainThreadData& main = GetMain(); |
204 if (!main.mirroring_layer || !main.mailbox.get() || | 206 if (!main.mirroring_layer || !main.mailbox.get() || |
205 main.mailbox->mailbox().IsZero()) | 207 main.mailbox->mailbox().IsZero()) |
206 return; | 208 return; |
207 if (main.needs_set_mailbox) { | 209 if (main.needs_set_mailbox) { |
208 main.mirroring_layer->SetTextureMailbox( | 210 main.mirroring_layer->SetTextureMailbox( |
209 cc::TextureMailbox(main.mailbox->holder()), | 211 cc::TextureMailbox(main.mailbox->holder()), |
210 cc::SingleReleaseCallback::Create( | 212 cc::SingleReleaseCallback::Create( |
211 base::Bind(ReleaseMailbox, main.mailbox)), | 213 base::Bind(ReleaseMailbox, main.mailbox)), |
212 size); | 214 size); |
213 main.needs_set_mailbox = false; | 215 main.needs_set_mailbox = false; |
214 } else { | 216 } else { |
215 main.mirroring_layer->SetTextureSize(size); | 217 main.mirroring_layer->SetTextureSize(size); |
216 } | 218 } |
217 main.mirroring_layer->SetBounds(gfx::Rect(size)); | 219 main.mirroring_layer->SetBounds(gfx::Rect(size)); |
| 220 main.mirroring_layer->SetTextureFlipped(main.flip_texture); |
218 } | 221 } |
219 | 222 |
220 void ReflectorImpl::FullRedrawOnMainThread(gfx::Size size) { | 223 void ReflectorImpl::FullRedrawOnMainThread(gfx::Size size) { |
221 MainThreadData& main = GetMain(); | 224 MainThreadData& main = GetMain(); |
222 if (!main.mirroring_layer) | 225 if (!main.mirroring_layer) |
223 return; | 226 return; |
224 UpdateTextureSizeOnMainThread(size); | 227 UpdateTextureSizeOnMainThread(size); |
225 main.mirroring_layer->SchedulePaint(main.mirroring_layer->bounds()); | 228 main.mirroring_layer->SchedulePaint(main.mirroring_layer->bounds()); |
226 } | 229 } |
227 | 230 |
228 void ReflectorImpl::UpdateSubBufferOnMainThread(gfx::Size size, | 231 void ReflectorImpl::UpdateSubBufferOnMainThread(const gfx::Size& size, |
229 gfx::Rect rect) { | 232 const gfx::Rect& rect) { |
230 MainThreadData& main = GetMain(); | 233 MainThreadData& main = GetMain(); |
231 if (!main.mirroring_layer) | 234 if (!main.mirroring_layer) |
232 return; | 235 return; |
233 UpdateTextureSizeOnMainThread(size); | 236 UpdateTextureSizeOnMainThread(size); |
| 237 |
| 238 int y = rect.y(); |
234 // Flip the coordinates to compositor's one. | 239 // Flip the coordinates to compositor's one. |
235 int y = size.height() - rect.y() - rect.height(); | 240 if (main.flip_texture) |
| 241 y = size.height() - rect.y() - rect.height(); |
236 gfx::Rect new_rect(rect.x(), y, rect.width(), rect.height()); | 242 gfx::Rect new_rect(rect.x(), y, rect.width(), rect.height()); |
237 main.mirroring_layer->SchedulePaint(new_rect); | 243 main.mirroring_layer->SchedulePaint(new_rect); |
238 } | 244 } |
239 | 245 |
240 void ReflectorImpl::FullRedrawContentOnMainThread() { | 246 void ReflectorImpl::FullRedrawContentOnMainThread(bool flip_texture) { |
241 MainThreadData& main = GetMain(); | 247 MainThreadData& main = GetMain(); |
| 248 main.flip_texture = flip_texture; |
242 main.mirrored_compositor->ScheduleFullRedraw(); | 249 main.mirrored_compositor->ScheduleFullRedraw(); |
243 } | 250 } |
244 | 251 |
245 } // namespace content | 252 } // namespace content |
OLD | NEW |