-
Notifications
You must be signed in to change notification settings - Fork 13
/
viz_osr_2575.patch
578 lines (528 loc) · 25.8 KB
/
viz_osr_2575.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
diff --git components/viz/common/features.cc components/viz/common/features.cc
index 6b08754c40c6ad50f6bfa70a1054e301c7fefb75..7045c2af9ceb55179523b9a37d337c40a7456346 100644
--- components/viz/common/features.cc
+++ components/viz/common/features.cc
@@ -71,7 +71,13 @@ const base::Feature kSimpleFrameRateThrottling{
// Use the SkiaRenderer.
const base::Feature kUseSkiaRenderer{"UseSkiaRenderer",
- base::FEATURE_ENABLED_BY_DEFAULT};
+#if defined(OS_ANDROID) || BUILDFLAG(IS_CHROMEOS_LACROS) || \
+ defined(OS_LINUX) || defined(OS_FUCHSIA)
+ base::FEATURE_ENABLED_BY_DEFAULT
+#else
+ base::FEATURE_DISABLED_BY_DEFAULT
+#endif
+};
// Kill-switch to disable de-jelly, even if flags/properties indicate it should
// be enabled.
diff --git components/viz/host/host_display_client.cc components/viz/host/host_display_client.cc
index d3970b4d86e1fadc5321e99be20813c0f811d6b3..0247ed7fecec2f9e3016948028e61495cdb958d3 100644
--- components/viz/host/host_display_client.cc
+++ components/viz/host/host_display_client.cc
@@ -46,9 +46,14 @@ void HostDisplayClient::OnDisplayReceivedCALayerParams(
}
#endif
-#if BUILDFLAG(IS_WIN)
+void HostDisplayClient::UseProxyOutputDevice(
+ UseProxyOutputDeviceCallback callback) {
+ std::move(callback).Run(false);
+}
+
void HostDisplayClient::CreateLayeredWindowUpdater(
mojo::PendingReceiver<mojom::LayeredWindowUpdater> receiver) {
+#if BUILDFLAG(IS_WIN)
if (!NeedsToUseLayerWindow(widget_)) {
DLOG(ERROR) << "HWND shouldn't be using a layered window";
return;
@@ -56,9 +61,12 @@ void HostDisplayClient::CreateLayeredWindowUpdater(
layered_window_updater_ =
std::make_unique<LayeredWindowUpdaterImpl>(widget_, std::move(receiver));
-}
#endif
+}
+void HostDisplayClient::CreateExternalRendererUpdater(
+ mojo::PendingReceiver<mojom::ExternalRendererUpdater> receiver) {
+}
// TODO(crbug.com/1052397): Revisit the macro expression once build flag switch
// of lacros-chrome is complete.
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS_LACROS)
diff --git components/viz/host/host_display_client.h components/viz/host/host_display_client.h
index 1c2885c42f4947bb22ce87c8b2d649689b278da1..9d4ad93b3faa1d64bb01d3a637242168c9c7b358 100644
--- components/viz/host/host_display_client.h
+++ components/viz/host/host_display_client.h
@@ -14,6 +14,7 @@
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "services/viz/privileged/mojom/compositing/display_private.mojom.h"
+#include "cef/libcef/browser/osr/external_renderer_updater.mojom.h"
#include "ui/gfx/native_widget_types.h"
namespace viz {
@@ -34,17 +35,20 @@ class VIZ_HOST_EXPORT HostDisplayClient : public mojom::DisplayClient {
mojo::PendingRemote<mojom::DisplayClient> GetBoundRemote(
scoped_refptr<base::SingleThreadTaskRunner> task_runner);
- private:
+ protected:
// mojom::DisplayClient implementation:
+ void UseProxyOutputDevice(UseProxyOutputDeviceCallback callback) override;
+
#if BUILDFLAG(IS_APPLE)
void OnDisplayReceivedCALayerParams(
const gfx::CALayerParams& ca_layer_params) override;
#endif
-#if BUILDFLAG(IS_WIN)
void CreateLayeredWindowUpdater(
mojo::PendingReceiver<mojom::LayeredWindowUpdater> receiver) override;
-#endif
+
+ void CreateExternalRendererUpdater(
+ mojo::PendingReceiver<mojom::ExternalRendererUpdater> receiver) override;
// TODO(crbug.com/1052397): Revisit the macro expression once build flag switch
// of lacros-chrome is complete.
diff --git components/viz/host/layered_window_updater_impl.cc components/viz/host/layered_window_updater_impl.cc
index b04f654fe820f821b18e059cdd40085fc2384c4e..131977a36591d5d2f89923007f89ea2beaf9bdea 100644
--- components/viz/host/layered_window_updater_impl.cc
+++ components/viz/host/layered_window_updater_impl.cc
@@ -44,7 +44,7 @@ void LayeredWindowUpdaterImpl::OnAllocatedSharedMemory(
// |region|'s handle will close when it goes out of scope.
}
-void LayeredWindowUpdaterImpl::Draw(DrawCallback draw_callback) {
+void LayeredWindowUpdaterImpl::Draw(const gfx::Rect& damage_rect, DrawCallback draw_callback) {
TRACE_EVENT0("viz", "LayeredWindowUpdaterImpl::Draw");
if (!canvas_) {
diff --git components/viz/host/layered_window_updater_impl.h components/viz/host/layered_window_updater_impl.h
index 309422bcf85810db88a048bd0930c4072b41f234..759549f3046f4a897b597409b670bb1c2de7bec0 100644
--- components/viz/host/layered_window_updater_impl.h
+++ components/viz/host/layered_window_updater_impl.h
@@ -38,7 +38,7 @@ class VIZ_HOST_EXPORT LayeredWindowUpdaterImpl
// mojom::LayeredWindowUpdater implementation.
void OnAllocatedSharedMemory(const gfx::Size& pixel_size,
base::UnsafeSharedMemoryRegion region) override;
- void Draw(DrawCallback draw_callback) override;
+ void Draw(const gfx::Rect& damage_rect, DrawCallback draw_callback) override;
private:
const HWND hwnd_;
diff --git components/viz/service/display_embedder/output_surface_provider_impl.cc components/viz/service/display_embedder/output_surface_provider_impl.cc
index 8a277c6337d446890bb32814a68db2a9d3d3cd72..ac9c73ca69a229c3dd35965a3c3e606dc77a17bf 100644
--- components/viz/service/display_embedder/output_surface_provider_impl.cc
+++ components/viz/service/display_embedder/output_surface_provider_impl.cc
@@ -17,6 +17,8 @@
#include "build/chromecast_buildflags.h"
#include "build/chromeos_buildflags.h"
#include "cc/base/switches.h"
+#include "cef/libcef/browser/osr/gl_output_surface_external.h"
+#include "cef/libcef/browser/osr/software_output_device_proxy.h"
#include "components/viz/common/display/renderer_settings.h"
#include "components/viz/common/frame_sinks/begin_frame_source.h"
#include "components/viz/service/display/display_compositor_memory_and_task_controller.h"
@@ -39,6 +41,7 @@
#include "gpu/ipc/scheduler_sequence.h"
#include "gpu/ipc/service/gpu_channel_manager_delegate.h"
#include "gpu/ipc/service/image_transport_surface.h"
+#include "mojo/public/cpp/bindings/sync_call_restrictions.h"
#include "ui/base/ui_base_switches.h"
#include "ui/gl/gl_context.h"
#include "ui/gl/init/gl_factory.h"
@@ -209,8 +212,19 @@ std::unique_ptr<OutputSurface> OutputSurfaceProviderImpl::CreateOutputSurface(
}
if (surface_handle == gpu::kNullSurfaceHandle) {
- output_surface = std::make_unique<GLOutputSurfaceOffscreen>(
- std::move(context_provider));
+ mojo::ScopedAllowSyncCallForTesting allow_sync;
+ bool use_proxy_output_device = false;
+ if (display_client->UseProxyOutputDevice(&use_proxy_output_device) &&
+ use_proxy_output_device) {
+ mojo::Remote<viz::mojom::ExternalRendererUpdater> external_renderer_updater;
+ display_client->CreateExternalRendererUpdater(external_renderer_updater.BindNewPipeAndPassReceiver());
+ output_surface = std::make_unique<GLOutputSurfaceExternal>(
+ std::move(context_provider), gpu_memory_buffer_manager_.get(),
+ std::move(external_renderer_updater));
+ } else {
+ output_surface = std::make_unique<GLOutputSurfaceOffscreen>(
+ std::move(context_provider));
+ }
} else if (context_provider->ContextCapabilities().surfaceless) {
#if defined(USE_OZONE) || BUILDFLAG(IS_APPLE) || BUILDFLAG(IS_ANDROID)
output_surface = std::make_unique<GLOutputSurfaceBufferQueue>(
@@ -247,6 +261,20 @@ OutputSurfaceProviderImpl::CreateSoftwareOutputDeviceForPlatform(
if (headless_)
return std::make_unique<SoftwareOutputDevice>();
+ {
+ mojo::ScopedAllowSyncCallForTesting allow_sync;
+ DCHECK(display_client);
+ bool use_proxy_output_device = false;
+ if (display_client->UseProxyOutputDevice(&use_proxy_output_device) &&
+ use_proxy_output_device) {
+ mojo::PendingRemote<mojom::LayeredWindowUpdater> layered_window_updater;
+ display_client->CreateLayeredWindowUpdater(
+ layered_window_updater.InitWithNewPipeAndPassReceiver());
+ return std::make_unique<SoftwareOutputDeviceProxy>(
+ std::move(layered_window_updater));
+ }
+ }
+
#if BUILDFLAG(IS_WIN)
return CreateSoftwareOutputDeviceWin(surface_handle, &output_device_backing_,
display_client);
diff --git components/viz/service/display_embedder/software_output_device_win.cc components/viz/service/display_embedder/software_output_device_win.cc
index 583e3e2525c753a0962d481fc67a3582df75d0e9..e1836039ad8a50ce05dbb700a7a8c2814bb72fa3 100644
--- components/viz/service/display_embedder/software_output_device_win.cc
+++ components/viz/service/display_embedder/software_output_device_win.cc
@@ -191,8 +191,9 @@ void SoftwareOutputDeviceWinProxy::EndPaintDelegated(
if (!canvas_)
return;
- layered_window_updater_->Draw(base::BindOnce(
- &SoftwareOutputDeviceWinProxy::DrawAck, base::Unretained(this)));
+ layered_window_updater_->Draw(
+ damage_rect, base::BindOnce(&SoftwareOutputDeviceWinProxy::DrawAck,
+ base::Unretained(this)));
waiting_on_draw_ack_ = true;
TRACE_EVENT_ASYNC_BEGIN0("viz", "SoftwareOutputDeviceWinProxy::Draw", this);
diff --git components/viz/service/BUILD.gn components/viz/service/BUILD.gn
index fe988e3bbcf0c9deb5592f24fdeda3016114e3bf..59531b68106cde534771f644bdea4937fa5eb826 100644
--- components/viz/service/BUILD.gn
+++ components/viz/service/BUILD.gn
@@ -221,6 +221,10 @@ viz_component("service") {
"transitions/transferable_resource_tracker.cc",
"transitions/transferable_resource_tracker.h",
"viz_service_export.h",
+ "//cef/libcef/browser/osr/gl_output_surface_external.cc",
+ "//cef/libcef/browser/osr/gl_output_surface_external.h",
+ "//cef/libcef/browser/osr/software_output_device_proxy.cc",
+ "//cef/libcef/browser/osr/software_output_device_proxy.h",
]
defines = [ "VIZ_SERVICE_IMPLEMENTATION" ]
diff --git content/browser/compositor/viz_process_transport_factory.cc content/browser/compositor/viz_process_transport_factory.cc
index 0e3af0f9280abe8560393325b400ad2543ed0556..8a1e93995b316a7d4ed5ec8cf3b52a4e77eaf62a 100644
--- content/browser/compositor/viz_process_transport_factory.cc
+++ content/browser/compositor/viz_process_transport_factory.cc
@@ -381,8 +381,13 @@ void VizProcessTransportFactory::OnEstablishedGpuChannel(
compositor_data.display_private.reset();
root_params->display_private =
compositor_data.display_private.BindNewEndpointAndPassReceiver();
- compositor_data.display_client =
- std::make_unique<HostDisplayClient>(compositor);
+ if (compositor->delegate()) {
+ compositor_data.display_client =
+ compositor->delegate()->CreateHostDisplayClient();
+ } else {
+ compositor_data.display_client =
+ std::make_unique<HostDisplayClient>(compositor);
+ }
root_params->display_client =
compositor_data.display_client->GetBoundRemote(resize_task_runner_);
diff --git gpu/ipc/common/dxgi_helpers.cc gpu/ipc/common/dxgi_helpers.cc
index 811fb1e995ccbb45bfc5c4976d20a6d202cdc66f..e142cb1d2f003b78360d1138e8a31ac91cbb654c 100644
--- gpu/ipc/common/dxgi_helpers.cc
+++ gpu/ipc/common/dxgi_helpers.cc
@@ -118,23 +118,6 @@ bool CopyDXGIBufferToShMem(
Microsoft::WRL::ComPtr<ID3D11DeviceContext> device_context;
d3d11_device->GetImmediateContext(&device_context);
- Microsoft::WRL::ComPtr<IDXGIKeyedMutex> keyed_mutex;
- hr = texture.As(&keyed_mutex);
-
- if (FAILED(hr)) {
- DLOG(ERROR) << "Failed to get keyed mutex. hr=" << std::hex << hr;
- return false;
- }
-
- // Key equal to 0 is also used by the producer. Therefore, this keyed mutex
- // acts purely as a regular mutex.
- hr = keyed_mutex->AcquireSync(0, INFINITE);
- if (FAILED(hr)) {
- DLOG(ERROR) << "Failed to acquire keyed mutex. hr=" << std::hex << hr;
- return false;
- }
- DXGIScopedReleaseKeyedMutex release_keyed_mutex(keyed_mutex, 0);
-
device_context->CopySubresourceRegion(staging_texture->Get(), 0, 0, 0, 0,
texture.Get(), 0, nullptr);
diff --git gpu/ipc/common/gpu_memory_buffer_impl_dxgi.cc gpu/ipc/common/gpu_memory_buffer_impl_dxgi.cc
index 12f546291af33f1402e4932d7ff9a9ff8f4ccc38..eb88dfdbba48ec371d478c1c735646d143c05c64 100644
--- gpu/ipc/common/gpu_memory_buffer_impl_dxgi.cc
+++ gpu/ipc/common/gpu_memory_buffer_impl_dxgi.cc
@@ -68,7 +68,7 @@ base::OnceClosure GpuMemoryBufferImplDXGI::AllocateForTesting(
D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET,
0,
D3D11_RESOURCE_MISC_SHARED_NTHANDLE |
- D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX};
+ D3D11_RESOURCE_MISC_SHARED};
Microsoft::WRL::ComPtr<ID3D11Texture2D> d3d11_texture;
diff --git gpu/ipc/service/gpu_memory_buffer_factory_dxgi.cc gpu/ipc/service/gpu_memory_buffer_factory_dxgi.cc
index af8364900c81458a4be54331502dd299d20916e2..4d47b62a4f2c0cf51c034f5ba4c82dd4f4ff2e7f 100644
--- gpu/ipc/service/gpu_memory_buffer_factory_dxgi.cc
+++ gpu/ipc/service/gpu_memory_buffer_factory_dxgi.cc
@@ -127,10 +127,10 @@ gfx::GpuMemoryBufferHandle GpuMemoryBufferFactoryDXGI::CreateGpuMemoryBuffer(
dxgi_format,
{1, 0},
D3D11_USAGE_DEFAULT,
- D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET,
+ D3D11_BIND_SHADER_RESOURCE,
0,
D3D11_RESOURCE_MISC_SHARED_NTHANDLE |
- D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX};
+ D3D11_RESOURCE_MISC_SHARED};
Microsoft::WRL::ComPtr<ID3D11Texture2D> d3d11_texture;
diff --git media/capture/video/win/gpu_memory_buffer_tracker.cc media/capture/video/win/gpu_memory_buffer_tracker.cc
index 91ac2af43e9cdd7f09f5d61a56894e91408e713b..4e92d302235e5d68b5e17fc7b80313324469cd57 100644
--- media/capture/video/win/gpu_memory_buffer_tracker.cc
+++ media/capture/video/win/gpu_memory_buffer_tracker.cc
@@ -35,7 +35,7 @@ base::win::ScopedHandle CreateNV12Texture(ID3D11Device* d3d11_device,
.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET,
.CPUAccessFlags = 0,
.MiscFlags = D3D11_RESOURCE_MISC_SHARED_NTHANDLE |
- D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX};
+ D3D11_RESOURCE_MISC_SHARED};
Microsoft::WRL::ComPtr<ID3D11Texture2D> d3d11_texture;
diff --git mojo/public/cpp/bindings/sync_call_restrictions.h mojo/public/cpp/bindings/sync_call_restrictions.h
index e7e67ee824b2a87eb14b45a3f2d76d471ff864fb..bb044cff83f584ac0a61db0e844ef5dea474b67a 100644
--- mojo/public/cpp/bindings/sync_call_restrictions.h
+++ mojo/public/cpp/bindings/sync_call_restrictions.h
@@ -42,6 +42,7 @@ class Compositor;
} // namespace ui
namespace viz {
+class GpuDisplayProvider;
class GpuHostImpl;
class HostFrameSinkManager;
class HostGpuMemoryBufferManager;
@@ -104,6 +105,8 @@ class COMPONENT_EXPORT(MOJO_CPP_BINDINGS) SyncCallRestrictions {
// For preventing frame swaps of wrong size during resize on Windows.
// (https://crbug.com/811945)
friend class ui::Compositor;
+ // For query of whether to use SoftwareOutputDevice or not.
+ friend class viz::GpuDisplayProvider;
// For calling sync mojo API to get cdm origin. The service and the client are
// running in the same process, so it won't block anything.
// TODO(159346933) Remove once the origin isolation logic is moved outside of
diff --git services/viz/privileged/mojom/compositing/BUILD.gn services/viz/privileged/mojom/compositing/BUILD.gn
index a3cf3488f98372fe777e818edfe8e812dc06300e..66af223c85f03b186bb0152870742e7ea9d9f5e1 100644
--- services/viz/privileged/mojom/compositing/BUILD.gn
+++ services/viz/privileged/mojom/compositing/BUILD.gn
@@ -19,6 +19,7 @@ mojom("compositing") {
]
public_deps = [
+ "//cef/libcef/browser/osr",
"//gpu/ipc/common:interfaces",
"//media/capture/mojom:video_capture",
"//media/mojo/mojom",
diff --git services/viz/privileged/mojom/compositing/display_private.mojom services/viz/privileged/mojom/compositing/display_private.mojom
index b2f873919d68633103d115d7d9550a098c1a254c..c5a32b44181c6b379617ad8241a1fa1cefed5492 100644
--- services/viz/privileged/mojom/compositing/display_private.mojom
+++ services/viz/privileged/mojom/compositing/display_private.mojom
@@ -13,6 +13,7 @@ import "ui/gfx/mojom/overlay_transform.mojom";
import "ui/gfx/mojom/transform.mojom";
import "ui/gfx/geometry/mojom/geometry.mojom";
import "ui/latency/mojom/latency_info.mojom";
+import "cef/libcef/browser/osr/external_renderer_updater.mojom";
import "services/viz/privileged/mojom/compositing/begin_frame_observer.mojom";
import "services/viz/privileged/mojom/compositing/layered_window_updater.mojom";
import "services/viz/privileged/mojom/compositing/vsync_parameter_observer.mojom";
@@ -97,14 +98,19 @@ interface DisplayPrivate {
};
interface DisplayClient {
+ [Sync]
+ UseProxyOutputDevice() => (bool success);
+
[EnableIf=is_mac]
OnDisplayReceivedCALayerParams(gfx.mojom.CALayerParams ca_layer_params);
// Creates a LayeredWindowUpdater implementation to draw into a layered
// window.
- [EnableIf=is_win]
CreateLayeredWindowUpdater(pending_receiver<LayeredWindowUpdater> receiver);
+ // Creates an ExternalRendererUpdater
+ CreateExternalRendererUpdater(pending_receiver<ExternalRendererUpdater> receiver);
+
// Notifies that a swap has occurred and provides information about the pixel
// size of the swapped frame.
[EnableIf=is_android]
diff --git services/viz/privileged/mojom/compositing/layered_window_updater.mojom services/viz/privileged/mojom/compositing/layered_window_updater.mojom
index 6b7fbb6cf13dc8ee6ade0878a9a2c1efc5d4d3f1..e2af75168cb914a7b3b4a6c9b6a285498c3f8e72 100644
--- services/viz/privileged/mojom/compositing/layered_window_updater.mojom
+++ services/viz/privileged/mojom/compositing/layered_window_updater.mojom
@@ -26,5 +26,5 @@ interface LayeredWindowUpdater {
// Draws to the HWND by copying pixels from shared memory. Callback must be
// called after draw operation is complete to signal shared memory can be
// modified.
- Draw() => ();
+ Draw(gfx.mojom.Rect damage_rect) => ();
};
diff --git ui/compositor/compositor.h ui/compositor/compositor.h
index 2f6d2ee4160f24cb01ae0ce36e07f1ddcc5025df..f7d8dd233e580047fb4cc0052a7c3e59983e7eef 100644
--- ui/compositor/compositor.h
+++ ui/compositor/compositor.h
@@ -31,7 +31,9 @@
#include "components/viz/common/frame_sinks/begin_frame_args.h"
#include "components/viz/common/surfaces/frame_sink_id.h"
#include "components/viz/common/surfaces/subtree_capture_id.h"
+#include "components/viz/host/host_display_client.h"
#include "components/viz/host/host_frame_sink_client.h"
+#include "components/viz/service/display/software_output_device.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "services/viz/privileged/mojom/compositing/vsync_parameter_observer.mojom-forward.h"
#include "third_party/skia/include/core/SkColor.h"
@@ -139,6 +141,14 @@ class COMPOSITOR_EXPORT ContextFactory {
virtual viz::HostFrameSinkManager* GetHostFrameSinkManager() = 0;
};
+class COMPOSITOR_EXPORT CompositorDelegate {
+ public:
+ virtual std::unique_ptr<viz::HostDisplayClient> CreateHostDisplayClient() = 0;
+
+ protected:
+ virtual ~CompositorDelegate() {}
+};
+
// Compositor object to take care of GPU painting.
// A Browser compositor object is responsible for generating the final
// displayable form of pixels comprising a single widget's contents. It draws an
@@ -180,6 +190,9 @@ class COMPOSITOR_EXPORT Compositor : public base::PowerSuspendObserver,
// Schedules a redraw of the layer tree associated with this compositor.
void ScheduleDraw();
+ CompositorDelegate* delegate() const { return delegate_; }
+ void SetDelegate(CompositorDelegate* delegate) { delegate_ = delegate; }
+
// Sets the root of the layer tree drawn by this Compositor. The root layer
// must have no parent. The compositor's root layer is reset if the root layer
// is destroyed. NULL can be passed to reset the root layer, in which case the
@@ -478,6 +491,8 @@ class COMPOSITOR_EXPORT Compositor : public base::PowerSuspendObserver,
std::unique_ptr<PendingBeginFrameArgs> pending_begin_frame_args_;
+ CompositorDelegate* delegate_ = nullptr;
+
// The root of the Layer tree drawn by this compositor.
raw_ptr<Layer> root_layer_ = nullptr;
diff --git ui/gl/direct_composition_surface_win_unittest.cc ui/gl/direct_composition_surface_win_unittest.cc
index 67ede44cc15f42ca7e337f60b1adfbede7d15f81..741c3dd30425f08b00344aef8c645828c962c089 100644
--- ui/gl/direct_composition_surface_win_unittest.cc
+++ ui/gl/direct_composition_surface_win_unittest.cc
@@ -95,7 +95,7 @@ Microsoft::WRL::ComPtr<ID3D11Texture2D> CreateNV12Texture(
desc.SampleDesc.Count = 1;
desc.BindFlags = 0;
if (shared) {
- desc.MiscFlags = D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX |
+ desc.MiscFlags = D3D11_RESOURCE_MISC_SHARED |
D3D11_RESOURCE_MISC_SHARED_NTHANDLE;
}
diff --git ui/gl/gl_image_dxgi.cc ui/gl/gl_image_dxgi.cc
index 15c1166be9978ca040f35617f40dbbf81d50c164..6f05585e228cacffd6d34a5f86c1719b64e683d7 100644
--- ui/gl/gl_image_dxgi.cc
+++ ui/gl/gl_image_dxgi.cc
@@ -23,10 +23,6 @@
namespace gl {
namespace {
-// Keys used to acquire and release the keyed mutex. Will need to be kept in
-// sync with any other code that reads from or draws to the same DXGI handle.
-const static UINT64 KEY_BIND = 0;
-const static UINT64 KEY_RELEASE = 1;
bool SupportedBindFormat(gfx::BufferFormat format) {
switch (format) {
@@ -152,7 +148,6 @@ bool GLImageDXGI::BindTexImage(unsigned target) {
return true;
DCHECK(texture_);
- DCHECK(keyed_mutex_);
if (!SupportedBindFormat(buffer_format_))
return false;
@@ -166,14 +161,6 @@ bool GLImageDXGI::BindTexImage(unsigned target) {
return false;
}
- // We don't wait, just return immediately.
- HRESULT hrWait = keyed_mutex_->AcquireSync(KEY_BIND, 0);
-
- if (hrWait == WAIT_TIMEOUT || hrWait == WAIT_ABANDONED || FAILED(hrWait)) {
- NOTREACHED();
- return false;
- }
-
return eglBindTexImage(
gl::GLSurfaceEGL::GetGLDisplayEGL()->GetHardwareDisplay(),
surface_, EGL_BACK_BUFFER) == EGL_TRUE;
@@ -220,10 +207,18 @@ void GLImageDXGI::ReleaseTexImage(unsigned target) {
return;
DCHECK(texture_);
- DCHECK(keyed_mutex_);
-
- keyed_mutex_->ReleaseSync(KEY_RELEASE);
-
+ // Copy to the shared texture as a form of jank synchronization
+ if (staging_.Get() && texture_.Get()) {
+ Microsoft::WRL::ComPtr<ID3D11Device> d3d11_device;
+ staging_->GetDevice(&d3d11_device);
+ if (d3d11_device.Get()) {
+ Microsoft::WRL::ComPtr<ID3D11DeviceContext> d3d11_ctx;
+ d3d11_device->GetImmediateContext(&d3d11_ctx);
+ if (d3d11_ctx.Get()) {
+ d3d11_ctx->CopyResource(staging_.Get(), texture_.Get());
+ }
+ }
+ }
eglReleaseTexImage(gl::GLSurfaceEGL::GetGLDisplayEGL()->GetHardwareDisplay(),
surface_, EGL_BACK_BUFFER);
}
@@ -243,15 +238,20 @@ bool GLImageDXGI::InitializeHandle(base::win::ScopedHandle handle,
return false;
if (FAILED(d3d11_device1->OpenSharedResource1(handle.Get(),
- IID_PPV_ARGS(&texture_)))) {
+ IID_PPV_ARGS(&staging_)))) {
return false;
}
D3D11_TEXTURE2D_DESC desc;
- texture_->GetDesc(&desc);
+ staging_->GetDesc(&desc);
if (desc.ArraySize <= level_)
return false;
- if (FAILED(texture_.As(&keyed_mutex_)))
- return false;
+
+ desc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
+ desc.MiscFlags = 0;
+
+ if (FAILED(d3d11_device1->CreateTexture2D(&desc, nullptr, &texture_))) {
+ return false;
+ }
handle_ = std::move(handle);
return true;
diff --git ui/gl/gl_image_dxgi.h ui/gl/gl_image_dxgi.h
index 1facae06e891c5766b56168da3a9d2cbe0c932f1..91596e4e3c412358ac0d0a22746407528c64da42 100644
--- ui/gl/gl_image_dxgi.h
+++ ui/gl/gl_image_dxgi.h
@@ -44,7 +44,6 @@ class GL_EXPORT GLImageDXGI : public GLImage {
void ReleaseTexImage(unsigned target) override;
const gfx::ColorSpace& color_space() const { return color_space_; }
- Microsoft::WRL::ComPtr<IDXGIKeyedMutex> keyed_mutex() { return keyed_mutex_; }
size_t level() const { return level_; }
Microsoft::WRL::ComPtr<ID3D11Texture2D> texture() { return texture_; }
@@ -59,12 +58,12 @@ class GL_EXPORT GLImageDXGI : public GLImage {
gfx::BufferFormat buffer_format_ = gfx::BufferFormat::BGRA_8888;
base::win::ScopedHandle handle_;
- Microsoft::WRL::ComPtr<IDXGIKeyedMutex> keyed_mutex_;
size_t level_ = 0;
gfx::Size size_;
EGLSurface surface_ = nullptr;
EGLStreamKHR stream_ = nullptr;
Microsoft::WRL::ComPtr<ID3D11Texture2D> texture_;
+ Microsoft::WRL::ComPtr<ID3D11Texture2D> staging_;
};
// This copies to a new texture on bind.
diff --git ui/gl/gl_image_dxgi_unittest.cc ui/gl/gl_image_dxgi_unittest.cc
index 4499b93fda22ec21a2831c5ce051bfe6bb0772d2..f388966098b4469ead62d98d755f172e1c303241 100644
--- ui/gl/gl_image_dxgi_unittest.cc
+++ ui/gl/gl_image_dxgi_unittest.cc
@@ -36,7 +36,7 @@ class GLImageDXGITestDelegate : public GLImageTestDelegateBase {
desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET;
desc.CPUAccessFlags = 0;
desc.MiscFlags = D3D11_RESOURCE_MISC_SHARED_NTHANDLE |
- D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX;
+ D3D11_RESOURCE_MISC_SHARED;
std::vector<unsigned char> originalData(size.width() * size.height() * 4);
for (int x = 0; x < size.width(); ++x) {
diff --git ui/gl/swap_chain_presenter.cc ui/gl/swap_chain_presenter.cc
index 049fa2a2f56693829d0df0b9dc23084e0d2a002d..8c17b8e6eca053cb25bb19ee6d8449f2f01c651c 100644
--- ui/gl/swap_chain_presenter.cc
+++ ui/gl/swap_chain_presenter.cc
@@ -989,8 +989,7 @@ bool SwapChainPresenter::PresentToSwapChain(ui::DCRendererLayerParams& params) {
if (image_dxgi) {
input_texture = image_dxgi->texture();
input_level = image_dxgi->level();
- // Keyed mutex may not exist.
- keyed_mutex = image_dxgi->keyed_mutex();
+ // Keyed mutex does not exist. lol
input_color_space = image_dxgi->color_space();
} else if (image_d3d) {
input_texture = image_d3d->texture();