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
3 // found in the LICENSE file.
5 #include "content/browser/compositor/software_browser_compositor_output_surface.h"
7 #include "base/location.h"
8 #include "base/memory/ref_counted.h"
9 #include "base/single_thread_task_runner.h"
10 #include "base/thread_task_runner_handle.h"
11 #include "base/time/time.h"
12 #include "cc/output/compositor_frame.h"
13 #include "cc/output/output_surface_client.h"
14 #include "cc/output/software_output_device.h"
15 #include "content/browser/renderer_host/render_widget_host_impl.h"
16 #include "ui/events/latency_info.h"
17 #include "ui/gfx/vsync_provider.h"
21 SoftwareBrowserCompositorOutputSurface::SoftwareBrowserCompositorOutputSurface(
22 scoped_ptr
<cc::SoftwareOutputDevice
> software_device
,
23 const scoped_refptr
<ui::CompositorVSyncManager
>& vsync_manager
)
24 : BrowserCompositorOutputSurface(software_device
.Pass(),
29 SoftwareBrowserCompositorOutputSurface::
30 ~SoftwareBrowserCompositorOutputSurface() {
33 void SoftwareBrowserCompositorOutputSurface::SwapBuffers(
34 cc::CompositorFrame
* frame
) {
35 base::TimeTicks swap_time
= base::TimeTicks::Now();
36 for (auto& latency
: frame
->metadata
.latency_info
) {
37 latency
.AddLatencyNumberWithTimestamp(
38 ui::INPUT_EVENT_GPU_SWAP_BUFFER_COMPONENT
, 0, 0, swap_time
, 1);
39 latency
.AddLatencyNumberWithTimestamp(
40 ui::INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT
, 0, 0,
43 base::ThreadTaskRunnerHandle::Get()->PostTask(
44 FROM_HERE
, base::Bind(&RenderWidgetHostImpl::CompositorFrameDrawn
,
45 frame
->metadata
.latency_info
));
47 gfx::VSyncProvider
* vsync_provider
= software_device()->GetVSyncProvider();
49 vsync_provider
->GetVSyncParameters(base::Bind(
50 &BrowserCompositorOutputSurface::OnUpdateVSyncParametersFromGpu
,
51 weak_factory_
.GetWeakPtr()));
53 PostSwapBuffersComplete();
54 client_
->DidSwapBuffers();
57 #if defined(OS_MACOSX)
58 void SoftwareBrowserCompositorOutputSurface::OnSurfaceDisplayed() {
59 // See GpuBrowserCompositorOutputSurface for when and how this is used.
60 NOTREACHED() << "Not expected for software surfaces.";
63 void SoftwareBrowserCompositorOutputSurface::SetSurfaceSuspendedForRecycle(
67 bool SoftwareBrowserCompositorOutputSurface::
68 SurfaceShouldNotShowFramesAfterSuspendForRecycle() const {
73 } // namespace content