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

Commit 68609475 authored by Mark Renouf's avatar Mark Renouf Committed by Android (Google) Code Review
Browse files

Merge "Fix ImageTileSet support for multiple drawables" into sc-dev

parents cc312a71 a1ecf939
Loading
Loading
Loading
Loading
+54 −25
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@
 */
package com.android.systemui.screenshot;

import android.annotation.AnyThread;
import android.graphics.Bitmap;
import android.graphics.HardwareRenderer;
import android.graphics.RecordingCanvas;
@@ -26,6 +27,9 @@ import android.util.Log;

import androidx.annotation.UiThread;

import com.android.internal.util.CallbackRegistry;
import com.android.internal.util.CallbackRegistry.NotifierCallback;

import java.util.ArrayList;
import java.util.List;

@@ -34,10 +38,14 @@ import java.util.List;
 * <p>
 * To display on-screen, use {@link #getDrawable()}.
 */
@UiThread
class ImageTileSet {

    private static final String TAG = "ImageTileSet";

    private CallbackRegistry<OnBoundsChangedListener, ImageTileSet, Rect> mOnBoundsListeners;
    private CallbackRegistry<OnContentChangedListener, ImageTileSet, Rect> mContentListeners;

    ImageTileSet(@UiThread Handler handler) {
        mHandler = handler;
    }
@@ -64,15 +72,43 @@ class ImageTileSet {
    private OnContentChangedListener mOnContentChangedListener;
    private OnBoundsChangedListener mOnBoundsChangedListener;

    void setOnBoundsChangedListener(OnBoundsChangedListener listener) {
        mOnBoundsChangedListener = listener;
    void addOnBoundsChangedListener(OnBoundsChangedListener listener) {
        if (mOnBoundsListeners == null) {
            mOnBoundsListeners = new CallbackRegistry<>(
                    new NotifierCallback<OnBoundsChangedListener, ImageTileSet, Rect>() {
                        @Override
                        public void onNotifyCallback(OnBoundsChangedListener callback,
                                ImageTileSet sender,
                                int arg, Rect newBounds) {
                            callback.onBoundsChanged(newBounds.left, newBounds.top, newBounds.right,
                                    newBounds.bottom);
                        }
                    });
        }
        mOnBoundsListeners.add(listener);
    }

    void setOnContentChangedListener(OnContentChangedListener listener) {
        mOnContentChangedListener = listener;
    void addOnContentChangedListener(OnContentChangedListener listener) {
        if (mContentListeners == null) {
            mContentListeners = new CallbackRegistry<>(
                    new NotifierCallback<OnContentChangedListener, ImageTileSet, Rect>() {
                        @Override
                        public void onNotifyCallback(OnContentChangedListener callback,
                                ImageTileSet sender,
                                int arg, Rect newBounds) {
                            callback.onContentChanged();
                        }
                    });
        }
        mContentListeners.add(listener);
    }

    @AnyThread
    void addTile(ImageTile tile) {
        if (!mHandler.getLooper().isCurrentThread()) {
            mHandler.post(() -> addTile(tile));
            return;
        }
        final Rect newBounds = new Rect(mBounds);
        final Rect newRect = tile.getLocation();
        mTiles.add(tile);
@@ -84,27 +120,15 @@ class ImageTileSet {
        notifyContentChanged();
    }

    void notifyContentChanged() {
        if (mOnContentChangedListener == null) {
            return;
        }
        if (mHandler.getLooper().isCurrentThread()) {
            mOnContentChangedListener.onContentChanged();
        } else {
            mHandler.post(() -> mOnContentChangedListener.onContentChanged());
    private void notifyContentChanged() {
        if (mContentListeners != null) {
            mContentListeners.notifyCallbacks(this, 0, null);
        }
    }

    void notifyBoundsChanged(Rect bounds) {
        if (mOnBoundsChangedListener == null) {
            return;
        }
        if (mHandler.getLooper().isCurrentThread()) {
            mOnBoundsChangedListener.onBoundsChanged(
                    bounds.left, bounds.top, bounds.right, bounds.bottom);
        } else {
            mHandler.post(() -> mOnBoundsChangedListener.onBoundsChanged(
                    bounds.left, bounds.top, bounds.right, bounds.bottom));
    private void notifyBoundsChanged(Rect bounds) {
        if (mOnBoundsListeners != null) {
            mOnBoundsListeners.notifyCallbacks(this, 0, bounds);
        }
    }

@@ -180,8 +204,13 @@ class ImageTileSet {
        return mBounds.height();
    }

    @AnyThread
    void clear() {
        if (mBounds.isEmpty()) {
        if (!mHandler.getLooper().isCurrentThread()) {
            mHandler.post(this::clear);
            return;
        }
        if (mTiles.isEmpty()) {
            return;
        }
        mBounds.setEmpty();
+2 −1
Original line number Diff line number Diff line
@@ -38,9 +38,10 @@ public class TiledImageDrawable extends Drawable {

    public TiledImageDrawable(ImageTileSet tiles) {
        mTiles = tiles;
        mTiles.setOnContentChangedListener(this::onContentChanged);
        mTiles.addOnContentChangedListener(this::onContentChanged);
    }


    private void onContentChanged() {
        if (mNode != null && mNode.hasDisplayList()) {
            mNode.discardDisplayList();