当前位置: 首页 > news >正文

Skia基础运用(Ubuntu环境下使用BUILD.gn)

1.拉取代码

git clone https://skia.googlesource.com/skia
python tools/git-sync-deps
// 这一步可能会出现部分错误,再次执行直到成功
// 这里面拉取完三方库之后会拉取node,linux等压缩包,从google下载

上面执行完,代码就完全拿到了

2.生成ninja

gn gen out/default
// 如果要导出compile_commands.json, 加入--export-compile-commands
// 可以用导出的文件加上clangd和clang配一波智能提示

3.增加自己的demo

skia
├── demo├── BUILD.gn└── main.cpp
└── out

增加demo代码如下

#include "include/codec/SkEncodedImageFormat.h"
#include "include/core/SkBitmap.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkPaint.h"
#include "include/core/SkRect.h"
#include "include/core/SkStream.h"
#include "include/core/SkTextBlob.h"
#include "include/core/SkTypeface.h"
#include "include/encode/SkJpegEncoder.h"
#include "src/core/SkDevice.h"
#include "src/encode/SkImageEncoderFns.h"
const char* pText = "Hello world!";
int main() {SkBitmap bitmap;SkImageInfo ii = SkImageInfo::Make(480, 320, kBGRA_8888_SkColorType, kPremul_SkAlphaType);bitmap.allocPixels(ii, ii.minRowBytes());SkPaint paint;paint.setStyle(SkPaint::kStroke_Style);paint.setColor(0xff1f78b4);paint.setStrokeWidth(8);bitmap.allocPixels();SkCanvas canvas(bitmap);canvas.clear(0xFF000000);  // 背景为透明色{SkRect rc;rc.fLeft = 123;rc.fTop = 0;rc.fRight = 222;rc.fBottom = 50;canvas.drawOval(rc, paint);}{paint.setColor(SK_ColorYELLOW);canvas.drawCircle(100, 100, 50, paint);}SkFILEWStream stream("./1bc.jpg");SkJpegEncoder::Encode(&stream, bitmap.pixmap(), {});return 0;
}

接下来增加同级目录下的BUILD.gn

import("//gn/skia.gni")
skia_executable("demo") {sources = ["main.cpp"]deps = ["../.:skia"]
}

目前还识别不到新增的demo编译目标,需要在总工程目录中增加如下内容

group("gdemo") {deps = ["//demo:demo"]
}

再生成一遍ninja,或者先弄第三步再执行第二步

5.执行编译

ninja -C out/demo demo

待执行编译之后,out/demo中会得到名字为demo的可执行文件,执行,得到生成的jpeg图片,这样我们就能愉快的学习源码了
canvas图片
我绘制文字貌似有问题,之后再写

http://www.lryc.cn/news/475725.html

相关文章:

  • Vue中props和data的优先级哪个更高?
  • springboot2.x使用SSE方式代理或者转发其他流式接口
  • consul入门教程
  • 软考:大数据架构设计
  • token无感刷新+处理并发的后端方案
  • 【系统设计】让 Java “动起来”:动态语言与静态语言的比较及 DSL 实现
  • TCP Analysis Flags 之 TCP Keep-Alive
  • mfc140u.dll丢失怎么办? mfc140u.dll文件缺失的修复技巧
  • Spring Security使用
  • CSS网页布局综合练习(涵盖大多CSS知识点)
  • 解决 Hardhat Verify 超时
  • ACIS创建各种基本体,举例说明
  • [CISCN 2019华北]PWN1-好久不见7
  • 代码随想录day16| 513找树左下角的值 、 路径总和 、 从中序与后序遍历序列构造二叉树
  • 使用 MMDetection 实现 Pascal VOC 数据集的目标检测项目练习(二) ubuntu的下载安装
  • 书生大模型实战营(第四期)——入门岛
  • 压强随着时间的变化
  • 2024年大厂AI大模型面试题精选与答案解析
  • Linux开发讲课47--- 详解 Linux 中的虚拟文件系统
  • 全球银行常用英语
  • 新160个crackme -090-tc.12
  • Swagger文档-Unable to scan documentation context default报错
  • SpringKafka生产者、消费者消息拦截
  • Qt报错QOCI driver not loaded且QOCI available的解决方法
  • python mac vscode 脚本文件的运行
  • Linux之du命令
  • WRF-LES与PALM微尺度气象大涡模拟
  • 桌面程序开发框架选择
  • Vue项目开发:Vuex使用,表单验证配置,ESLint关闭与常见问题解决方案
  • 源鲁杯2024赛题复现Web Misc部分WP