Skip to content

Commit 0fc4352

Browse files
committed
update: migrate some demos to chromium 110 version
1 parent d9989a3 commit 0fc4352

24 files changed

+251
-665
lines changed

README.md

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,25 @@ This project is used to demonstrate how to use some basic mechanisms in chromium
2020
2121
Demo list:
2222

23-
1. [v91] `demo_exe`: The simplest demo to demonstrate gn and create your own exe;
24-
1. [v91] `demo_log`: Demo log library;
25-
1. [v91] `demo_tracing_console`: Demonstrate using Trace to output to the console;
26-
1. [v91] `demo_task_thread_pool`: Demonstrate the use of thread pool ThreadPool;
27-
1. [v91] `demo_task_executor`: Demonstrate using the message loop SingleThreadTaskExecutor;
28-
1. [v91] `demo_callback`: Demo Bind&Callback related content;
29-
1. [v91] `demo_mojo_single_process`: Demonstrate the use of the `mojo` library in a single process;
30-
1. [v91] `demo_mojo_multiple_process`: Demonstrate the use of the `mojo` library in multiple processes;
31-
1. [v91] `demo_mojo_multiple_process_binding`: Demonstrate using the binding layer of the `mojo` library in multiple processes;
23+
1. [v110] `demo_exe`: The simplest demo to demonstrate gn and create your own exe;
24+
1. [v110] `demo_log`: Demo log library;
25+
1. [v110] `demo_tracing_console`: Demonstrate using Trace to output to the console;
26+
1. [v110] `demo_task_thread_pool`: Demonstrate the use of thread pool ThreadPool;
27+
1. [v110] `demo_task_executor`: Demonstrate using the message loop SingleThreadTaskExecutor;
28+
1. [v110] `demo_callback`: Demo Bind&Callback related content;
29+
1. [v110] `demo_mojo_single_process`: Demonstrate the use of the `mojo` library in a single process;
30+
1. [v110] `demo_mojo_multiple_process`: Demonstrate the use of the `mojo` library in multiple processes;
31+
1. [v110] `demo_mojo_multiple_process_binding`: Demonstrate using the binding layer of the `mojo` library in multiple processes;
3232
1. [v91] `demo_services`: Demonstrate the use of servcies and multi-process architecture based on `mojo`;
33-
1. [v91] `demo_ipc`: Demonstrate the use of IPC interface based on `mojo`;
33+
1. [v110] `demo_ipc`: Demonstrate the use of IPC interface based on `mojo`;
3434
1. [v91] `demo_mojo_v8`: Demonstrate the use of js to access the mojo interface;
35-
1. [v91] `demo_memory`: Demonstrate the use of SharedMemory;
36-
1. [v91] `demo_tracing_perfetto`: Demonstrate the output of Trace as Json format (used to interface with perfetto);
37-
1. [v91] `demo_tracing_perfetto_content`: Demonstrate how the content module is connected to perfetto;
38-
1. [v91] `demo_resources`: Demo resources related content, including grit, l10n, pak, etc.;
39-
1. [v91] `demo_gl`: Demonstrate using `//ui/gl` for GPU rendering;
35+
1. [v110] `demo_memory`: Demonstrate the use of SharedMemory;
36+
1. [v110] `demo_tracing_perfetto`: Demonstrate the output of Trace as Json format (used to interface with perfetto);
37+
1. [v110] `demo_tracing_perfetto_content`: Demonstrate how the content module is connected to perfetto;
38+
1. [v110] `demo_resources`: Demo resources related content, including grit, l10n, pak, etc.;
39+
1. [v110] `demo_gl`: Demonstrate using `//ui/gl` for GPU rendering;
4040
1. `demo_viz_gui`: Demonstrate using `viz` to display the GUI interface;
41-
1. [v91] `demo_viz_offscreen`: Demonstrate using `viz` for off-screen rendering;
41+
1. [v110] `demo_viz_offscreen`: Demonstrate using `viz` for off-screen rendering;
4242
1. `demo_viz_gui_gpu`: Demonstrate the use of `viz` for hardware accelerated rendering;
4343
1. `demo_viz_layer`: Demonstrate the use of `viz` for interactive rendering;
4444
1. `demo_viz_layer_offscreen`, demonstrate using VIZ's `CopyOutput` interface for off-screen rendering;
@@ -101,6 +101,10 @@ Public documents are in the [docs](./docs) directory, and other documents are in
101101
102102
## Changelog
103103
104+
### 2022.12.4
105+
106+
- Migrate some demo to v110;
107+
104108
### 2022.4.27
105109
106110
- Add demo_gin,demonstrate how to use gin to create a javascript runtime;

