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.pipeline; 18 19 import android.graphics.Bitmap; 20 import com.android.gallery3d.filtershow.filters.FiltersManager; 21 22 public class RenderingRequestTask extends ProcessingTask { 23 24 private CachingPipeline mPreviewPipeline = null; 25 private boolean mPipelineIsOn = false; 26 27 public void setPreviewScaleFactor(float previewScale) { 28 mPreviewPipeline.setPreviewScaleFactor(previewScale); 29 } 30 31 static class Render implements Request { 32 RenderingRequest request; 33 } 34 35 static class RenderResult implements Result { 36 RenderingRequest request; 37 } 38 39 public RenderingRequestTask() { 40 mPreviewPipeline = new CachingPipeline( 41 FiltersManager.getManager(), "Normal"); 42 } 43 44 public void setOriginal(Bitmap bitmap) { 45 mPreviewPipeline.setOriginal(bitmap); 46 mPipelineIsOn = true; 47 } 48 49 public void stop() { 50 mPreviewPipeline.stop(); 51 } 52 53 public void postRenderingRequest(RenderingRequest request) { 54 if (!mPipelineIsOn) { 55 return; 56 } 57 Render render = new Render(); 58 render.request = request; 59 postRequest(render); 60 } 61 62 @Override 63 public Result doInBackground(Request message) { 64 RenderingRequest request = ((Render) message).request; 65 RenderResult result = null; 66 if (request.getType() == RenderingRequest.GEOMETRY_RENDERING) { 67 mPreviewPipeline.renderGeometry(request); 68 } else if (request.getType() == RenderingRequest.FILTERS_RENDERING) { 69 mPreviewPipeline.renderFilters(request); 70 } else { 71 mPreviewPipeline.render(request); 72 } 73 result = new RenderResult(); 74 result.request = request; 75 return result; 76 } 77 78 @Override 79 public void onResult(Result message) { 80 if (message == null) { 81 return; 82 } 83 RenderingRequest request = ((RenderResult) message).request; 84 request.markAvailable(); 85 } 86 87 } 88