ThreadedRenderer.java revision 44fd8d24f761f82d21e9b00932648a1b6bf91449
1cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck/*
2cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck * Copyright (C) 2013 The Android Open Source Project
3cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck *
4cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck * Licensed under the Apache License, Version 2.0 (the "License");
5cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck * you may not use this file except in compliance with the License.
6cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck * You may obtain a copy of the License at
7cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck *
8cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck *      http://www.apache.org/licenses/LICENSE-2.0
9cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck *
10cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck * Unless required by applicable law or agreed to in writing, software
11cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck * distributed under the License is distributed on an "AS IS" BASIS,
12cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck * See the License for the specific language governing permissions and
14cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck * limitations under the License.
15cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck */
16cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck
17cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reckpackage android.view;
18cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck
1904fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reckimport android.graphics.Bitmap;
20cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reckimport android.graphics.Rect;
21cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reckimport android.graphics.SurfaceTexture;
22cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reckimport android.os.SystemClock;
23cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reckimport android.os.Trace;
24cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reckimport android.view.Surface.OutOfResourcesException;
25cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reckimport android.view.View.AttachInfo;
26cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck
27cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reckimport java.io.PrintWriter;
28cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck
29cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck/**
30cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck * Hardware renderer that proxies the rendering to a render thread. Most calls
314f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck * are currently synchronous.
324f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck * TODO: Make draw() async.
334f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck * TODO: Figure out how to share the DisplayList between two threads (global lock?)
34cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck *
35cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck * The UI thread can block on the RenderThread, but RenderThread must never
36cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck * block on the UI thread.
37cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck *
384f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck * ThreadedRenderer creates an instance of RenderProxy. RenderProxy in turn creates
394f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck * and manages a CanvasContext on the RenderThread. The CanvasContext is fully managed
404f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck * by the lifecycle of the RenderProxy.
414f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck *
42cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck * Note that although currently the EGL context & surfaces are created & managed
43cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck * by the render thread, the goal is to move that into a shared structure that can
44cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck * be managed by both threads. EGLSurface creation & deletion should ideally be
45cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck * done on the UI thread and not the RenderThread to avoid stalling the
46cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck * RenderThread with surface buffer allocation.
47cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck *
48cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck * @hide
49cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck */
50cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reckpublic class ThreadedRenderer extends HardwareRenderer {
51cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck    private static final String LOGTAG = "ThreadedRenderer";
52cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck
534f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck    private static final Rect NULL_RECT = new Rect(-1, -1, -1, -1);
54cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck
55cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck    private int mWidth, mHeight;
564f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck    private long mNativeProxy;
57cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck
583dfe19f72cbd95b201e89376ae1810c5c9229b00John Reck    ThreadedRenderer(boolean translucent) {
594f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck        mNativeProxy = nCreateProxy(translucent);
604f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck        setEnabled(mNativeProxy != 0);
61cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck    }
62cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck
63cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck    @Override
64cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck    void destroy(boolean full) {
654f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck        nDestroyCanvas(mNativeProxy);
66cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck    }
67cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck
68cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck    @Override
69cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck    boolean initialize(Surface surface) throws OutOfResourcesException {
704f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck        return nInitialize(mNativeProxy, surface);
71cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck    }
72cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck
73cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck    @Override
74cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck    void updateSurface(Surface surface) throws OutOfResourcesException {
754f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck        nUpdateSurface(mNativeProxy, surface);
76cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck    }
77cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck
78cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck    @Override
79cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck    void destroyHardwareResources(View view) {
804f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck        destroyResources(view);
814f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck        // TODO: GLES20Canvas.flushCaches(GLES20Canvas.FLUSH_CACHES_LAYERS);
824f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck    }
834f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck
844f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck    private static void destroyResources(View view) {
854f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck        view.destroyHardwareResources();
864f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck
874f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck        if (view instanceof ViewGroup) {
884f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck            ViewGroup group = (ViewGroup) view;
894f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck
904f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck            int count = group.getChildCount();
914f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck            for (int i = 0; i < count; i++) {
924f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck                destroyResources(group.getChildAt(i));
934f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck            }
944f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck        }
95cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck    }
96cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck
97cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck    @Override
98cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck    void invalidate(Surface surface) {
994f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck        updateSurface(surface);
100cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck    }
101cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck
102cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck    @Override
103cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck    boolean safelyRun(Runnable action) {
104fc53ef27793a39e9effd829e9cae02a9ca14147eJohn Reck        nRunWithGlContext(mNativeProxy, action);
105fc53ef27793a39e9effd829e9cae02a9ca14147eJohn Reck        return true;
106cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck    }
107cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck
108cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck    @Override
109cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck    void setup(int width, int height) {
110cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck        mWidth = width;
111cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck        mHeight = height;
1124f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck        nSetup(mNativeProxy, width, height);
113cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck    }
114cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck
115cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck    @Override
116cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck    int getWidth() {
117cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck        return mWidth;
118cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck    }
119cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck
120cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck    @Override
121cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck    int getHeight() {
122cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck        return mHeight;
123cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck    }
124cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck
125cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck    @Override
126cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck    void dumpGfxInfo(PrintWriter pw) {
127cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck        // TODO Auto-generated method stub
128cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck    }
129cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck
130cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck    @Override
131cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck    long getFrameCount() {
132cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck        // TODO Auto-generated method stub
133cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck        return 0;
134cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck    }
135cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck
136cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck    @Override
137cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck    boolean loadSystemProperties() {
1384f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck        return false;
139cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck    }
140cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck
141cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck    /**
142cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck     * TODO: Remove
143cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck     * Temporary hack to allow RenderThreadTest prototype app to trigger
144cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck     * replaying a DisplayList after modifying the displaylist properties
145cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck     *
146cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck     *  @hide */
147cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck    public void repeatLastDraw() {
148cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck    }
149cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck
150cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck    @Override
15144fd8d24f761f82d21e9b00932648a1b6bf91449John Reck    void swapDisplayListData(long displayList, long newData) {
15244fd8d24f761f82d21e9b00932648a1b6bf91449John Reck        nSwapDisplayListData(mNativeProxy, displayList, newData);
15344fd8d24f761f82d21e9b00932648a1b6bf91449John Reck    }
15444fd8d24f761f82d21e9b00932648a1b6bf91449John Reck
15544fd8d24f761f82d21e9b00932648a1b6bf91449John Reck    @Override
156cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck    void draw(View view, AttachInfo attachInfo, HardwareDrawCallbacks callbacks, Rect dirty) {
157cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck        attachInfo.mIgnoreDirtyState = true;
158cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck        attachInfo.mDrawingTime = SystemClock.uptimeMillis();
159cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck        view.mPrivateFlags |= View.PFLAG_DRAWN;
160cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck
161cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck        view.mRecreateDisplayList = (view.mPrivateFlags & View.PFLAG_INVALIDATED)
162cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck                == View.PFLAG_INVALIDATED;
163cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck        view.mPrivateFlags &= ~View.PFLAG_INVALIDATED;
164cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck
165cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck        Trace.traceBegin(Trace.TRACE_TAG_VIEW, "getDisplayList");
166cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck        DisplayList displayList = view.getDisplayList();
167cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck        Trace.traceEnd(Trace.TRACE_TAG_VIEW);
168cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck
169cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck        view.mRecreateDisplayList = false;
170cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck
1714f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck        if (dirty == null) {
1724f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck            dirty = NULL_RECT;
1734f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck        }
1744f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck        nDrawDisplayList(mNativeProxy, displayList.getNativeDisplayList(),
1754f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck                dirty.left, dirty.top, dirty.right, dirty.bottom);
176cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck    }
177cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck
178cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck    @Override
17919b6bcfd83eb7fb92ebd06d2fec89e308311f1d0John Reck    void detachFunctor(long functor) {
18019b6bcfd83eb7fb92ebd06d2fec89e308311f1d0John Reck        nDetachFunctor(mNativeProxy, functor);
18119b6bcfd83eb7fb92ebd06d2fec89e308311f1d0John Reck    }
18219b6bcfd83eb7fb92ebd06d2fec89e308311f1d0John Reck
18319b6bcfd83eb7fb92ebd06d2fec89e308311f1d0John Reck    @Override
18419b6bcfd83eb7fb92ebd06d2fec89e308311f1d0John Reck    void attachFunctor(AttachInfo attachInfo, long functor) {
18519b6bcfd83eb7fb92ebd06d2fec89e308311f1d0John Reck        nAttachFunctor(mNativeProxy, functor);
186cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck    }
187cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck
188cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck    @Override
18904fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    HardwareLayer createDisplayListLayer(int width, int height) {
19019b6bcfd83eb7fb92ebd06d2fec89e308311f1d0John Reck        long layer = nCreateDisplayListLayer(mNativeProxy, width, height);
19119b6bcfd83eb7fb92ebd06d2fec89e308311f1d0John Reck        return HardwareLayer.adoptDisplayListLayer(this, layer);
192cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck    }
193cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck
194cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck    @Override
19519b6bcfd83eb7fb92ebd06d2fec89e308311f1d0John Reck    HardwareLayer createTextureLayer() {
19619b6bcfd83eb7fb92ebd06d2fec89e308311f1d0John Reck        long layer = nCreateTextureLayer(mNativeProxy);
19719b6bcfd83eb7fb92ebd06d2fec89e308311f1d0John Reck        return HardwareLayer.adoptTextureLayer(this, layer);
198cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck    }
199cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck
200cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck    @Override
20119b6bcfd83eb7fb92ebd06d2fec89e308311f1d0John Reck    SurfaceTexture createSurfaceTexture(final HardwareLayer layer) {
20219b6bcfd83eb7fb92ebd06d2fec89e308311f1d0John Reck        final SurfaceTexture[] ret = new SurfaceTexture[1];
20319b6bcfd83eb7fb92ebd06d2fec89e308311f1d0John Reck        nRunWithGlContext(mNativeProxy, new Runnable() {
20419b6bcfd83eb7fb92ebd06d2fec89e308311f1d0John Reck            @Override
20519b6bcfd83eb7fb92ebd06d2fec89e308311f1d0John Reck            public void run() {
20619b6bcfd83eb7fb92ebd06d2fec89e308311f1d0John Reck                ret[0] = layer.createSurfaceTexture();
20719b6bcfd83eb7fb92ebd06d2fec89e308311f1d0John Reck            }
20819b6bcfd83eb7fb92ebd06d2fec89e308311f1d0John Reck        });
20919b6bcfd83eb7fb92ebd06d2fec89e308311f1d0John Reck        return ret[0];
210cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck    }
211cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck
212cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck    @Override
21319b6bcfd83eb7fb92ebd06d2fec89e308311f1d0John Reck    boolean copyLayerInto(final HardwareLayer layer, final Bitmap bitmap) {
21419b6bcfd83eb7fb92ebd06d2fec89e308311f1d0John Reck        return nCopyLayerInto(mNativeProxy,
21519b6bcfd83eb7fb92ebd06d2fec89e308311f1d0John Reck                layer.getDeferredLayerUpdater(), bitmap.mNativeBitmap);
216cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck    }
217cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck
218cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck    @Override
21919b6bcfd83eb7fb92ebd06d2fec89e308311f1d0John Reck    void pushLayerUpdate(HardwareLayer layer) {
22019b6bcfd83eb7fb92ebd06d2fec89e308311f1d0John Reck        // TODO: Remove this, it's not needed outside of GLRenderer
22119b6bcfd83eb7fb92ebd06d2fec89e308311f1d0John Reck    }
22219b6bcfd83eb7fb92ebd06d2fec89e308311f1d0John Reck
22319b6bcfd83eb7fb92ebd06d2fec89e308311f1d0John Reck    @Override
22419b6bcfd83eb7fb92ebd06d2fec89e308311f1d0John Reck    void onLayerCreated(HardwareLayer layer) {
22519b6bcfd83eb7fb92ebd06d2fec89e308311f1d0John Reck        // TODO: Is this actually useful?
22619b6bcfd83eb7fb92ebd06d2fec89e308311f1d0John Reck    }
22719b6bcfd83eb7fb92ebd06d2fec89e308311f1d0John Reck
22819b6bcfd83eb7fb92ebd06d2fec89e308311f1d0John Reck    @Override
22919b6bcfd83eb7fb92ebd06d2fec89e308311f1d0John Reck    void flushLayerUpdates() {
23019b6bcfd83eb7fb92ebd06d2fec89e308311f1d0John Reck        // TODO: Figure out what this should do or remove it
23119b6bcfd83eb7fb92ebd06d2fec89e308311f1d0John Reck    }
23219b6bcfd83eb7fb92ebd06d2fec89e308311f1d0John Reck
23319b6bcfd83eb7fb92ebd06d2fec89e308311f1d0John Reck    @Override
23419b6bcfd83eb7fb92ebd06d2fec89e308311f1d0John Reck    void onLayerDestroyed(HardwareLayer layer) {
23519b6bcfd83eb7fb92ebd06d2fec89e308311f1d0John Reck        nDestroyLayer(mNativeProxy, layer.getDeferredLayerUpdater());
236cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck    }
237cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck
238cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck    @Override
239cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck    void setName(String name) {
240cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck    }
241cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck
2424f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck    @Override
2434f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck    protected void finalize() throws Throwable {
2444f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck        try {
2454f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck            nDeleteProxy(mNativeProxy);
2464f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck        } finally {
2474f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck            super.finalize();
248cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck        }
249cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck    }
250cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck
2514f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck    /** @hide */
2524f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck    public static native void postToRenderThread(Runnable runnable);
253cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck
2544f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck    private static native long nCreateProxy(boolean translucent);
2554f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck    private static native void nDeleteProxy(long nativeProxy);
256cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck
2574f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck    private static native boolean nInitialize(long nativeProxy, Surface window);
2584f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck    private static native void nUpdateSurface(long nativeProxy, Surface window);
2594f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck    private static native void nSetup(long nativeProxy, int width, int height);
26044fd8d24f761f82d21e9b00932648a1b6bf91449John Reck    private static native void nSwapDisplayListData(long nativeProxy, long displayList,
26144fd8d24f761f82d21e9b00932648a1b6bf91449John Reck            long newData);
2624f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck    private static native void nDrawDisplayList(long nativeProxy, long displayList,
2634f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck            int dirtyLeft, int dirtyTop, int dirtyRight, int dirtyBottom);
264fc53ef27793a39e9effd829e9cae02a9ca14147eJohn Reck    private static native void nRunWithGlContext(long nativeProxy, Runnable runnable);
2654f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck    private static native void nDestroyCanvas(long nativeProxy);
266cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck
2674f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck    private static native void nAttachFunctor(long nativeProxy, long functor);
2684f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck    private static native void nDetachFunctor(long nativeProxy, long functor);
26919b6bcfd83eb7fb92ebd06d2fec89e308311f1d0John Reck
27019b6bcfd83eb7fb92ebd06d2fec89e308311f1d0John Reck    private static native long nCreateDisplayListLayer(long nativeProxy, int width, int height);
27119b6bcfd83eb7fb92ebd06d2fec89e308311f1d0John Reck    private static native long nCreateTextureLayer(long nativeProxy);
27219b6bcfd83eb7fb92ebd06d2fec89e308311f1d0John Reck    private static native boolean nCopyLayerInto(long nativeProxy, long layer, long bitmap);
27319b6bcfd83eb7fb92ebd06d2fec89e308311f1d0John Reck    private static native void nDestroyLayer(long nativeProxy, long layer);
274cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck}
275