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.rs.image; 18 19import java.lang.Math; 20 21import android.view.Surface; 22import android.renderscript.Allocation; 23import android.renderscript.Element; 24import android.renderscript.RenderScript; 25import android.renderscript.ScriptIntrinsicConvolve3x3; 26import android.renderscript.ScriptIntrinsicColorMatrix; 27import android.renderscript.Type; 28import android.renderscript.Matrix4f; 29import android.util.Log; 30 31public class UsageIO extends TestBase { 32 private ScriptIntrinsicColorMatrix mMatrix; 33 34 private Allocation mScratchPixelsAllocation1; 35 private Allocation mScratchPixelsAllocation2; 36 37 public UsageIO() { 38 } 39 40 public void createTest(android.content.res.Resources res) { 41 mMatrix = ScriptIntrinsicColorMatrix.create(mRS, Element.U8_4(mRS)); 42 43 Matrix4f m = new Matrix4f(); 44 m.set(1, 0, 0.2f); 45 m.set(1, 1, 0.9f); 46 m.set(1, 2, 0.2f); 47 mMatrix.setColorMatrix(m); 48 49 Type connect = mInPixelsAllocation.getType(); 50 51 mScratchPixelsAllocation1 = Allocation.createTyped(mRS, connect, Allocation.USAGE_IO_OUTPUT | Allocation.USAGE_SCRIPT); 52 mScratchPixelsAllocation2 = Allocation.createTyped(mRS, connect, Allocation.USAGE_IO_INPUT | Allocation.USAGE_SCRIPT); 53 54 Surface s = mScratchPixelsAllocation2.getSurface(); 55 mScratchPixelsAllocation1.setSurface(s); 56 } 57 58 public void runTest() { 59 mScratchPixelsAllocation1.copyFrom(mInPixelsAllocation); 60 mScratchPixelsAllocation1.ioSend(); 61 mScratchPixelsAllocation2.ioReceive(); 62 mMatrix.forEach(mScratchPixelsAllocation2, mOutPixelsAllocation); 63 } 64 65} 66