summaryrefslogtreecommitdiff
path: root/android
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.com>2014-07-08 16:43:31 +0200
committerTomaž Vajngerl <tomaz.vajngerl@collabora.com>2014-07-10 11:17:54 +0200
commitd646e43cc088c70c2d8c2decaf1590ede0f3e898 (patch)
tree13cba3d66901310299573cffc4be80a3f3a059c3 /android
parentd4ab22323a34c286b411044a598f5041e189d159 (diff)
LOAndroid3: CairoImage, BufferedCairoImage update to latest code
Change-Id: If6b7e63a89c13015d4a96fae1862c9ccf6b04237
Diffstat (limited to 'android')
-rw-r--r--android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/BufferedCairoImage.java89
-rw-r--r--android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/CairoImage.java40
-rw-r--r--android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/CheckerboardImage.java5
3 files changed, 43 insertions, 91 deletions
diff --git a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/BufferedCairoImage.java b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/BufferedCairoImage.java
index 7a98be339c0c..ce836fe07e8f 100644
--- a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/BufferedCairoImage.java
+++ b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/BufferedCairoImage.java
@@ -1,90 +1,51 @@
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
- * ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (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.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is Mozilla Android code.
- *
- * The Initial Developer of the Original Code is Mozilla Foundation.
- * Portions created by the Initial Developer are Copyright (C) 2009-2010
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- * Patrick Walton <pcwalton@mozilla.com>
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.gecko.gfx;
+
import android.graphics.Bitmap;
+import android.util.Log;
import org.libreoffice.DirectBufferAllocator;
import java.nio.ByteBuffer;
-//import org.mozilla.gecko.GeckoAppShell;
-
/**
* A Cairo image that simply saves a buffer of pixel data.
*/
public class BufferedCairoImage extends CairoImage {
+ private static String LOGTAG = "GeckoBufferedCairoImage";
private ByteBuffer mBuffer;
private IntSize mSize;
private int mFormat;
- private boolean mNeedToFreeBuffer = false;
/**
* Creates a buffered Cairo image from a byte buffer.
*/
public BufferedCairoImage(ByteBuffer inBuffer, int inWidth, int inHeight, int inFormat) {
- mBuffer = inBuffer;
- mSize = new IntSize(inWidth, inHeight);
- mFormat = inFormat;
+ setBuffer(inBuffer, inWidth, inHeight, inFormat);
}
/**
* Creates a buffered Cairo image from an Android bitmap.
*/
public BufferedCairoImage(Bitmap bitmap) {
- mFormat = CairoUtils.bitmapConfigToCairoFormat(bitmap.getConfig());
- mSize = new IntSize(bitmap.getWidth(), bitmap.getHeight());
- mNeedToFreeBuffer = true;
- // XXX Why is this * 4? Shouldn't it depend on mFormat?
- mBuffer = DirectBufferAllocator.allocate(mSize.getArea() * 4);
+ setBitmap(bitmap);
+ }
- bitmap.copyPixelsToBuffer(mBuffer.asIntBuffer());
+ private synchronized void freeBuffer() {
+ mBuffer = DirectBufferAllocator.free(mBuffer);
}
- protected void finalize() throws Throwable {
+ @Override
+ public void destroy() {
try {
- if (mNeedToFreeBuffer && mBuffer != null) {
- DirectBufferAllocator.free(mBuffer);
- }
- mNeedToFreeBuffer = false;
- mBuffer = null;
- } finally {
- super.finalize();
+ freeBuffer();
+ } catch (Exception ex) {
+ Log.e(LOGTAG, "error clearing buffer: ", ex);
}
}
@@ -102,5 +63,21 @@ public class BufferedCairoImage extends CairoImage {
public int getFormat() {
return mFormat;
}
-}
+
+ public void setBuffer(ByteBuffer buffer, int width, int height, int format) {
+ freeBuffer();
+ mBuffer = buffer;
+ mSize = new IntSize(width, height);
+ mFormat = format;
+ }
+
+ public void setBitmap(Bitmap bitmap) {
+ mFormat = CairoUtils.bitmapConfigToCairoFormat(bitmap.getConfig());
+ mSize = new IntSize(bitmap.getWidth(), bitmap.getHeight());
+
+ int bpp = CairoUtils.bitsPerPixelForCairoFormat(mFormat);
+ mBuffer = DirectBufferAllocator.allocate(mSize.getArea() * bpp);
+ bitmap.copyPixelsToBuffer(mBuffer.asIntBuffer());
+ }
+}
diff --git a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/CairoImage.java b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/CairoImage.java
index 06c389dd0524..5a18a4bb1995 100644
--- a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/CairoImage.java
+++ b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/CairoImage.java
@@ -1,39 +1,7 @@
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
- * ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (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.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is Mozilla Android code.
- *
- * The Initial Developer of the Original Code is Mozilla Foundation.
- * Portions created by the Initial Developer are Copyright (C) 2009-2010
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- * Patrick Walton <pcwalton@mozilla.com>
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.gecko.gfx;
@@ -45,6 +13,8 @@ import java.nio.ByteBuffer;
public abstract class CairoImage {
public abstract ByteBuffer getBuffer();
+ public abstract void destroy();
+
public abstract IntSize getSize();
public abstract int getFormat();
diff --git a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/CheckerboardImage.java b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/CheckerboardImage.java
index 05a4d57a7346..7af94fa7052a 100644
--- a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/CheckerboardImage.java
+++ b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/CheckerboardImage.java
@@ -160,6 +160,11 @@ public class CheckerboardImage extends CairoImage {
}
@Override
+ public void destroy() {
+
+ }
+
+ @Override
public IntSize getSize() {
return new IntSize(SIZE, SIZE);
}