Chromium源码由浅入深(三)
接前一篇文章:Chromium源码由浅入深(二)
上一回说到了关键的“钥匙”:browserBridge.gpuInfo,本文就针对其进行深入探究。
先来看前半部分,browserBridge。
在content/browser/resources/gpu/gpu_internals.js中有以下代码:
import './info_view.js';import {BrowserBridge} from './browser_bridge.js';// Injected script from C++ or test environments may reference `browserBridge`
// as a property of the global object.
window.browserBridge = new BrowserBridge();/*** Main entry point. called once the page has loaded.*/
function onLoad() {// Create the views.document.querySelector('info-view').addBrowserBridgeListeners(window.browserBridge);// Because of inherent raciness (between the deprecated DevTools API which// telemtry uses to drive the relevant tests, and the asynchronous loading of// JS modules like this one) it's possible for telemetry tests to inject code// *before* `browserBridge` is set and the DOM is populated. This flag is used// to synchronize script injection by tests to prevent such races.window.gpuPagePopulated = true;
}document.addEventListener('DOMContentLoaded', onLoad);
代码注释说得清楚:从C++或测试环境注入的脚本可能引用“browserBridge”作为全局对象的属性。
BrowserBridge类的定义在Cromium源码中一共有两处,一处在chrome/browser/resources/net_internals/browser_bridge.js中,另一处在content/browser/resources/gpu/browser_bridge.js中。由于上边代码中是“import {BrowserBridge} from './browser_bridge.js';”,也就是引用的是当前路径下的browser_bridge.js,即content/browser/resources/gpu/下的browser_bridge.js,也就是第二处定义。
代码如下:
/*** This class provides a 'bridge' for communicating between javascript and the* browser. When run outside of WebUI, e.g. as a regular webpage, it provides* synthetic data to assist in testing.*/
export class BrowserBridge extends EventTarget {constructor() {super();this.nextRequestId_ = 0;this.pendingCallbacks_ = [];this.logMessages_ = [];// Tell c++ code that we are ready to receive GPU Info.chrome.send('browserBridgeInitialized');this.beginRequestClientInfo_();this.beginRequestLogMessages_();}dispatchEvent_(eventName) {this.dispatchEvent(new CustomEvent(eventName, {bubbles: true, composed: true}));}applySimulatedData_(data) {// set up things according to the simulated datathis.gpuInfo_ = data.gpuInfo;this.clientInfo_ = data.clientInfo;this.logMessages_ = data.logMessages;this.dispatchEvent_('gpuInfoUpdate');this.dispatchEvent_('clientInfoChange');this.dispatchEvent_('logMessagesChange');}/*** Sends a message to the browser with specified args. The* browser will reply asynchronously via the provided callback.*/callAsync(submessage, args, callback) {const requestId = this.nextRequestId_;this.nextRequestId_ += 1;this.pendingCallbacks_[requestId] = callback;if (!args) {chrome.send('callAsync', [requestId.toString(), submessage]);} else {const allArgs = [requestId.toString(), submessage].concat(args);chrome.send('callAsync', allArgs);}}/*** Called by gpu c++ code when client info is ready.*/onCallAsyncReply(requestId, args) {if (this.pendingCallbacks_[requestId] === undefined) {throw new Error('requestId ' + requestId + ' is not pending');}const callback = this.pendingCallbacks_[requestId];callback(args);delete this.pendingCallbacks_[requestId];}/*** Get gpuInfo data.*/get gpuInfo() {return this.gpuInfo_;}/*** Called from gpu c++ code when GPU Info is updated.*/onGpuInfoUpdate(gpuInfo) {this.gpuInfo_ = gpuInfo;this.dispatchEvent_('gpuInfoUpdate');}/*** This function begins a request for the ClientInfo. If it comes back* as undefined, then we will issue the request again in 250ms.*/beginRequestClientInfo_() {this.callAsync('requestClientInfo', undefined,(function(data) {if (data === undefined) { // try again in 250 mswindow.setTimeout(this.beginRequestClientInfo_.bind(this), 250);} else {this.clientInfo_ = data;this.dispatchEvent_('clientInfoChange');}}).bind(this));}/*** Returns information about the currently running Chrome build.*/get clientInfo() {return this.clientInfo_;}/*** This function checks for new GPU_LOG messages.* If any are found, a refresh is triggered.*/beginRequestLogMessages_() {this.callAsync('requestLogMessages', undefined,(function(messages) {if (messages.length !== this.logMessages_.length) {this.logMessages_ = messages;this.dispatchEvent_('logMessagesChange');}// check again in 250 mswindow.setTimeout(this.beginRequestLogMessages_.bind(this), 250);}).bind(this));}/*** Returns an array of log messages issued by the GPU process, if any.*/get logMessages() {return this.logMessages_;}/*** Returns the value of the "Sandboxed" row.*/isSandboxedForTesting() {for (const info of this.gpuInfo_.basicInfo) {if (info.description === 'Sandboxed') {return info.value;}}return false;}
}
再来看后半部分,gpuInfo。
在上边content/browser/resources/gpu/gpu_internals.js的代码中有以下一段:
/*** Main entry point. called once the page has loaded.*/
function onLoad() {// Create the views.document.querySelector('info-view').addBrowserBridgeListeners(window.browserBridge);
addBrowserBridgeListeners函数在content/browser/resources/gpu/info_view.js中,代码如下:
addBrowserBridgeListeners(browserBridge) {browserBridge.addEventListener('gpuInfoUpdate', this.refresh.bind(this, browserBridge));browserBridge.addEventListener('logMessagesChange', this.refresh.bind(this, browserBridge));browserBridge.addEventListener('clientInfoChange', this.refresh.bind(this, browserBridge));this.refresh(browserBridge);}
而'gpuInfoUpdate'这个关键字则有两处相关调用。一处在content/browser/resources/gpu/browser_bridge.js中,代码如下:
applySimulatedData_(data) {// set up things according to the simulated datathis.gpuInfo_ = data.gpuInfo;this.clientInfo_ = data.clientInfo;this.logMessages_ = data.logMessages;this.dispatchEvent_('gpuInfoUpdate');this.dispatchEvent_('clientInfoChange');this.dispatchEvent_('logMessagesChange');}
另一处也是在同文件中,代码如下:
/*** Called from gpu c++ code when GPU Info is updated.*/onGpuInfoUpdate(gpuInfo) {this.gpuInfo_ = gpuInfo;this.dispatchEvent_('gpuInfoUpdate');}
显然后者更为关键和常用。再次查找调用onGpuInfoUpdate函数的地方,只有一处,在content/browser/gpu/gpu_internals_ui.cc中,代码如下:
void GpuMessageHandler::OnGpuInfoUpdate() {// Get GPU Info.const gpu::GPUInfo gpu_info = GpuDataManagerImpl::GetInstance()->GetGPUInfo();const gfx::GpuExtraInfo gpu_extra_info =GpuDataManagerImpl::GetInstance()->GetGpuExtraInfo();base::Value::Dict gpu_info_val = GetGpuInfo();// Add in blocklisting featuresbase::Value::Dict feature_status;feature_status.Set("featureStatus", GetFeatureStatus());feature_status.Set("problems", GetProblems());base::Value::List workarounds;for (const auto& workaround : GetDriverBugWorkarounds())workarounds.Append(workaround);feature_status.Set("workarounds", std::move(workarounds));gpu_info_val.Set("featureStatus", std::move(feature_status));if (!GpuDataManagerImpl::GetInstance()->IsGpuProcessUsingHardwareGpu()) {const gpu::GPUInfo gpu_info_for_hardware_gpu =GpuDataManagerImpl::GetInstance()->GetGPUInfoForHardwareGpu();if (gpu_info_for_hardware_gpu.IsInitialized()) {base::Value::Dict feature_status_for_hardware_gpu;feature_status_for_hardware_gpu.Set("featureStatus",GetFeatureStatusForHardwareGpu());feature_status_for_hardware_gpu.Set("problems",GetProblemsForHardwareGpu());base::Value::List workarounds_for_hardware_gpu;for (const auto& workaround : GetDriverBugWorkaroundsForHardwareGpu())workarounds_for_hardware_gpu.Append(workaround);feature_status_for_hardware_gpu.Set("workarounds", std::move(workarounds_for_hardware_gpu));gpu_info_val.Set("featureStatusForHardwareGpu",std::move(feature_status_for_hardware_gpu));const gpu::GpuFeatureInfo gpu_feature_info_for_hardware_gpu =GpuDataManagerImpl::GetInstance()->GetGpuFeatureInfoForHardwareGpu();base::Value::List gpu_info_for_hardware_gpu_val = GetBasicGpuInfo(gpu_info_for_hardware_gpu, gpu_feature_info_for_hardware_gpu,gfx::GpuExtraInfo{});gpu_info_val.Set("basicInfoForHardwareGpu",std::move(gpu_info_for_hardware_gpu_val));}}gpu_info_val.Set("compositorInfo", CompositorInfo());gpu_info_val.Set("gpuMemoryBufferInfo", GpuMemoryBufferInfo(gpu_extra_info));gpu_info_val.Set("displayInfo", GetDisplayInfo());gpu_info_val.Set("videoAcceleratorsInfo", GetVideoAcceleratorsInfo());gpu_info_val.Set("ANGLEFeatures", GetANGLEFeatures());gpu_info_val.Set("devicePerfInfo", GetDevicePerfInfo());gpu_info_val.Set("dawnInfo", GetDawnInfo());// Send GPU Info to javascript.web_ui()->CallJavascriptFunctionUnsafe("browserBridge.onGpuInfoUpdate",std::move(gpu_info_val));
}
这个函数就是接下来要花大力气探究的核心函数。
欲知后事如何,且看下回分解。
相关文章:
Chromium源码由浅入深(三)
接前一篇文章:Chromium源码由浅入深(二) 上一回说到了关键的“钥匙”:browserBridge.gpuInfo,本文就针对其进行深入探究。 先来看前半部分,browserBridge。 在content/browser/resources/gpu/gpu_interna…...

如何集成验证码短信API到你的应用程序
引言 当你需要为你的应用程序增加安全性和用户验证功能时,集成验证码短信API是一个明智的选择。验证码短信API可以帮助你轻松实现用户验证、密码重置和账户恢复等功能,提高用户体验并增强应用程序的安全性。本文将介绍如何将验证码短信API集成到你的应用…...
Linux- 由映射文件I/O问题引出的SIGBUS 空洞文件(Sparse File)
SIGBUS SIGBUS是一个在Unix-like操作系统中的信号,它通常表示非法访问内存,而这种非法访问的原因与常见的SIGSEGV(段错误)有所不同。以下是可能导致SIGBUS的常见情况: 未对齐的内存访问:某些硬件平台要求数…...
代码随想录图论 第二天 | 695. 岛屿的最大面积 1020. 飞地的数量
代码随想录图论 第二天 | 695. 岛屿的最大面积 1020. 飞地的数量 一、695. 岛屿的最大面积 题目链接:https://leetcode.cn/problems/max-area-of-island/ 思路:典型的遍历模板题,我采用深度优先,每块岛屿递归遍历的时候计数&…...

R语言代码示例
以下是一个使用R语言和httrOAuth库的下载器程序,用于下载的内容。程序使用以下代码。 # 安装和加载必要的库 install.packages("httr") install.packages("httrOAuth") library(httr) library(httrOAuth) # 设置 http_proxy <- "du…...
ESP32网络开发实例-将 ESP32 连接到 EMQX Cloud MQTT Broker
将 ESP32 连接到 EMQX Cloud MQTT Broker 文章目录 将 ESP32 连接到 EMQX Cloud MQTT Broker1、MQTT介绍2、软件准备3、硬件准备4、代码实现5、MQTT测试在本文中,将介绍使用 EMQX Cloud MQTT 服务器。 首先,我们将介绍如何将 ESP32 开发板连接到 EMQX Cloud MQTT 服务器。 我…...

基于Kubesphere容器云平台物联网云平台Devops实践
基于Kubesphere容器云平台物联网云平台Devops实践 项目背景 公司是做工业物联网相关业务的,现业务是云平台,技术栈 后端为 Springboot2.7JDK11 ,前端为 Vue3Ts,需要搭建自动化运维平台以实现业务代码自动部署上线,…...

淘宝商品详情页API接口|tb获取商品主图接口
淘宝的 API 开发接口,我们需要做下面几件事情。 1)开放平台注册开发者账号; 2)然后为每个淘宝应用注册一个应用程序键(App Key) ; 3)下载淘宝 API 的 SDK 并掌握基本的 API 基础知识和调用&a…...