README_zh.md

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,25 @@
1313
1414
Demo 列表:
1515

16-
1. [v91] `demo_exe`: 最简单的 demo,演示 gn 及创建自己的 exe;
17-
1. [v91] `demo_log`: 演示使用日志库;
18-
1. [v91] `demo_tracing_console`: 演示使用 Trace 输出到控制台;
19-
1. [v91] `demo_task_thread_pool`: 演示使用线程池 ThreadPool 位于demo_task下;
20-
1. [v91] `demo_task_executor`: 演示使用消息循环 SingleThreadTaskExecutor 位于demo_task下;
21-
1. [v91] `demo_callback`: 演示 Bind&Callback 相关内容;
22-
1. [v91] `demo_mojo_single_process`: 演示在单进程中使用 `mojo` 库;
23-
1. [v91] `demo_mojo_multiple_process`: 演示在多进程中使用 `mojo` 库;
24-
1. [v91] `demo_mojo_multiple_process_binding`: 演示在多进程中使用 `mojo` 库的 binding 层;
16+
1. [v110] `demo_exe`: 最简单的 demo,演示 gn 及创建自己的 exe;
17+
1. [v110] `demo_log`: 演示使用日志库;
18+
1. [v110] `demo_tracing_console`: 演示使用 Trace 输出到控制台;
19+
1. [v110] `demo_task_thread_pool`: 演示使用线程池 ThreadPool 位于demo_task下;
20+
1. [v110] `demo_task_executor`: 演示使用消息循环 SingleThreadTaskExecutor 位于demo_task下;
21+
1. [v110] `demo_callback_(once|repeating)`: 演示 Bind&Callback 相关内容;
22+
1. [v110] `demo_mojo_single_process`: 演示在单进程中使用 `mojo` 库;
23+
1. [v110] `demo_mojo_multiple_process`: 演示在多进程中使用 `mojo` 库;
24+
1. [v110] `demo_mojo_multiple_process_binding`: 演示在多进程中使用 `mojo` 库的 binding 层;
2525
1. [v91] `demo_services`: 演示使用基于 `mojo` 的 servcies 及多进程架构;
26-
1. [v91] `demo_ipc`: 演示使用基于 `mojo` 的 IPC 接口;
26+
1. [v110] `demo_ipc`: 演示使用基于 `mojo` 的 IPC 接口;
2727
1. [v91] `demo_mojo_v8`: 演示使用 js 访问 mojo 接口;
28-
1. [v91] `demo_memory`: 演示使用 SharedMemory;
29-
1. [v91] `demo_tracing_perfetto`: 演示将 Trace 输出为 Json 格式(用来对接 perfetto);
30-
1. [v91] `demo_tracing_perfetto_content`: 演示 content 模块是如何对接 perfetto 的;
31-
1. [v91] `demo_resources`: 演示 resources 相关内容,包括 grit,l10n,pak 等;
32-
1. [v91] `demo_gl`: 演示使用 `//ui/gl` 进行 GPU 渲染;
28+
1. [v110] `demo_memory`: 演示使用 SharedMemory;
29+
1. [v110] `demo_tracing_perfetto`: 演示将 Trace 输出为 Json 格式(用来对接 perfetto);
30+
1. [v110] `demo_tracing_perfetto_content`: 演示 content 模块是如何对接 perfetto 的;
31+
1. [v110] `demo_resources`: 演示 resources 相关内容,包括 grit,l10n,pak 等;
32+
1. [v110] `demo_gl`: 演示使用 `//ui/gl` 进行 GPU 渲染;
3333
1. `demo_viz_gui`: 演示使用 `viz` 显示 GUI 界面;
34-
1. [v91] `demo_viz_offscreen`: 演示使用 `viz` 进行离屏渲染;
34+
1. [v110] `demo_viz_offscreen`: 演示使用 `viz` 进行离屏渲染;
3535
1. `demo_viz_gui_gpu`: 演示使用 `viz` 进行硬件加速渲染;
3636
1. `demo_viz_layer`: 演示使用 `viz` 进行交互渲染;
3737
1. `demo_viz_layer_offscreen`, 演示使用 VIZ 的 `CopyOutput` 接口进行离屏渲染;
@@ -92,6 +92,11 @@ Demo 列表:
9292
- 添加 demo, 演示 `tab capture api` 的原理;
9393
9494
## 更新日志
95+
96+
### 2022.12.4
97+
98+
- 升级一些 demo 到 110 版本;
99+
95100
### 2022.04.27
96101
97102
- 添加 demo_gin,演示如何使用gin创建一个简单的js运行时。

