想了解更多关于开源的内容,请访问:51CTO 开源基础软件社区https://ost.51cto.com上一篇文章讲解了编译开源gpu驱动,并把gpu驱动添加到编译框架中,此时理论上gpu已经可以调用,但是我们需要一些手段进行测试,以确认gpu能够正常工作。这里分享我用过的两个测试程序,glmark2和一个简单的三角形绘制程序。移植GPU过程中受到开源社区里各位大神的指导,特别是AlgoIdeas和lhl,特此鸣谢。# Copyright (c) Hisilicon Technologies Co., Ltd. 2021-2021. All rights reserved
import("//build/ohos.gni")
ohos_shared_library("native_window_wrapper") {
sources = ["native_window_wrapper.cpp"]
include_dirs = [
"."
]
cflags = [
"-Wall",
"-Werror",
"-Wno-cast-qual",
"-Wno-pointer-arith",
"-Wno-unused-parameter",
"-Wno-unused-variable",
"-Wno-delete-incomplete",
]
deps = [
"//foundation/window/window_manager/wm:libwm",
"//foundation/graphic/graphic_2d/frameworks/surface:surface",
"//foundation/graphic/graphic_2d/rosen/modules/render_service_client:librender_service_client",
]
# 添加OH部件配置
part_name = "window_manager"
subsystem_name = "window"
}#修改OHOS_ROOT为自己的目录
OHOS_ROOT = /home/algoideas/openharmony/master
改为
OHOS_ROOT = /home/diemit/OpenHarmony
#修改三处--sysroot
--sysroot=$(OHOS_ROOT)/out/a311d/obj/third_party/musl
改为
--sysroot=$(OHOS_ROOT)/out/rpi4/obj/third_party/musl
#修改lib链接
CLIBS += -L$(OHOS_ROOT)/device/soc/rockchip/hardware/gpu/lib -lmali-bifrost-g52-g2p0-ohos
CLIBS += -L$(OHOS_ROOT)/out/rk3568/packages/phone/system/lib -lhilog -lsurface.z -lutils.z
改为
CLIBS += -L$(OHOS_ROOT)/device/soc/broadcom/bcm2711/standard/hardware/gpu/lib -lgallium_dri
CLIBS += -L$(OHOS_ROOT)/out/rpi4/packages/phone/system/lib -lhilog -lsurface.z -lutils.z#修改OHOS_ROOT为自己的目录
OHOS_ROOT = /home/algoideas/openharmony/master
改为
OHOS_ROOT = /home/diemit/OpenHarmony
#修改三处--sysroot
--sysroot=$(OHOS_ROOT)/out/a311d/obj/third_party/musl
改为
--sysroot=$(OHOS_ROOT)/out/sagit/obj/third_party/musl
#修改lib链接
CLIBS += -L$(OHOS_ROOT)/device/soc/rockchip/hardware/gpu/lib -lmali-bifrost-g52-g2p0-ohos
CLIBS += -L$(OHOS_ROOT)/out/rk3568/packages/phone/system/lib -lhilog -lsurface.z -lutils.z
改为
CLIBS += -L$(OHOS_ROOT)/device/soc/qualcomm/msm8998/hardware/gpu/lib64 -lgallium_dri
CLIBS += -L$(OHOS_ROOT)/out/sagit/packages/phone/system/lib64 -lhilog -lsurface.z -lutils.z
#修改
CFLAGS :=
#删除
-march=armv7-a \
-mfloat-abi=softfp \
-mtune=generic-armv7-a \
-mfpu=neon \
-mthumb \
#修改
--target=arm-linux-ohosmusl \
改为
--target=aarch64-linux-ohosmusl \cd native_window_ohos
makeohos_prebuilt_executable("native_main") {
source = "native_window_ohos/native_main"
part_name = "qualcomm_products"
install_images = [ "system" ]
install_enable = true
}native_main
修改
run_build_cmd += '-Dplatforms=ohos -Degl-native-platform=ohos -Ddri-drivers= -Dgallium-drivers=freedreno \
-Dvulkan-drivers= -Dgbm=enabled -Degl=enabled -Dcpp_rtti=false -Dglx=disabled -Dtools= -Ddri-search-path=/vendor/lib64/chipsetsdk '
修改后
run_build_cmd += '-Dflavors=ohos-glesv2 '
其他保持不变native_ohos_lib = static_library(
'native-ohos',
'native-state-ohos.cpp',
+ 'ohos_wrapper_linker.cpp',
dependencies: [libmatrix_headers_dep],
)
native_ohos_dep = declare_dependency(#include "ohos_wrapper_linker.h"
#include <dlfcn.h>
#include "log.h"
bool OhosWrapperLinker::Init()
{
wrapperModule_ = dlopen(WRAPPER_LIB_NAME, RTLD_NOW | RTLD_NOLOAD);
if (wrapperModule_ != nullptr) {
Log::debug("Module '%s' already loaded \n", WRAPPER_LIB_NAME);
} else {
Log::debug("Loading module %s\n", WRAPPER_LIB_NAME);
wrapperModule_ = dlopen(WRAPPER_LIB_NAME, RTLD_NOW);
if (wrapperModule_ == nullptr) {
Log::debug("Failed to load module: %s \n", dlerror());
return false;
}
}
using InitFunc = bool (*)(WrapperFunc *funcs);
InitFunc func = reinterpret_cast<InitFunc>(dlsym(wrapperModule_, WRAPPER_FUNC_GET));
if (func == nullptr) {
Log::debug("Failed to lookup %s function: %s\n", WRAPPER_FUNC_GET, dlerror());
dlclose(wrapperModule_);
return false;
}
if (func(&wapperFuncs_)) {
wrapper_ = wapperFuncs_.CreateWindowWrapper();
} else {
Log::debug("can not get wrapper functions \n");
return false;
}
if (wrapper_ != nullptr) {
Log::debug("wrapper init success\n");
return true;
}
return false;
}
bool OhosWrapperLinker::CreateWindow(uint32_t w, uint32_t h)
{
return wapperFuncs_.CreateWindow(wrapper_, w, h);
}
void* OhosWrapperLinker::GetWindow()
{
return wapperFuncs_.GetNativeWindow(wrapper_);
}
void OhosWrapperLinker::SetVisibility(bool visible)
{
wapperFuncs_.SetVisibility(wrapper_, visible);
}#include <cstdint>
extern "C" {
typedef struct {
void* (*CreateWindowWrapper)();
bool (*CreateWindow)(void* wrapper, uint32_t w, uint32_t h);
void* (*GetNativeWindow)(void* wrapper);
void (*SetVisibility)(void* wrapper, bool visible);
void (*DestroyWindowWrapper)(void* wrapper);
} WrapperFunc;
}
class OhosWrapperLinker
{
public:
bool Init();
bool CreateWindow(uint32_t w, uint32_t h);
void *GetWindow();
void SetVisibility(bool visible);
private:
static constexpr const char *WRAPPER_LIB_NAME = "libnative_window_wrapper.z.so";
static constexpr const char *WRAPPER_FUNC_GET = "GetWrapperFunc";
WrapperFunc wapperFuncs_;
void* wrapper_ = nullptr;
void *wrapperModule_ = nullptr;
};#ifndef GLMARK2_NATIVE_STATE_OHOS_H_
#define GLMARK2_NATIVE_STATE_OHOS_H_
#include "native-state.h"
+#include "ohos_wrapper_linker.h"
class NativeStateOhos : public NativeState
{
@@ -27,6 +28,9 @@ class NativeStateOhos : public NativeState
/* Flips the display */
void flip();
+ private:
+ OhosWrapperLinker wrapper;
+ WindowProperties properties_;
};
#endif // GLMARK2_NATIVE_STATE_OHOS_H_#include "native-state-ohos.h"
#include "log.h"
/* Initializes the native display */
bool NativeStateOhos::init_display()
{
//Log::debug("%s@%s:%d", __FUNCTION__, __FILE__, __LINE__);
return wrapper.Init();
}
/* Gets the native display */
void *NativeStateOhos::display()
{
//Log::debug("%s@%s:%d", __FUNCTION__, __FILE__, __LINE__);
return nullptr;
}
/* Creates (or recreates) the native window */
bool NativeStateOhos::create_window(WindowProperties const &properties)
{
properties_ = properties;
return wrapper.CreateWindow(properties.width, properties.height);
}
/*
* Gets the native window and its properties.
* The dimensions may be different than the ones requested.
*/
void *NativeStateOhos::window(WindowProperties &properties)
{
properties = properties_;
return wrapper.GetWindow();
}
/* Sets the visibility of the native window */
void NativeStateOhos::visible(bool v)
{
wrapper.SetVisibility(v);
return;
}
/* Whether the user has requested an exit */
bool NativeStateOhos::should_quit()
{
return false;
}
/* Flips the display */
void NativeStateOhos::flip()
{
return;
}- native_display_ = reinterpret_cast<EGLNativeDisplayType>(native_display);
+ native_display_ = static_cast<EGLNativeDisplayType>((intptr_t)native_display);python ohos/build_ohos64.py ~/ohos_beta5 sagit ~/ohos_beta5/glmark2_2/ohos_prebuilt_executable("glmark2") {
source = "glmark2/glmark2-es2-ohos"
part_name = "qualcomm_products"
install_images = [ "system" ]
install_enable = true
}默认分辨率运行800*600
glmark2-es2-ohos --data-path /data/media/glmark2/
指定分辨率1080*1920
glmark2-es2-ohos -s 1080*1920 --data-path /data/media/glmark2/
至此OpenGL接口的测试程序如何进行编译以及调用验证讲解完毕,希望能对大家有所帮助,下篇我会分享一下树莓派4与小米6在适配gpu时遇到的问题以及解决的过程。很好奇,就使用rubyonrails自动化单元测试而言,你们正在做什么?您是否创建了一个脚本来在cron中运行rake作业并将结果邮寄给您?git中的预提交Hook?只是手动调用?我完全理解测试,但想知道在错误发生之前捕获错误的最佳实践是什么。让我们理所当然地认为测试本身是完美无缺的,并且可以正常工作。下一步是什么以确保他们在正确的时间将可能有害的结果传达给您? 最佳答案 不确定您到底想听什么,但是有几个级别的自动代码库控制:在处理某项功能时,您可以使用类似autotest的内容获得关于哪些有效,哪些无效的即时反馈。要确保您的提
我需要在客户计算机上运行Ruby应用程序。通常需要几天才能完成(复制大备份文件)。问题是如果启用sleep,它会中断应用程序。否则,计算机将持续运行数周,直到我下次访问为止。有什么方法可以防止执行期间休眠并让Windows在执行后休眠吗?欢迎任何疯狂的想法;-) 最佳答案 Here建议使用SetThreadExecutionStateWinAPI函数,使应用程序能够通知系统它正在使用中,从而防止系统在应用程序运行时进入休眠状态或关闭显示。像这样的东西:require'Win32API'ES_AWAYMODE_REQUIRED=0x0
Rackup通过Rack的默认处理程序成功运行任何Rack应用程序。例如:classRackAppdefcall(environment)['200',{'Content-Type'=>'text/html'},["Helloworld"]]endendrunRackApp.new但是当最后一行更改为使用Rack的内置CGI处理程序时,rackup给出“NoMethodErrorat/undefinedmethod`call'fornil:NilClass”:Rack::Handler::CGI.runRackApp.newRack的其他内置处理程序也提出了同样的反对意见。例如Rack
我想用ruby编写一个小的命令行实用程序并将其作为gem分发。我知道安装后,Guard、Sass和Thor等某些gem可以从命令行自行运行。为了让gem像二进制文件一样可用,我需要在我的gemspec中指定什么。 最佳答案 Gem::Specification.newdo|s|...s.executable='name_of_executable'...endhttp://docs.rubygems.org/read/chapter/20 关于ruby-在Ruby中编写命令行实用程序
我正在编写一个包含C扩展的gem。通常当我写一个gem时,我会遵循TDD的过程,我会写一个失败的规范,然后处理代码直到它通过,等等......在“ext/mygem/mygem.c”中我的C扩展和在gemspec的“扩展”中配置的有效extconf.rb,如何运行我的规范并仍然加载我的C扩展?当我更改C代码时,我需要采取哪些步骤来重新编译代码?这可能是个愚蠢的问题,但是从我的gem的开发源代码树中输入“bundleinstall”不会构建任何native扩展。当我手动运行rubyext/mygem/extconf.rb时,我确实得到了一个Makefile(在整个项目的根目录中),然后当
我构建了两个需要相互通信和发送文件的Rails应用程序。例如,一个Rails应用程序会发送请求以查看其他应用程序数据库中的表。然后另一个应用程序将呈现该表的json并将其发回。我还希望一个应用程序将存储在其公共(public)目录中的文本文件发送到另一个应用程序的公共(public)目录。我从来没有做过这样的事情,所以我什至不知道从哪里开始。任何帮助,将不胜感激。谢谢! 最佳答案 无论Rails是什么,几乎所有Web应用程序都有您的要求,大多数现代Web应用程序都需要相互通信。但是有一个小小的理解需要你坚持下去,网站不应直接访问彼此
我尝试运行2.x应用程序。我使用rvm并为此应用程序设置其他版本的ruby:$rvmuseree-1.8.7-head我尝试运行服务器,然后出现很多错误:$script/serverNOTE:Gem.source_indexisdeprecated,useSpecification.Itwillberemovedonorafter2011-11-01.Gem.source_indexcalledfrom/Users/serg/rails_projects_terminal/work_proj/spohelp/config/../vendor/rails/railties/lib/r
我有一个围绕一些对象的包装类,我想将这些对象用作散列中的键。包装对象和解包装对象应映射到相同的键。一个简单的例子是这样的:classAattr_reader:xdefinitialize(inner)@inner=innerenddefx;@inner.x;enddef==(other)@inner.x==other.xendenda=A.new(o)#oisjustanyobjectthatallowso.xb=A.new(o)h={a=>5}ph[a]#5ph[b]#nil,shouldbe5ph[o]#nil,shouldbe5我试过==、===、eq?并散列所有无济于事。
我有一些Ruby代码,如下所示:Something.createdo|x|x.foo=barend我想编写一个测试,它使用double代替block参数x,这样我就可以调用:x_double.should_receive(:foo).with("whatever").这可能吗? 最佳答案 specify'something'dox=doublex.should_receive(:foo=).with("whatever")Something.should_receive(:create).and_yield(x)#callthere
刚入门rails,开始慢慢理解。有人可以解释或给我一些关于在application_controller中编码的好处或时间和原因的想法吗?有哪些用例。您如何为Rails应用程序使用应用程序Controller?我不想在那里放太多代码,因为据我了解,每个请求都会调用此Controller。这是真的? 最佳答案 ApplicationController实际上是您应用程序中的每个其他Controller都将从中继承的类(尽管这不是强制性的)。我同意不要用太多代码弄乱它并保持干净整洁的态度,尽管在某些情况下ApplicationContr