JAVA面试笔记
JAVA就业课程 面试整体流程 1.1 简单的自我介绍 我是xxxx,工作xxx年.我先后在xxxx公司、yyyy公司工作。先后做个xxxx项目、yyyy项目。 1.2 你简单介绍一下xxxx项目 为了解决xxxx问题,开发了一套xxxx系统,该系统主要有那些部分组成。简单介绍项目的整体架…...

尚硅谷Flume(仅有基础)
q 1 概述 1.1 定义 Flume 是Cloudera 提供的一个高可用的,高可靠的,分布式的海量日志采集、聚合和传输的系统。Flume 基于流式架构,灵活简单。 Flume最主要的作用就是,实时读取服务器本地磁盘的数据,将数据写入到HD…...
JS中this的绑定规则
如果有人问你this指向哪里?但又不给你说调用位置,那他就是在耍流氓。 – 龚港浩 1、默认绑定 首先要介绍的是最常用的函数调用类型:独立函数调用。可以把这条规则看作是无法应用其他规则时的默认规则。 function foo() {console.log( this…...

酷开科技 | 酷开系统大屏电视,打造精彩家庭场景
在信息资讯不发达的年代,电视机一直都是个人及家庭重要的信息获取渠道和家庭娱乐中心,是每个家庭必不可少的大家电之一!在快节奏的现代生活中,受手机和平板的冲击,电视机这个曾经的客厅“霸主”一度失去了“主角光环”…...
GDPU 数据结构 天码行空6
一、实验目的 1、掌握串的顺序存储结构 2、掌握顺序串的基本操作方法(插入、删除等)。 3、掌握串的链式存储结构。 4、掌握链式串的几种基本操作(插入、删除等)。 5、掌握Brute-Force算法 二、实验内容 1、编写函数BFIndex(Str…...

机器学习实验三:决策树-隐形眼镜分类(判断视力程度)
决策树-隐形眼镜分类(判断视力程度) Title : 使用决策树预测隐形眼镜类型 # Description :隐形眼镜数据是非常著名的数据集 ,它包含很多患者眼部状况的观察条件以及医生推荐的隐形眼镜类型 。 # 隐形眼镜类型包括硬材质 、软材质以及不适合佩…...

广州华锐互动:VR技术应用到工程项目施工安全培训的好处
随着科技的飞速发展,虚拟现实(VR)技术已经深入到各个领域。在建筑施工领域,VR技术的应用为工程项目施工安全培训带来了许多好处。本文将探讨VR技术在这方面的优势和应用。 首先,VR技术能够提供沉浸式的安全培训体验。通过VR设备,学…...

Hadoop3.0大数据处理学习1(Haddop介绍、部署、Hive部署)
Hadoop3.0快速入门 学习步骤: 三大组件的基本理论和实际操作Hadoop3的使用,实际开发流程结合具体问题,提供排查思路 开发技术栈: Linux基础操作、Sehll脚本基础JavaSE、Idea操作MySQL Hadoop简介 Hadoop是一个适合海量数据存…...

C笔记:引用调用,通过指针传递
代码 #include<stdio.h> int max1(int num1,int num2) {if(num1 < num2){num1 num2;}else{num2 num1;} } int max2(int *num1,int *num2) {if(num1 < num2){*num1 *num2; // 把 num2 赋值给 num1 }else{*num2 *num1;} } int main() {int num1 0,num2 -2;int…...

【方法】如何给PDF文件添加“打开密码”?
PDF文件可以在线浏览,但如果想要给文件添加“打开密码”,就需要用到软件工具,下面小编分享两种常用的工具,小伙伴们可以根据需要选择。 工具一:PDF编辑器 PDF阅读器一般是没有设置密码的功能模块,PDF编辑器…...

单源最短路径 -- Dijkstra
Dijkstra算法就适用于解决带权重的有向图上的单源最短路径问题 -- 同时算法要求图中所有边的权重非负(这个很重要) 针对一个带权有向图G , 将所有节点分为两组S和Q , S是已经确定的最短路径的节点集合,在初始时为空&…...
Java--多态及抽象类与接口
1.多态 以不同参数调用父类方法,可以得到不同的处理,子类中无需定义相同功能的方法,避免了重复代码编写,只需要实例化一个继承父类的子类对象,即可调用相应的方法,而只需要维护附父类方法即可。 package c…...

深入浅出Asp.Net Core MVC应用开发系列-AspNetCore中的日志记录
ASP.NET Core 是一个跨平台的开源框架,用于在 Windows、macOS 或 Linux 上生成基于云的新式 Web 应用。 ASP.NET Core 中的日志记录 .NET 通过 ILogger API 支持高性能结构化日志记录,以帮助监视应用程序行为和诊断问题。 可以通过配置不同的记录提供程…...
Java 语言特性(面试系列1)
一、面向对象编程 1. 封装(Encapsulation) 定义:将数据(属性)和操作数据的方法绑定在一起,通过访问控制符(private、protected、public)隐藏内部实现细节。示例: public …...

(十)学生端搭建
本次旨在将之前的已完成的部分功能进行拼装到学生端,同时完善学生端的构建。本次工作主要包括: 1.学生端整体界面布局 2.模拟考场与部分个人画像流程的串联 3.整体学生端逻辑 一、学生端 在主界面可以选择自己的用户角色 选择学生则进入学生登录界面…...

突破不可导策略的训练难题:零阶优化与强化学习的深度嵌合
强化学习(Reinforcement Learning, RL)是工业领域智能控制的重要方法。它的基本原理是将最优控制问题建模为马尔可夫决策过程,然后使用强化学习的Actor-Critic机制(中文译作“知行互动”机制),逐步迭代求解…...

Unity3D中Gfx.WaitForPresent优化方案
前言 在Unity中,Gfx.WaitForPresent占用CPU过高通常表示主线程在等待GPU完成渲染(即CPU被阻塞),这表明存在GPU瓶颈或垂直同步/帧率设置问题。以下是系统的优化方案: 对惹,这里有一个游戏开发交流小组&…...

PL0语法,分析器实现!
简介 PL/0 是一种简单的编程语言,通常用于教学编译原理。它的语法结构清晰,功能包括常量定义、变量声明、过程(子程序)定义以及基本的控制结构(如条件语句和循环语句)。 PL/0 语法规范 PL/0 是一种教学用的小型编程语言,由 Niklaus Wirth 设计,用于展示编译原理的核…...

MySQL 8.0 OCP 英文题库解析(十三)
Oracle 为庆祝 MySQL 30 周年,截止到 2025.07.31 之前。所有人均可以免费考取原价245美元的MySQL OCP 认证。 从今天开始,将英文题库免费公布出来,并进行解析,帮助大家在一个月之内轻松通过OCP认证。 本期公布试题111~120 试题1…...
重启Eureka集群中的节点,对已经注册的服务有什么影响
先看答案,如果正确地操作,重启Eureka集群中的节点,对已经注册的服务影响非常小,甚至可以做到无感知。 但如果操作不当,可能会引发短暂的服务发现问题。 下面我们从Eureka的核心工作原理来详细分析这个问题。 Eureka的…...
Python 包管理器 uv 介绍
Python 包管理器 uv 全面介绍 uv 是由 Astral(热门工具 Ruff 的开发者)推出的下一代高性能 Python 包管理器和构建工具,用 Rust 编写。它旨在解决传统工具(如 pip、virtualenv、pip-tools)的性能瓶颈,同时…...

【从零学习JVM|第三篇】类的生命周期(高频面试题)
前言: 在Java编程中,类的生命周期是指类从被加载到内存中开始,到被卸载出内存为止的整个过程。了解类的生命周期对于理解Java程序的运行机制以及性能优化非常重要。本文会深入探寻类的生命周期,让读者对此有深刻印象。 目录 …...