Android non-hardware accelerated drawing simple process

Source: Internet
Author: User

The hardware acceleration here refers to the OpenGL + GPU

If hardware acceleration is not applicable:

1 Viewrootimpl.java Draw:
if (!dirty.isempty () | | misanimating | | accessibilityfocusdirty) {
if (mattachinfo.mhardwarerenderer! = null && mAttachInfo.mHardwareRenderer.isEnabled ()) {
...
MAttachInfo.mHardwareRenderer.draw (MView, Mattachinfo, this); Drawing with Hardware
...
} else {
Drawing with Software
if (!drawsoftware (surface, Mattachinfo, Xoffset, Yoffset, scalingrequired, dirty)) {
Return
}
}

2. Drawsoftware:
...
Canvas = Msurface.lockcanvas (dirty); Dequeuebuffer, apply buffer to SF to construct a canvas
...
Mview.draw (canvas); Call draw in the view class, use canvas to paint
...
Surface.unlockcanvasandpost (canvas); Queuebuffer submitted to SF
...

3. The implementation of canvas drawing, such as Canvas.java DrawArc:
= "Native_drawarc

4. Android_graphics_canvas.cpp:
static Jninativemethod gmethods[] = {
...
{"Native_drawarc", "(JFFFFFFZJ) V", (void*) Canvasjni::d Rawarc},
...
}
= static void DrawArc (jnienv* env, Jobject, Jlong Canvashandle, Jfloat left, jfloat top,
Jfloat right, JF Loat Bottom, Jfloat startangle, Jfloat sweepAngle,
Jboolean usecenter, Jlong painthandle) {
Const paint* Paint = R Einterpret_cast<paint*> (Painthandle);
Get_canvas (Canvashandle)->drawarc (left, top, right, bottom, startangle, SweepAngle,
Usecenter, *paint);
} Where does the
//Canvashandle come from?
Static Jlong Initraster (jnienv* env, Jobject, Jobject jbitmap) {
Skbitmap bitmap;
if (jbitmap! = NULL) {
G Raphicsjni::getskbitmap (env, Jbitmap, &bitmap);
}
Return reinterpret_cast<jlong> (Canvas::create_canvas (bitmap));
}

5. SkiaCanvas.cpp:
canvas* Canvas::create_canvas (const skbitmap& bitmap) {
return new Skiacanvas (bitmap);
}
=
Skiacanvas::skiacanvas (const skbitmap& bitmap): Mhighcontrasttext (False) {
Mcanvas.reset (New Skcanvas (bitmap));
}

Finally transferred to the Skcanvas? It is Google's 2d Image Library, which is constructed with bitmap, drawing on bitmap
Source is located in android/external/skia/

So the package hierarchy is Canvas.java (Java)-"Android_graphics_canvas.cpp (JNI)-" SkiaCanvas.cpp (native)-"Skcanvas (so Lib)

Android non-hardware accelerated drawing simple process

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.