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 HighresRenderingRequestTask extends ProcessingTask { 23 24 private CachingPipeline mHighresPreviewPipeline = null; 25 private boolean mPipelineIsOn = false; 26 27 public void setHighresPreviewScaleFactor(float highResPreviewScale) { 28 mHighresPreviewPipeline.setHighResPreviewScaleFactor(highResPreviewScale); 29 } 30 31 public void setPreviewScaleFactor(float previewScale) { 32 mHighresPreviewPipeline.setPreviewScaleFactor(previewScale); 33 } 34 35 static class Render implements Request { 36 RenderingRequest request; 37 } 38 39 static class RenderResult implements Result { 40 RenderingRequest request; 41 } 42 43 public HighresRenderingRequestTask() { 44 mHighresPreviewPipeline = new CachingPipeline( 45 FiltersManager.getHighresManager(), "Highres"); 46 } 47 48 public void setOriginal(Bitmap bitmap) { 49 mHighresPreviewPipeline.setOriginal(bitmap); 50 } 51 52 public void setOriginalBitmapHighres(Bitmap originalHires) { 53 mPipelineIsOn = true; 54 } 55 56 public void stop() { 57 mHighresPreviewPipeline.stop(); 58 } 59 60 public void postRenderingRequest(RenderingRequest request) { 61 if (!mPipelineIsOn) { 62 return; 63 } 64 Render render = new Render(); 65 render.request = request; 66 postRequest(render); 67 } 68 69 @Override 70 public Result doInBackground(Request message) { 71 RenderingRequest request = ((Render) message).request; 72 RenderResult result = null; 73 mHighresPreviewPipeline.renderHighres(request); 74 result = new RenderResult(); 75 result.request = request; 76 return result; 77 } 78 79 @Override 80 public void onResult(Result message) { 81 if (message == null) { 82 return; 83 } 84 RenderingRequest request = ((RenderResult) message).request; 85 request.markAvailable(); 86 } 87 88 @Override 89 public boolean isDelayedTask() { return true; } 90 } 91