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