2 * Copyright (C) 2013 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com.android.gallery3d.filtershow.pipeline;
19 import android.graphics.Bitmap;
20 import android.graphics.Canvas;
21 import android.renderscript.Allocation;
22 import android.renderscript.RenderScript;
23 import android.util.Log;
24 import com.android.gallery3d.filtershow.cache.BitmapCache;
25 import com.android.gallery3d.filtershow.imageshow.MasterImage;
28 private static final String LOGTAG = "Buffer";
29 private Bitmap mBitmap;
30 private Allocation mAllocation;
31 private boolean mUseAllocation = false;
32 private ImagePreset mPreset;
34 public Buffer(Bitmap bitmap) {
35 RenderScript rs = CachingPipeline.getRenderScriptContext();
37 BitmapCache cache = MasterImage.getImage().getBitmapCache();
38 mBitmap = cache.getBitmapCopy(bitmap, BitmapCache.PREVIEW_CACHE);
41 // TODO: recreate the allocation when the RS context changes
42 mAllocation = Allocation.createFromBitmap(rs, mBitmap,
43 Allocation.MipmapControl.MIPMAP_NONE,
44 Allocation.USAGE_SHARED | Allocation.USAGE_SCRIPT);
48 public boolean isSameSize(Bitmap bitmap) {
49 if (mBitmap == null || bitmap == null) {
52 if (mBitmap.getWidth() == bitmap.getWidth()
53 && mBitmap.getHeight() == bitmap.getHeight()) {
59 public synchronized void useBitmap(Bitmap bitmap) {
60 Canvas canvas = new Canvas(mBitmap);
61 canvas.drawBitmap(bitmap, 0, 0, null);
64 public synchronized Bitmap getBitmap() {
68 public Allocation getAllocation() {
74 mAllocation.copyTo(mBitmap);
78 public ImagePreset getPreset() {
82 public void setPreset(ImagePreset preset) {
83 if ((mPreset == null) || (!mPreset.same(preset))) {
84 mPreset = new ImagePreset(preset);
86 mPreset.updateWith(preset);
90 public void remove() {
91 BitmapCache cache = MasterImage.getImage().getBitmapCache();
92 if (cache.cache(mBitmap)) {