• android非硬件加速绘制简单流程


    这里的硬件加速是指openGL + GPU

    如果不适用硬件加速:

    1 ViewRootImpl.java draw:
    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;
    }
    }

    2. drawSoftware:
    ...
    canvas = mSurface.lockCanvas(dirty); //dequeueBuffer, 向sf申请buffer 构造一个canvas
    ...
    mView.draw(canvas); //调用view类中的draw,使用canvas画图
    ...
    surface.unlockCanvasAndPost(canvas); // queueBuffer 提交到sf
    ...

    3. canvas 画图的实现如 Canvas.java 中drawArc:
    =》 native_drawArc

    4. android_graphics_canvas.cpp:
    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));
    }

    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));
    }

    //最终调到了SkCanvas ? 它是google的2d图像库,这里用bitmap构造,在bitmap上画图
    源码位于android/external/skia/

    所以封装层次是 Canvas.java (Java) -》 android_graphics_canvas.cpp(JNI) -》SkiaCanvas.cpp(native) -》 SkCanvas (so lib)

  • 相关阅读:
    idea如何使用git关联远程仓库
    项目首次上传至git仓库步骤
    Eclipse 的 Java Web 项目环境搭建
    Postman
    Postman接口测试之POST、GET请求方法
    接口测试3A原则
    使用unittest和ddt进行数据驱动
    每天进步一点点006
    每天进步一点点005
    Selenium2+python自动化1-环境搭建(悠悠课程之路)
  • 原文地址:https://www.cnblogs.com/hushpa/p/7125476.html
Copyright © 2020-2023  润新知