Android Core Analytics (Surface&canvas)-----Android GDI

Source: Internet
Author: User
Surface&canvas

Canvas for the meaning of the canvas. Most of the graphics on the Android top are done by canvas instances, but canvas is more of an interface wrapper. Drawpaints, Drawpoints,drawrect,drawbitmap ...

1 The essential relationship between canvas and surface

For this section, we're not going to look at the Skia graphics engine itself, we need to know where our graphics are placed in the end, and how this canvas is connected to surface.

Canvas (Java) corresponds to 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 Action:

Graphicbuffer:lock

Getbuffermapper () .lock<-> Graphicbuffermapper:: Lock

Mallocmod->lock<->gralloc_module_t::lock

The graphics buffer address of surface (Mlockedbuffe) can be obtained by Surfacelock.

(1) Establish a bitmap device connected with the Skcanvas, which uses the graphics buffer address obtained above to make its own bitmap memory.

(2) The mapping target device for setting Skcanvas is the bitmap.

Through this process, the relationship between Surfacecontrol and canvas is established. 2 origin of View:ondraw

Instead of using OpenGL to draw, when Android changes the View property, creates a new view, or z-order changes, it needs to repaint the view on the system screen, where our view executes OnDraw (canvas).

Viewroot.java

Performtraversals (..)

...

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.