Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(653)

Side by Side Diff: content/browser/compositor/reflector_impl.cc

Issue 846063002: compositor: Fix texture flipping for SW mirroring with surfaceless (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add tests Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
11 #include "content/common/gpu/client/gl_helper.h" 11 #include "content/common/gpu/client/gl_helper.h"
12 #include "ui/compositor/layer.h" 12 #include "ui/compositor/layer.h"
13 13
14 namespace content { 14 namespace content {
15 15
16 ReflectorImpl::ReflectorImpl( 16 ReflectorImpl::ReflectorImpl(
17 ui::Compositor* mirrored_compositor, 17 ui::Compositor* mirrored_compositor,
18 ui::Layer* mirroring_layer, 18 ui::Layer* mirroring_layer,
19 IDMap<BrowserCompositorOutputSurface>* output_surface_map, 19 IDMap<BrowserCompositorOutputSurface>* output_surface_map,
20 base::MessageLoopProxy* compositor_thread_loop, 20 base::MessageLoopProxy* compositor_thread_loop,
21 int surface_id) 21 int surface_id)
22 : impl_unsafe_(output_surface_map), 22 : impl_unsafe_(output_surface_map),
23 main_unsafe_(mirrored_compositor, mirroring_layer), 23 main_unsafe_(mirrored_compositor, mirroring_layer),
24 impl_message_loop_(compositor_thread_loop), 24 impl_message_loop_(compositor_thread_loop),
25 main_message_loop_(base::MessageLoopProxy::current()), 25 main_message_loop_(base::MessageLoopProxy::current()),
26 surface_id_(surface_id) { 26 surface_id_(surface_id),
27 flip_texture_(false) {
27 GLHelper* helper = ImageTransportFactory::GetInstance()->GetGLHelper(); 28 GLHelper* helper = ImageTransportFactory::GetInstance()->GetGLHelper();
28 MainThreadData& main = GetMain(); 29 MainThreadData& main = GetMain();
29 main.mailbox = new OwnedMailbox(helper); 30 main.mailbox = new OwnedMailbox(helper);
30 impl_message_loop_->PostTask( 31 impl_message_loop_->PostTask(
31 FROM_HERE, 32 FROM_HERE,
32 base::Bind( 33 base::Bind(
33 &ReflectorImpl::InitOnImplThread, this, main.mailbox->holder())); 34 &ReflectorImpl::InitOnImplThread, this, main.mailbox->holder()));
34 } 35 }
35 36
36 ReflectorImpl::MainThreadData::MainThreadData( 37 ReflectorImpl::MainThreadData::MainThreadData(
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 177
177 void ReflectorImpl::AttachToOutputSurfaceOnImplThread( 178 void ReflectorImpl::AttachToOutputSurfaceOnImplThread(
178 const gpu::MailboxHolder& mailbox_holder, 179 const gpu::MailboxHolder& mailbox_holder,
179 BrowserCompositorOutputSurface* output_surface) { 180 BrowserCompositorOutputSurface* output_surface) {
180 ImplThreadData& impl = GetImpl(); 181 ImplThreadData& impl = GetImpl();
181 if (output_surface == impl.output_surface) 182 if (output_surface == impl.output_surface)
182 return; 183 return;
183 if (impl.output_surface) 184 if (impl.output_surface)
184 DetachFromOutputSurface(); 185 DetachFromOutputSurface();
185 impl.output_surface = output_surface; 186 impl.output_surface = output_surface;
187 flip_texture_ = !output_surface->capabilities().flipped_output_surface;
danakj 2015/01/22 01:04:20 capabilities are not initialized until the context
achaulk 2015/01/23 16:45:52 Done.
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.
196 main_message_loop_->PostTask( 198 main_message_loop_->PostTask(
197 FROM_HERE, 199 FROM_HERE,
198 base::Bind(&ReflectorImpl::FullRedrawContentOnMainThread, 200 base::Bind(&ReflectorImpl::FullRedrawContentOnMainThread,
danakj 2015/01/22 01:04:20 Maybe pass the flipped bool along here, so you can
199 scoped_refptr<ReflectorImpl>(this))); 201 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(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 (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() {
241 MainThreadData& main = GetMain(); 247 MainThreadData& main = GetMain();
242 main.mirrored_compositor->ScheduleFullRedraw(); 248 main.mirrored_compositor->ScheduleFullRedraw();
243 } 249 }
244 250
245 } // namespace content 251 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698