博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Understanding Canvas and Surface concepts
阅读量:6588 次
发布时间:2019-06-24

本文共 3015 字,大约阅读时间需要 10 分钟。

  hot3.png

Here are some definitions:

  • A Surface is an object holding pixels that are being composited to the screen. Every window you see on the screen (a dialog, your full-screen activity, the status bar) has its own surface that it draws in to, and Surface Flinger renders these to the final display in their correct Z-order. A surface typically has more than one buffer (usually two) to do double-buffered rendering: the application can be drawing its next UI state while the surface flinger is compositing the screen using the last buffer, without needing to wait for the application to finish drawing.

  • A window is basically like you think of a window on the desktop. It has a single Surface in which the contents of the window is rendered. An application interacts with the Window Manager to create windows; the Window Manager creates a Surface for each window and gives it to the application for drawing. The application can draw whatever it wants in the Surface; to the Window Manager it is just an opaque rectangle.

  • A View is an interactive UI element inside of a window. A window has a single view hierarchy attached to it, which provides all of the behavior of the window. Whenever the window needs to be redrawn (such as because a view has invalidated itself), this is done into the window's Surface. The Surface is locked, which returns a Canvas that can be used to draw into it. A draw traversal is done down the hierarchy, handing the Canvas down for each view to draw its part of the UI. Once done, the Surface is unlocked and posted so that the just drawn buffer is swapped to the foreground to then be composited to the screen by Surface Flinger.

  • A SurfaceView is a special implementation of View that also creates its own dedicated Surface for the application to directly draw into (outside of the normal view hierarchy, which otherwise must share the single Surface for the window). The way this works is simpler than you may expect -- all SurfaceView does is ask the window manager to create a new window, telling it to Z-order that window either immediately behind or in front of the SurfaceView's window, and positioning it to match where the SurfaceView appears in the containing window. If the surface is being placed behind the main window (in Z order), SurfaceView also fills its part of the main window with transparency so that the surface can be seen.

  • A Bitmap is just an interface to some pixel data. The pixels may be allocated by Bitmap itself when you are directly creating one, or it may be pointing to pixels it doesn't own such as what internally happens to hook a Canvas up to a Surface for drawing. (A Bitmap is created and pointed to the current drawing buffer of the Surface.)

Also please keep in mind that, as this implies, a SurfaceView is a pretty heavy-weight object. If you have multiple SurfaceViews in a particular UI, stop and think about whether this is really needed. If you have more than two, you almost certainly have too many.

转载于:https://my.oschina.net/jerikc/blog/464754

你可能感兴趣的文章
(EM算法)The EM Algorithm
查看>>
grep用法
查看>>
top
查看>>
HTTP与HTTPS简介
查看>>
rhcsa第二天笔记
查看>>
一则 gfs2 集群文件系统无法挂载的解决案例
查看>>
曾经的你
查看>>
ArrayList的subList方法
查看>>
想当好员工,想加薪,想提高的最起码应该注意的几项工作习惯
查看>>
经典SQL语句大全(转)
查看>>
linux下repair filesystem模式修复方法
查看>>
Oracle从非归档模式变成归档模式
查看>>
互联网时代: 从Uber的供需匹配看开发需求
查看>>
在CentOS 6.7部署wordpress博客系统Discuz论坛系统
查看>>
中兴U880刷机
查看>>
Spring4学习笔记-泛型依赖注入
查看>>
OSPF的虚拟链路
查看>>
AngularJS 字符串
查看>>
thinkphp-条件判断-范围判断-in
查看>>
log.py——打印出独立IP,并统计独立IP数
查看>>