Skip to content

Commit 4097ae8

Browse files
committed
Revert "Remove PassThroughImageTransport and GLSurfaceAdapter"
Reason for revert: see #101 This reverts commit f8d4ce8.
1 parent e6e7991 commit 4097ae8

File tree

6 files changed

+544
-2
lines changed

6 files changed

+544
-2
lines changed

gpu/ipc/service/BUILD.gn

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ component("service") {
4040
"image_decode_accelerator_worker.h",
4141
"image_transport_surface.h",
4242
"image_transport_surface_delegate.h",
43+
"pass_through_image_transport_surface.cc",
44+
"pass_through_image_transport_surface.h",
4345
"raster_command_buffer_stub.cc",
4446
"raster_command_buffer_stub.h",
4547
"shared_image_stub.cc",

gpu/ipc/service/image_transport_surface_mac.mm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "gpu/ipc/service/image_transport_surface.h"
66

77
#include "gpu/ipc/service/image_transport_surface_overlay_mac.h"
8+
#include "gpu/ipc/service/pass_through_image_transport_surface.h"
89
#include "ui/gfx/native_widget_types.h"
910
#include "ui/gl/buildflags.h"
1011
#include "ui/gl/gl_surface_stub.h"
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
// Copyright 2016 The Chromium Authors
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#include "gpu/ipc/service/pass_through_image_transport_surface.h"
6+
7+
#include <utility>
8+
9+
#include "base/functional/bind.h"
10+
#include "base/functional/callback_helpers.h"
11+
#include "base/metrics/histogram_macros.h"
12+
#include "base/metrics/histogram_macros_local.h"
13+
#include "base/time/time.h"
14+
#include "build/build_config.h"
15+
#include "gpu/command_buffer/common/swap_buffers_complete_params.h"
16+
#include "ui/gfx/vsync_provider.h"
17+
#include "ui/gl/gl_context.h"
18+
#include "ui/gl/gl_features.h"
19+
20+
namespace gpu {
21+
22+
namespace {
23+
// Number of swap generations before vsync is reenabled after we've stopped
24+
// doing multiple swaps per frame.
25+
const int kMultiWindowSwapEnableVSyncDelay = 60;
26+
27+
int g_current_swap_generation_ = 0;
28+
int g_num_swaps_in_current_swap_generation_ = 0;
29+
int g_last_multi_window_swap_generation_ = 0;
30+
31+
} // anonymous namespace
32+
33+
PassThroughImageTransportSurface::PassThroughImageTransportSurface(
34+
base::WeakPtr<ImageTransportSurfaceDelegate> delegate,
35+
gl::GLSurface* surface,
36+
bool override_vsync_for_multi_window_swap)
37+
: GLSurfaceAdapter(surface),
38+
is_gpu_vsync_disabled_(!features::UseGpuVsync()),
39+
is_multi_window_swap_vsync_override_enabled_(
40+
override_vsync_for_multi_window_swap),
41+
delegate_(delegate) {}
42+
43+
PassThroughImageTransportSurface::~PassThroughImageTransportSurface() = default;
44+
45+
bool PassThroughImageTransportSurface::Initialize(gl::GLSurfaceFormat format) {
46+
// The surface is assumed to have already been initialized.
47+
return true;
48+
}
49+
50+
gfx::SwapResult PassThroughImageTransportSurface::SwapBuffers(
51+
PresentationCallback callback,
52+
gfx::FrameData data) {
53+
StartSwapBuffers();
54+
gfx::SwapResult result =
55+
gl::GLSurfaceAdapter::SwapBuffers(std::move(callback), data);
56+
return result;
57+
}
58+
59+
void PassThroughImageTransportSurface::SwapBuffersAsync(
60+
SwapCompletionCallback completion_callback,
61+
PresentationCallback presentation_callback,
62+
gfx::FrameData data) {
63+
StartSwapBuffers();
64+
65+
gl::GLSurfaceAdapter::SwapBuffersAsync(
66+
std::move(completion_callback), std::move(presentation_callback), data);
67+
}
68+
69+
gfx::SwapResult PassThroughImageTransportSurface::SwapBuffersWithBounds(
70+
const std::vector<gfx::Rect>& rects,
71+
PresentationCallback callback,
72+
gfx::FrameData data) {
73+
StartSwapBuffers();
74+
gfx::SwapResult result = gl::GLSurfaceAdapter::SwapBuffersWithBounds(
75+
rects, std::move(callback), data);
76+
return result;
77+
}
78+
79+
gfx::SwapResult PassThroughImageTransportSurface::PostSubBuffer(
80+
int x,
81+
int y,
82+
int width,
83+
int height,
84+
PresentationCallback callback,
85+
gfx::FrameData data) {
86+
StartSwapBuffers();
87+
gfx::SwapResult result = gl::GLSurfaceAdapter::PostSubBuffer(
88+
x, y, width, height, std::move(callback), data);
89+
90+
return result;
91+
}
92+
93+
void PassThroughImageTransportSurface::PostSubBufferAsync(
94+
int x,
95+
int y,
96+
int width,
97+
int height,
98+
SwapCompletionCallback completion_callback,
99+
PresentationCallback presentation_callback,
100+
gfx::FrameData data) {
101+
StartSwapBuffers();
102+
gl::GLSurfaceAdapter::PostSubBufferAsync(x, y, width, height,
103+
104+
std::move(completion_callback),
105+
106+
std::move(presentation_callback),
107+
data);
108+
}
109+
110+
void PassThroughImageTransportSurface::SetVSyncEnabled(bool enabled) {
111+
if (vsync_enabled_ == enabled)
112+
return;
113+
vsync_enabled_ = enabled;
114+
GLSurfaceAdapter::SetVSyncEnabled(enabled);
115+
}
116+
117+
void PassThroughImageTransportSurface::TrackMultiSurfaceSwap() {
118+
// This code is a simple way of enforcing that we only vsync if one surface
119+
// is swapping per frame. This provides single window cases a stable refresh
120+
// while allowing multi-window cases to not slow down due to multiple syncs
121+
// on a single thread. A better way to fix this problem would be to have
122+
// each surface present on its own thread.
123+
if (g_current_swap_generation_ == swap_generation_) {
124+
// No other surface has swapped since we swapped last time.
125+
if (g_num_swaps_in_current_swap_generation_ > 1)
126+
g_last_multi_window_swap_generation_ = g_current_swap_generation_;
127+
g_num_swaps_in_current_swap_generation_ = 0;
128+
g_current_swap_generation_++;
129+
}
130+
131+
swap_generation_ = g_current_swap_generation_;
132+
g_num_swaps_in_current_swap_generation_++;
133+
134+
multiple_surfaces_swapped_ =
135+
(g_num_swaps_in_current_swap_generation_ > 1) ||
136+
(g_current_swap_generation_ - g_last_multi_window_swap_generation_ <
137+
kMultiWindowSwapEnableVSyncDelay);
138+
}
139+
140+
void PassThroughImageTransportSurface::UpdateVSyncEnabled() {
141+
if (is_gpu_vsync_disabled_) {
142+
return;
143+
}
144+
145+
if (is_multi_window_swap_vsync_override_enabled_) {
146+
SetVSyncEnabled(!multiple_surfaces_swapped_);
147+
}
148+
}
149+
150+
void PassThroughImageTransportSurface::StartSwapBuffers() {
151+
TrackMultiSurfaceSwap();
152+
UpdateVSyncEnabled();
153+
}
154+
155+
} // namespace gpu
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
// Copyright 2016 The Chromium Authors
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#ifndef GPU_IPC_SERVICE_PASS_THROUGH_IMAGE_TRANSPORT_SURFACE_H_
6+
#define GPU_IPC_SERVICE_PASS_THROUGH_IMAGE_TRANSPORT_SURFACE_H_
7+
8+
#include <stdint.h>
9+
10+
#include <memory>
11+
#include <vector>
12+
13+
#include "base/containers/queue.h"
14+
#include "base/memory/weak_ptr.h"
15+
#include "gpu/ipc/service/image_transport_surface.h"
16+
#include "gpu/ipc/service/image_transport_surface_delegate.h"
17+
#include "ui/gl/gl_surface.h"
18+
19+
namespace gpu {
20+
21+
// An implementation of ImageTransportSurface that implements GLSurface through
22+
// GLSurfaceAdapter, thereby forwarding GLSurface methods through to it.
23+
class PassThroughImageTransportSurface : public gl::GLSurfaceAdapter {
24+
public:
25+
PassThroughImageTransportSurface(
26+
base::WeakPtr<ImageTransportSurfaceDelegate> delegate,
27+
gl::GLSurface* surface,
28+
bool override_vsync_for_multi_window_swap);
29+
30+
PassThroughImageTransportSurface(const PassThroughImageTransportSurface&) =
31+
delete;
32+
PassThroughImageTransportSurface& operator=(
33+
const PassThroughImageTransportSurface&) = delete;
34+
35+
// GLSurface implementation.
36+
bool Initialize(gl::GLSurfaceFormat format) override;
37+
gfx::SwapResult SwapBuffers(PresentationCallback callback,
38+
gfx::FrameData data) override;
39+
void SwapBuffersAsync(SwapCompletionCallback completion_callback,
40+
PresentationCallback presentation_callback,
41+
gfx::FrameData data) override;
42+
gfx::SwapResult SwapBuffersWithBounds(const std::vector<gfx::Rect>& rects,
43+
PresentationCallback callback,
44+
gfx::FrameData data) override;
45+
gfx::SwapResult PostSubBuffer(int x,
46+
int y,
47+
int width,
48+
int height,
49+
PresentationCallback callback,
50+
gfx::FrameData data) override;
51+
void PostSubBufferAsync(int x,
52+
int y,
53+
int width,
54+
int height,
55+
SwapCompletionCallback completion_callback,
56+
PresentationCallback presentation_callback,
57+
gfx::FrameData data) override;
58+
void SetVSyncEnabled(bool enabled) override;
59+
60+
private:
61+
~PassThroughImageTransportSurface() override;
62+
63+
void TrackMultiSurfaceSwap();
64+
void UpdateVSyncEnabled();
65+
66+
void StartSwapBuffers();
67+
68+
const bool is_gpu_vsync_disabled_;
69+
const bool is_multi_window_swap_vsync_override_enabled_;
70+
base::WeakPtr<ImageTransportSurfaceDelegate> delegate_;
71+
int swap_generation_ = 0;
72+
bool vsync_enabled_ = true;
73+
bool multiple_surfaces_swapped_ = false;
74+
};
75+
76+
} // namespace gpu
77+
78+
#endif // GPU_IPC_SERVICE_PASS_THROUGH_IMAGE_TRANSPORT_SURFACE_H_

0 commit comments

Comments
 (0)