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

Side by Side Diff: components/mus/surfaces/direct_output_surface.cc

Issue 1821863002: Hook up ui::Compositor to Display's BeginFrameSource (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase; refactor mus output surface Created 4 years, 8 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 "components/mus/surfaces/direct_output_surface.h" 5 #include "components/mus/surfaces/direct_output_surface.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "cc/output/compositor_frame.h" 10 #include "cc/output/compositor_frame.h"
11 #include "cc/output/context_provider.h" 11 #include "cc/output/context_provider.h"
12 #include "cc/output/output_surface_client.h" 12 #include "cc/output/output_surface_client.h"
13 #include "gpu/command_buffer/client/context_support.h" 13 #include "gpu/command_buffer/client/context_support.h"
14 #include "gpu/command_buffer/client/gles2_interface.h" 14 #include "gpu/command_buffer/client/gles2_interface.h"
15 15
16 namespace mus { 16 namespace mus {
17 17
18 DirectOutputSurface::DirectOutputSurface( 18 DirectOutputSurface::DirectOutputSurface(
19 const scoped_refptr<cc::ContextProvider>& context_provider) 19 scoped_refptr<SurfacesContextProvider> context_provider,
20 : cc::OutputSurface(context_provider), weak_ptr_factory_(this) {} 20 base::SingleThreadTaskRunner* task_runner)
21 : cc::OutputSurface(context_provider),
22 synthetic_begin_frame_source_(new cc::SyntheticBeginFrameSource(
23 task_runner,
24 cc::BeginFrameArgs::DefaultInterval())),
25 weak_ptr_factory_(this) {
26 context_provider->SetDelegate(this);
27 }
21 28
22 DirectOutputSurface::~DirectOutputSurface() {} 29 DirectOutputSurface::~DirectOutputSurface() {}
23 30
24 bool DirectOutputSurface::BindToClient(cc::OutputSurfaceClient* client) { 31 bool DirectOutputSurface::BindToClient(cc::OutputSurfaceClient* client) {
25 if (!cc::OutputSurface::BindToClient(client)) 32 if (!cc::OutputSurface::BindToClient(client))
26 return false; 33 return false;
27 34
35 client->SetBeginFrameSource(synthetic_begin_frame_source_.get());
36
28 if (capabilities_.uses_default_gl_framebuffer) { 37 if (capabilities_.uses_default_gl_framebuffer) {
29 capabilities_.flipped_output_surface = 38 capabilities_.flipped_output_surface =
30 context_provider()->ContextCapabilities().gpu.flips_vertically; 39 context_provider()->ContextCapabilities().gpu.flips_vertically;
31 } 40 }
32 return true; 41 return true;
33 } 42 }
34 43
44 void DirectOutputSurface::OnVSyncParametersUpdated(int64_t timebase,
45 int64_t interval) {
46 auto timebase_time_ticks = base::TimeTicks::FromInternalValue(timebase);
sunnyps 2016/04/01 22:35:25 nit: Don't really need the _time_ticks and _time_d
enne (OOO) 2016/04/02 00:18:38 This code was moved from TopLevelDisplayClient, an
sunnyps 2016/04/02 00:47:15 ah, ok nvm.
47 auto interval_time_delta = base::TimeDelta::FromInternalValue(interval);
48
49 if (interval_time_delta.is_zero()) {
50 // TODO(brianderson): We should not be receiving 0 intervals.
51 interval_time_delta = cc::BeginFrameArgs::DefaultInterval();
52 }
53
54 synthetic_begin_frame_source_->OnUpdateVSyncParameters(timebase_time_ticks,
55 interval_time_delta);
56 }
57
35 void DirectOutputSurface::SwapBuffers(cc::CompositorFrame* frame) { 58 void DirectOutputSurface::SwapBuffers(cc::CompositorFrame* frame) {
36 DCHECK(context_provider_); 59 DCHECK(context_provider_);
37 DCHECK(frame->gl_frame_data); 60 DCHECK(frame->gl_frame_data);
38 if (frame->gl_frame_data->sub_buffer_rect == 61 if (frame->gl_frame_data->sub_buffer_rect ==
39 gfx::Rect(frame->gl_frame_data->size)) { 62 gfx::Rect(frame->gl_frame_data->size)) {
40 context_provider_->ContextSupport()->Swap(); 63 context_provider_->ContextSupport()->Swap();
41 } else { 64 } else {
42 context_provider_->ContextSupport()->PartialSwapBuffers( 65 context_provider_->ContextSupport()->PartialSwapBuffers(
43 frame->gl_frame_data->sub_buffer_rect); 66 frame->gl_frame_data->sub_buffer_rect);
44 } 67 }
45 68
46 gpu::gles2::GLES2Interface* gl = context_provider_->ContextGL(); 69 gpu::gles2::GLES2Interface* gl = context_provider_->ContextGL();
47 const GLuint64 fence_sync = gl->InsertFenceSyncCHROMIUM(); 70 const GLuint64 fence_sync = gl->InsertFenceSyncCHROMIUM();
48 gl->ShallowFlushCHROMIUM(); 71 gl->ShallowFlushCHROMIUM();
49 72
50 gpu::SyncToken sync_token; 73 gpu::SyncToken sync_token;
51 gl->GenUnverifiedSyncTokenCHROMIUM(fence_sync, sync_token.GetData()); 74 gl->GenUnverifiedSyncTokenCHROMIUM(fence_sync, sync_token.GetData());
52 75
53 context_provider_->ContextSupport()->SignalSyncToken( 76 context_provider_->ContextSupport()->SignalSyncToken(
54 sync_token, base::Bind(&OutputSurface::OnSwapBuffersComplete, 77 sync_token, base::Bind(&OutputSurface::OnSwapBuffersComplete,
55 weak_ptr_factory_.GetWeakPtr())); 78 weak_ptr_factory_.GetWeakPtr()));
56 client_->DidSwapBuffers(); 79 client_->DidSwapBuffers();
57 } 80 }
58 81
59 } // namespace mus 82 } // namespace mus
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698