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