标签:left surface fff asa face cpp erp erer enter 这里的硬件加速是指openGL + GPU 如果不适用硬件加速: 1 ViewRootImpl.java draw: 2. drawSoftware: 3. canvas 画图的实现如 Canvas.java 中drawArc: 4. android_graphics_canvas.cpp: 5. SkiaCanvas.cpp: //最终调到了SkCanvas ? 它是google的2d图像库,这里用bitmap构造,在bitmap上画图 所以封装层次是 Canvas.java (Java) -》 android_graphics_canvas.cpp(JNI) -》SkiaCanvas.cpp(native) -》 SkCanvas (so lib) android非硬件加速绘制简单流程 标签:left surface fff asa face cpp erp erer enter 原文:
if (!dirty.isEmpty() || mIsAnimating || accessibilityFocusDirty) {
if (mAttachInfo.mHardwareRenderer != null && mAttachInfo.mHardwareRenderer.isEnabled()) {
...
mAttachInfo.mHardwareRenderer.draw(mView, mAttachInfo, this); //使用硬件绘制
...
} else {
//使用软件绘制
if (!drawSoftware(surface, mAttachInfo, xOffset, yOffset, scalingRequired, dirty)) {
return;
}
}
...
canvas = mSurface.lockCanvas(dirty); //dequeueBuffer, 向sf申请buffer 构造一个canvas
...
mView.draw(canvas); //调用view类中的draw,使用canvas画图
...
surface.unlockCanvasAndPost(canvas); // queueBuffer 提交到sf
...
=》 native_drawArc
static JNINativeMethod gMethods[] = {
...
{"native_drawArc","(JFFFFFFZJ)V", (void*) CanvasJNI::drawArc},
...
}
=> static void drawArc(JNIEnv* env, jobject, jlong canvasHandle, jfloat left, jfloat top,
jfloat right, jfloat bottom, jfloat startAngle, jfloat sweepAngle,
jboolean useCenter, jlong paintHandle) {
const Paint* paint = reinterpret_cast<Paint*>(paintHandle);
get_canvas(canvasHandle)->drawArc(left, top, right, bottom, startAngle, sweepAngle,
useCenter, *paint);
}
// canvasHandle从何而来?
static jlong initRaster(JNIEnv* env, jobject, jobject jbitmap) {
SkBitmap bitmap;
if (jbitmap != NULL) {
GraphicsJNI::getSkBitmap(env, jbitmap, &bitmap);
}
return reinterpret_cast<jlong>(Canvas::create_canvas(bitmap));
}
Canvas* Canvas::create_canvas(const SkBitmap& bitmap) {
return new SkiaCanvas(bitmap);
}
=>
SkiaCanvas::SkiaCanvas(const SkBitmap& bitmap) : mHighContrastText(false) {
mCanvas.reset(new SkCanvas(bitmap));
}
源码位于android/external/skia/