RenderingRequest.java revision f3bcc676e245727b20c7d6123cb39361e84b1dc9
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
17package com.android.gallery3d.filtershow.cache;
18
19import android.graphics.Bitmap;
20import android.graphics.Rect;
21import com.android.gallery3d.app.Log;
22import com.android.gallery3d.filtershow.filters.FiltersManager;
23import com.android.gallery3d.filtershow.imageshow.MasterImage;
24import com.android.gallery3d.filtershow.presets.FilterEnvironment;
25import com.android.gallery3d.filtershow.presets.ImagePreset;
26
27public 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    private static final Bitmap.Config mConfig = Bitmap.Config.ARGB_8888;
45
46    public static void post(Bitmap source, ImagePreset preset, int type, RenderingRequestCaller caller) {
47        RenderingRequest.post(source, preset, type, caller, null, null);
48    }
49
50    public static void post(Bitmap source, ImagePreset preset, int type,
51                            RenderingRequestCaller caller, Rect bounds, Rect destination) {
52        if (((type != PARTIAL_RENDERING && type != HIGHRES_RENDERING) && source == null)
53                || preset == null || caller == null) {
54            Log.v(LOGTAG, "something null: source: " + source
55                    + " or preset: " + preset + " or caller: " + caller);
56            return;
57        }
58        RenderingRequest request = new RenderingRequest();
59        Bitmap bitmap = null;
60        if (type == FULL_RENDERING
61                || type == GEOMETRY_RENDERING
62                || type == ICON_RENDERING) {
63            CachingPipeline pipeline = new CachingPipeline(
64                    FiltersManager.getManager(), "Icon");
65            bitmap = pipeline.renderGeometryIcon(source, preset);
66        } else if (type != PARTIAL_RENDERING && type != HIGHRES_RENDERING) {
67            bitmap = Bitmap.createBitmap(source.getWidth(), source.getHeight(), mConfig);
68        }
69
70        request.setBitmap(bitmap);
71        ImagePreset passedPreset = new ImagePreset(preset);
72        passedPreset.setImageLoader(MasterImage.getImage().getImageLoader());
73        request.setOriginalImagePreset(preset);
74        request.setScaleFactor(MasterImage.getImage().getScaleFactor());
75
76        if (type == PARTIAL_RENDERING) {
77            request.setBounds(bounds);
78            request.setDestination(destination);
79            passedPreset.setPartialRendering(true, bounds);
80        }
81
82        request.setImagePreset(passedPreset);
83        request.setType(type);
84        request.setCaller(caller);
85        request.post();
86    }
87
88    public void post() {
89        FilteringPipeline.getPipeline().postRenderingRequest(this);
90    }
91
92    public void markAvailable() {
93        if (mBitmap == null || mImagePreset == null
94                || mCaller == null) {
95            return;
96        }
97        mCaller.available(this);
98    }
99
100    public boolean isDirect() {
101        return mIsDirect;
102    }
103
104    public void setDirect(boolean isDirect) {
105        mIsDirect = isDirect;
106    }
107
108    public Bitmap getBitmap() {
109        return mBitmap;
110    }
111
112    public void setBitmap(Bitmap bitmap) {
113        mBitmap = bitmap;
114    }
115
116    public ImagePreset getImagePreset() {
117        return mImagePreset;
118    }
119
120    public void setImagePreset(ImagePreset imagePreset) {
121        mImagePreset = imagePreset;
122    }
123
124    public int getType() {
125        return mType;
126    }
127
128    public void setType(int type) {
129        mType = type;
130    }
131
132    public void setCaller(RenderingRequestCaller caller) {
133        mCaller = caller;
134    }
135
136    public Rect getBounds() {
137        return mBounds;
138    }
139
140    public void setBounds(Rect bounds) {
141        mBounds = bounds;
142    }
143
144    public void setScaleFactor(float scaleFactor) {
145        mScaleFactor = scaleFactor;
146    }
147
148    public float getScaleFactor() {
149        return mScaleFactor;
150    }
151
152    public Rect getDestination() {
153        return mDestination;
154    }
155
156    public void setDestination(Rect destination) {
157        mDestination = destination;
158    }
159
160    public ImagePreset getOriginalImagePreset() {
161        return mOriginalImagePreset;
162    }
163
164    public void setOriginalImagePreset(ImagePreset originalImagePreset) {
165        mOriginalImagePreset = originalImagePreset;
166    }
167}
168