「App:Library:LVGL:docs:Overview:Drawing」の版間の差分
32行目: | 32行目: | ||
The main difference is that with LVGL you don't have to store two frame buffers (which usually requires external RAM) but only smaller draw buffer(s) that can easily fit into internal RAM. | The main difference is that with LVGL you don't have to store two frame buffers (which usually requires external RAM) but only smaller draw buffer(s) that can easily fit into internal RAM. | ||
− | | | + | |LVGLを使えば、何も手動で描く必要はありません。 |
+ | |||
+ | オブジェクト(ボタン、ラベル、円弧など)を作成し、移動、変更するだけで、LVGLは必要なものをリフレッシュして再描画します。 | ||
+ | |||
+ | しかし、LVGLでどのように描画が行われるかを基本的に理解しておくことは、カスタマイズの追加やバグの発見を容易にするため、あるいは単なる好奇心で、役に立つことがあるのです。 | ||
+ | |||
+ | 基本的なコンセプトは、ディスプレイに直接描画するのではなく、まず内部のドローバッファに描画することです。 | ||
+ | |||
+ | 描画(レンダリング)の準備ができると、そのバッファがディスプレイにコピーされます。 | ||
+ | |||
+ | |||
+ | ドローバッファは、ディスプレイのサイズより小さくすることができます。 | ||
+ | |||
+ | LVGLは、与えられたドローバッファに収まる「タイル」で単純にレンダリングします。 | ||
+ | |||
+ | この方法は、ディスプレイへの直接描画と比較して、主に2つの利点があります。 | ||
+ | # UIのレイヤーを描画している間のちらつきを回避することができます。例えば、LVGLがディスプレイに直接描画する場合、背景+ボタン+テキストを描画すると、それぞれの「ステージ」が短時間だけ表示されることになる。 | ||
+ | # ピクセルアクセスのたびにディスプレイを直接読み書きするよりも、内部RAMのバッファを変更し、最終的に1ピクセルだけ書き込む方が高速になるのです。(例:SPIインターフェイスを持つディスプレイコントローラ経由)。 | ||
+ | |||
+ | |||
+ | このコンセプトは、ディスプレイサイズのフレームバッファが2つある「従来の」ダブルバッファリングとは異なることに注意してください:1つはディスプレイに表示する現在の画像を保持し、レンダリングは他の(非アクティブな)フレームバッファで行われ、レンダリングの終了時にそれらが交換されます。 | ||
+ | |||
+ | |||
+ | 主な違いは、LVGLでは、2つのフレームバッファ(これは通常、外部RAMを必要とします)を保存する必要がなく、内部RAMに簡単に収まる小さな描画バッファ(複数可)だけでよいということです。 | ||
|} | |} | ||
:[[App:Library:LVGL:docs:Overview|戻る : Previous]] | :[[App:Library:LVGL:docs:Overview|戻る : Previous]] | ||
67行目: | 90行目: | ||
# Two buffers - LVGL can immediately draw to the second buffer when the first is sent to <code style="color: #bb0000;">flush_cb</code> because the flushing should be done by DMA (or similar hardware) in the background. | # Two buffers - LVGL can immediately draw to the second buffer when the first is sent to <code style="color: #bb0000;">flush_cb</code> because the flushing should be done by DMA (or similar hardware) in the background. | ||
# Double buffering - <code style="color: #bb0000;">flush_cb</code> should only swap the addresses of the frame buffers. | # Double buffering - <code style="color: #bb0000;">flush_cb</code> should only swap the addresses of the frame buffers. | ||
− | | | + | |まず,LVGL の Buffering モードに慣れるようにしてください. |
+ | |||
+ | LVGLは以下の手順で画面を更新しています。 | ||
+ | # UIで再描画を必要とするようなことが起こる。例えば、ボタンが押された、チャートが変更された、アニメーションが起こった、などです。 | ||
+ | # LVGLは、変更されたオブジェクトの旧領域と新領域を、Invalid area bufferと呼ばれるバッファに保存します。最適化のため、場合によっては、オブジェクトはバッファに追加されません。 | ||
+ | #* 隠されたオブジェクトは追加されません。 | ||
+ | #* 親から完全にはみ出したオブジェクトは追加されません。 | ||
+ | #* 親から部分的にはみ出した領域は、親の領域に合わせて切り取られます。 | ||
+ | #* 他の画面上のオブジェクトは追加されません。 | ||
+ | # In every <code style="color: #bb0000;">LV_DISP_DEF_REFR_PERIOD</code> (set in <code style="color: #bb0000;">lv_conf.h</code>) the following happens: | ||
+ | #* LVGL checks the invalid areas and joins those that are adjacent or intersecting. | ||
+ | #* Takes the first joined area, if it's smaller than the ''draw buffer'', then simply renders the area's content into the ''draw buffer''. If the area doesn't fit into the buffer, draw as many lines as possible to the ''draw buffer''. | ||
+ | #* When the area is rendered, call <code style="color: #bb0000;">flush_cb</code> from the display driver to refresh the display. | ||
+ | #* If the area was larger than the buffer, render the remaining parts too. | ||
+ | #* Repeat the same with remaining joined areas. | ||
+ | |||
+ | When an area is redrawn the library searches the top-most object which covers that area and starts drawing from that object. For example, if a button's label has changed, the library will see that it's enough to draw the button under the text and it's not necessary to redraw the display under the rest of the button too. | ||
+ | |||
+ | The difference between buffering modes regarding the drawing mechanism is the following: | ||
+ | |||
+ | # One buffer - LVGL needs to wait for <code style="color: #bb0000;">lv_disp_flush_ready()</code> (called from <code style="color: #bb0000;">flush_cb</code>) before starting to redraw the next part. | ||
+ | # Two buffers - LVGL can immediately draw to the second buffer when the first is sent to <code style="color: #bb0000;">flush_cb</code> because the flushing should be done by DMA (or similar hardware) in the background. | ||
+ | # Double buffering - <code style="color: #bb0000;">flush_cb</code> should only swap the addresses of the frame buffers. | ||
|} | |} | ||
:[[App:Library:LVGL:docs:Overview|戻る : Previous]] | :[[App:Library:LVGL:docs:Overview|戻る : Previous]] |
2022年7月1日 (金) 18:46時点における版
https://docs.lvgl.io/8.2/overview/drawing.html
Drawing
英文 | 自動翻訳 |
---|---|
With LVGL, you don't need to draw anything manually. Just create objects (like buttons, labels, arc, etc.), move and change them, and LVGL will refresh and redraw what is required. However, it can be useful to have a basic understanding of how drawing happens in LVGL to add customization, make it easier to find bugs or just out of curiosity. The basic concept is to not draw directly onto the display but rather to first draw on an internal draw buffer. When a drawing (rendering) is ready that buffer is copied to the display.
LVGL will simply render in "tiles" that fit into the given draw buffer. This approach has two main advantages compared to directly drawing to the display:
|
LVGLを使えば、何も手動で描く必要はありません。
オブジェクト(ボタン、ラベル、円弧など)を作成し、移動、変更するだけで、LVGLは必要なものをリフレッシュして再描画します。 しかし、LVGLでどのように描画が行われるかを基本的に理解しておくことは、カスタマイズの追加やバグの発見を容易にするため、あるいは単なる好奇心で、役に立つことがあるのです。 基本的なコンセプトは、ディスプレイに直接描画するのではなく、まず内部のドローバッファに描画することです。 描画(レンダリング)の準備ができると、そのバッファがディスプレイにコピーされます。
LVGLは、与えられたドローバッファに収まる「タイル」で単純にレンダリングします。 この方法は、ディスプレイへの直接描画と比較して、主に2つの利点があります。
|
Mechanism of screen refreshing
英文 | 自動翻訳 |
---|---|
Be sure to get familiar with the Buffering modes of LVGL first. LVGL refreshes the screen in the following steps:
When an area is redrawn the library searches the top-most object which covers that area and starts drawing from that object. For example, if a button's label has changed, the library will see that it's enough to draw the button under the text and it's not necessary to redraw the display under the rest of the button too. The difference between buffering modes regarding the drawing mechanism is the following:
|
まず,LVGL の Buffering モードに慣れるようにしてください.
LVGLは以下の手順で画面を更新しています。
When an area is redrawn the library searches the top-most object which covers that area and starts drawing from that object. For example, if a button's label has changed, the library will see that it's enough to draw the button under the text and it's not necessary to redraw the display under the rest of the button too. The difference between buffering modes regarding the drawing mechanism is the following:
|
Masking
英文 | 自動翻訳 |
---|---|
Masking is the basic concept of LVGL's draw engine. To use LVGL it's not required to know about the mechanisms described here but you might find interesting to know how drawing works under hood. Knowing about masking comes in handy if you want to customize drawing. To learn about masking let's see the steps of drawing first. LVGL performs the following steps to render any shape, image or text. It can be considered as a drawing pipeline.
LVGL has the following built-in mask types which can be calculated and applied real-time:
Masks are used to create almost every basic primitive:
|
Using masks
英文 | 自動翻訳 |
---|---|
Every mask type has a related parameter structure to describe the mask's data. The following parameter types exist:
A parameter can be added and removed any number of times, but it needs to be freed when not required anymore.
|
Hook drawing
英文 | 自動翻訳 |
---|---|
Although widgets can be easily customized by styles there might be cases when something more custom is required. To ensure a great level of flexibility LVGL sends a lot of events during drawing with parameters that tell what LVGL is about to draw. Some fields of these parameters can be modified to draw something else or any custom drawing operations can be added manually. A good use case for this is the Button matrix widget. By default, its buttons can be styled in different states, but you can't style the buttons one by one. However, an event is sent for every button and you can, for example, tell LVGL to use different colors on a specific button or to manually draw an image on some buttons. Each of these events is described in detail below. |
Main drawing
英文 | 自動翻訳 |
---|---|
These events are related to the actual drawing of an object. E.g. the drawing of buttons, texts, etc. happens here.
The clip area is required in draw functions to make them draw only on a limited area. |
LV_EVENT_DRAW_MAIN_BEGIN
英文 | 自動翻訳 |
---|---|
Sent before starting to draw an object. This is a good place to add masks manually. E.g. add a line mask that "removes" the right side of an object. |
LV_EVENT_DRAW_MAIN
英文 | 自動翻訳 |
---|---|
The actual drawing of an object happens in this event. E.g. a rectangle for a button is drawn here. First, the widgets' internal events are called to perform drawing and after that you can draw anything on top of them. For example you can add a custom text or an image. |
LV_EVENT_DRAW_MAIN_END
英文 | 自動翻訳 |
---|---|
Called when the main drawing is finished. You can draw anything here as well and it's also a good place to remove any masks created in |
Post drawing
英文 | 自動翻訳 |
---|---|
Post drawing events are called when all the children of an object are drawn. For example LVGL use the post drawing phase to draw scrollbars because they should be above all of the children.
|
LV_EVENT_DRAW_POST_BEGIN
英文 | 自動翻訳 |
---|---|
Sent before starting the post draw phase. Masks can be added here too to mask out the post drawn content. |
LV_EVENT_DRAW_POST
英文 | 自動翻訳 |
---|---|
The actual drawing should happen here. |
LV_EVENT_DRAW_POST_END
英文 | 自動翻訳 |
---|---|
Called when post drawing has finished. If masks were not removed in |
Part drawing
英文 | 自動翻訳 |
---|---|
When LVGL draws a part of an object (e.g. a slider's indicator, a table's cell or a button matrix's button) it sends events before and after drawing that part with some context of the drawing.
In these events an Not all fields are set for every part and widget.
// Always set const lv_area_t * clip_area; // The current clip area, required if you need to draw something in the event uint32_t part; // The current part for which the event is sent uint32_t id; // The index of the part. E.g. a button's index on button matrix or table cell index. // Draw desciptors, set only if related lv_draw_rect_dsc_t * rect_dsc; // A draw descriptor that can be modified to changed what LVGL will draw. Set only for rectangle-like parts lv_draw_label_dsc_t * label_dsc; // A draw descriptor that can be modified to changed what LVGL will draw. Set only for text-like parts lv_draw_line_dsc_t * line_dsc; // A draw descriptor that can be modified to changed what LVGL will draw. Set only for line-like parts lv_draw_img_dsc_t * img_dsc; // A draw descriptor that can be modified to changed what LVGL will draw. Set only for image-like parts lv_draw_arc_dsc_t * arc_dsc; // A draw descriptor that can be modified to changed what LVGL will draw. Set only for arc-like parts // Other parameters lv_area_t * draw_area; // The area of the part being drawn const lv_point_t * p1; // A point calculated during drawing. E.g. a point of a chart or the center of an arc. const lv_point_t * p2; // A point calculated during drawing. E.g. a point of a chart. char text[16]; // A text calculated during drawing. Can be modified. E.g. tick labels on a chart axis. lv_coord_t radius; // E.g. the radius of an arc (not the corner radius). int32_t value; // A value calculated during drawing. E.g. Chart's tick line value. const void * sub_part_ptr; // A pointer the identifies something in the part. E.g. chart series.
|
LV_EVENT_DRAW_PART_BEGIN
英文 | 自動翻訳 |
---|---|
Start the drawing of a part. This is a good place to modify the draw descriptors (e.g. |
LV_EVENT_DRAW_PART_END
英文 | 自動翻訳 |
---|---|
Finish the drawing of a part. This is a good place to draw extra content on the part or remove masks added in |
Others
LV_EVENT_COVER_CHECK
英文 | 自動翻訳 |
---|---|
This event is used to check whether an object fully covers an area or not.
Here are some reasons why an object would be unable to fully cover an area:
In short if for any reason the area below an object is visible than the object doesn't cover that area. Before sending this event LVGL checks if at least the widget's coordinates fully cover the area or not. If not the event is not called.
The existing properties known by a widget are handled in its internal events. E.g. if a widget has > 0 radius it might not cover an area, but you need to handle |
LV_EVENT_REFR_EXT_DRAW_SIZE
英文 | 自動翻訳 |
---|---|
If you need to draw outside a widget, LVGL needs to know about it to provide extra space for drawing. Let's say you create an event which writes the current value of a slider above its knob. In this case LVGL needs to know that the slider's draw area should be larger with the size required for the text. You can simply set the required draw area with |