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.support.v8.renderscript.Allocation;
21 import android.support.v8.renderscript.RenderScript;
24 private static final String LOGTAG = "Buffer";
25 private Bitmap mBitmap;
26 private Allocation mAllocation;
27 private boolean mUseAllocation = false;
28 private static final Bitmap.Config BITMAP_CONFIG = Bitmap.Config.ARGB_8888;
29 private ImagePreset mPreset;
31 public Buffer(Bitmap bitmap) {
32 RenderScript rs = CachingPipeline.getRenderScriptContext();
34 mBitmap = bitmap.copy(BITMAP_CONFIG, true);
37 // TODO: recreate the allocation when the RS context changes
38 mAllocation = Allocation.createFromBitmap(rs, mBitmap,
39 Allocation.MipmapControl.MIPMAP_NONE,
40 Allocation.USAGE_SHARED | Allocation.USAGE_SCRIPT);
44 public void setBitmap(Bitmap bitmap) {
45 mBitmap = bitmap.copy(BITMAP_CONFIG, true);
48 public Bitmap getBitmap() {
52 public Allocation getAllocation() {
58 mAllocation.copyTo(mBitmap);
62 public ImagePreset getPreset() {
66 public void setPreset(ImagePreset preset) {
67 if ((mPreset == null) || (!mPreset.same(preset))) {
68 mPreset = new ImagePreset(preset);
70 mPreset.updateWith(preset);