Android core analysis (28) -- Android GDI surface & canvas

Source: Internet
Author: User
Surface & canvas

Canvas indicates the meaning of the canvas. The upper-layer plotting of Android is almost done through the canvas instance. In fact, canvas is more of an interface packaging. Drawpaints, drawpoints, drawrect, drawbitmap...

1 Essential Relationship Between canvas and Surface

For this section, we will not study the skia graphics engine itself. What we need to know is how the image we make is placed in that place and how the canvas is connected to the surface.

Canvas (Java) has a native canvas C ++ object in the C ++ native layer.

Lockcanvas () @ Java

Surface_lockCanvas@android_view_Surface.cpp

Surfacecontrol-> New Surface (Control) @ surface. cpp

Surface: Lock operation:

Graphicbuffer: Lock

Getbuffermapper (). Lock graphicbuffermapper: Lock

Mallocmod-> lockgralloc_module_t: Lock

Surfacelock can be used to obtain the graphic buffer address corresponding to the surface (mlockedbuffe.

(1) create a bitmap device connected to skcanvas. The bitmap uses the image buffer address obtained above as its own bitmap memory.

(2) set the drawing target device of skcanvas to this bitmap.

Through this process, the connection between surfacecontrol and canvas is established.


2 view: ondraw Source

When OpenGL is not used for rendering, the view attribute of Android changes. When a new view or Z-order changes, you need to re-draw the view on the System screen, at this time, our view will execute ondraw (canvas). Where is the root cause?

Viewroot. Java

Extends mtraversals (..)

...

Draw ()

Canvas = surface. lockcanvas (dirty );

...

Mview. Draw (canvas );

Draw (CAVAS) @ view. Java

Background. Draw (canvas );

Ondraw (CAVAS)

Dispatchdraw (CAVAS)

Ondrawscrolbars (CAVAS)

Surface. unlockcanvasandpost (canvas );

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.