Showing posts with label graphics. Show all posts
Showing posts with label graphics. Show all posts

Monday, February 24, 2014

Some important Terms useful for Display Driver Engineers.

As being part of display driver team, most of the time I need to refresh few of the terms used in display prcessor. 

so here are few of those, I will try to keep on adding here as I encouter any of the term : [I will try to give you simplest meaning for fast understanding, you can refer wikipedia or any other source for more details]

1. Tiling :  It is like generating a larger graphics from re-using a number of smaller graphics to save RAM and increase real-time rendering performance. For example if there is picture of grass field, so you can only store of a portion of that field, and while displaying you can re-use the same portion again and again to create full scale image.

2. Gamma Correction : Human vision, under common illumination conditions (not pitch black nor blindingly bright), follows an approximate gamma or power function. If images are not gamma encoded, they allocate too many bits or too much bandwidth to highlights that humans cannot differentiate, and too few bits/bandwidth to shadow values that humans are sensitive to and would require more bits/bandwidth to maintain the same visual quality. So with this correction, we define a linear function, which coverts the image to compatible image gamma corrected image.

3. Dithering : Dithering is used in computer graphics to create the illusion of "color depth" in images with a limited color palette - a technique (also known as color quantization). In a dithered image, colors that are not available in the palette are approximated by a diffusion of colored pixels from within the available palette.
So in simple terms using it, we create new colors which is not availble in the color palette(set of colors).

4. Histogram:  Its graphical representation of the distribution of the intensity(brightness perception of a color for humans) of the pixels present in a picture. On the basis of this histogram, further brightness of every pixel can be modified to improve the end result.

5. Alpha Blending: Alpha blending is the process of combining a translucent foreground color with a background color, thereby producing a new blended color. So it foreground is transparent then final result will be background color, if foreground is opaque, final result will be foreground color only.

6. Color Keying:  This technique is used for compositing two images together based on color hues. It is used heavily in many fields to remove a background from the subject of a pahoto or video.

Thursday, January 16, 2014

SurfaceFlinger Basics

Thank you Guys, For such a great response for my last post on SurfaceFlinger. Here I am trying to add few more things which will help you clear your understanding on SurfaceFlinger. 

Terms User in SurfaceFlinger:

  • Canvas : 2D drawing object, object which used to draw on screen bitmap.
  • Surface : Drawing Buffer
  • Window : A visual area containing some kind of user interface.
  • SurfaceFlinger : Surface Manager
  • View : This is user interface, it’s a rectangular area on the screen for drawing and event handling.
  • ViewGroup : Subclass of view that contain other views(called children). It is the base class for layouts which are invisible containers that hold other views or viewgroups.
How Views are Created: 
  • When view is ready to be drawn it will inform using requestLayout() to the parent to schedule a traversal.
  • Which is turn will traversal up till ViewRoot.
  • scheduleTraversal() will post message to UI thread to start performTraversal().
  • performTraversal() does 3 things.
  1. Measure Pass : It is called to find out how big a view should be and how it should be measured and positioned.
  2. Layout Pass : Each parent will position all of its children using the sizes computed in the measure pass. 
  3. Deawing : ViewRoot will get the canvas by calling surface.lockCanvas(), it updates the canvas by passing it to view.drawCanvas(). 
  • After drawing the ViewRoot will pass the canvas to surface by surface.unlockCanvasAndPost().
As mentioned earlier, whenever there is a change in view, relayoutWindow()[ViewRootImpl.java] will be called. Further flows will be like 

relayoutWindow()[ViewrootImpl.java] ---> relayoutWindow()[WindowManagerService.java]------

-->createSurfaceLocked()[WindowStateAnimator.java] -----> SurfaceControl()[SurfaceControl.java]---

---> nativeCreate()[android_view_SurfaceControl.cpp] -------> createSurface()[Client.cpp] --------

--> createLayer()[SurfaceFlinger.cpp] --------> createNormalLayer()[SurfaceFlinger.cpp] -----------

--> setBuffer()[Layer.cpp] -------> 

setDefaultBufferSize()/ setDefaultBufferFormat()/ setDefaultBufferUsageBits()[BufferQueue.cpp]


How Surface is drawn:

So now as surface has been created, so created surface reference will be returned to ViewRootImpl. Further it will call

draw()[ViewRootImpl.java]----------------------------------------------------------------------------------> drawSoftware()[ViewRootImpl.java] ---------> lockCanvas()[Surface.java]
                                                              ---------> drawColors()[Canvas.java]
                                                              ---------> draw()[View.java]
                                                              ---------> unlockCanvas()[Surface.java]

Here draw() [View.java]draws different things like 1) draw background 2) draw views content 3) draw children(like animation) 4) draw decorations( scrollbars for ex).

lockCanvas() is used to attach the canvas to layer and internally it calls dequeueBuffer() which gets the GraphicBuffer to put the content in it.

And unlockCanvas() is used to detach the canvas from layer and internally it will call queuebuffer() which is used to post the content.

Added one more post on SurfaceFlinger, ,check it out  here