OSDN Git Service

e5bc411de4218680bc47e49bca6ff581f1bc17c8
[android-x86/packages-apps-Gallery2.git] / src / com / android / gallery3d / filtershow / cache / RenderingRequest.java
1 /*
2  * Copyright (C) 2013 The Android Open Source Project
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package com.android.gallery3d.filtershow.cache;
18
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;
26
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;
45
46     private static final Bitmap.Config mConfig = Bitmap.Config.ARGB_8888;
47
48     public static void post(Bitmap source, ImagePreset preset, int type, RenderingRequestCaller caller) {
49         RenderingRequest.post(source, preset, type, caller, null, null);
50     }
51
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);
58             return;
59         }
60         RenderingRequest request = new RenderingRequest();
61         Bitmap bitmap = null;
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);
71         }
72
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());
78
79         if (type == PARTIAL_RENDERING) {
80             request.setBounds(bounds);
81             request.setDestination(destination);
82             passedPreset.setPartialRendering(true, bounds);
83         }
84
85         request.setImagePreset(passedPreset);
86         request.setType(type);
87         request.setCaller(caller);
88         request.post();
89     }
90
91     public void post() {
92         FilteringPipeline.getPipeline().postRenderingRequest(this);
93     }
94
95     public void markAvailable() {
96         if (mBitmap == null || mImagePreset == null
97                 || mCaller == null) {
98             return;
99         }
100         mCaller.available(this);
101     }
102
103     public boolean isDirect() {
104         return mIsDirect;
105     }
106
107     public void setDirect(boolean isDirect) {
108         mIsDirect = isDirect;
109     }
110
111     public Bitmap getBitmap() {
112         return mBitmap;
113     }
114
115     public void setBitmap(Bitmap bitmap) {
116         mBitmap = bitmap;
117     }
118
119     public ImagePreset getImagePreset() {
120         return mImagePreset;
121     }
122
123     public void setImagePreset(ImagePreset imagePreset) {
124         mImagePreset = imagePreset;
125     }
126
127     public int getType() {
128         return mType;
129     }
130
131     public void setType(int type) {
132         mType = type;
133     }
134
135     public void setCaller(RenderingRequestCaller caller) {
136         mCaller = caller;
137     }
138
139     public Rect getBounds() {
140         return mBounds;
141     }
142
143     public void setBounds(Rect bounds) {
144         mBounds = bounds;
145     }
146
147     public void setScaleFactor(float scaleFactor) {
148         mScaleFactor = scaleFactor;
149     }
150
151     public float getScaleFactor() {
152         return mScaleFactor;
153     }
154
155     public Rect getDestination() {
156         return mDestination;
157     }
158
159     public void setDestination(Rect destination) {
160         mDestination = destination;
161     }
162
163     public ImagePreset getOriginalImagePreset() {
164         return mOriginalImagePreset;
165     }
166
167     public void setOriginalImagePreset(ImagePreset originalImagePreset) {
168         mOriginalImagePreset = originalImagePreset;
169     }
170 }