Просмотр исходного кода

awtk库更新:
1.打通LCD1图层的透明度通道,显示出LCD0图层的画面,实现双图层同显
2.修复自带透明度的字体显示异常的问题

helen 2 недель назад
Родитель
Сommit
f42365cb43

+ 50 - 5
amt630hv160-freertos-beta/lib/awtk/awtk/3rd/vglite/vgcanvas_nanovg_vglite.c

@@ -1113,8 +1113,11 @@ NVGcontext* nvgCreateVGLite(uint32_t w, uint32_t h, uint32_t stride, enum NVGtex
 
 	ctx = nvgCreateInternal(&params);
 	if (ctx == NULL) goto error;
-
-	nvgInitVGL(ctx, &params, w, h, stride, format, data);
+	static int vglite_init_flag = 0;
+	if (vglite_init_flag == 0) {
+		vglite_init_flag = 1;
+		nvgInitVGL(ctx, &params, w, h, stride, format, data);
+	}
 
 	printf("VGLite init success\r\n");
 
@@ -1467,7 +1470,7 @@ static uint32_t get_vglite_vertor_font(stbtt_vertex* vertices, int num_vertices)
 	dataSize *= 2;
 
 	if (dataSize > PATH_MAX_SIZE) {
-		printf("font lib number over limit, plz defind FONT_LIB_COUNT\n");
+		printf("PATH_MAX_SIZE font path to long, num_vertices = %d,dataSize = %d \r\n\n", num_vertices, dataSize);
 		return 0;
 	}
 
@@ -1527,7 +1530,8 @@ static uint32_t get_vglite_vertor_font(stbtt_vertex* vertices, int num_vertices)
 	return dataSize;
 }
 
