Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ddd72599 authored by Chris Craik's avatar Chris Craik Committed by Android (Google) Code Review
Browse files

Merge "Rename and simplify DisplayList Canvas classes"

parents 2fb1d066 c9070ebd
Loading
Loading
Loading
Loading
+40 −8
Original line number Original line Diff line number Diff line
@@ -16,6 +16,7 @@


package android.view;
package android.view;


import android.annotation.NonNull;
import android.graphics.Bitmap;
import android.graphics.Bitmap;
import android.graphics.CanvasProperty;
import android.graphics.CanvasProperty;
import android.graphics.NinePatch;
import android.graphics.NinePatch;
@@ -24,19 +25,50 @@ import android.graphics.Path;
import android.graphics.Picture;
import android.graphics.Picture;
import android.graphics.Rect;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.RectF;
import android.util.Pools.SynchronizedPool;


/**
/**
 * An implementation of Canvas on top of OpenGL ES 2.0.
 * An implementation of a GL canvas that records drawing operations.
 * This is intended for use with a DisplayList. This class keeps a list of all the Paint and
 * Bitmap objects that it draws, preventing the backing memory of Bitmaps from being freed while
 * the DisplayList is still holding a native reference to the memory.
 */
 */
class GLES20Canvas extends HardwareCanvas {
class DisplayListCanvas extends HardwareCanvas {
    // The recording canvas pool should be large enough to handle a deeply nested
    // view hierarchy because display lists are generated recursively.
    private static final int POOL_LIMIT = 25;

    private static final SynchronizedPool<DisplayListCanvas> sPool =
            new SynchronizedPool<DisplayListCanvas>(POOL_LIMIT);

    RenderNode mNode;
    private int mWidth;
    private int mWidth;
    private int mHeight;
    private int mHeight;


    private float[] mPoint;
    private float[] mLine;


    private Rect mClipBounds;
    static DisplayListCanvas obtain(@NonNull RenderNode node) {
    private RectF mPathBounds;
        if (node == null) throw new IllegalArgumentException("node cannot be null");
        DisplayListCanvas canvas = sPool.acquire();
        if (canvas == null) {
            canvas = new DisplayListCanvas();
        }
        canvas.mNode = node;
        return canvas;
    }

    void recycle() {
        mNode = null;
        sPool.release(this);
    }

    long finishRecording() {
        return nFinishRecording(mNativeCanvasWrapper);
    }

    @Override
    public boolean isRecordingFor(Object o) {
        return o == mNode;
    }


    ///////////////////////////////////////////////////////////////////////////
    ///////////////////////////////////////////////////////////////////////////
    // JNI
    // JNI
@@ -53,8 +85,8 @@ class GLES20Canvas extends HardwareCanvas {
    // Constructors
    // Constructors
    ///////////////////////////////////////////////////////////////////////////
    ///////////////////////////////////////////////////////////////////////////


    // TODO: Merge with GLES20RecordingCanvas

    protected GLES20Canvas() {
    private DisplayListCanvas() {
        super(nCreateDisplayListRenderer());
        super(nCreateDisplayListRenderer());
    }
    }


+0 −65
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2010 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.NonNull;
import android.util.Pools.SynchronizedPool;

/**
 * An implementation of a GL canvas that records drawing operations.
 * This is intended for use with a DisplayList. This class keeps a list of all the Paint and
 * Bitmap objects that it draws, preventing the backing memory of Bitmaps from being freed while
 * the DisplayList is still holding a native reference to the memory.
 */
class GLES20RecordingCanvas extends GLES20Canvas {
    // The recording canvas pool should be large enough to handle a deeply nested
    // view hierarchy because display lists are generated recursively.
    private static final int POOL_LIMIT = 25;

    private static final SynchronizedPool<GLES20RecordingCanvas> sPool =
            new SynchronizedPool<GLES20RecordingCanvas>(POOL_LIMIT);

    RenderNode mNode;

    private GLES20RecordingCanvas() {
        super();
    }

    static GLES20RecordingCanvas obtain(@NonNull RenderNode node) {
        if (node == null) throw new IllegalArgumentException("node cannot be null");
        GLES20RecordingCanvas canvas = sPool.acquire();
        if (canvas == null) {
            canvas = new GLES20RecordingCanvas();
        }
        canvas.mNode = node;
        return canvas;
    }

    void recycle() {
        mNode = null;
        sPool.release(this);
    }

    long finishRecording() {
        return nFinishRecording(mNativeCanvasWrapper);
    }

    @Override
    public boolean isRecordingFor(Object o) {
        return o == mNode;
    }
}
+1 −1
Original line number Original line Diff line number Diff line
@@ -119,6 +119,6 @@ public abstract class HardwareCanvas extends Canvas {
            CanvasProperty<Paint> paint);
            CanvasProperty<Paint> paint);


    public static void setProperty(String name, String value) {
    public static void setProperty(String name, String value) {
        GLES20Canvas.setProperty(name, value);
        DisplayListCanvas.setProperty(name, value);
    }
    }
}
}
+2 −2
Original line number Original line Diff line number Diff line
@@ -205,7 +205,7 @@ public abstract class HardwareRenderer {
     *         false otherwise
     *         false otherwise
     */
     */
    public static boolean isAvailable() {
    public static boolean isAvailable() {
        return GLES20Canvas.isAvailable();
        return DisplayListCanvas.isAvailable();
    }
    }


    /**
    /**
@@ -423,7 +423,7 @@ public abstract class HardwareRenderer {
     */
     */
    static HardwareRenderer create(Context context, boolean translucent) {
    static HardwareRenderer create(Context context, boolean translucent) {
        HardwareRenderer renderer = null;
        HardwareRenderer renderer = null;
        if (GLES20Canvas.isAvailable()) {
        if (DisplayListCanvas.isAvailable()) {
            renderer = new ThreadedRenderer(context, translucent);
            renderer = new ThreadedRenderer(context, translucent);
        }
        }
        return renderer;
        return renderer;
+3 −3
Original line number Original line Diff line number Diff line
@@ -225,7 +225,7 @@ public class RenderNode {
     * @see #isValid()
     * @see #isValid()
     */
     */
    public HardwareCanvas start(int width, int height) {
    public HardwareCanvas start(int width, int height) {
        HardwareCanvas canvas = GLES20RecordingCanvas.obtain(this);
        HardwareCanvas canvas = DisplayListCanvas.obtain(this);
        canvas.setViewport(width, height);
        canvas.setViewport(width, height);
        // The dirty rect should always be null for a display list
        // The dirty rect should always be null for a display list
        canvas.onPreDraw(null);
        canvas.onPreDraw(null);
@@ -241,11 +241,11 @@ public class RenderNode {
     * @see #isValid()
     * @see #isValid()
     */
     */
    public void end(HardwareCanvas endCanvas) {
    public void end(HardwareCanvas endCanvas) {
        if (!(endCanvas instanceof GLES20RecordingCanvas)) {
        if (!(endCanvas instanceof DisplayListCanvas)) {
            throw new IllegalArgumentException("Passed an invalid canvas to end!");
            throw new IllegalArgumentException("Passed an invalid canvas to end!");
        }
        }


        GLES20RecordingCanvas canvas = (GLES20RecordingCanvas) endCanvas;
        DisplayListCanvas canvas = (DisplayListCanvas) endCanvas;
        canvas.onPostDraw();
        canvas.onPostDraw();
        long renderNodeData = canvas.finishRecording();
        long renderNodeData = canvas.finishRecording();
        nSetDisplayListData(mNativeRenderNode, renderNodeData);
        nSetDisplayListData(mNativeRenderNode, renderNodeData);
Loading