summaryrefslogtreecommitdiff
path: root/core/java/android
diff options
context:
space:
mode:
Diffstat (limited to 'core/java/android')
-rw-r--r--core/java/android/app/ActivityThread.java8
-rw-r--r--core/java/android/view/Choreographer.java1
-rw-r--r--core/java/android/view/FrameInfo.java118
-rw-r--r--core/java/android/view/FrameMetricsObserver.java5
-rw-r--r--core/java/android/view/TextureLayer.java8
-rw-r--r--core/java/android/view/ThreadedRenderer.java659
-rw-r--r--core/java/android/view/ViewRootImpl.java7
7 files changed, 66 insertions, 740 deletions
diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java
index 9079f1a174a2..805fb6829129 100644
--- a/core/java/android/app/ActivityThread.java
+++ b/core/java/android/app/ActivityThread.java
@@ -72,6 +72,7 @@ import android.database.sqlite.SQLiteDebug;
import android.database.sqlite.SQLiteDebug.DbStats;
import android.graphics.Bitmap;
import android.graphics.Canvas;
+import android.graphics.HardwareRenderer;
import android.graphics.ImageDecoder;
import android.hardware.display.DisplayManagerGlobal;
import android.net.ConnectivityManager;
@@ -5652,7 +5653,7 @@ public final class ActivityThread extends ClientTransactionHandler {
int uid = Process.myUid();
String[] packages = getPackageManager().getPackagesForUid(uid);
if (packages != null) {
- ThreadedRenderer.setupDiskCache(codeCacheDir);
+ HardwareRenderer.setupDiskCache(codeCacheDir);
RenderScriptCacheDir.setupDiskCache(codeCacheDir);
}
} catch (RemoteException e) {
@@ -5887,7 +5888,8 @@ public final class ActivityThread extends ClientTransactionHandler {
// Allow renderer debugging features if we're debuggable.
boolean isAppDebuggable = (data.appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;
- ThreadedRenderer.setDebuggingEnabled(isAppDebuggable || Build.IS_DEBUGGABLE);
+ HardwareRenderer.setDebuggingEnabled(isAppDebuggable || Build.IS_DEBUGGABLE);
+ HardwareRenderer.setPackageName(data.appInfo.packageName);
/**
* Initialize the default http proxy in this process for the reasons we set the time zone.
@@ -5954,7 +5956,7 @@ public final class ActivityThread extends ClientTransactionHandler {
StrictMode.setThreadPolicyMask(oldMask);
}
} else {
- ThreadedRenderer.setIsolatedProcess(true);
+ HardwareRenderer.setIsolatedProcess(true);
}
// If we use profiles, setup the dex reporter to notify package manager
diff --git a/core/java/android/view/Choreographer.java b/core/java/android/view/Choreographer.java
index a8727760095b..96ef8ba1a241 100644
--- a/core/java/android/view/Choreographer.java
+++ b/core/java/android/view/Choreographer.java
@@ -21,6 +21,7 @@ import static android.view.DisplayEventReceiver.VSYNC_SOURCE_SURFACE_FLINGER;
import android.annotation.TestApi;
import android.annotation.UnsupportedAppUsage;
+import android.graphics.FrameInfo;
import android.hardware.display.DisplayManagerGlobal;
import android.os.Build;
import android.os.Handler;
diff --git a/core/java/android/view/FrameInfo.java b/core/java/android/view/FrameInfo.java
deleted file mode 100644
index 6c5e048f05d2..000000000000
--- a/core/java/android/view/FrameInfo.java
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
- * Copyright (C) 2015 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package android.view;
-
-import android.annotation.LongDef;
-
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-
-/**
- * Class that contains all the timing information for the current frame. This
- * is used in conjunction with the hardware renderer to provide
- * continous-monitoring jank events
- *
- * All times in nanoseconds from CLOCK_MONOTONIC/System.nanoTime()
- *
- * To minimize overhead from System.nanoTime() calls we infer durations of
- * things by knowing the ordering of the events. For example, to know how
- * long layout & measure took it's displayListRecordStart - performTraversalsStart.
- *
- * These constants must be kept in sync with FrameInfo.h in libhwui and are
- * used for indexing into AttachInfo's mFrameInfo long[], which is intended
- * to be quick to pass down to native via JNI, hence a pre-packed format
- *
- * @hide
- */
-final class FrameInfo {
-
- long[] mFrameInfo = new long[9];
-
- // Various flags set to provide extra metadata about the current frame
- private static final int FLAGS = 0;
-
- // Is this the first-draw following a window layout?
- public static final long FLAG_WINDOW_LAYOUT_CHANGED = 1;
-
- @LongDef(flag = true, value = {
- FLAG_WINDOW_LAYOUT_CHANGED })
- @Retention(RetentionPolicy.SOURCE)
- public @interface FrameInfoFlags {}
-
- // The intended vsync time, unadjusted by jitter
- private static final int INTENDED_VSYNC = 1;
-
- // Jitter-adjusted vsync time, this is what was used as input into the
- // animation & drawing system
- private static final int VSYNC = 2;
-
- // The time of the oldest input event
- private static final int OLDEST_INPUT_EVENT = 3;
-
- // The time of the newest input event
- private static final int NEWEST_INPUT_EVENT = 4;
-
- // When input event handling started
- private static final int HANDLE_INPUT_START = 5;
-
- // When animation evaluations started
- private static final int ANIMATION_START = 6;
-
- // When ViewRootImpl#performTraversals() started
- private static final int PERFORM_TRAVERSALS_START = 7;
-
- // When View:draw() started
- private static final int DRAW_START = 8;
-
- public void setVsync(long intendedVsync, long usedVsync) {
- mFrameInfo[INTENDED_VSYNC] = intendedVsync;
- mFrameInfo[VSYNC] = usedVsync;
- mFrameInfo[OLDEST_INPUT_EVENT] = Long.MAX_VALUE;
- mFrameInfo[NEWEST_INPUT_EVENT] = 0;
- mFrameInfo[FLAGS] = 0;
- }
-
- public void updateInputEventTime(long inputEventTime, long inputEventOldestTime) {
- if (inputEventOldestTime < mFrameInfo[OLDEST_INPUT_EVENT]) {
- mFrameInfo[OLDEST_INPUT_EVENT] = inputEventOldestTime;
- }
- if (inputEventTime > mFrameInfo[NEWEST_INPUT_EVENT]) {
- mFrameInfo[NEWEST_INPUT_EVENT] = inputEventTime;
- }
- }
-
- public void markInputHandlingStart() {
- mFrameInfo[HANDLE_INPUT_START] = System.nanoTime();
- }
-
- public void markAnimationsStart() {
- mFrameInfo[ANIMATION_START] = System.nanoTime();
- }
-
- public void markPerformTraversalsStart() {
- mFrameInfo[PERFORM_TRAVERSALS_START] = System.nanoTime();
- }
-
- public void markDrawStart() {
- mFrameInfo[DRAW_START] = System.nanoTime();
- }
-
- public void addFlags(@FrameInfoFlags long flags) {
- mFrameInfo[FLAGS] |= flags;
- }
-
-}
diff --git a/core/java/android/view/FrameMetricsObserver.java b/core/java/android/view/FrameMetricsObserver.java
index 597089b98e1a..0f38e847f4bd 100644
--- a/core/java/android/view/FrameMetricsObserver.java
+++ b/core/java/android/view/FrameMetricsObserver.java
@@ -40,8 +40,9 @@ public class FrameMetricsObserver {
@UnsupportedAppUsage
private FrameMetrics mFrameMetrics;
- /* package */ Window.OnFrameMetricsAvailableListener mListener;
- /* package */ VirtualRefBasePtr mNative;
+ /* pacage */ Window.OnFrameMetricsAvailableListener mListener;
+ /** @hide */
+ public VirtualRefBasePtr mNative;
/**
* Creates a FrameMetricsObserver
diff --git a/core/java/android/view/TextureLayer.java b/core/java/android/view/TextureLayer.java
index d89d634c6a25..46dd436e27a5 100644
--- a/core/java/android/view/TextureLayer.java
+++ b/core/java/android/view/TextureLayer.java
@@ -18,6 +18,7 @@ package android.view;
import android.annotation.Nullable;
import android.graphics.Bitmap;
+import android.graphics.HardwareRenderer;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.SurfaceTexture;
@@ -32,10 +33,10 @@ import com.android.internal.util.VirtualRefBasePtr;
* @hide
*/
public final class TextureLayer {
- private ThreadedRenderer mRenderer;
+ private HardwareRenderer mRenderer;
private VirtualRefBasePtr mFinalizer;
- private TextureLayer(ThreadedRenderer renderer, long deferredUpdater) {
+ private TextureLayer(HardwareRenderer renderer, long deferredUpdater) {
if (renderer == null || deferredUpdater == 0) {
throw new IllegalArgumentException("Either hardware renderer: " + renderer
+ " or deferredUpdater: " + deferredUpdater + " is invalid");
@@ -139,7 +140,8 @@ public final class TextureLayer {
mRenderer.pushLayerUpdate(this);
}
- static TextureLayer adoptTextureLayer(ThreadedRenderer renderer, long layer) {
+ /** @hide */
+ public static TextureLayer adoptTextureLayer(HardwareRenderer renderer, long layer) {
return new TextureLayer(renderer, layer);
}
diff --git a/core/java/android/view/ThreadedRenderer.java b/core/java/android/view/ThreadedRenderer.java
index f0f4c1c595b8..bac0154cc392 100644
--- a/core/java/android/view/ThreadedRenderer.java
+++ b/core/java/android/view/ThreadedRenderer.java
@@ -16,36 +16,24 @@
package android.view;
-import android.annotation.IntDef;
import android.annotation.NonNull;
-import android.annotation.UnsupportedAppUsage;
-import android.app.ActivityManager;
import android.content.Context;
import android.content.res.TypedArray;
-import android.graphics.Bitmap;
+import android.graphics.HardwareRenderer;
import android.graphics.Point;
import android.graphics.RecordingCanvas;
import android.graphics.Rect;
import android.graphics.RenderNode;
-import android.os.IBinder;
-import android.os.ParcelFileDescriptor;
-import android.os.RemoteException;
-import android.os.ServiceManager;
import android.os.SystemProperties;
import android.os.Trace;
-import android.util.Log;
import android.view.Surface.OutOfResourcesException;
import android.view.View.AttachInfo;
import android.view.animation.AnimationUtils;
import com.android.internal.R;
-import com.android.internal.util.VirtualRefBasePtr;
-import java.io.File;
import java.io.FileDescriptor;
import java.io.PrintWriter;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
/**
* Threaded renderer that proxies the rendering to a render thread. Most calls
@@ -66,15 +54,7 @@ import java.lang.annotation.RetentionPolicy;
*
* @hide
*/
-public final class ThreadedRenderer {
- private static final String LOG_TAG = "ThreadedRenderer";
-
- /**
- * Name of the file that holds the shaders cache.
- */
- private static final String CACHE_PATH_SHADERS = "com.android.opengl.shaders_cache";
- private static final String CACHE_PATH_SKIASHADERS = "com.android.skia.shaders_cache";
-
+public final class ThreadedRenderer extends HardwareRenderer {
/**
* System property used to enable or disable threaded rendering profiling.
* The default value of this property is assumed to be false.
@@ -271,21 +251,6 @@ public final class ThreadedRenderer {
}
/**
- * Sets the directory to use as a persistent storage for threaded rendering
- * resources.
- *
- * @param cacheDir A directory the current process can write to
- *
- * @hide
- */
- @UnsupportedAppUsage
- public static void setupDiskCache(File cacheDir) {
- ThreadedRenderer.setupShadersDiskCache(
- new File(cacheDir, CACHE_PATH_SHADERS).getAbsolutePath(),
- new File(cacheDir, CACHE_PATH_SKIASHADERS).getAbsolutePath());
- }
-
- /**
* Creates a threaded renderer using OpenGL.
*
* @param translucent True if the surface is translucent, false otherwise
@@ -300,55 +265,10 @@ public final class ThreadedRenderer {
return renderer;
}
- /**
- * Invoke this method when the system is running out of memory. This
- * method will attempt to recover as much memory as possible, based on
- * the specified hint.
- *
- * @param level Hint about the amount of memory that should be trimmed,
- * see {@link android.content.ComponentCallbacks}
- */
- public static void trimMemory(int level) {
- nTrimMemory(level);
- }
-
- public static void overrideProperty(@NonNull String name, @NonNull String value) {
- if (name == null || value == null) {
- throw new IllegalArgumentException("name and value must be non-null");
- }
- nOverrideProperty(name, value);
- }
-
- // Keep in sync with DrawFrameTask.h SYNC_* flags
- // Nothing interesting to report
- private static final int SYNC_OK = 0;
- // Needs a ViewRoot invalidate
- private static final int SYNC_INVALIDATE_REQUIRED = 1 << 0;
- // Spoiler: the reward is GPU-accelerated drawing, better find that Surface!
- private static final int SYNC_LOST_SURFACE_REWARD_IF_FOUND = 1 << 1;
- // setStopped is true, drawing is false
- // TODO: Remove this and SYNC_LOST_SURFACE_REWARD_IF_FOUND?
- // This flag isn't really used as there's nothing that we care to do
- // in response, so it really just exists to differentiate from LOST_SURFACE
- // but possibly both can just be deleted.
- private static final int SYNC_CONTEXT_IS_STOPPED = 1 << 2;
- private static final int SYNC_FRAME_DROPPED = 1 << 3;
-
private static final String[] VISUALIZERS = {
PROFILE_PROPERTY_VISUALIZE_BARS,
};
- private static final int FLAG_DUMP_FRAMESTATS = 1 << 0;
- private static final int FLAG_DUMP_RESET = 1 << 1;
- private static final int FLAG_DUMP_ALL = FLAG_DUMP_FRAMESTATS;
-
- @IntDef(flag = true, prefix = { "FLAG_DUMP_" }, value = {
- FLAG_DUMP_FRAMESTATS,
- FLAG_DUMP_RESET
- })
- @Retention(RetentionPolicy.SOURCE)
- public @interface DumpFlags {}
-
// Size of the rendered content.
private int mWidth, mHeight;
@@ -362,51 +282,37 @@ public final class ThreadedRenderer {
// Whether the surface has insets. Used to protect opacity.
private boolean mHasInsets;
- // Light and shadow properties specified by the theme.
+ // Light properties specified by the theme.
private final float mLightY;
private final float mLightZ;
private final float mLightRadius;
- private final int mAmbientShadowAlpha;
- private final int mSpotShadowAlpha;
- private long mNativeProxy;
private boolean mInitialized = false;
- private RenderNode mRootNode;
private boolean mRootNodeNeedsUpdate;
private boolean mEnabled;
private boolean mRequested = true;
- private boolean mIsOpaque = false;
ThreadedRenderer(Context context, boolean translucent, String name) {
+ super();
+ setName(name);
+ setOpaque(!translucent);
+
final TypedArray a = context.obtainStyledAttributes(null, R.styleable.Lighting, 0, 0);
mLightY = a.getDimension(R.styleable.Lighting_lightY, 0);
mLightZ = a.getDimension(R.styleable.Lighting_lightZ, 0);
mLightRadius = a.getDimension(R.styleable.Lighting_lightRadius, 0);
- mAmbientShadowAlpha =
- (int) (255 * a.getFloat(R.styleable.Lighting_ambientShadowAlpha, 0) + 0.5f);
- mSpotShadowAlpha = (int) (255 * a.getFloat(R.styleable.Lighting_spotShadowAlpha, 0) + 0.5f);
+ float ambientShadowAlpha = a.getFloat(R.styleable.Lighting_ambientShadowAlpha, 0);
+ float spotShadowAlpha = a.getFloat(R.styleable.Lighting_spotShadowAlpha, 0);
a.recycle();
-
- long rootNodePtr = nCreateRootRenderNode();
- mRootNode = RenderNode.adopt(rootNodePtr);
- mRootNode.setClipToBounds(false);
- mIsOpaque = !translucent;
- mNativeProxy = nCreateProxy(translucent, rootNodePtr);
- nSetName(mNativeProxy, name);
-
- ProcessInitializer.sInstance.init(context, mNativeProxy);
-
- loadSystemProperties();
+ setLightSourceAlpha(ambientShadowAlpha, spotShadowAlpha);
}
- /**
- * Destroys the threaded rendering context.
- */
- void destroy() {
+ @Override
+ public void destroy() {
mInitialized = false;
updateEnabledState(null);
- nDestroy(mNativeProxy, mRootNode.mNativeRenderNode);
+ super.destroy();
}
/**
@@ -464,7 +370,7 @@ public final class ThreadedRenderer {
boolean status = !mInitialized;
mInitialized = true;
updateEnabledState(surface);
- nInitialize(mNativeProxy, surface);
+ setSurface(surface);
return status;
}
@@ -505,26 +411,18 @@ public final class ThreadedRenderer {
*/
void updateSurface(Surface surface) throws OutOfResourcesException {
updateEnabledState(surface);
- nUpdateSurface(mNativeProxy, surface);
- }
-
- /**
- * Halts any current rendering into the surface. Use this if it is unclear whether
- * or not the surface used by the ThreadedRenderer will be changing. It
- * Suspends any rendering into the surface, but will not do any destruction.
- *
- * Any subsequent draws will override the pause, resuming normal operation.
- */
- boolean pauseSurface(Surface surface) {
- return nPauseSurface(mNativeProxy, surface);
+ setSurface(surface);
}
- /**
- * Hard stops or resumes rendering into the surface. This flag is used to
- * determine whether or not it is safe to use the given surface *at all*
- */
- void setStopped(boolean stopped) {
- nSetStopped(mNativeProxy, stopped);
+ @Override
+ public void setSurface(Surface surface) {
+ // TODO: Do we ever pass a non-null but isValid() = false surface?
+ // This is here to be super conservative for ViewRootImpl
+ if (surface != null && surface.isValid()) {
+ super.setSurface(surface);
+ } else {
+ super.setSurface(null);
+ }
}
/**
@@ -535,7 +433,7 @@ public final class ThreadedRenderer {
*/
void destroyHardwareResources(View view) {
destroyResources(view);
- nDestroyHardwareResources(mNativeProxy);
+ destroyHardwareResources();
}
private static void destroyResources(View view) {
@@ -543,14 +441,6 @@ public final class ThreadedRenderer {
}
/**
- * Detaches the layer's surface texture from the GL context and releases
- * the texture id
- */
- void detachSurfaceTexture(long hardwareLayer) {
- nDetachSurfaceTexture(mNativeProxy, hardwareLayer);
- }
-
- /**
* Sets up the renderer for drawing.
*
* @param width The width of the drawing surface.
@@ -581,8 +471,6 @@ public final class ThreadedRenderer {
}
mRootNode.setLeftTopRightBottom(-mInsetLeft, -mInsetTop, mSurfaceWidth, mSurfaceHeight);
- nSetup(mNativeProxy, mLightRadius,
- mAmbientShadowAlpha, mSpotShadowAlpha);
setLightCenter(attachInfo);
}
@@ -598,27 +486,7 @@ public final class ThreadedRenderer {
attachInfo.mDisplay.getRealSize(displaySize);
final float lightX = displaySize.x / 2f - attachInfo.mWindowLeft;
final float lightY = mLightY - attachInfo.mWindowTop;
-
- nSetLightCenter(mNativeProxy, lightX, lightY, mLightZ);
- }
-
- /**
- * Change the ThreadedRenderer's opacity
- */
- void setOpaque(boolean opaque) {
- mIsOpaque = opaque && !mHasInsets;
- nSetOpaque(mNativeProxy, mIsOpaque);
- }
-
- boolean isOpaque() {
- return mIsOpaque;
- }
-
- /**
- * Enable/disable wide gamut rendering on this renderer.
- */
- void setWideGamut(boolean wideGamut) {
- nSetWideGamut(mNativeProxy, wideGamut);
+ setLightSourceGeometry(lightX, lightY, mLightZ, mLightRadius);
}
/**
@@ -663,18 +531,12 @@ public final class ThreadedRenderer {
break;
}
}
- nDumpProfileInfo(mNativeProxy, fd, flags);
+ dumpProfileInfo(fd, flags);
}
- /**
- * Loads system properties used by the renderer. This method is invoked
- * whenever system properties are modified. Implementations can use this
- * to trigger live updates of the renderer based on properties.
- *
- * @return True if a property has changed.
- */
- boolean loadSystemProperties() {
- boolean changed = nLoadSystemProperties(mNativeProxy);
+ @Override
+ public boolean loadSystemProperties() {
+ boolean changed = super.loadSystemProperties();
if (changed) {
invalidateRoot();
}
@@ -695,72 +557,27 @@ public final class ThreadedRenderer {
updateViewTreeDisplayList(view);
if (mRootNodeNeedsUpdate || !mRootNode.hasDisplayList()) {
- RecordingCanvas canvas = mRootNode.start(mSurfaceWidth, mSurfaceHeight);
+ RecordingCanvas canvas = mRootNode.startRecording(mSurfaceWidth, mSurfaceHeight);
try {
final int saveCount = canvas.save();
canvas.translate(mInsetLeft, mInsetTop);
callbacks.onPreDraw(canvas);
- canvas.insertReorderBarrier();
+ canvas.enableZ();
canvas.drawRenderNode(view.updateDisplayListIfDirty());
- canvas.insertInorderBarrier();
+ canvas.disableZ();
callbacks.onPostDraw(canvas);
canvas.restoreToCount(saveCount);
mRootNodeNeedsUpdate = false;
} finally {
- mRootNode.end(canvas);
+ mRootNode.endRecording();
}
}
Trace.traceEnd(Trace.TRACE_TAG_VIEW);
}
/**
- * Adds a rendernode to the renderer which can be drawn and changed asynchronously to the
- * rendernode of the UI thread.
- * @param node The node to add.
- * @param placeFront If true, the render node will be placed in front of the content node,
- * otherwise behind the content node.
- */
- @UnsupportedAppUsage
- public void addRenderNode(RenderNode node, boolean placeFront) {
- nAddRenderNode(mNativeProxy, node.mNativeRenderNode, placeFront);
- }
-
- /**
- * Only especially added render nodes can be removed.
- * @param node The node which was added via addRenderNode which should get removed again.
- */
- @UnsupportedAppUsage
- public void removeRenderNode(RenderNode node) {
- nRemoveRenderNode(mNativeProxy, node.mNativeRenderNode);
- }
-
- /**
- * Draws a particular render node. If the node is not the content node, only the additional
- * nodes will get drawn and the content remains untouched.
- * @param node The node to be drawn.
- */
- @UnsupportedAppUsage
- public void drawRenderNode(RenderNode node) {
- nDrawRenderNode(mNativeProxy, node.mNativeRenderNode);
- }
-
- /**
- * To avoid unnecessary overdrawing of the main content all additionally passed render nodes
- * will be prevented to overdraw this area. It will be synchronized with the draw call.
- * This should be updated in the content view's draw call.
- * @param left The left side of the protected bounds.
- * @param top The top side of the protected bounds.
- * @param right The right side of the protected bounds.
- * @param bottom The bottom side of the protected bounds.
- */
- @UnsupportedAppUsage
- public void setContentDrawBounds(int left, int top, int right, int bottom) {
- nSetContentDrawBounds(mNativeProxy, left, top, right, bottom);
- }
-
- /**
* Interface used to receive callbacks whenever a view is drawn by
* a threaded renderer instance.
*/
@@ -819,11 +636,10 @@ public final class ThreadedRenderer {
attachInfo.mPendingAnimatingRenderNodes = null;
}
- final long[] frameInfo = choreographer.mFrameInfo.mFrameInfo;
if (frameDrawingCallback != null) {
- nSetFrameCallback(mNativeProxy, frameDrawingCallback);
+ setFrameCallback(frameDrawingCallback);
}
- int syncResult = nSyncAndDrawFrame(mNativeProxy, frameInfo, frameInfo.length);
+ int syncResult = syncAndDrawFrame(choreographer.mFrameInfo);
if ((syncResult & SYNC_LOST_SURFACE_REWARD_IF_FOUND) != 0) {
setEnabled(false);
attachInfo.mViewRootImpl.mSurface.release();
@@ -831,207 +647,40 @@ public final class ThreadedRenderer {
// if it is still needed or do nothing if we are no longer drawing
attachInfo.mViewRootImpl.invalidate();
}
- if ((syncResult & SYNC_INVALIDATE_REQUIRED) != 0) {
+ if ((syncResult & SYNC_REDRAW_REQUESTED) != 0) {
attachInfo.mViewRootImpl.invalidate();
}
}
- void setFrameCompleteCallback(FrameCompleteCallback callback) {
- nSetFrameCompleteCallback(mNativeProxy, callback);
- }
-
- static void invokeFunctor(long functor, boolean waitForCompletion) {
- nInvokeFunctor(functor, waitForCompletion);
- }
-
- /**
- * 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.
- *
- * @return A hardware layer
- */
- TextureLayer createTextureLayer() {
- long layer = nCreateTextureLayer(mNativeProxy);
- return TextureLayer.adoptTextureLayer(this, layer);
- }
-
-
- void buildLayer(RenderNode node) {
- if (node.hasDisplayList()) {
- nBuildLayer(mNativeProxy, node.mNativeRenderNode);
- }
- }
-
-
- boolean copyLayerInto(final TextureLayer layer, final Bitmap bitmap) {
- return nCopyLayerInto(mNativeProxy,
- layer.getDeferredLayerUpdater(), bitmap);
- }
-
- /**
- * Indicates that the specified hardware layer needs to be updated
- * as soon as possible.
- *
- * @param layer The hardware layer that needs an update
- */
- void pushLayerUpdate(TextureLayer layer) {
- nPushLayerUpdate(mNativeProxy, layer.getDeferredLayerUpdater());
- }
-
- /**
- * Tells the HardwareRenderer that the layer is destroyed. The renderer
- * should remove the layer from any update queues.
- */
- void onLayerDestroyed(TextureLayer layer) {
- nCancelLayerUpdate(mNativeProxy, layer.getDeferredLayerUpdater());
- }
-
- /**
- * Blocks until all previously queued work has completed.
- */
- void fence() {
- nFence(mNativeProxy);
- }
-
- /**
- * Prevents any further drawing until draw() is called. This is a signal
- * that the contents of the RenderNode tree are no longer safe to play back.
- * In practice this usually means that there are Functor pointers in the
- * display list that are no longer valid.
- */
- void stopDrawing() {
- nStopDrawing(mNativeProxy);
- }
-
- /**
- * Called by {@link ViewRootImpl} when a new performTraverals is scheduled.
- */
- public void notifyFramePending() {
- nNotifyFramePending(mNativeProxy);
- }
-
-
- void registerAnimatingRenderNode(RenderNode animator) {
- nRegisterAnimatingRenderNode(mRootNode.mNativeRenderNode, animator.mNativeRenderNode);
- }
-
- void registerVectorDrawableAnimator(NativeVectorDrawableAnimator animator) {
- nRegisterVectorDrawableAnimator(mRootNode.mNativeRenderNode,
- animator.getAnimatorNativePtr());
- }
-
- public static int copySurfaceInto(Surface surface, Rect srcRect, Bitmap bitmap) {
- if (srcRect == null) {
- // Empty rect means entire surface
- return nCopySurfaceInto(surface, 0, 0, 0, 0, bitmap);
- } else {
- return nCopySurfaceInto(surface, srcRect.left, srcRect.top,
- srcRect.right, srcRect.bottom, bitmap);
- }
- }
-
- /**
- * Creates a {@link android.graphics.Bitmap.Config#HARDWARE} bitmap from the given
- * RenderNode. Note that the RenderNode should be created as a root node (so x/y of 0,0), and
- * not the RenderNode from a View.
- **/
- @UnsupportedAppUsage
- public static Bitmap createHardwareBitmap(RenderNode node, int width, int height) {
- return nCreateHardwareBitmap(node.mNativeRenderNode, width, height);
- }
-
- /**
- * Sets whether or not high contrast text rendering is enabled. The setting is global
- * but only affects content rendered after the change is made.
- */
- public static void setHighContrastText(boolean highContrastText) {
- nSetHighContrastText(highContrastText);
- }
-
- /**
- * If set RenderThread will avoid doing any IPC using instead a fake vsync & DisplayInfo source
- */
- public static void setIsolatedProcess(boolean isIsolated) {
- nSetIsolatedProcess(isIsolated);
- }
-
- /**
- * If set extra graphics debugging abilities will be enabled such as dumping skp
- */
- public static void setDebuggingEnabled(boolean enable) {
- nSetDebuggingEnabled(enable);
- }
-
- void allocateBuffers(Surface surface) {
- nAllocateBuffers(mNativeProxy, surface);
- }
-
- @Override
- protected void finalize() throws Throwable {
- try {
- nDeleteProxy(mNativeProxy);
- mNativeProxy = 0;
- } finally {
- super.finalize();
- }
- }
-
/** The root of everything */
public @NonNull RenderNode getRootNode() {
return mRootNode;
}
- private boolean mForceDark = false;
-
- /**
- * Whether or not the force-dark feature should be used for this renderer.
- */
- public boolean setForceDark(boolean enable) {
- if (mForceDark != enable) {
- mForceDark = enable;
- nSetForceDark(mNativeProxy, enable);
- return true;
- }
- return false;
- }
-
/**
* Basic synchronous renderer. Currently only used to render the Magnifier, so use with care.
* TODO: deduplicate against ThreadedRenderer.
*
* @hide
*/
- public static class SimpleRenderer {
- private final RenderNode mRootNode;
- private long mNativeProxy;
- private final float mLightY, mLightZ;
- private Surface mSurface;
- private final FrameInfo mFrameInfo = new FrameInfo();
+ public static class SimpleRenderer extends HardwareRenderer {
+ private final float mLightY, mLightZ, mLightRadius;
public SimpleRenderer(final Context context, final String name, final Surface surface) {
+ super();
+ setName(name);
+ setOpaque(false);
+ setSurface(surface);
final TypedArray a = context.obtainStyledAttributes(null, R.styleable.Lighting, 0, 0);
mLightY = a.getDimension(R.styleable.Lighting_lightY, 0);
mLightZ = a.getDimension(R.styleable.Lighting_lightZ, 0);
- final float lightRadius = a.getDimension(R.styleable.Lighting_lightRadius, 0);
+ mLightRadius = a.getDimension(R.styleable.Lighting_lightRadius, 0);
final int ambientShadowAlpha =
(int) (255 * a.getFloat(R.styleable.Lighting_ambientShadowAlpha, 0) + 0.5f);
final int spotShadowAlpha =
(int) (255 * a.getFloat(R.styleable.Lighting_spotShadowAlpha, 0) + 0.5f);
a.recycle();
-
- final long rootNodePtr = nCreateRootRenderNode();
- mRootNode = RenderNode.adopt(rootNodePtr);
- mRootNode.setClipToBounds(false);
- mNativeProxy = nCreateProxy(true /* translucent */, rootNodePtr);
- nSetName(mNativeProxy, name);
-
- ProcessInitializer.sInstance.init(context, mNativeProxy);
- nLoadSystemProperties(mNativeProxy);
-
- nSetup(mNativeProxy, lightRadius, ambientShadowAlpha, spotShadowAlpha);
-
- mSurface = surface;
- nUpdateSurface(mNativeProxy, surface);
+ setLightSourceAlpha(ambientShadowAlpha, spotShadowAlpha);
}
/**
@@ -1045,7 +694,7 @@ public final class ThreadedRenderer {
final float lightX = displaySize.x / 2f - windowLeft;
final float lightY = mLightY - windowTop;
- nSetLightCenter(mNativeProxy, lightX, lightY, mLightZ);
+ setLightSourceGeometry(lightX, lightY, mLightZ, mLightRadius);
}
public RenderNode getRootNode() {
@@ -1057,222 +706,10 @@ public final class ThreadedRenderer {
*/
public void draw(final FrameDrawingCallback callback) {
final long vsync = AnimationUtils.currentAnimationTimeMillis() * 1000000L;
- mFrameInfo.setVsync(vsync, vsync);
- mFrameInfo.addFlags(1 << 2 /* VSYNC */);
if (callback != null) {
- nSetFrameCallback(mNativeProxy, callback);
+ setFrameCallback(callback);
}
- nSyncAndDrawFrame(mNativeProxy, mFrameInfo.mFrameInfo, mFrameInfo.mFrameInfo.length);
+ syncAndDrawFrame(vsync);
}
-
- /**
- * Destroy the renderer.
- */
- public void destroy() {
- mSurface = null;
- nDestroy(mNativeProxy, mRootNode.mNativeRenderNode);
- }
-
- @Override
- protected void finalize() throws Throwable {
- try {
- nDeleteProxy(mNativeProxy);
- mNativeProxy = 0;
- } finally {
- super.finalize();
- }
- }
- }
-
- /**
- * Interface used to receive callbacks when a frame is being drawn.
- */
- public interface FrameDrawingCallback {
- /**
- * Invoked during a frame drawing.
- *
- * @param frame The id of the frame being drawn.
- */
- void onFrameDraw(long frame);
}
-
- /**
- * Interface used to be notified when a frame has finished rendering
- */
- public interface FrameCompleteCallback {
- /**
- * Invoked after a frame draw
- *
- * @param frameNr The id of the frame that was drawn.
- */
- void onFrameComplete(long frameNr);
- }
-
- private static class ProcessInitializer {
- static ProcessInitializer sInstance = new ProcessInitializer();
-
- private boolean mInitialized = false;
-
- private Context mAppContext;
- private IGraphicsStats mGraphicsStatsService;
- private IGraphicsStatsCallback mGraphicsStatsCallback = new IGraphicsStatsCallback.Stub() {
- @Override
- public void onRotateGraphicsStatsBuffer() throws RemoteException {
- rotateBuffer();
- }
- };
-
- private ProcessInitializer() {}
-
- synchronized void init(Context context, long renderProxy) {
- if (mInitialized) return;
- mInitialized = true;
- mAppContext = context.getApplicationContext();
-
- initSched(renderProxy);
-
- if (mAppContext != null) {
- initGraphicsStats();
- }
- }
-
- private void initSched(long renderProxy) {
- try {
- int tid = nGetRenderThreadTid(renderProxy);
- ActivityManager.getService().setRenderThread(tid);
- } catch (Throwable t) {
- Log.w(LOG_TAG, "Failed to set scheduler for RenderThread", t);
- }
- }
-
- private void initGraphicsStats() {
- try {
- IBinder binder = ServiceManager.getService("graphicsstats");
- if (binder == null) return;
- mGraphicsStatsService = IGraphicsStats.Stub.asInterface(binder);
- requestBuffer();
- } catch (Throwable t) {
- Log.w(LOG_TAG, "Could not acquire gfx stats buffer", t);
- }
- }
-
- private void rotateBuffer() {
- nRotateProcessStatsBuffer();
- requestBuffer();
- }
-
- private void requestBuffer() {
- try {
- final String pkg = mAppContext.getApplicationInfo().packageName;
- ParcelFileDescriptor pfd = mGraphicsStatsService
- .requestBufferForProcess(pkg, mGraphicsStatsCallback);
- nSetProcessStatsBuffer(pfd.getFd());
- pfd.close();
- } catch (Throwable t) {
- Log.w(LOG_TAG, "Could not acquire gfx stats buffer", t);
- }
- }
- }
-
- void addFrameMetricsObserver(FrameMetricsObserver observer) {
- long nativeObserver = nAddFrameMetricsObserver(mNativeProxy, observer);
- observer.mNative = new VirtualRefBasePtr(nativeObserver);
- }
-
- void removeFrameMetricsObserver(FrameMetricsObserver observer) {
- nRemoveFrameMetricsObserver(mNativeProxy, observer.mNative.get());
- observer.mNative = null;
- }
-
- /** b/68769804: For low FPS experiments. */
- public static void setFPSDivisor(int divisor) {
- nHackySetRTAnimationsEnabled(divisor <= 1);
- }
-
- /**
- * Changes the OpenGL context priority if IMG_context_priority extension is available. Must be
- * called before any OpenGL context is created.
- *
- * @param priority The priority to use. Must be one of EGL_CONTEXT_PRIORITY_* values.
- */
- public static void setContextPriority(int priority) {
- nSetContextPriority(priority);
- }
-
- /** Not actually public - internal use only. This doc to make lint happy */
- public static native void disableVsync();
-
- static native void setupShadersDiskCache(String cacheFile, String skiaCacheFile);
-
- private static native void nRotateProcessStatsBuffer();
- private static native void nSetProcessStatsBuffer(int fd);
- private static native int nGetRenderThreadTid(long nativeProxy);
-
- private static native long nCreateRootRenderNode();
- private static native long nCreateProxy(boolean translucent, long rootRenderNode);
- private static native void nDeleteProxy(long nativeProxy);
-
- private static native boolean nLoadSystemProperties(long nativeProxy);
- private static native void nSetName(long nativeProxy, String name);
-
- private static native void nInitialize(long nativeProxy, Surface window);
- private static native void nUpdateSurface(long nativeProxy, Surface window);
- private static native boolean nPauseSurface(long nativeProxy, Surface window);
- private static native void nSetStopped(long nativeProxy, boolean stopped);
- private static native void nSetup(long nativeProxy,
- float lightRadius, int ambientShadowAlpha, int spotShadowAlpha);
- private static native void nSetLightCenter(long nativeProxy,
- float lightX, float lightY, float lightZ);
- private static native void nSetOpaque(long nativeProxy, boolean opaque);
- private static native void nSetWideGamut(long nativeProxy, boolean wideGamut);
- private static native int nSyncAndDrawFrame(long nativeProxy, long[] frameInfo, int size);
- private static native void nDestroy(long nativeProxy, long rootRenderNode);
- private static native void nRegisterAnimatingRenderNode(long rootRenderNode, long animatingNode);
- private static native void nRegisterVectorDrawableAnimator(long rootRenderNode, long animator);
-
- private static native void nInvokeFunctor(long functor, boolean waitForCompletion);
-
- private static native long nCreateTextureLayer(long nativeProxy);
- private static native void nBuildLayer(long nativeProxy, long node);
- private static native boolean nCopyLayerInto(long nativeProxy, long layer, Bitmap bitmap);
- private static native void nPushLayerUpdate(long nativeProxy, long layer);
- private static native void nCancelLayerUpdate(long nativeProxy, long layer);
- private static native void nDetachSurfaceTexture(long nativeProxy, long layer);
-
- private static native void nDestroyHardwareResources(long nativeProxy);
- private static native void nTrimMemory(int level);
- private static native void nOverrideProperty(String name, String value);
-
- private static native void nFence(long nativeProxy);
- private static native void nStopDrawing(long nativeProxy);
- private static native void nNotifyFramePending(long nativeProxy);
-
- private static native void nDumpProfileInfo(long nativeProxy, FileDescriptor fd,
- @DumpFlags int dumpFlags);
-
- private static native void nAddRenderNode(long nativeProxy, long rootRenderNode,
- boolean placeFront);
- private static native void nRemoveRenderNode(long nativeProxy, long rootRenderNode);
- private static native void nDrawRenderNode(long nativeProxy, long rootRenderNode);
- private static native void nSetContentDrawBounds(long nativeProxy, int left,
- int top, int right, int bottom);
- private static native void nSetFrameCallback(long nativeProxy, FrameDrawingCallback callback);
- private static native void nSetFrameCompleteCallback(long nativeProxy,
- FrameCompleteCallback callback);
-
- private static native long nAddFrameMetricsObserver(long nativeProxy, FrameMetricsObserver observer);
- private static native void nRemoveFrameMetricsObserver(long nativeProxy, long nativeObserver);
-
- private static native int nCopySurfaceInto(Surface surface,
- int srcLeft, int srcTop, int srcRight, int srcBottom, Bitmap bitmap);
-
- private static native Bitmap nCreateHardwareBitmap(long renderNode, int width, int height);
- private static native void nSetHighContrastText(boolean enabled);
- // For temporary experimentation b/66945974
- private static native void nHackySetRTAnimationsEnabled(boolean enabled);
- private static native void nSetDebuggingEnabled(boolean enabled);
- private static native void nSetIsolatedProcess(boolean enabled);
- private static native void nSetContextPriority(int priority);
- private static native void nAllocateBuffers(long nativeProxy, Surface window);
- private static native void nSetForceDark(long nativeProxy, boolean enabled);
}
diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java
index dd1f6407682f..a23d68b17245 100644
--- a/core/java/android/view/ViewRootImpl.java
+++ b/core/java/android/view/ViewRootImpl.java
@@ -46,6 +46,8 @@ import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Color;
+import android.graphics.FrameInfo;
+import android.graphics.HardwareRenderer.FrameDrawingCallback;
import android.graphics.Matrix;
import android.graphics.PixelFormat;
import android.graphics.Point;
@@ -84,7 +86,6 @@ import android.util.TimeUtils;
import android.util.TypedValue;
import android.view.Surface.OutOfResourcesException;
import android.view.SurfaceControl.Transaction;
-import android.view.ThreadedRenderer.FrameDrawingCallback;
import android.view.View.AttachInfo;
import android.view.View.FocusDirection;
import android.view.View.MeasureSpec;
@@ -2148,7 +2149,7 @@ public final class ViewRootImpl implements ViewParent,
// relayoutWindow may decide to destroy mSurface. As that decision
// happens in WindowManager service, we need to be defensive here
// and stop using the surface in case it gets destroyed.
- if (mAttachInfo.mThreadedRenderer.pauseSurface(mSurface)) {
+ if (mAttachInfo.mThreadedRenderer.pause()) {
// Animations were running so we need to push a frame
// to resume them
mDirty.set(0, 0, mWidth, mHeight);
@@ -2266,7 +2267,7 @@ public final class ViewRootImpl implements ViewParent,
& View.PFLAG_REQUEST_TRANSPARENT_REGIONS) == 0) {
// Don't pre-allocate if transparent regions
// are requested as they may not be needed
- mAttachInfo.mThreadedRenderer.allocateBuffers(mSurface);
+ mAttachInfo.mThreadedRenderer.allocateBuffers();
}
} catch (OutOfResourcesException e) {
handleOutOfResourcesException(e);