-void vglite_draw_glyph_truetype(stbtt_fontinfo* sf, wchar_t chr, const rect_t* dst, rect_t* r, float_t scale, float tx, float ty, vg_lite_color_t color) {
+void vglite_draw_glyph_truetype(stbtt_fontinfo* sf, wchar_t chr, const rect_t* dst, rect_t* r, float_t scale, float tx, float ty,
+								vg_lite_color_t color, uint8_t global_alpha) {
 	int glyphIndex, num_vertices;
 	stbtt_vertex* vertices;
 	vg_lite_error_t error;
@@ -1535,7 +1539,7 @@ void vglite_draw_glyph_truetype(stbtt_fontinfo* sf, wchar_t chr, const rect_t* d
 	vg_lite_path_t pathx = {0};
 	vg_lite_matrix_t matrix = {0};
 	uint32_t bounds[4] = {dst->x, dst->y - dst->h, dst->w, dst->y};
-	int32_t x0,x1,y0,y1;
+	int32_t x0, x1, y0, y1;
 	uint32_t start_address, rt_pixsize, dataSize = 0, vertFlag = 0;
 	void* tempData;
 	vg_lite_enable_scissor();
@@ -1566,6 +1570,9 @@ void vglite_draw_glyph_truetype(stbtt_fontinfo* sf, wchar_t chr, const rect_t* d
 		num_vertices = stbtt_GetGlyphShape(sf, glyphIndex, &vertices);
 		vertFlag = 1;
 		dataSize = get_vglite_vertor_font(vertices, num_vertices);
+		if (dataSize <= 0) {
+			printf("dataSize %d,glyphIndex:%d,chr:%lc\r\n", (uint32_t)tempData, glyphIndex, chr);
+		}
 #ifdef VGLITE_FONT_CACHE
 #ifndef FONT_CACHE_CH
 		if (charFlag)
@@ -1594,6 +1601,11 @@ void vglite_draw_glyph_truetype(stbtt_fontinfo* sf, wchar_t chr, const rect_t* d
 	start_address = rt->address + bounds[1] * rt->stride + bounds[0] * rt_pixsize;
 	ark_g2d_invalidate_cache(start_address, bounds[2], bounds[3], rt->stride, rt_pixsize);
 	vg_lite_set_draw_path_type(&pathx, VG_LITE_DRAW_FILL_PATH);
+
+	if (global_alpha != 0xFF) {
+		uint32_t alpha_ch = (((color >> 24) * global_alpha) >> 8) << 24;
+		color = color & 0x00FFFFFF | alpha_ch;
+	}
 	CHECK_ERROR(vg_lite_draw(rt, &pathx, VG_LITE_FILL_NON_ZERO, &matrix, VG_LITE_BLEND_SRC_OVER, color));
 	CHECK_ERROR(vg_lite_flush());
 	vg_lite_clear_path(&pathx);
@@ -1636,3 +1648,36 @@ void vglite_draw_dash_line(vgcanvas_t* vg, float_t* pts, uint32_t data_size, col
 	vg_lite_clear_path(&pathx);
 	vg_lite_disable_scissor();
 }
+
+static int clear_alpha_flag = 0;
+// clear_alpha_flag:
+// 0 - Disable alpha clear
+// 1 - Enable alpha clear
+// Set clear_alpha_flag
+int lcd_set_clear_alpha(int clear_alpha_value) {
+	clear_alpha_flag = clear_alpha_value;
+	return clear_alpha_flag;
+}
+
+// Get clear_alpha_flag
+int lcd_get_clear_alpha(void) {
+	return clear_alpha_flag;
+}
+
+// x, y, w, h:
+// Rectangle position and size
+// color:
+// Clear color.
+// Use 0x00000000 to clear the region with full transparency.
+void vg_lite_clear_rect(int32_t x, int32_t y, int32_t w, int32_t h, uint32_t color) {
+	vg_lite_rectangle_t dstRect = {x, y, w, h};
+	vg_lite_color_t vg_color = color;
+	vg_lite_buffer_t* rt;
+	ret_t ret;
+	rt = (vg_lite_buffer_t*)vglite_get_render_target();
+	if (!rt) {
+		printf("rt not found, %d\r\n", __LINE__);
+	}
+	vg_lite_clear(rt, &dstRect, vg_color);
+	vg_lite_finish();
+}

+ 31 - 4
amt630hv160-freertos-beta/lib/awtk/awtk/src/lcd/lcd_mem.inc

@@ -105,7 +105,7 @@ static bitmap_t* lcd_mem_init_online_fb(lcd_t* lcd, bitmap_t* fb, lcd_orientatio
 
   return fb;
 }
-
+extern int lcd_get_clear_alpha(void);
 static ret_t lcd_mem_begin_frame(lcd_t* lcd, const dirty_rects_t* dirty_rects) {
   lcd_mem_t* mem = (lcd_mem_t*)lcd;
   vgcanvas_t* vg = lcd_get_vgcanvas(lcd);
@@ -141,7 +141,28 @@ static ret_t lcd_mem_begin_frame(lcd_t* lcd, const dirty_rects_t* dirty_rects) {
     }
   }
 #else
-  return RET_OK;
+  if(lcd_get_clear_alpha() == 1) {
+    dirty_rects = lcd_get_dirty_rects(lcd);
+    if (lcd->draw_mode == LCD_DRAW_OFFLINE || dirty_rects == NULL) {
+      bitmap_t fb;
+      lcd_mem_init_drawing_fb(lcd, &fb);
+      rect_t r = rect_init(0, 0, lcd_get_physical_width(lcd), lcd_get_physical_height(lcd));
+      return image_clear(&fb, &r, color_init(0x0, 0x0, 0x0, 0x0));
+    } else {
+      if (dirty_rects->disable_multiple) {
+        return lcd_mem_clear_rect_impl(lcd, dirty_rects->max.x, dirty_rects->max.y, dirty_rects->max.w, dirty_rects->max.h, color_init(0x0, 0x0, 0x0, 0x0));
+      } else {
+        int32_t i = 0;
+        for (i = 0; i < dirty_rects->nr; i++) {
+          const rect_t* iter = dirty_rects->rects + i;
+          lcd_mem_clear_rect_impl(lcd, iter->x, iter->y, iter->w, iter->h, color_init(0x0, 0x0, 0x0, 0x0));
+        }
+        return RET_OK;
+      }
+    }
+  } else {
+    return RET_OK;
+  }
 #endif
 }
 
@@ -184,8 +205,14 @@ static ret_t lcd_mem_clear_rect_impl(lcd_t* lcd, xy_t x, xy_t y, wh_t w, wh_t h,
     rr = rect_init(x, y, w, h);
   }
 
+#ifdef WITH_NANOVG_VGLITE
+  extern void vg_lite_clear_rect(int32_t x, int32_t y, int32_t w, int32_t h, uint32_t color);
+  vg_lite_clear_rect(x, y, w, h, c.color);
+  return RET_OK;
+#else
   lcd_mem_init_drawing_fb(lcd, &fb);
   return image_clear(&fb, &rr, c);
+#endif
 }
 
 static ret_t lcd_mem_clear_rect(lcd_t* lcd, xy_t x, xy_t y, wh_t w, wh_t h) {
@@ -460,9 +487,9 @@ static ret_t lcd_mem_draw_glyph(lcd_t* lcd, glyph_t* glyph, const rect_t* src, x
 #ifdef VGLITE_FONT
 //#include "vg_lite.h"
 #include "stb\stb_truetype.h"
-extern void vglite_draw_glyph_truetype(void* sf, wchar_t chr, const rect_t* dst, rect_t* r , float_t scale, float tx, float ty, uint32_t color);
+extern void vglite_draw_glyph_truetype(void* sf, wchar_t chr, const rect_t* dst, rect_t* r , float_t scale, float tx, float ty, uint32_t color, uint8_t global_alpha);
 static ret_t vglite_draw_text_vglite(lcd_t* lcd, void* sf, wchar_t chr, const rect_t* dst, rect_t* r , float_t scale, float tx, float ty) {
-  vglite_draw_glyph_truetype(sf, chr, dst, r, scale, tx, ty, lcd->text_color.color);
+  vglite_draw_glyph_truetype(sf, chr, dst, r, scale, tx, ty, lcd->text_color.color, lcd->global_alpha);
   return RET_OK;
 }
 #endif