|
| 1 | +package com.wanjian.sak.system.canvas.compact; |
| 2 | + |
| 3 | +import android.graphics.Canvas; |
| 4 | +import android.graphics.FrameInfo; |
| 5 | +import android.graphics.HardwareRenderer; |
| 6 | +import android.graphics.RecordingCanvas; |
| 7 | +import android.graphics.RenderNode; |
| 8 | +import android.view.Choreographer; |
| 9 | +import android.view.ThreadedRenderer; |
| 10 | +import android.view.View; |
| 11 | +import android.view.ViewFrameInfo; |
| 12 | +import android.view.ViewRootImpl; |
| 13 | + |
| 14 | +import java.lang.reflect.Field; |
| 15 | +import java.lang.reflect.Method; |
| 16 | + |
| 17 | +class HardwareCanvasV31Impl extends HardwareCanvasV29Impl { |
| 18 | + HardwareCanvasV31Impl(ViewRootImpl viewRootImpl) { |
| 19 | + super(viewRootImpl); |
| 20 | + } |
| 21 | + |
| 22 | + @Override |
| 23 | + protected void markDrawStart(Choreographer choreographer) { |
| 24 | + try { |
| 25 | + ViewFrameInfo frameInfo = getViewFrameInfo(); |
| 26 | + frameInfo.markDrawStart(); |
| 27 | + } catch (Exception e) { |
| 28 | + throw new RuntimeException(e); |
| 29 | + } |
| 30 | + } |
| 31 | + |
| 32 | + private ViewFrameInfo getViewFrameInfo() { |
| 33 | + try { |
| 34 | + Field mFrameInfoF = ViewRootImpl.class.getDeclaredField("mViewFrameInfo"); |
| 35 | + mFrameInfoF.setAccessible(true); |
| 36 | + ViewFrameInfo frameInfo = (ViewFrameInfo) mFrameInfoF.get(viewRootImpl); |
| 37 | + return frameInfo; |
| 38 | + } catch (Exception e) { |
| 39 | + throw new RuntimeException(e); |
| 40 | + } |
| 41 | + } |
| 42 | + |
| 43 | + private FrameInfo getFrameInfo() { |
| 44 | + try { |
| 45 | + Method mFrameInfoM = ViewRootImpl.class.getDeclaredMethod("getUpdatedFrameInfo"); |
| 46 | + mFrameInfoM.setAccessible(true); |
| 47 | + FrameInfo frameInfo = (FrameInfo) mFrameInfoM.invoke(viewRootImpl); |
| 48 | + return frameInfo; |
| 49 | + } catch (Exception e) { |
| 50 | + throw new RuntimeException(e); |
| 51 | + } |
| 52 | + } |
| 53 | + |
| 54 | + @Override |
| 55 | + protected void nSyncAndDrawFrame() { |
| 56 | + try { |
| 57 | + ThreadedRenderer renderer = getHardwareRenderer(viewRootImpl); |
| 58 | + Method method = HardwareRenderer.class.getDeclaredMethod("syncAndDrawFrame", FrameInfo.class); |
| 59 | + method.setAccessible(true); |
| 60 | + method.invoke(renderer, getFrameInfo()); |
| 61 | + } catch (Exception e) { |
| 62 | + throw new RuntimeException(e); |
| 63 | + } |
| 64 | + } |
| 65 | +} |
0 commit comments