From 645b8a905ad70a7d0623dfbbfe6da720da038de9 Mon Sep 17 00:00:00 2001 From: Xavier Ducrohet Date: Mon, 29 Nov 2010 17:49:19 -0800 Subject: ADT/Layoutlib: New API to let the caller instantiate the bitmap. This allows us to use a bitmap more compatible with SWT. In ADT's case, because the bitmap needs to be converted to SWT before being displayed, we create a BufferedImage using a byte[] instead of a int[] so that we can simply do an array copy. Also, we reuse the generated BufferedImage unless the size changed, which lets us see less GC during animation playback. Change-Id: I0062a4f4442ff6469cf0ad4f501c1fbe8c719400 --- .../com/android/layoutlib/api/IImageFactory.java | 41 ++++++++++++++++++++++ .../src/com/android/layoutlib/api/SceneParams.java | 11 ++++++ 2 files changed, 52 insertions(+) create mode 100644 layoutlib_api/src/com/android/layoutlib/api/IImageFactory.java (limited to 'layoutlib_api/src/com/android/layoutlib/api') diff --git a/layoutlib_api/src/com/android/layoutlib/api/IImageFactory.java b/layoutlib_api/src/com/android/layoutlib/api/IImageFactory.java new file mode 100644 index 0000000..626423e --- /dev/null +++ b/layoutlib_api/src/com/android/layoutlib/api/IImageFactory.java @@ -0,0 +1,41 @@ +/* + * 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 com.android.layoutlib.api; + +import java.awt.image.BufferedImage; + +/** + * Image Factory Interface. + * + * An Image factory's task is to create the {@link BufferedImage} into which the scene will be + * rendered. The goal is to let the layoutlib caller create an image that's optimized for its use + * case. + * + * If no factory is passed in {@link SceneParams#setImageFactory(IImageFactory)}, then a default + * {@link BufferedImage} of type {@link BufferedImage#TYPE_INT_ARGB} is created. + * + */ +public interface IImageFactory { + + /** + * Creates a buffered image with the given size + * @param width the width of the image + * @param height the height of the image + * @return a new (or reused) BufferedImage of the given size. + */ + BufferedImage getImage(int width, int height); +} diff --git a/layoutlib_api/src/com/android/layoutlib/api/SceneParams.java b/layoutlib_api/src/com/android/layoutlib/api/SceneParams.java index 0eb9768..1bbd96a 100644 --- a/layoutlib_api/src/com/android/layoutlib/api/SceneParams.java +++ b/layoutlib_api/src/com/android/layoutlib/api/SceneParams.java @@ -64,6 +64,8 @@ public class SceneParams { private int mCustomBackgroundColor; private long mTimeout; + private IImageFactory mImageFactory = null; + /** * * @param layoutDescription the {@link IXmlPullParser} letting the LayoutLib Bridge visit the @@ -136,6 +138,7 @@ public class SceneParams { mCustomBackgroundEnabled = params.mCustomBackgroundEnabled; mCustomBackgroundColor = params.mCustomBackgroundColor; mTimeout = params.mTimeout; + mImageFactory = params.mImageFactory; } public void setCustomBackgroundColor(int color) { @@ -147,6 +150,10 @@ public class SceneParams { mTimeout = timeout; } + public void setImageFactory(IImageFactory imageFactory) { + mImageFactory = imageFactory; + } + public IXmlPullParser getLayoutDescription() { return mLayoutDescription; } @@ -214,4 +221,8 @@ public class SceneParams { public long getTimeout() { return mTimeout; } + + public IImageFactory getImageFactory() { + return mImageFactory; + } } -- cgit v1.1