framebuf-control.html
来自「ecos3.0 beta 的官方文档,html格式」· HTML 代码 · 共 918 行 · 第 1/2 页
HTML
918 行
<CODE
CLASS="STRUCTFIELD"
>fbvp_y</CODE
> fields will be filled in. To move
the viewport use <TT
CLASS="LITERAL"
>CYG_FB_IOCTL_VIEWPORT_SET_POSITION</TT
>
with <CODE
CLASS="STRUCTFIELD"
>fbvp_x</CODE
> and
<CODE
CLASS="STRUCTFIELD"
>fbvp_y</CODE
> set to the top left corner of the
new viewport within the framebuffer, and
<CODE
CLASS="STRUCTFIELD"
>fbvp_when</CODE
> set to either
<TT
CLASS="LITERAL"
>CYG_FB_UPDATE_NOW</TT
> or
<TT
CLASS="LITERAL"
>CYG_FB_UPDATE_VERTICAL_RETRACE</TT
>. If the device
driver cannot easily synchronize to a vertical retrace period then
this last field is ignored.
</P
><TABLE
BORDER="5"
BGCOLOR="#E0E0F0"
WIDTH="70%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>void
move_viewport(cyg_fb* fb, int dx, int dy)
{
#ifdef CYGHWR_IO_FRAMEBUF_FUNCTIONALITY_VIEWPORT
cyg_fb_ioctl_viewport viewport;
int len = sizeof(cyg_fb_ioctl_viewport);
int result;
result = cyg_fb_ioctl(fb, CYG_FB_IOCTL_VIEWPORT_GET_POSITION,
&viewport, &len);
if (result != 0) {
…
}
if (((int)viewport.fbvp_x + dx) < 0) {
viewport.fbvp_x = 0;
} else if ((viewport.fbvp_x + dx + fb->fb_viewport_width) > fb->fb_width) {
viewport.fbvp_x = fb->fb_width - fb->fb_viewport_width;
} else {
viewport.fbvp_x += dx;
}
if (((int)viewport.fbvp_y + dy) < 0) {
viewport.fbvp_y = 0;
} else if ((viewport.fbvp_y + dy + fb->fb_viewport_height) > fb->fb_height) {
viewport.fbvp_y = fb->fb_height - fb->fb_viewport_height;
} else {
viewport.fbvp_y += dy;
}
result = cyg_fb_ioctl(fb, CYG_FB_IOCTL_VIEWPORT_SET_POSITION,
&viewport, &len);
if (result != 0) {
…
}
#else
CYG_UNUSED_PARAM(cyg_fb*, fb);
CYG_UNUSED_PARAM(int, dx);
CYG_UNUSED_PARAM(int, dy);
#endif
}
</PRE
></TD
></TR
></TABLE
><P
>If an attempt is made to move the viewport beyond the boundaries of
the framebuffer then the resulting behaviour is undefined. Some
hardware may behave reasonably, wrapping around as appropriate, but
portable code cannot assume this. The above code fragment is careful
to clip the viewport to the framebuffer dimensions.
</P
></DIV
><DIV
CLASS="REFSECT2"
><A
NAME="FRAMEBUF-CONTROL-IOCTL-PAGEFLIP"
></A
><H3
>Page Flipping</H3
><TABLE
BORDER="5"
BGCOLOR="#E0E0F0"
WIDTH="70%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
># define CYG_FB_IOCTL_PAGE_FLIPPING_GET_PAGES 0x0200
# define CYG_FB_IOCTL_PAGE_FLIPPING_SET_PAGES 0x0201
typedef struct cyg_fb_ioctl_page_flip {
cyg_uint32 fbpf_number_pages;
cyg_uint32 fbpf_visible_page;
cyg_uint32 fbpf_drawable_page;
cyg_ucount16 fbpf_when; // set-only, now or vert retrace
} cyg_fb_ioctl_page_flip;
</PRE
></TD
></TR
></TABLE
><P
>On some targets the framebuffer has enough memory for several pages,
only one of which is visible at a time. This allows the application
to draw into one page while displaying another. Once drawing is
complete the display is flipped to the newly drawn page, and the
previously displayed page is now available for updating. This
technique is used for smooth animation, especially in games. The flag
<TT
CLASS="LITERAL"
>CYG_FB_FLAGS0_PAGE_FLIPPING</TT
> indicates support for
this functionality.
</P
><P
><TT
CLASS="LITERAL"
>CYG_FB_IOCTL_PAGE_FLIPPING_GET_PAGES</TT
> can be used to
get the current settings of the page flipping support. The data
argument should be a pointer to a
<CODE
CLASS="STRUCTNAME"
>cyg_fb_ioctl_page_flip</CODE
> structure. The
resulting <CODE
CLASS="STRUCTFIELD"
>fbpf_number_pages</CODE
> field indicates
the total number of pages available: 2 is common, but more pages are
possible. <CODE
CLASS="STRUCTFIELD"
>fbpf_visible_page</CODE
> gives the page
that is currently visible to the user, and will be between 0 and
(<CODE
CLASS="STRUCTFIELD"
>fbpf_number_pages</CODE
> - 1).
Similarly <CODE
CLASS="STRUCTFIELD"
>fbpf_drawable_page</CODE
> gives the page
that is currently visible. It is implementation-defined whether or not
the visible and drawable page can be the same one.
</P
><P
><TT
CLASS="LITERAL"
>CYG_FB_IOCTL_PAGE_FLIPPING_SET_PAGES</TT
> can be used to
change the visible and drawable page. The
<CODE
CLASS="STRUCTFIELD"
>fbpf_number_pages</CODE
> field is ignored.
<CODE
CLASS="STRUCTFIELD"
>fbpf_visible_page</CODE
> and
<CODE
CLASS="STRUCTFIELD"
>fbpf_drawable_page</CODE
> give the new settings.
<CODE
CLASS="STRUCTFIELD"
>fbpf_when</CODE
> should be one of
<TT
CLASS="LITERAL"
>CYG_FB_UPDATE_NOW</TT
> or
<TT
CLASS="LITERAL"
>CYG_FB_UPDATE_VERTICAL_RETRACE</TT
>, but may be ignored
by some device drivers.
</P
><TABLE
BORDER="5"
BGCOLOR="#E0E0F0"
WIDTH="70%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>#if !(CYG_FB_FLAGS0(FRAMEBUF) & CYG_FB_FLAGS0_PAGE_FLIPPING)
# error Current framebuffer device does not support page flipping
#endif
static cyg_uint32 current_visible = 0;
static void
page_flip_init(cyg_fb_colour background)
{
cyg_fb_ioctl_page_flip flip;
size_t len = sizeof(cyg_fb_ioctl_page_flip);
flip.fbpf_visible_page = current_visible;
flip.fbpf_drawable_page = 1 - current_visible;
flip.fbpf_when = CYG_FB_UPDATE_NOW;
CYG_FB_IOCTL(FRAMEBUF, CYG_FB_IOCTL_PAGE_FLIPPING_SET_PAGES,
&flip, &len);
CYG_FB_FILL_BLOCK(FRAMEBUF, 0, 0,
CYG_FB_WIDTH(FRAMEBUF), CYG_FB_HEIGHT(FRAMEBUF),
background);
flip.fbpf_visible_page = 1 - current_visible;
flip.fbpf_drawable_page = current_visible;
CYG_FB_IOCTL(FRAMEBUF, CYG_FB_IOCTL_PAGE_FLIPPING_SET_PAGES,
&flip, &len);
CYG_FB_FILL_BLOCK(FRAMEBUF, 0, 0,
CYG_FB_WIDTH(FRAMEBUF), CYG_FB_HEIGHT(FRAMEBUF),
background);
current_visible = 1 - current_visible;
}
static void
page_flip_toggle(void)
{
cyg_fb_ioctl_page_flip flip;
size_t len = sizeof(cyg_fb_ioctl_page_flip);
flip.fbpf_visible_page = 1 - current_visible;
flip.fbpf_drawable_page = current_visible;
CYG_FB_IOCTL(FRAMEBUF, CYG_FB_IOCTL_PAGE_FLIPPING_SET_PAGES,
&flip, &len);
current_visible = 1 - current_visible;
}
</PRE
></TD
></TR
></TABLE
><P
>A page flip typically just changes a couple of pointers within the
hardware and device driver. No attempt is made to synchronize the
contents of the pages, that is left to higher-level code.
</P
></DIV
><DIV
CLASS="REFSECT2"
><A
NAME="FRAMEBUF-CONTROL-IOCTL-BLANK"
></A
><H3
>Blanking the Screen</H3
><TABLE
BORDER="5"
BGCOLOR="#E0E0F0"
WIDTH="70%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
># define CYG_FB_IOCTL_BLANK_GET 0x0300
# define CYG_FB_IOCTL_BLANK_SET 0x0301
typedef struct cyg_fb_ioctl_blank {
cyg_bool fbbl_on;
} cyg_fb_ioctl_blank;
</PRE
></TD
></TR
></TABLE
><P
>Some hardware allows the display to be switched off or blanked without
shutting down the entire framebuffer device, greatly reducing power
consumption. The current blanking state can be obtained using
<TT
CLASS="LITERAL"
>CYG_FB_IOCTL_BLANK_GET</TT
> and the state can be updated
using <TT
CLASS="LITERAL"
>CYG_FB_IOCTL_BLANK_SET</TT
>. The data argument
should be a pointer to a <CODE
CLASS="STRUCTNAME"
>cyg_fb_ioctl_blank</CODE
>
structure. Support for this functionality is indicated by the
<TT
CLASS="LITERAL"
>CYG_FB_FLAGS0_BLANK</TT
> flag.
</P
><TABLE
BORDER="5"
BGCOLOR="#E0E0F0"
WIDTH="70%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>static cyg_bool
display_blanked(cyg_fb_* fb)
{
cyg_fb_ioctl_blank blank;
size_t len = sizeof(cyg_fb_ioctl_blank);
if (! (fb->fb_flags0 & CYG_FB_FLAGS0_BLANK)) {
return false;
}
(void) cyg_fb_ioctl(fb, CYG_FB_IOCTL_BLANK_GET, &blank, &len);
return !blank.fbbl_on;
}
</PRE
></TD
></TR
></TABLE
></DIV
><DIV
CLASS="REFSECT2"
><A
NAME="FRAMEBUF-CONTROL-IOCTL-BACKLIGHT"
></A
><H3
>Controlling the Backlight</H3
><TABLE
BORDER="5"
BGCOLOR="#E0E0F0"
WIDTH="70%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
># define CYG_FB_IOCTL_BACKLIGHT_GET 0x0400
# define CYG_FB_IOCTL_BACKLIGHT_SET 0x0401
typedef struct cyg_fb_ioctl_backlight {
cyg_ucount32 fbbl_current;
cyg_ucount32 fbbl_max;
} cyg_fb_ioctl_backlight;
</PRE
></TD
></TR
></TABLE
><P
>Many LCD panels provide some sort of backlight, making the display
easier to read at the cost of increased power consumption. Support for
this is indicated by the <TT
CLASS="LITERAL"
>CYG_FB_FLAGS0_BACKLIGHT</TT
>
flag. <TT
CLASS="LITERAL"
>CYG_FB_IOCTL_BACKLIGHT_GET</TT
> can be used to get
both the current setting and the maximum value. If the maximum is 1
then the backlight can only be switched on or off. Otherwise it is
possible to control the intensity.
</P
><TABLE
BORDER="5"
BGCOLOR="#E0E0F0"
WIDTH="70%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>static void
set_backlight_50_percent(void)
{
#if (CYG_FB_FLAGS0(FRAMEBUF) & CYG_FB_FLAGS0_BACKLIGHT)
cyg_fb_ioctl_backlight backlight;
size_t len = sizeof(cyg_fb_ioctl_backlight);
CYG_FB_IOCTL(FRAMEBUF, CYG_FB_IOCTL_BACKLIGHT_GET, &backlight, &len);
backlight.fbbl_current = (backlight.fbbl_max + 1) >> 1;
CYG_FB_IOCTL(FRAMEBUF, CYG_FB_IOCTL_BACKLIGHT_SET, &backlight, &len);
#endif
}
</PRE
></TD
></TR
></TABLE
></DIV
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="framebuf-parameters.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="ecos-ref.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="framebuf-colour.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>Framebuffer Parameters</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="io-framebuf.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>Framebuffer Colours</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?