demo.cc

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,26 @@
1414
#include "base/task/single_thread_task_executor.h"
1515
#include "base/task/thread_pool/thread_pool_instance.h"
1616

17+
#include <errno.h>
18+
#include <limits.h>
19+
#include <sched.h>
20+
#include <signal.h>
21+
#include <stddef.h>
22+
#include <stdint.h>
23+
#include <stdio.h>
24+
#include <sys/syscall.h>
25+
#include <sys/types.h>
26+
#include <sys/wait.h>
27+
#include <unistd.h>
28+
29+
#include "base/bind.h"
30+
#include "base/compiler_specific.h"
31+
#include "base/files/file_path.h"
32+
#include "base/files/file_util.h"
33+
#include "base/logging.h"
34+
#include "base/posix/eintr_wrapper.h"
35+
#include "base/process/launch.h"
36+
1737
/**
1838
* 这个项目是个基础的入门demo,关于消息循环如果现在不明白可以先不用关注它,后面的
1939
* demo_task_executor 会专门演示它。
@@ -36,7 +56,19 @@ int main(int argc, char** argv) {
3656
// 复制当前文件来创建新的demo
3757
LOG(INFO) << "hello,world!";
3858

59+
const pid_t pid =
60+
base::ForkWithFlags(CLONE_NEWUSER | SIGCHLD, nullptr, nullptr);
61+
62+
if (pid == -1) {
63+
return -1;
64+
}
65+
66+
if (pid == 0) {
67+
_exit(0);
68+
}
69+
70+
3971
LOG(INFO) << "running...";
40-
base::RunLoop().Run();
72+
// base::RunLoop().Run();
4173
return 0;
4274
}

demo_cc/BUILD.gn

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ template("cc") {
2323
"//ui/platform_window",
2424
]
2525

26-
if (use_x11) {
26+
if (ozone_platform_x11) {
2727
deps += [
2828
"//ui/events/platform/x11",
29-
"//ui/platform_window/x11",
29+
"//ui/ozone",
3030
]
3131
#configs += [ "//build/config/linux:x11" ]
3232
}

demo_gl/BUILD.gn

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ executable("demo_gl") {
2727
# "//skia",
2828
]
2929

30-
if (use_x11) {
30+
if (ozone_platform_x11) {
3131
deps += [
3232
"//ui/events/platform/x11",
33-
"//ui/platform_window/x11",
33+
"//ui/ozone",
3434
]
3535
#configs += [ "//build/config/linux:x11" ]
3636
}

demo_gl/demo_gl.cc

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
1-
/**
2-
* 由于目前手上没有 Linux 设备可供调试UI,因此这个 demo 可能不能够直接运行,可能需要添加某些参数配置或者环境初始化代码;
3-
*/
4-
51
#include "base/at_exit.h"
62
#include "base/callback.h"
73
#include "base/command_line.h"
84
#include "base/files/file_path.h"
95
#include "base/i18n/icu_util.h"
106
#include "base/logging.h"
11-
#include "base/macros.h"
7+
// #include "base/macros.h"
128
#include "base/memory/ptr_util.h"
139
#include "base/message_loop/message_pump_type.h"
1410
#include "base/path_service.h"
@@ -135,6 +131,15 @@ class DemoWindowHost : public ui::PlatformWindowDelegate {
135131
// props.opacity = ui::PlatformWindowOpacity::kTranslucentWindow;
136132
// props.background_color = 0;
137133
#if defined(USE_OZONE)
134+
// Make Ozone run in single-process mode.
135+
ui::OzonePlatform::InitParams params;
136+
params.single_process = true;
137+
138+
// This initialization must be done after TaskEnvironment has
139+
// initialized the UI thread.
140+
ui::OzonePlatform::InitializeForUI(params);
141+
ui::OzonePlatform::InitializeForGPU(params);
142+
138143
return ui::OzonePlatform::GetInstance()->CreatePlatformWindow(
139144
this, std::move(props));
140145
#elif defined(OS_WIN)
@@ -153,9 +158,9 @@ class DemoWindowHost : public ui::PlatformWindowDelegate {
153158
DCHECK_NE(widget_, gfx::kNullAcceleratedWidget);
154159
TRACE_EVENT0("shell", "InitializeDemo");
155160
if (!g_gl_surface) {
156-
gl::init::InitializeGLOneOff();
161+
gl::GLDisplay* display = gl::init::InitializeGLOneOff(0);
157162

158-
g_gl_surface = gl::init::CreateViewGLSurface(widget_);
163+
g_gl_surface = gl::init::CreateViewGLSurface(display, widget_);
159164

160165
scoped_refptr<gl::GLShareGroup> share_group =
161166
base::MakeRefCounted<gl::GLShareGroup>();
@@ -180,11 +185,11 @@ class DemoWindowHost : public ui::PlatformWindowDelegate {
180185
static unsigned int i = 0;
181186
glClearColor(1.f, (i++) % 10 / 10.f + 0.1f, 0, 1.f);
182187
glClear(GL_COLOR_BUFFER_BIT);
183-
g_gl_surface->SwapBuffers(base::DoNothing());
188+
g_gl_surface->SwapBuffers(base::DoNothing(), gl::FrameData());
184189
base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
185190
FROM_HERE,
186191
base::BindOnce(&DemoWindowHost::InitializeDemo, base::Unretained(this)),
187-
base::TimeDelta::FromSeconds(1));
192+
base::Seconds(1));
188193
}
189194

190195
// ui::PlatformWindowDelegate:
@@ -193,12 +198,12 @@ class DemoWindowHost : public ui::PlatformWindowDelegate {
193198
void OnWillDestroyAcceleratedWidget() override {}
194199
void OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget) override {
195200
widget_ = widget;
196-
#if !defined(OS_WIN)
197-
// 如果需要去除窗口边框,将true改为false
198-
platform_window_->SetUseNativeFrame(true); // windows crash here
199-
#endif
200-
if (platform_window_)
201+
202+
if (platform_window_) {
203+
// 如果需要去除窗口边框,将true改为false
204+
platform_window_->SetUseNativeFrame(true);
201205
InitializeDemo();
206+
}
202207
}
203208

204209
void OnDamageRect(const gfx::Rect& damaged_region) override {}
@@ -233,7 +238,8 @@ class DemoWindowHost : public ui::PlatformWindowDelegate {
233238
if (close_closure_)
234239
std::move(close_closure_).Run();
235240
}
236-
void OnWindowStateChanged(ui::PlatformWindowState new_state) override {}
241+
void OnWindowStateChanged(ui::PlatformWindowState old_state,
242+
ui::PlatformWindowState new_state) override {}
237243
void OnLostCapture() override {}
238244
void OnAcceleratedWidgetDestroyed() override {}
239245
void OnActivationChanged(bool active) override {}
@@ -246,8 +252,6 @@ class DemoWindowHost : public ui::PlatformWindowDelegate {
246252
scoped_refptr<gl::GLSurface> g_gl_surface;
247253
scoped_refptr<gl::GLContext> g_gl_context;
248254
scoped_refptr<gpu::SharedContextState> g_context_state;
249-
250-
DISALLOW_COPY_AND_ASSIGN(DemoWindowHost);
251255
};
252256

253257
} // namespace demo
@@ -276,7 +280,7 @@ int main(int argc, char** argv) {
276280
base::ThreadPoolInstance::CreateAndStartWithDefaultParams("DemoGL");
277281

278282
// 在Linux上,x11和aura都是默认开启的
279-
#if defined(USE_X11)
283+
// #if defined(USE_X11)
280284
// This demo uses InProcessContextFactory which uses X on a separate Gpu
281285
// thread.
282286
// gfx::InitializeThreadedX11();
@@ -288,7 +292,7 @@ int main(int argc, char** argv) {
288292
// 错误,默认的Xlib异常处理会打印错误日志然后强制结束程序。
289293
// 这些错误大多是并发导致的代码执行顺序问题,所以修改起来没有那么容易。
290294
// ui::SetDefaultX11ErrorHandlers();
291-
#endif
295+
// #endif
292296

293297
auto event_source_ = ui::PlatformEventSource::CreateDefault();
294298

demo_ipc/demo_ipc.cc

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
#include "base/at_exit.h"
77
#include "base/command_line.h"
88
#include "base/logging.h"
9+
#include <base/run_loop.h>
910
#include "base/task/single_thread_task_executor.h"
10-
#include "base/task/post_task.h"
11+
// #include "base/task/post_task.h"
1112
#include "base/task/thread_pool/thread_pool_instance.h"
1213
#include "base/process/launch.h"
1314
#include "base/threading/thread.h"
@@ -33,7 +34,7 @@
3334

3435
// For bindings API
3536
// #include "mojo/public/cpp/bindings/binding.h"
36-
#include "mojo/public/cpp/bindings/interface_ptr.h"
37+
// #include "mojo/public/cpp/bindings/interface_ptr.h"
3738

3839
// For associated bindings API
3940
// #include "mojo/public/cpp/bindings/associated_binding.h"
@@ -52,28 +53,6 @@
5253
#include "ipc/message_filter.h"
5354

5455
#include "demo_ipc_messages.h"
55-
56-
// 在新版本中这些类被重命名,这里模拟新版本
57-
template <class T>
58-
using Remote = mojo::InterfacePtr<T>;
59-
template <class T>
60-
using PendingRemote = mojo::InterfacePtrInfo<T>;
61-
template <class T>
62-
using Receiver = mojo::Receiver<T>;
63-
// using Receiver = mojo::InterfaceRequest<T>;
64-
template <class T>
65-
using PendingReceiver = mojo::InterfaceRequest<T>;
66-
67-
// 以下定义用于模拟新版本的关联接口
68-
template <class T>
69-
using AssociatedRemote = mojo::AssociatedRemote<T>;
70-
template <class T>
71-
using PendingAssociatedRemote = mojo::AssociatedInterfacePtrInfo<T>;
72-
template <class T>
73-
using AssociatedReceiver = mojo::AssociatedReceiver<T>;
74-
template <class T>
75-
using PendingAssociatedReceiver = mojo::AssociatedInterfaceRequest<T>;
76-
7756
class ProducerListener : public IPC::Listener {
7857
public:
7958
ProducerListener(){}

demo_ipc/demo_ipc_messages.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
#ifndef DEMO_IPC_MESSAGES_H_
22
#define DEMO_IPC_MESSAGES_H_
33

4+
// #define IPC_MESSAGE_IMPL
45
#include "ipc/ipc_message.h"
56
#include "ipc/ipc_message_macros.h"
7+
#include "ipc/ipc_message_start.h"
68
#include "ipc/ipc_param_traits.h"
79

810
// 使用 IPCTestMsgStart 来测试,它不能随意命名,必须存在于 ipc/ipc_message_start.h 中

0 commit comments

Comments
 (0)