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.cache;
19 import android.graphics.Bitmap;
20 import android.graphics.Rect;
21 import com.android.gallery3d.app.Log;
22 import com.android.gallery3d.filtershow.filters.FiltersManager;
23 import com.android.gallery3d.filtershow.imageshow.MasterImage;
24 import com.android.gallery3d.filtershow.presets.FilterEnvironment;
25 import com.android.gallery3d.filtershow.presets.ImagePreset;
27 public class RenderingRequest {
28 private static final String LOGTAG = "RenderingRequest";
29 private boolean mIsDirect = false;
30 private Bitmap mBitmap = null;
31 private ImagePreset mImagePreset = null;
32 private ImagePreset mOriginalImagePreset = null;
33 private RenderingRequestCaller mCaller = null;
34 private float mScaleFactor = 1.0f;
35 private Rect mBounds = null;
36 private Rect mDestination = null;
37 private int mType = FULL_RENDERING;
38 public static final int FULL_RENDERING = 0;
39 public static final int FILTERS_RENDERING = 1;
40 public static final int GEOMETRY_RENDERING = 2;
41 public static final int ICON_RENDERING = 3;
42 public static final int PARTIAL_RENDERING = 4;
43 public static final int HIGHRES_RENDERING = 5;
44 public static final int STYLE_ICON_RENDERING = 6;
46 private static final Bitmap.Config mConfig = Bitmap.Config.ARGB_8888;
48 public static void post(Bitmap source, ImagePreset preset, int type, RenderingRequestCaller caller) {
49 RenderingRequest.post(source, preset, type, caller, null, null);
52 public static void post(Bitmap source, ImagePreset preset, int type,
53 RenderingRequestCaller caller, Rect bounds, Rect destination) {
54 if (((type != PARTIAL_RENDERING && type != HIGHRES_RENDERING) && source == null)
55 || preset == null || caller == null) {
56 Log.v(LOGTAG, "something null: source: " + source
57 + " or preset: " + preset + " or caller: " + caller);
60 RenderingRequest request = new RenderingRequest();
62 if (type == FULL_RENDERING
63 || type == GEOMETRY_RENDERING
64 || type == ICON_RENDERING
65 || type == STYLE_ICON_RENDERING) {
66 CachingPipeline pipeline = new CachingPipeline(
67 FiltersManager.getManager(), "Icon");
68 bitmap = pipeline.renderGeometryIcon(source, preset);
69 } else if (type != PARTIAL_RENDERING && type != HIGHRES_RENDERING) {
70 bitmap = Bitmap.createBitmap(source.getWidth(), source.getHeight(), mConfig);
73 request.setBitmap(bitmap);
74 ImagePreset passedPreset = new ImagePreset(preset);
75 passedPreset.setImageLoader(MasterImage.getImage().getImageLoader());
76 request.setOriginalImagePreset(preset);
77 request.setScaleFactor(MasterImage.getImage().getScaleFactor());
79 if (type == PARTIAL_RENDERING) {
80 request.setBounds(bounds);
81 request.setDestination(destination);
82 passedPreset.setPartialRendering(true, bounds);
85 request.setImagePreset(passedPreset);
86 request.setType(type);
87 request.setCaller(caller);
92 FilteringPipeline.getPipeline().postRenderingRequest(this);
95 public void markAvailable() {
96 if (mBitmap == null || mImagePreset == null
100 mCaller.available(this);
103 public boolean isDirect() {
107 public void setDirect(boolean isDirect) {
108 mIsDirect = isDirect;
111 public Bitmap getBitmap() {
115 public void setBitmap(Bitmap bitmap) {
119 public ImagePreset getImagePreset() {
123 public void setImagePreset(ImagePreset imagePreset) {
124 mImagePreset = imagePreset;
127 public int getType() {
131 public void setType(int type) {
135 public void setCaller(RenderingRequestCaller caller) {
139 public Rect getBounds() {
143 public void setBounds(Rect bounds) {
147 public void setScaleFactor(float scaleFactor) {
148 mScaleFactor = scaleFactor;
151 public float getScaleFactor() {
155 public Rect getDestination() {
159 public void setDestination(Rect destination) {
160 mDestination = destination;
163 public ImagePreset getOriginalImagePreset() {
164 return mOriginalImagePreset;
167 public void setOriginalImagePreset(ImagePreset originalImagePreset) {
168 mOriginalImagePreset = originalImagePreset;