mirror of
https://gitee.com/zlgopen/awtk.git
synced 2024-11-30 02:58:26 +08:00
vgcanvas supports framebuffer which has special stride
This commit is contained in:
parent
9a2438cad4
commit
768d0a5467
@ -13,7 +13,7 @@ class bitmap : public RawBitmapT {
|
||||
typedef PixelT pixel;
|
||||
|
||||
public:
|
||||
bitmap(count_t width, count_t height, uint8_t* data);
|
||||
bitmap(count_t width, count_t height, count_t stride, uint8_t* data);
|
||||
|
||||
pixel* row_ptr(count_t y);
|
||||
const pixel* row_ptr(count_t y) const;
|
||||
@ -70,8 +70,8 @@ struct pixel_bpp<pixel8> {
|
||||
};
|
||||
|
||||
template <typename PixelT, typename RawBitmapT>
|
||||
inline bitmap<PixelT, RawBitmapT>::bitmap(count_t width, count_t height, uint8_t* data)
|
||||
: RawBitmapT(width, height, pixel_bpp<PixelT>::bpp, data) {
|
||||
inline bitmap<PixelT, RawBitmapT>::bitmap(count_t width, count_t height, count_t stride, uint8_t* data)
|
||||
: RawBitmapT(width, height, stride, pixel_bpp<PixelT>::bpp, data) {
|
||||
}
|
||||
|
||||
template <typename PixelT, typename RawBitmapT>
|
||||
|
@ -10,7 +10,7 @@ typedef uint8_t* image_handle;
|
||||
namespace agge {
|
||||
class raw_bitmap : noncopyable {
|
||||
public: // General
|
||||
raw_bitmap(count_t width, count_t height, bits_per_pixel bpp, uint8_t* data);
|
||||
raw_bitmap(count_t width, count_t height, count_t stride, bits_per_pixel bpp, uint8_t* data);
|
||||
~raw_bitmap() {
|
||||
}
|
||||
|
||||
@ -24,9 +24,6 @@ class raw_bitmap : noncopyable {
|
||||
image_handle native() const;
|
||||
void blit(int x, int y, count_t width, count_t height) const;
|
||||
|
||||
private:
|
||||
count_t calculate_stride(count_t width) const;
|
||||
|
||||
private:
|
||||
uint8_t* _memory;
|
||||
count_t _stride;
|
||||
@ -35,9 +32,9 @@ class raw_bitmap : noncopyable {
|
||||
image_handle _native;
|
||||
};
|
||||
|
||||
inline raw_bitmap::raw_bitmap(count_t width, count_t height, bits_per_pixel bpp, uint8_t* data)
|
||||
inline raw_bitmap::raw_bitmap(count_t width, count_t height, count_t stride, bits_per_pixel bpp, uint8_t* data)
|
||||
: _memory(data), _width(width), _height(height), _bpp(bpp), _native(0) {
|
||||
_stride = this->calculate_stride(width);
|
||||
_stride = stride;
|
||||
}
|
||||
|
||||
inline count_t raw_bitmap::width() const {
|
||||
@ -60,7 +57,4 @@ inline image_handle raw_bitmap::native() const {
|
||||
return _native;
|
||||
}
|
||||
|
||||
inline count_t raw_bitmap::calculate_stride(count_t width) const {
|
||||
return (width * (_bpp / 8) + 3) & ~3;
|
||||
}
|
||||
} // namespace agge
|
||||
|
@ -343,43 +343,39 @@ static void aggnvg__renderDelete(void* uptr) {
|
||||
delete agg;
|
||||
}
|
||||
|
||||
static void nvgInitAGG(AGGNVGcontext* agg, NVGparams* params, int32_t w, int32_t h,
|
||||
static void nvgInitAGG(AGGNVGcontext* agg, NVGparams* params, uint32_t w, uint32_t h, uint32_t stride,
|
||||
enum NVGtexture format, uint8_t* data) {
|
||||
agg->w = w;
|
||||
agg->h = h;
|
||||
agg->data = data;
|
||||
agg->format = format;
|
||||
agg->stride = stride;
|
||||
params->renderTriangles = NULL;
|
||||
|
||||
switch (agg->format) {
|
||||
case NVG_TEXTURE_BGRA: {
|
||||
params->renderStroke = renderStroke<agg::pixfmt_bgra32>;
|
||||
params->renderFill = renderFill<agg::pixfmt_bgra32>;
|
||||
agg->stride = w * 4;
|
||||
break;
|
||||
}
|
||||
case NVG_TEXTURE_RGBA: {
|
||||
params->renderStroke = renderStroke<agg::pixfmt_rgba32>;
|
||||
params->renderFill = renderFill<agg::pixfmt_rgba32>;
|
||||
agg->stride = w * 4;
|
||||
break;
|
||||
}
|
||||
case NVG_TEXTURE_BGR: {
|
||||
params->renderStroke = renderStroke<agg::pixfmt_bgr24>;
|
||||
params->renderFill = renderFill<agg::pixfmt_bgr24>;
|
||||
agg->stride = w * 3;
|
||||
break;
|
||||
}
|
||||
case NVG_TEXTURE_RGB: {
|
||||
params->renderStroke = renderStroke<agg::pixfmt_rgb24>;
|
||||
params->renderFill = renderFill<agg::pixfmt_rgb24>;
|
||||
agg->stride = w * 3;
|
||||
break;
|
||||
}
|
||||
case NVG_TEXTURE_BGR565: {
|
||||
params->renderStroke = renderStroke<agg::pixfmt_rgb565>;
|
||||
params->renderFill = renderFill<agg::pixfmt_rgb565>;
|
||||
agg->stride = w * 2;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
@ -389,15 +385,15 @@ static void nvgInitAGG(AGGNVGcontext* agg, NVGparams* params, int32_t w, int32_t
|
||||
}
|
||||
}
|
||||
|
||||
void nvgReinitAgge(NVGcontext* ctx, int32_t w, int32_t h, enum NVGtexture format,
|
||||
void nvgReinitAgge(NVGcontext* ctx, uint32_t w, uint32_t h, uint32_t stride, enum NVGtexture format,
|
||||
uint8_t* data) {
|
||||
NVGparams* params = nvgGetParams(ctx);
|
||||
AGGNVGcontext* agg = (AGGNVGcontext*)(params->userPtr);
|
||||
|
||||
nvgInitAGG(agg, params, w, h, format, data);
|
||||
nvgInitAGG(agg, params, w, h, stride, format, data);
|
||||
}
|
||||
|
||||
NVGcontext* nvgCreateAGG(int32_t w, int32_t h, enum NVGtexture format, uint8_t* data) {
|
||||
NVGcontext* nvgCreateAGG(uint32_t w, uint32_t h, uint32_t stride, enum NVGtexture format, uint8_t* data) {
|
||||
NVGparams params;
|
||||
NVGcontext* ctx = NULL;
|
||||
AGGNVGcontext* agg = new AGGNVGcontext();
|
||||
@ -417,7 +413,7 @@ NVGcontext* nvgCreateAGG(int32_t w, int32_t h, enum NVGtexture format, uint8_t*
|
||||
params.userPtr = agg;
|
||||
params.edgeAntiAlias = 1;
|
||||
|
||||
nvgInitAGG(agg, ¶ms, w, h, format, data);
|
||||
nvgInitAGG(agg, ¶ms, w, h, stride, format, data);
|
||||
|
||||
ctx = nvgCreateInternal(¶ms);
|
||||
if (ctx == NULL) goto error;
|
||||
|
@ -15,8 +15,8 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
NVGcontext* nvgCreateAGG(int32_t w, int32_t h, enum NVGtexture format, uint8_t* data);
|
||||
void nvgReinitAgge(NVGcontext* ctx, int32_t w, int32_t h, enum NVGtexture, uint8_t* data);
|
||||
NVGcontext* nvgCreateAGG(uint32_t w, uint32_t h, uint32_t stride, enum NVGtexture format, uint8_t* data);
|
||||
void nvgReinitAgge(NVGcontext* ctx, uint32_t w, uint32_t h, uint32_t stride, enum NVGtexture, uint8_t* data);
|
||||
void nvgDeleteAGG(NVGcontext* ctx);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -67,8 +67,9 @@ struct AGGENVGcontext {
|
||||
uint8_t a;
|
||||
|
||||
/*frame buffer*/
|
||||
int32_t w;
|
||||
int32_t h;
|
||||
uint32_t w;
|
||||
uint32_t h;
|
||||
uint32_t stride;
|
||||
uint8_t* data;
|
||||
enum NVGtexture format;
|
||||
|
||||
@ -220,7 +221,7 @@ template <typename PixelT>
|
||||
void renderPaint(AGGENVGcontext* agge, NVGpaint* paint) {
|
||||
agge::renderer& ren = agge->ren;
|
||||
agge::rasterizer<agge::clipper<int> >& ras = agge->ras;
|
||||
agge::bitmap<PixelT, agge::raw_bitmap> surface(agge->w, agge->h, agge->data);
|
||||
agge::bitmap<PixelT, agge::raw_bitmap> surface(agge->w, agge->h, agge->stride, agge->data);
|
||||
|
||||
if (paint->image > 0) {
|
||||
float invxform[6];
|
||||
@ -230,28 +231,28 @@ void renderPaint(AGGENVGcontext* agge, NVGpaint* paint) {
|
||||
switch (tex->type) {
|
||||
case NVG_TEXTURE_RGBA: {
|
||||
typedef agge::bitmap<agge::pixel32_rgba, agge::raw_bitmap> rgba_bitmap_t;
|
||||
rgba_bitmap_t src(tex->width, tex->height, (uint8_t*)(tex->data));
|
||||
rgba_bitmap_t src(tex->width, tex->height, tex->width*4, (uint8_t*)(tex->data));
|
||||
agge::nanovg_image_blender<PixelT, rgba_bitmap_t> color(&src, (float*)invxform);
|
||||
ren(surface, 0, ras, color, agge::winding<>());
|
||||
break;
|
||||
}
|
||||
case NVG_TEXTURE_BGRA: {
|
||||
typedef agge::bitmap<agge::pixel32_bgra, agge::raw_bitmap> bgra_bitmap_t;
|
||||
bgra_bitmap_t src(tex->width, tex->height, (uint8_t*)(tex->data));
|
||||
bgra_bitmap_t src(tex->width, tex->height, tex->width*4, (uint8_t*)(tex->data));
|
||||
agge::nanovg_image_blender<PixelT, bgra_bitmap_t> color(&src, (float*)invxform);
|
||||
ren(surface, 0, ras, color, agge::winding<>());
|
||||
break;
|
||||
}
|
||||
case NVG_TEXTURE_BGR565: {
|
||||
typedef agge::bitmap<agge::pixel16_bgr565, agge::raw_bitmap> bgr565_bitmap_t;
|
||||
bgr565_bitmap_t src(tex->width, tex->height, (uint8_t*)(tex->data));
|
||||
bgr565_bitmap_t src(tex->width, tex->height, tex->width*2, (uint8_t*)(tex->data));
|
||||
agge::nanovg_image_blender<PixelT, bgr565_bitmap_t> color(&src, (float*)invxform);
|
||||
ren(surface, 0, ras, color, agge::winding<>());
|
||||
break;
|
||||
}
|
||||
case NVG_TEXTURE_RGB: {
|
||||
typedef agge::bitmap<agge::pixel24_rgb, agge::raw_bitmap> rgb_bitmap_t;
|
||||
rgb_bitmap_t src(tex->width, tex->height, (uint8_t*)(tex->data));
|
||||
rgb_bitmap_t src(tex->width, tex->height, tex->width*3, (uint8_t*)(tex->data));
|
||||
agge::nanovg_image_blender<PixelT, rgb_bitmap_t> color(&src, (float*)invxform);
|
||||
ren(surface, 0, ras, color, agge::winding<>());
|
||||
break;
|
||||
@ -330,40 +331,37 @@ static void aggenvg__renderDelete(void* uptr) {
|
||||
delete agge;
|
||||
}
|
||||
|
||||
static void nvgInitAGGE(AGGENVGcontext* agge, NVGparams* params, int32_t w, int32_t h,
|
||||
static void nvgInitAGGE(AGGENVGcontext* agge, NVGparams* params, uint32_t w, uint32_t h, uint32_t stride,
|
||||
enum NVGtexture format, uint8_t* data) {
|
||||
agge->w = w;
|
||||
agge->h = h;
|
||||
agge->data = data;
|
||||
agge->stride = stride;
|
||||
agge->format = format;
|
||||
params->renderTriangles = NULL;
|
||||
|
||||
switch (agge->format) {
|
||||
case NVG_TEXTURE_RGBA: {
|
||||
params->renderTriangles = renderTriangles<agge::pixel32_rgba>;
|
||||
params->renderStroke = renderStroke<agge::pixel32_rgba>;
|
||||
params->renderFill = renderFill<agge::pixel32_rgba>;
|
||||
break;
|
||||
}
|
||||
case NVG_TEXTURE_BGRA: {
|
||||
params->renderTriangles = renderTriangles<agge::pixel32_bgra>;
|
||||
params->renderStroke = renderStroke<agge::pixel32_bgra>;
|
||||
params->renderFill = renderFill<agge::pixel32_bgra>;
|
||||
break;
|
||||
}
|
||||
case NVG_TEXTURE_RGB: {
|
||||
params->renderTriangles = renderTriangles<agge::pixel24_rgb>;
|
||||
params->renderStroke = renderStroke<agge::pixel24_rgb>;
|
||||
params->renderFill = renderFill<agge::pixel24_rgb>;
|
||||
break;
|
||||
}
|
||||
case NVG_TEXTURE_BGR: {
|
||||
params->renderTriangles = renderTriangles<agge::pixel24_bgr>;
|
||||
params->renderStroke = renderStroke<agge::pixel24_bgr>;
|
||||
params->renderFill = renderFill<agge::pixel24_bgr>;
|
||||
break;
|
||||
}
|
||||
case NVG_TEXTURE_BGR565: {
|
||||
params->renderTriangles = renderTriangles<agge::pixel16_bgr565>;
|
||||
params->renderStroke = renderStroke<agge::pixel16_bgr565>;
|
||||
params->renderFill = renderFill<agge::pixel16_bgr565>;
|
||||
break;
|
||||
@ -375,15 +373,15 @@ static void nvgInitAGGE(AGGENVGcontext* agge, NVGparams* params, int32_t w, int3
|
||||
}
|
||||
}
|
||||
|
||||
void nvgReinitAgge(NVGcontext* ctx, int32_t w, int32_t h, enum NVGtexture format,
|
||||
void nvgReinitAgge(NVGcontext* ctx, uint32_t w, uint32_t h, uint32_t stride, enum NVGtexture format,
|
||||
uint8_t* data) {
|
||||
NVGparams* params = nvgGetParams(ctx);
|
||||
AGGENVGcontext* agge = (AGGENVGcontext*)(params->userPtr);
|
||||
|
||||
nvgInitAGGE(agge, params, w, h, format, data);
|
||||
nvgInitAGGE(agge, params, w, h, stride, format, data);
|
||||
}
|
||||
|
||||
NVGcontext* nvgCreateAGGE(int32_t w, int32_t h, enum NVGtexture format, uint8_t* data) {
|
||||
NVGcontext* nvgCreateAGGE(uint32_t w, uint32_t h, uint32_t stride, enum NVGtexture format, uint8_t* data) {
|
||||
NVGparams params;
|
||||
NVGcontext* ctx = NULL;
|
||||
AGGENVGcontext* agge = new AGGENVGcontext();
|
||||
@ -403,7 +401,7 @@ NVGcontext* nvgCreateAGGE(int32_t w, int32_t h, enum NVGtexture format, uint8_t*
|
||||
params.userPtr = agge;
|
||||
params.edgeAntiAlias = 1;
|
||||
|
||||
nvgInitAGGE(agge, ¶ms, w, h, format, data);
|
||||
nvgInitAGGE(agge, ¶ms, w, h, stride, format, data);
|
||||
|
||||
ctx = nvgCreateInternal(¶ms);
|
||||
if (ctx == NULL) goto error;
|
||||
|
@ -15,8 +15,8 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
NVGcontext* nvgCreateAGGE(int32_t w, int32_t h, enum NVGtexture format, uint8_t* data);
|
||||
void nvgReinitAgge(NVGcontext* ctx, int32_t w, int32_t h, enum NVGtexture format,
|
||||
NVGcontext* nvgCreateAGGE(uint32_t w, uint32_t h, uint32_t stride, enum NVGtexture format, uint8_t* data);
|
||||
void nvgReinitAgge(NVGcontext* ctx, uint32_t w, uint32_t h, uint32_t stride, enum NVGtexture format,
|
||||
uint8_t* data);
|
||||
void nvgDeleteAGGE(NVGcontext* ctx);
|
||||
|
||||
|
@ -13,7 +13,7 @@
|
||||
static void run_test(int32_t w, int32_t h, int32_t BPP, const char* filename) {
|
||||
int32_t size = w * h * BPP;
|
||||
uint8_t* data = (uint8_t*)malloc(size);
|
||||
NVGcontext* vg = nvgCreateAGG(w, h, BPP == 2 ? NVG_TEXTURE_BGR565 : NVG_TEXTURE_RGBA, data);
|
||||
NVGcontext* vg = nvgCreateAGG(w, h, w*BPP, BPP == 2 ? NVG_TEXTURE_BGR565 : NVG_TEXTURE_RGBA, data);
|
||||
|
||||
memset(data, 0xff, size);
|
||||
do_draw(vg, w, h);
|
||||
|
@ -13,7 +13,7 @@
|
||||
static void run_test(int32_t w, int32_t h, int32_t BPP, const char* filename) {
|
||||
int32_t size = w * h * BPP;
|
||||
uint8_t* data = (uint8_t*)malloc(size);
|
||||
NVGcontext* vg = nvgCreateAGG(w, h, BPP == 2 ? NVG_TEXTURE_BGR565 : NVG_TEXTURE_RGBA, data);
|
||||
NVGcontext* vg = nvgCreateAGG(w, h, w*BPP, BPP == 2 ? NVG_TEXTURE_BGR565 : NVG_TEXTURE_RGBA, data);
|
||||
|
||||
memset(data, 0xff, size);
|
||||
|
||||
|
@ -14,7 +14,7 @@
|
||||
static void run_test(int32_t w, int32_t h, int32_t BPP, const char* filename) {
|
||||
int32_t size = w * h * BPP;
|
||||
uint8_t* data = (uint8_t*)malloc(size);
|
||||
NVGcontext* vg = nvgCreateAGG(w, h, BPP == 2 ? NVG_TEXTURE_BGR565 : NVG_TEXTURE_RGBA, data);
|
||||
NVGcontext* vg = nvgCreateAGG(w, h, w*BPP, BPP == 2 ? NVG_TEXTURE_BGR565 : NVG_TEXTURE_RGBA, data);
|
||||
|
||||
memset(data, 0xff, size);
|
||||
do_stroke(vg, w, h);
|
||||
|
@ -13,7 +13,7 @@
|
||||
static void run_test(int32_t w, int32_t h, int32_t BPP, const char* filename) {
|
||||
int32_t size = w * h * BPP;
|
||||
uint8_t* data = (uint8_t*)malloc(size);
|
||||
NVGcontext* vg = nvgCreateAGGE(w, h, BPP == 2 ? NVG_TEXTURE_BGR565 : NVG_TEXTURE_BGRA, data);
|
||||
NVGcontext* vg = nvgCreateAGGE(w, h, w * BPP, BPP == 2 ? NVG_TEXTURE_BGR565 : NVG_TEXTURE_BGRA, data);
|
||||
|
||||
memset(data, 0xff, size);
|
||||
do_draw(vg, w, h);
|
||||
|
@ -13,7 +13,7 @@
|
||||
static void run_test(int32_t w, int32_t h, int32_t BPP, const char* filename) {
|
||||
int32_t size = w * h * BPP;
|
||||
uint8_t* data = (uint8_t*)malloc(size);
|
||||
NVGcontext* vg = nvgCreateAGGE(w, h, BPP == 2 ? NVG_TEXTURE_BGR565 : NVG_TEXTURE_BGRA, data);
|
||||
NVGcontext* vg = nvgCreateAGGE(w, h, w*BPP, BPP == 2 ? NVG_TEXTURE_BGR565 : NVG_TEXTURE_BGRA, data);
|
||||
|
||||
memset(data, 0xff, size);
|
||||
|
||||
|
@ -14,7 +14,7 @@
|
||||
static void run_test(int32_t w, int32_t h, int32_t BPP, const char* filename) {
|
||||
int32_t size = w * h * BPP;
|
||||
uint8_t* data = (uint8_t*)malloc(size);
|
||||
NVGcontext* vg = nvgCreateAGGE(w, h, BPP == 2 ? NVG_TEXTURE_BGR565 : NVG_TEXTURE_BGRA, data);
|
||||
NVGcontext* vg = nvgCreateAGGE(w, h, w*BPP, BPP == 2 ? NVG_TEXTURE_BGR565 : NVG_TEXTURE_BGRA, data);
|
||||
|
||||
memset(data, 0xff, size);
|
||||
do_stroke(vg, w, h);
|
||||
|
@ -1,5 +1,11 @@
|
||||
# 最新动态
|
||||
|
||||
* 2018/10/25
|
||||
* 重新实现take\_snapshot,支持特殊的stride。
|
||||
* 自动过滤重复的pointer\_move事件。
|
||||
* 完善list\_item。
|
||||
* vgcanvas支持特殊的stride。
|
||||
|
||||
* 2018/10/24
|
||||
* 重构blend。
|
||||
* framebuffer/bitmap支持line\_length(即stride/pitch)
|
||||
|
@ -361,11 +361,12 @@ ret_t vgcanvas_draw_icon(vgcanvas_t* vg, bitmap_t* img, float_t sx, float_t sy,
|
||||
return vgcanvas_draw_image(vg, img, sx, sy, sw, sh, x, y, w, h);
|
||||
}
|
||||
|
||||
ret_t vgcanvas_reinit(vgcanvas_t* vg, uint32_t w, uint32_t h, bitmap_format_t format, void* data) {
|
||||
ret_t vgcanvas_reinit(vgcanvas_t* vg, uint32_t w, uint32_t h, uint32_t stride,
|
||||
bitmap_format_t format, void* data) {
|
||||
return_value_if_fail(vg != NULL && data != NULL, RET_BAD_PARAMS);
|
||||
|
||||
if (vg->vt->reinit != NULL) {
|
||||
return vg->vt->reinit(vg, w, h, format, data);
|
||||
return vg->vt->reinit(vg, w, h, stride, format, data);
|
||||
}
|
||||
|
||||
return RET_NOT_IMPL;
|
||||
|
@ -39,8 +39,8 @@ typedef struct _framebuffer_object_t {
|
||||
struct _vgcanvas_t;
|
||||
typedef struct _vgcanvas_t vgcanvas_t;
|
||||
|
||||
typedef ret_t (*vgcanvas_reinit_t)(vgcanvas_t* vg, uint32_t w, uint32_t h, bitmap_format_t format,
|
||||
void* data);
|
||||
typedef ret_t (*vgcanvas_reinit_t)(vgcanvas_t* vg, uint32_t w, uint32_t h, uint32_t stride,
|
||||
bitmap_format_t format, void* data);
|
||||
typedef ret_t (*vgcanvas_begin_frame_t)(vgcanvas_t* vg, rect_t* dirty_rect);
|
||||
typedef ret_t (*vgcanvas_end_frame_t)(vgcanvas_t* vg);
|
||||
|
||||
@ -287,12 +287,14 @@ struct _vgcanvas_t {
|
||||
* @annotation ["constructor"]
|
||||
* @param {uint32_t} w 宽度
|
||||
* @param {uint32_t} h 高度
|
||||
* @param {uint32_t} stride 一行占用的字节数。
|
||||
* @param {bitmap_format_t} format 如果data是framebuffer,format指定data的格式。
|
||||
* @param {void*} data framebuffer或其它ctx。
|
||||
*
|
||||
* @return {vgcanvas_t} 返回vgcanvas
|
||||
*/
|
||||
vgcanvas_t* vgcanvas_create(uint32_t w, uint32_t h, bitmap_format_t format, void* data);
|
||||
vgcanvas_t* vgcanvas_create(uint32_t w, uint32_t h, uint32_t stride, bitmap_format_t format,
|
||||
void* data);
|
||||
|
||||
/**
|
||||
* @method vgcanvas_begin_path
|
||||
@ -309,12 +311,14 @@ ret_t vgcanvas_begin_path(vgcanvas_t* vg);
|
||||
* @param {vgcanvas_t*} vg vgcanvas对象。
|
||||
* @param {uint32_t} w 宽度
|
||||
* @param {uint32_t} h 高度
|
||||
* @param {uint32_t} stride 一行占用的字节数。
|
||||
* @param {bitmap_format_t} format 如果data是framebuffer,format指定data的格式。
|
||||
* @param {void*} data framebuffer或其它ctx。
|
||||
*
|
||||
* @return {ret_t} 返回RET_OK表示成功,否则表示失败。
|
||||
*/
|
||||
ret_t vgcanvas_reinit(vgcanvas_t* vg, uint32_t w, uint32_t h, bitmap_format_t format, void* data);
|
||||
ret_t vgcanvas_reinit(vgcanvas_t* vg, uint32_t w, uint32_t h, uint32_t stride,
|
||||
bitmap_format_t format, void* data);
|
||||
|
||||
/**
|
||||
* @method vgcanvas_begin_frame
|
||||
|
@ -257,11 +257,14 @@ static vgcanvas_t* lcd_mem_get_vgcanvas(lcd_t* lcd) {
|
||||
bitmap_t fb;
|
||||
lcd_mem_t* mem = (lcd_mem_t*)lcd;
|
||||
lcd_mem_init_drawing_fb(lcd, &fb);
|
||||
uint32_t line_length = lcd_mem_get_line_length(mem);
|
||||
|
||||
if (mem->vgcanvas == NULL) {
|
||||
mem->vgcanvas = vgcanvas_create(fb.w, fb.h, (bitmap_format_t)(fb.format), (uint32_t*)(fb.data));
|
||||
mem->vgcanvas = vgcanvas_create(fb.w, fb.h, line_length, (bitmap_format_t)(fb.format),
|
||||
(uint32_t*)(fb.data));
|
||||
} else {
|
||||
vgcanvas_reinit(mem->vgcanvas, fb.w, fb.h, (bitmap_format_t)(fb.format), (uint32_t*)(fb.data));
|
||||
vgcanvas_reinit(mem->vgcanvas, fb.w, fb.h, line_length, (bitmap_format_t)(fb.format),
|
||||
(uint32_t*)(fb.data));
|
||||
}
|
||||
|
||||
return mem->vgcanvas;
|
||||
|
@ -35,7 +35,7 @@ lcd_t* lcd_nanovg_init(SDL_Window* sdl_window) {
|
||||
return_value_if_fail(sdl_window != NULL, NULL);
|
||||
|
||||
SDL_GetWindowSize(sdl_window, &w, &h);
|
||||
vg = vgcanvas_create(w, h, 0, sdl_window);
|
||||
vg = vgcanvas_create(w, h, 0, 0, sdl_window);
|
||||
return_value_if_fail(vg != NULL, NULL);
|
||||
|
||||
return lcd_vgcanvas_init(w, h, vg);
|
||||
|
@ -568,7 +568,7 @@ static ret_t vgcanvas_nanovg_unbind_fbo(vgcanvas_t* vgcanvas, framebuffer_object
|
||||
return RET_NOT_IMPL;
|
||||
}
|
||||
|
||||
static ret_t vgcanvas_nanovg_reinit(vgcanvas_t* vgcanvas, uint32_t w, uint32_t h,
|
||||
static ret_t vgcanvas_nanovg_reinit(vgcanvas_t* vgcanvas, uint32_t w, uint32_t h, uint32_t stride,
|
||||
bitmap_format_t format, void* data) {
|
||||
vgcanvas_nanovg_t* canvas = (vgcanvas_nanovg_t*)vgcanvas;
|
||||
NVGcontext* vg = canvas->vg;
|
||||
@ -576,7 +576,7 @@ static ret_t vgcanvas_nanovg_reinit(vgcanvas_t* vgcanvas, uint32_t w, uint32_t h
|
||||
vgcanvas->w = w;
|
||||
vgcanvas->h = h;
|
||||
vgcanvas->buff = (uint32_t*)data;
|
||||
nvgReinitAgge(vg, w, h, bitmap_format_to_nanovg(format), data);
|
||||
nvgReinitAgge(vg, w, h, stride, bitmap_format_to_nanovg(format), data);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
@ -639,7 +639,7 @@ static int vgcanvas_nanovg_ensure_image(vgcanvas_nanovg_t* canvas, bitmap_t* img
|
||||
return i;
|
||||
}
|
||||
#else
|
||||
static ret_t vgcanvas_nanovg_reinit(vgcanvas_t* vg, uint32_t w, uint32_t h, bitmap_format_t format,
|
||||
static ret_t vgcanvas_nanovg_reinit(vgcanvas_t* vg, uint32_t w, uint32_t h, uint32_t stride, bitmap_format_t format,
|
||||
void* data) {
|
||||
(void)vg;
|
||||
(void)w;
|
||||
@ -825,7 +825,8 @@ static const vgcanvas_vtable_t vt = {vgcanvas_nanovg_reinit,
|
||||
vgcanvas_nanovg_destroy};
|
||||
|
||||
#if defined(WITH_NANOVG_SOFT)
|
||||
vgcanvas_t* vgcanvas_create(uint32_t w, uint32_t h, bitmap_format_t format, void* data) {
|
||||
vgcanvas_t* vgcanvas_create(uint32_t w, uint32_t h, uint32_t stride, bitmap_format_t format,
|
||||
void* data) {
|
||||
enum NVGtexture f = bitmap_format_to_nanovg(format);
|
||||
vgcanvas_nanovg_t* nanovg = (vgcanvas_nanovg_t*)TKMEM_ZALLOC(vgcanvas_nanovg_t);
|
||||
return_value_if_fail(nanovg != NULL, NULL);
|
||||
@ -836,9 +837,9 @@ vgcanvas_t* vgcanvas_create(uint32_t w, uint32_t h, bitmap_format_t format, void
|
||||
nanovg->base.ratio = 1;
|
||||
nanovg->base.buff = (uint32_t*)data;
|
||||
#if defined(WITH_NANOVG_AGG)
|
||||
nanovg->vg = nvgCreateAGG(w, h, f, (uint8_t*)data);
|
||||
nanovg->vg = nvgCreateAGG(w, h, stride, f, (uint8_t*)data);
|
||||
#elif defined(WITH_NANOVG_AGGE)
|
||||
nanovg->vg = nvgCreateAGGE(w, h, f, (uint8_t*)data);
|
||||
nanovg->vg = nvgCreateAGGE(w, h, stride, f, (uint8_t*)data);
|
||||
#else
|
||||
#error "not supported"
|
||||
#endif
|
||||
@ -846,7 +847,7 @@ vgcanvas_t* vgcanvas_create(uint32_t w, uint32_t h, bitmap_format_t format, void
|
||||
return &(nanovg->base);
|
||||
}
|
||||
#else /*OpenGL*/
|
||||
vgcanvas_t* vgcanvas_create(uint32_t w, uint32_t h, bitmap_format_t format, void* sdl_window) {
|
||||
vgcanvas_t* vgcanvas_create(uint32_t w, uint32_t h, uint32_t stride, bitmap_format_t format, void* sdl_window) {
|
||||
int ww = 0;
|
||||
int wh = 0;
|
||||
int fw = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user