=========================
UPDATE: After several days googling and experiments, I have found the answers for most of those dumb questions. See the answers I submitted.
=========
What is the responsibility of Android Window?
Here are some questions:
- Is it responsible for collecting and dispatching the input?
- What is the relationship between the view and window? Same as the relationship between surface and window in DFB?
- What is the relationship between an activity and window? Will each Activity has a window?
- Is it possible to create a window from application ? And when it is necessary?
- Does Android support multi-window?
EDIT: Add more questions:
What is responsibilities of various class , such as Window, View, Canvas, Surface and how they collaborate with each other?
How many windows usually an Activity have?
3.Will all the views in one Activity will be attached to Window? What does attach mean?
Every window have surface? Every Canvas has surface?
View is responsible for focus/keyEvent/ manager, while Cavus is only responsible for "drawing" operation.
WindowManager is responsible for Window stacking? How that is related with SurfaceFlinger?
View doesn't own a Surface , the Window the view contained owns?
The View draw itself using canvas got by calling surface.lockCanvas().
When onDraw(Canvas) will be called? How & who pass the canvas parameters?
Does Canvas has size? Will Window's surface always be full screen?
EDIT again:
After watching this wonderful presentatin provided by Romain Guy http://www.youtube.com/watch?v=duefsFTJXzc&feature=feedwll&list=WL , several questions are resolved and add several more :)
- Will every Activity has one ViewRoot and thus one Window?
- Is there any need to create a window explictly? and Will the surface for the window always be full screen?
- Will status bar be in another Window?
- What is the size of the surface? Will that always be full screen?
No. ViewRoot is responsible for this.
?
Yes, most of the time. However, a SurfaceView has its own window. So, if an Activity has a SurfaceView it will have more than one Window.
Not necessary.
Sure. Using HierachyView you can clearly see that there is more than one Window exists in the system.
Usually one.
Every Window has a surface and
Surface
usesCanvas
to draw on the surface.YES.
Not Sure of WindowManager's responsibility. (TODO)
SurfaceFlinger
is used to compose the Surface that is associated with different Window/Activity.View will draw on surface using Canvas. The window the view is attached to owns the surface.
This could be understood by implement a customize view, when you should override the
onDraw(Canvas)
method in your derived class.YES.
onDraw()
will be called by theRootView
and when invalidate is called. The canvas parameter is passed from the RootView.I cannot say for sure. But when I create a customize view, the size of the canvas got from onDraw(Canvas) is full screen.
However, in my understanding, for performance sake, the Surface for the window should not always be full screen. But this assumption has not been verified. For example, the statusBar window should not be full screen.
YES.
No need to create the Window explicitly per se.
YES.
Appreciating that you asked all those questions. 1) AFAIK every Activity has alteast one ViewRoot and every ViewRoot has atleast one window 2) There is no need to create window explicitly and I think it should always be full window .. although not sure about this 3) Yes it can be, we can place status bar in another windows 4) Not is can be part of window, not always covers full screen.
Please correct my understanding if I stated anything wrong here.
Here is a very basic and simple conceptual overview of how interaction happens among the Window, Surface, Canvas, and Bitmap.
Look at this answer by hackbod, great explanation.