LibreOffice Module android (master) 1
BufferedCairoImage.java
Go to the documentation of this file.
1/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6package org.mozilla.gecko.gfx;
7
8
9import android.graphics.Bitmap;
10import android.util.Log;
11
13
14import java.nio.ByteBuffer;
15
19public class BufferedCairoImage extends CairoImage {
20 private static String LOGTAG = "GeckoBufferedCairoImage";
21 private ByteBuffer mBuffer;
22 private IntSize mSize;
23 private int mFormat;
24
28 public BufferedCairoImage(ByteBuffer inBuffer, int inWidth, int inHeight, int inFormat) {
29 setBuffer(inBuffer, inWidth, inHeight, inFormat);
30 }
31
35 public BufferedCairoImage(Bitmap bitmap) {
36 setBitmap(bitmap);
37 }
38
39 private synchronized void freeBuffer() {
40 mBuffer = DirectBufferAllocator.free(mBuffer);
41 }
42
43 @Override
44 public void destroy() {
45 try {
46 freeBuffer();
47 } catch (Exception ex) {
48 Log.e(LOGTAG, "error clearing buffer: ", ex);
49 }
50 }
51
52 @Override
53 public ByteBuffer getBuffer() {
54 return mBuffer;
55 }
56
57 @Override
58 public IntSize getSize() {
59 return mSize;
60 }
61
62 @Override
63 public int getFormat() {
64 return mFormat;
65 }
66
67
68 public void setBuffer(ByteBuffer buffer, int width, int height, int format) {
69 freeBuffer();
70 mBuffer = buffer;
71 mSize = new IntSize(width, height);
72 mFormat = format;
73 }
74
75 public void setBitmap(Bitmap bitmap) {
76 mFormat = CairoUtils.bitmapConfigToCairoFormat(bitmap.getConfig());
77 mSize = new IntSize(bitmap.getWidth(), bitmap.getHeight());
78
80 mBuffer = DirectBufferAllocator.allocate(mSize.getArea() * bpp);
81 bitmap.copyPixelsToBuffer(mBuffer.asIntBuffer());
82 }
83}
A Cairo image that simply saves a buffer of pixel data.
BufferedCairoImage(ByteBuffer inBuffer, int inWidth, int inHeight, int inFormat)
Creates a buffered Cairo image from a byte buffer.
void setBuffer(ByteBuffer buffer, int width, int height, int format)
BufferedCairoImage(Bitmap bitmap)
Creates a buffered Cairo image from an Android bitmap.
Utility methods useful when displaying Cairo bitmaps using OpenGL ES.
Definition: CairoUtils.java:13
static int bitmapConfigToCairoFormat(Bitmap.Config config)
Definition: CairoUtils.java:28
static int bitsPerPixelForCairoFormat(int cairoFormat)
Definition: CairoUtils.java:16
@ Exception