Add drawGlFunctor support to RenderThread
Add gl functor to the prototype support to allow webview team to begin playing with RT Also create RemoteGLRenderer to avoid needing to make breaking changes to GLRenderer. Currently the differences are mainly around mFunctorsRunnable and how it queues itself up Change-Id: I1ca39056189b68cd7b8dded4dd5889d331f6660a
This commit is contained in:
@@ -1123,66 +1123,6 @@ public class GLRenderer extends HardwareRenderer {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
void drawDisplayList(DisplayList displayList, View.AttachInfo attachInfo,
|
||||
HardwareDrawCallbacks callbacks, Rect dirty) {
|
||||
if (canDraw()) {
|
||||
if (!hasDirtyRegions()) {
|
||||
dirty = null;
|
||||
}
|
||||
|
||||
// We are already on the correct thread
|
||||
final int surfaceState = checkRenderContextUnsafe();
|
||||
if (surfaceState != SURFACE_STATE_ERROR) {
|
||||
HardwareCanvas canvas = mCanvas;
|
||||
|
||||
if (mProfileEnabled) {
|
||||
mProfileLock.lock();
|
||||
}
|
||||
|
||||
dirty = beginFrame(canvas, dirty, surfaceState);
|
||||
|
||||
int saveCount = 0;
|
||||
int status = DisplayList.STATUS_DONE;
|
||||
|
||||
long start = getSystemTime();
|
||||
try {
|
||||
status = prepareFrame(dirty);
|
||||
|
||||
saveCount = canvas.save();
|
||||
callbacks.onHardwarePreDraw(canvas);
|
||||
|
||||
status |= drawDisplayList(attachInfo, canvas, displayList, status);
|
||||
} catch (Exception e) {
|
||||
Log.e(LOG_TAG, "An error has occurred while drawing:", e);
|
||||
} finally {
|
||||
callbacks.onHardwarePostDraw(canvas);
|
||||
canvas.restoreToCount(saveCount);
|
||||
|
||||
mDrawDelta = getSystemTime() - start;
|
||||
|
||||
if (mDrawDelta > 0) {
|
||||
mFrameCount++;
|
||||
|
||||
debugOverdraw(attachInfo, dirty, canvas, displayList);
|
||||
debugDirtyRegions(dirty, canvas);
|
||||
drawProfileData(attachInfo);
|
||||
}
|
||||
}
|
||||
|
||||
onPostDraw();
|
||||
|
||||
swapBuffers(status);
|
||||
|
||||
if (mProfileEnabled) {
|
||||
mProfileLock.unlock();
|
||||
}
|
||||
|
||||
attachInfo.mIgnoreDirtyState = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
void draw(View view, View.AttachInfo attachInfo, HardwareDrawCallbacks callbacks,
|
||||
Rect dirty) {
|
||||
@@ -1539,7 +1479,7 @@ public class GLRenderer extends HardwareRenderer {
|
||||
return (int) (dp * density + 0.5f);
|
||||
}
|
||||
|
||||
private static native boolean loadProperties();
|
||||
static native boolean loadProperties();
|
||||
|
||||
static native void setupShadersDiskCache(String cacheFile);
|
||||
|
||||
@@ -1547,14 +1487,14 @@ public class GLRenderer extends HardwareRenderer {
|
||||
* Notifies EGL that the frame is about to be rendered.
|
||||
* @param size
|
||||
*/
|
||||
private static native void beginFrame(int[] size);
|
||||
static native void beginFrame(int[] size);
|
||||
|
||||
/**
|
||||
* Returns the current system time according to the renderer.
|
||||
* This method is used for debugging only and should not be used
|
||||
* as a clock.
|
||||
*/
|
||||
private static native long getSystemTime();
|
||||
static native long getSystemTime();
|
||||
|
||||
/**
|
||||
* Preserves the back buffer of the current surface after a buffer swap.
|
||||
@@ -1565,7 +1505,7 @@ public class GLRenderer extends HardwareRenderer {
|
||||
* @return True if the swap behavior was successfully changed,
|
||||
* false otherwise.
|
||||
*/
|
||||
private static native boolean preserveBackBuffer();
|
||||
static native boolean preserveBackBuffer();
|
||||
|
||||
/**
|
||||
* Indicates whether the current surface preserves its back buffer
|
||||
@@ -1574,7 +1514,7 @@ public class GLRenderer extends HardwareRenderer {
|
||||
* @return True, if the surface's EGL_SWAP_BEHAVIOR is EGL_BUFFER_PRESERVED,
|
||||
* false otherwise
|
||||
*/
|
||||
private static native boolean isBackBufferPreserved();
|
||||
static native boolean isBackBufferPreserved();
|
||||
|
||||
class DrawPerformanceDataProvider extends GraphDataProvider {
|
||||
private final int mGraphType;
|
||||
|
||||
@@ -407,18 +407,6 @@ public abstract class HardwareRenderer {
|
||||
abstract void draw(View view, View.AttachInfo attachInfo, HardwareDrawCallbacks callbacks,
|
||||
Rect dirty);
|
||||
|
||||
/**
|
||||
* Temporary hook to draw a display list directly, only used if sUseRenderThread
|
||||
* is true.
|
||||
*
|
||||
* @param displayList The display list to draw
|
||||
* @param attachInfo AttachInfo tied to the specified view.
|
||||
* @param callbacks Callbacks invoked when drawing happens.
|
||||
* @param dirty The dirty rectangle to update, can be null.
|
||||
*/
|
||||
abstract void drawDisplayList(DisplayList displayList, View.AttachInfo attachInfo,
|
||||
HardwareDrawCallbacks callbacks, Rect dirty);
|
||||
|
||||
/**
|
||||
* Creates a new hardware layer. A hardware layer built by calling this
|
||||
* method will be treated as a texture layer, instead of as a render target.
|
||||
@@ -527,10 +515,11 @@ public abstract class HardwareRenderer {
|
||||
static HardwareRenderer create(boolean translucent) {
|
||||
HardwareRenderer renderer = null;
|
||||
if (GLES20Canvas.isAvailable()) {
|
||||
renderer = new GLRenderer(translucent);
|
||||
}
|
||||
if (renderer != null && sUseRenderThread) {
|
||||
renderer = new ThreadedRenderer((GLRenderer)renderer);
|
||||
if (sUseRenderThread) {
|
||||
renderer = new ThreadedRenderer(translucent);
|
||||
} else {
|
||||
renderer = new GLRenderer(translucent);
|
||||
}
|
||||
}
|
||||
return renderer;
|
||||
}
|
||||
|
||||
1538
core/java/android/view/RemoteGLRenderer.java
Normal file
1538
core/java/android/view/RemoteGLRenderer.java
Normal file
File diff suppressed because it is too large
Load Diff
@@ -50,19 +50,20 @@ public class ThreadedRenderer extends HardwareRenderer {
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
static HashMap<String, Method> sMethodLut = new HashMap<String, Method>() {{
|
||||
Method[] methods = HardwareRenderer.class.getDeclaredMethods();
|
||||
Method[] methods = RemoteGLRenderer.class.getDeclaredMethods();
|
||||
for (Method m : methods) {
|
||||
put(m.getName(), m);
|
||||
m.setAccessible(true);
|
||||
put(m.getName() + ":" + m.getParameterTypes().length, m);
|
||||
}
|
||||
}};
|
||||
static boolean sNeedsInit = true;
|
||||
|
||||
private HardwareRenderer mRemoteRenderer;
|
||||
private RemoteGLRenderer mRemoteRenderer;
|
||||
private int mWidth, mHeight;
|
||||
private RTJob mPreviousDraw;
|
||||
|
||||
ThreadedRenderer(GLRenderer backingRenderer) {
|
||||
mRemoteRenderer = backingRenderer;
|
||||
ThreadedRenderer(boolean translucent) {
|
||||
mRemoteRenderer = new RemoteGLRenderer(this, translucent);
|
||||
setEnabled(true);
|
||||
if (sNeedsInit) {
|
||||
sNeedsInit = false;
|
||||
@@ -166,12 +167,6 @@ public class ThreadedRenderer extends HardwareRenderer {
|
||||
throw new NoSuchMethodError();
|
||||
}
|
||||
|
||||
@Override
|
||||
void drawDisplayList(DisplayList displayList, AttachInfo attachInfo,
|
||||
HardwareDrawCallbacks callbacks, Rect dirty) {
|
||||
throw new NoSuchMethodError();
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: Remove
|
||||
* Temporary hack to allow RenderThreadTest prototype app to trigger
|
||||
@@ -233,12 +228,12 @@ public class ThreadedRenderer extends HardwareRenderer {
|
||||
|
||||
@Override
|
||||
void detachFunctor(int functor) {
|
||||
throw new NoSuchMethodError();
|
||||
run("detachFunctor", functor);
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean attachFunctor(AttachInfo attachInfo, int functor) {
|
||||
throw new NoSuchMethodError();
|
||||
return (Boolean) run("attachFunctor", attachInfo, functor);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -262,7 +257,7 @@ public class ThreadedRenderer extends HardwareRenderer {
|
||||
|
||||
private RTJob post(String method, Object... args) {
|
||||
RTJob job = new RTJob();
|
||||
job.method = sMethodLut.get(method);
|
||||
job.method = sMethodLut.get(method + ":" + args.length);
|
||||
job.args = args;
|
||||
job.target = mRemoteRenderer;
|
||||
if (job.method == null) {
|
||||
@@ -274,7 +269,7 @@ public class ThreadedRenderer extends HardwareRenderer {
|
||||
|
||||
private Object run(String method, Object... args) {
|
||||
RTJob job = new RTJob();
|
||||
job.method = sMethodLut.get(method);
|
||||
job.method = sMethodLut.get(method + ":" + args.length);
|
||||
job.args = args;
|
||||
job.target = mRemoteRenderer;
|
||||
if (job.method == null) {
|
||||
|
||||
Reference in New Issue
Block a user