summaryrefslogtreecommitdiff
path: root/java/tests/ImageProcessing_jb/src/com/android/rs/image/ImageProcessingActivityJB.java
blob: e49e9cc8b792ea5831ef25b6c80359ba93ee0b1b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
/*
 * Copyright (C) 2012 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.rs.imagejb;

import android.app.Activity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.SeekBar;
import android.widget.Spinner;
import android.widget.TextView;
import android.view.View;
import android.view.TextureView;
import android.view.Surface;
import android.graphics.SurfaceTexture;
import android.graphics.Point;

import android.util.Log;
import android.renderscript.ScriptC;
import android.renderscript.RenderScript;
import android.renderscript.Type;
import android.renderscript.Allocation;
import android.renderscript.Element;
import android.renderscript.Script;


public class ImageProcessingActivityJB extends Activity
                                       implements SeekBar.OnSeekBarChangeListener,
                                                  TextureView.SurfaceTextureListener {
    private final String TAG = "Img";

    private Spinner mSpinner;
    private SeekBar mBar1;
    private SeekBar mBar2;
    private SeekBar mBar3;
    private SeekBar mBar4;
    private SeekBar mBar5;

    private int mBars[] = new int[5];
    private int mBarsOld[] = new int[5];

    private TextView mText1;
    private TextView mText2;
    private TextView mText3;
    private TextView mText4;
    private TextView mText5;
    private SizedTV mDisplayView;

    private int mTestList[];
    private float mTestResults[];

    private boolean mToggleIO;
    private boolean mToggleDVFS;
    private boolean mToggleLong;
    private boolean mTogglePause;
    private boolean mToggleAnimate;
    private boolean mToggleDisplay;
    private int mBitmapWidth;
    private int mBitmapHeight;
    private boolean mDemoMode;

    // Updates pending is a counter of how many kernels have been
    // sent to RS for processing
    //
    // In benchmark this is incremented each time a kernel is launched and
    // decremented each time a kernel completes
    //
    // In demo mode, each UI input increments the counter and it is zeroed
    // when the latest settings are sent to RS for processing.
    private int mUpdatesPending;

    // In demo mode this is used to count updates in the pipeline.  It's
    // incremented when work is submitted to RS and decremented when invalidate is
    // called to display a result.
    private int mShowsPending;


    static public class SizedTV extends TextureView {
        int mWidth;
        int mHeight;

        public SizedTV(android.content.Context c) {
            super(c);
            mWidth = 800;
            mHeight = 450;
        }

        public SizedTV(android.content.Context c, android.util.AttributeSet attrs) {
            super(c, attrs);
            mWidth = 800;
            mHeight = 450;
        }

        public SizedTV(android.content.Context c, android.util.AttributeSet attrs, int f) {
            super(c, attrs, f);
            mWidth = 800;
            mHeight = 450;
        }

        protected void onMeasure(int w, int h) {
            setMeasuredDimension(mWidth, mHeight);
        }
    }

    /////////////////////////////////////////////////////////////////////////

    // Message processor to handle notifications for when kernel completes
    private class MessageProcessor extends RenderScript.RSMessageHandler {
        MessageProcessor() {
        }

        public void run() {
            synchronized(mProcessor) {
                // In demo mode, decrement the pending displays and notify the
                // UI processor it can now enqueue more work if additional updates
                // are blocked by a full pipeline.
                if (mShowsPending > 0) {
                    mShowsPending --;
                    mProcessor.notifyAll();
                }
            }
        }
    }


    /////////////////////////////////////////////////////////////////////////
    // Processor is a helper thread for running the work without
    // blocking the UI thread.
    class Processor extends Thread {
        RenderScript mRS;
        Allocation mInPixelsAllocation;
        Allocation mInPixelsAllocation2;
        Allocation mOutDisplayAllocation;
        Allocation mOutPixelsAllocation;

        private Surface mOutSurface;
        private float mLastResult;
        private boolean mRun = true;
        private boolean mDoingBenchmark;
        private TestBase mTest;
        private TextureView mDisplayView;

        private boolean mBenchmarkMode;

        // We don't want to call the "changed" methods excessively as this
        // can cause extra work for drivers.  Before running a test update
        // any bars which have changed.
        void runTest() {
            if (mBars[0] != mBarsOld[0]) {
                mTest.onBar1Changed(mBars[0]);
                mBarsOld[0] = mBars[0];
            }
            if (mBars[1] != mBarsOld[1]) {
                mTest.onBar2Changed(mBars[1]);
                mBarsOld[1] = mBars[1];
            }
            if (mBars[2] != mBarsOld[2]) {
                mTest.onBar3Changed(mBars[2]);
                mBarsOld[2] = mBars[2];
            }
            if (mBars[3] != mBarsOld[3]) {
                mTest.onBar4Changed(mBars[3]);
                mBarsOld[3] = mBars[3];
            }
            if (mBars[4] != mBarsOld[4]) {
                mTest.onBar5Changed(mBars[4]);
                mBarsOld[4] = mBars[4];
            }
            mTest.runTest();
        }

        Processor(RenderScript rs, TextureView v, boolean benchmarkMode) {
            mRS = rs;
            mDisplayView = v;

            mRS.setMessageHandler(new MessageProcessor());

            switch(mBitmapWidth) {
            case 3840:
                mInPixelsAllocation = Allocation.createFromBitmapResource(
                        mRS, getResources(), R.drawable.img3840x2160a);
                mInPixelsAllocation2 = Allocation.createFromBitmapResource(
                        mRS, getResources(), R.drawable.img3840x2160b);
                break;
            case 1920:
                mInPixelsAllocation = Allocation.createFromBitmapResource(
                        mRS, getResources(), R.drawable.img1920x1080a);
                mInPixelsAllocation2 = Allocation.createFromBitmapResource(
                        mRS, getResources(), R.drawable.img1920x1080b);
                break;
            case 1280:
                mInPixelsAllocation = Allocation.createFromBitmapResource(
                        mRS, getResources(), R.drawable.img1280x720a);
                mInPixelsAllocation2 = Allocation.createFromBitmapResource(
                        mRS, getResources(), R.drawable.img1280x720b);
                break;
            case 800:
                mInPixelsAllocation = Allocation.createFromBitmapResource(
                        mRS, getResources(), R.drawable.img800x450a);
                mInPixelsAllocation2 = Allocation.createFromBitmapResource(
                        mRS, getResources(), R.drawable.img800x450b);
                break;
            }

            // We create the output allocation using USAGE_IO_OUTPUT so we can share the
            // bits with a TextureView.  This is more efficient than using a bitmap.
            mOutDisplayAllocation = Allocation.createTyped(mRS, mInPixelsAllocation.getType(),
                                                               Allocation.MipmapControl.MIPMAP_NONE,
                                                               Allocation.USAGE_SCRIPT |
                                                               Allocation.USAGE_IO_OUTPUT);
            mOutPixelsAllocation = mOutDisplayAllocation;

            if (!mToggleIO) {
                // Not using USAGE_IO for the script so create a non-io kernel to copy from
                mOutPixelsAllocation = Allocation.createTyped(mRS, mInPixelsAllocation.getType(),
                                                              Allocation.MipmapControl.MIPMAP_NONE,
                                                              Allocation.USAGE_SCRIPT);
            }

            mBenchmarkMode = benchmarkMode;
            start();
        }

        class Result {
            float totalTime;
            int itterations;
        }

        // Run one loop of kernels for at least the specified minimum time.
        // The function returns the average time in ms for the test run
        private Result runBenchmarkLoop(float minTime) {
            mUpdatesPending = 0;
            Result r = new Result();

            long t = java.lang.System.currentTimeMillis();
            do {
                synchronized(this) {
                    // Shows pending is used to track the number of kernels in the RS pipeline
                    // We throttle it to 2.  This provide some buffering to allow a kernel to be started
                    // before we are nofitied the previous finished.  However, larger numbers are uncommon
                    // in interactive apps as they introduce 'lag' between user input and display.
                    mShowsPending++;
                    if (mShowsPending > 2) {
                        try {
                            this.wait();
                        } catch(InterruptedException e) {
                        }
                    }
                }

                // If animations are enabled update the test state.
                if (mToggleAnimate) {
                    mTest.animateBars(r.totalTime);
                }

                // Run the kernel
                mTest.runTest();
                r.itterations ++;

                if (mToggleDisplay) {
                    // If we are not outputting directly to the TextureView we need to copy from
                    // our temporary buffer.
                    if (mOutDisplayAllocation != mOutPixelsAllocation) {
                        mOutDisplayAllocation.copyFrom(mOutPixelsAllocation);
                    }

                    // queue the update of the TextureView with the allocation contents
                    mOutDisplayAllocation.ioSend();
                }

                // Send our RS message handler a message so we know when this work has completed
                mRS.sendMessage(0, null);

                long t2 = java.lang.System.currentTimeMillis();
                r.totalTime += (t2 - t) / 1000.f;
                t = t2;
            } while (r.totalTime < minTime);

            // Wait for any stray operations to complete and update the final time
            mRS.finish();
            long t2 = java.lang.System.currentTimeMillis();
            r.totalTime += (t2 - t) / 1000.f;
            t = t2;
            return r;
        }


        // Get a benchmark result for a specific test
        private float getBenchmark() {
            mDoingBenchmark = true;
            mUpdatesPending = 0;

            long result = 0;
            float runtime = 1.f;
            if (mToggleLong) {
                runtime = 10.f;
            }

            if (mToggleDVFS) {
                mDvfsWar.go();
            }

            // We run a short bit of work before starting the actual test
            // this is to let any power management do its job and respond
            runBenchmarkLoop(0.3f);

            // Run the actual benchmark
            Result r = runBenchmarkLoop(runtime);

            Log.v("rs", "Test: time=" + r.totalTime +"s,  frames=" + r.itterations +
                  ", avg=" + r.totalTime / r.itterations * 1000.f);

            mDoingBenchmark = false;
            return r.totalTime / r.itterations * 1000.f;
        }

        public void run() {
            Surface lastSurface = null;
            while (mRun) {
                // Our loop for launching tests or benchmarks
                synchronized(this) {
                    // If we have no work to do, or we have displays pending, wait
                    if ((mUpdatesPending == 0) || (mShowsPending != 0)) {
                        try {
                            this.wait();
                        } catch(InterruptedException e) {
                        }
                    }

                    // We may have been asked to exit while waiting
                    if (!mRun) return;

                    // During startup we may not have a surface yet to display, if
                    // this is the case, wait.
                    if ((mOutSurface == null) || (mOutPixelsAllocation == null)) {
                        continue;
                    }

                    // Our display surface changed, set it.
                    if (lastSurface != mOutSurface) {
                        mOutDisplayAllocation.setSurface(mOutSurface);
                        lastSurface = mOutSurface;
                    }
                }

                if (mBenchmarkMode) {
                    // Loop over the tests we want to benchmark
                    for (int ct=0; (ct < mTestList.length) && mRun; ct++) {

                        // For reproducibility we wait a short time for any sporadic work
                        // created by the user touching the screen to launch the test to pass.
                        // Also allows for things to settle after the test changes.
                        mRS.finish();
                        try {
                            sleep(250);
                        } catch(InterruptedException e) {
                        }

                        // If we just ran a test, we destroy it here to relieve some memory pressure
                        if (mTest != null) {
                            mTest.destroy();
                        }

                        // Select the next test
                        mTest = changeTest(mTestList[ct], false);

                        // If the user selected the "long pause" option, wait
                        if (mTogglePause) {
                            for (int i=0; (i < 100) && mRun; i++) {
                                try {
                                    sleep(100);
                                } catch(InterruptedException e) {
                                }
                            }
                        }

                        // Run the test
                        mTestResults[ct] = getBenchmark();
                    }
                    onBenchmarkFinish(mRun);
                } else {
                    boolean update = false;
                    synchronized(this) {
                        // If we have updates to process and are not blocked by pending shows,
                        // start the next kernel
                        if ((mUpdatesPending > 0) && (mShowsPending == 0)) {
                            mUpdatesPending = 0;
                            update = true;
                            mShowsPending++;
                        }
                    }

                    if (update) {
                        // Run the kernel
                        runTest();

                        // If we are not outputting directly to the TextureView we need to copy from
                        // our temporary buffer.
                        if (mOutDisplayAllocation != mOutPixelsAllocation) {
                            mOutDisplayAllocation.copyFrom(mOutPixelsAllocation);
                        }

                        // queue the update of the TextureView with the allocation contents
                        mOutDisplayAllocation.ioSend();

                        // Send our RS message handler a message so we know when this work has completed
                        mRS.sendMessage(0, null);
                    }
                }
            }

        }

        public void update() {
            // something UI related has changed, enqueue an update if one is not
            // already pending.  Wake the worker if needed
            synchronized(this) {
                if (mUpdatesPending < 2) {
                    mUpdatesPending++;
                    notifyAll();
                }
            }
        }

        public void setSurface(Surface s) {
            mOutSurface = s;
            update();
        }

        public void exit() {
            mRun = false;

            synchronized(this) {
                notifyAll();
            }

            try {
                this.join();
            } catch(InterruptedException e) {
            }

            mInPixelsAllocation.destroy();
            mInPixelsAllocation2.destroy();
            if (mOutPixelsAllocation != mOutDisplayAllocation) {
                mOutPixelsAllocation.destroy();
            }

            if (mTest != null) {
                mTest.destroy();
                mTest = null;
            }
            mOutDisplayAllocation.destroy();
            mRS.destroy();

            mInPixelsAllocation = null;
            mInPixelsAllocation2 = null;
            mOutPixelsAllocation = null;
            mOutDisplayAllocation = null;
            mRS = null;
        }
    }

    ///////////////////////////////////////////////////////////////////////////////////////

    static class DVFSWorkaround {
        static class spinner extends Thread {
            boolean mRun = true;
            long mNextSleep;

            spinner() {
                setPriority(MIN_PRIORITY);
                start();
            }

            public void run() {
                while (mRun) {
                    Thread.yield();
                    synchronized(this) {
                        long t = java.lang.System.currentTimeMillis();
                        if (t > mNextSleep) {
                            try {
                                this.wait();
                            } catch(InterruptedException e) {
                            }
                        }
                    }
                }
            }

            public void go(long t) {
                synchronized(this) {
                    mNextSleep = t;
                    notifyAll();
                }
            }
        }

        spinner s1;
        DVFSWorkaround() {
            s1 = new spinner();
        }

        void go() {
            long t = java.lang.System.currentTimeMillis() + 2000;
            s1.go(t);
        }

        void destroy() {
            synchronized(this) {
                s1.mRun = false;
                notifyAll();
            }
        }
    }
    DVFSWorkaround mDvfsWar = new DVFSWorkaround();

    ///////////////////////////////////////////////////////////


    private boolean mDoingBenchmark;
    public Processor mProcessor;

    TestBase changeTest(IPTestListJB.TestName t, boolean setupUI) {
        TestBase tb = IPTestListJB.newTest(t);

        tb.createBaseTest(this);
        if (setupUI) {
            setupBars(tb);
        }
        return tb;
    }

    TestBase changeTest(int id, boolean setupUI) {
        IPTestListJB.TestName t = IPTestListJB.TestName.values()[id];
        return changeTest(t, setupUI);
    }

    public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
        if (fromUser) {
            if (seekBar == mBar1) {
                mBars[0] = progress;
            } else if (seekBar == mBar2) {
                mBars[1] = progress;
            } else if (seekBar == mBar3) {
                mBars[2] = progress;
            } else if (seekBar == mBar4) {
                mBars[3] = progress;
            } else if (seekBar == mBar5) {
                mBars[4] = progress;
            }
            mProcessor.update();
        }
    }

    public void onStartTrackingTouch(SeekBar seekBar) {
    }

    public void onStopTrackingTouch(SeekBar seekBar) {
    }

    void setupBars(TestBase t) {
        mSpinner.setVisibility(View.VISIBLE);
        t.onSpinner1Setup(mSpinner);

        mBar1.setVisibility(View.VISIBLE);
        mText1.setVisibility(View.VISIBLE);
        t.onBar1Setup(mBar1, mText1);

        mBar2.setVisibility(View.VISIBLE);
        mText2.setVisibility(View.VISIBLE);
        t.onBar2Setup(mBar2, mText2);

        mBar3.setVisibility(View.VISIBLE);
        mText3.setVisibility(View.VISIBLE);
        t.onBar3Setup(mBar3, mText3);

        mBar4.setVisibility(View.VISIBLE);
        mText4.setVisibility(View.VISIBLE);
        t.onBar4Setup(mBar4, mText4);

        mBar5.setVisibility(View.VISIBLE);
        mText5.setVisibility(View.VISIBLE);
        t.onBar5Setup(mBar5, mText5);
    }

    void hideBars() {
        mSpinner.setVisibility(View.INVISIBLE);

        mBar1.setVisibility(View.INVISIBLE);
        mText1.setVisibility(View.INVISIBLE);

        mBar2.setVisibility(View.INVISIBLE);
        mText2.setVisibility(View.INVISIBLE);

        mBar3.setVisibility(View.INVISIBLE);
        mText3.setVisibility(View.INVISIBLE);

        mBar4.setVisibility(View.INVISIBLE);
        mText4.setVisibility(View.INVISIBLE);

        mBar5.setVisibility(View.INVISIBLE);
        mText5.setVisibility(View.INVISIBLE);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        mDisplayView = (SizedTV) findViewById(R.id.display);

        mSpinner = (Spinner) findViewById(R.id.spinner1);

        mBar1 = (SeekBar) findViewById(R.id.slider1);
        mBar2 = (SeekBar) findViewById(R.id.slider2);
        mBar3 = (SeekBar) findViewById(R.id.slider3);
        mBar4 = (SeekBar) findViewById(R.id.slider4);
        mBar5 = (SeekBar) findViewById(R.id.slider5);

        mBar1.setOnSeekBarChangeListener(this);
        mBar2.setOnSeekBarChangeListener(this);
        mBar3.setOnSeekBarChangeListener(this);
        mBar4.setOnSeekBarChangeListener(this);
        mBar5.setOnSeekBarChangeListener(this);

        mText1 = (TextView) findViewById(R.id.slider1Text);
        mText2 = (TextView) findViewById(R.id.slider2Text);
        mText3 = (TextView) findViewById(R.id.slider3Text);
        mText4 = (TextView) findViewById(R.id.slider4Text);
        mText5 = (TextView) findViewById(R.id.slider5Text);
    }

    @Override
    protected void onPause() {
        super.onPause();
        mProcessor.exit();
    }

    public void onBenchmarkFinish(boolean ok) {
        if (ok) {
            Intent intent = new Intent();
            intent.putExtra("tests", mTestList);
            intent.putExtra("results", mTestResults);
            setResult(RESULT_OK, intent);
        } else {
            setResult(RESULT_CANCELED);
        }
        finish();
    }


    void startProcessor() {
        if (!mDemoMode) {
            hideBars();
        }

        Point size = new Point();
        getWindowManager().getDefaultDisplay().getSize(size);

        int mScreenWidth = size.x;
        int mScreenHeight = size.y;

        int tw = mBitmapWidth;
        int th = mBitmapHeight;

        if (tw > mScreenWidth || th > mScreenHeight) {
            float s1 = (float)tw / (float)mScreenWidth;
            float s2 = (float)th / (float)mScreenHeight;

            if (s1 > s2) {
                tw /= s1;
                th /= s1;
            } else {
                tw /= s2;
                th /= s2;
            }
        }

        android.util.Log.v("rs", "TV sizes " + tw + ", " + th);

        mDisplayView.mWidth = tw;
        mDisplayView.mHeight = th;
        //mDisplayView.setTransform(new android.graphics.Matrix());

        mProcessor = new Processor(RenderScript.create(this), mDisplayView, !mDemoMode);
        mDisplayView.setSurfaceTextureListener(this);

        if (mDemoMode) {
            mProcessor.mTest = changeTest(mTestList[0], true);
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        Intent i = getIntent();
        mTestList = i.getIntArrayExtra("tests");

        mToggleIO = i.getBooleanExtra("enable io", false);
        mToggleDVFS = i.getBooleanExtra("enable dvfs", false);
        mToggleLong = i.getBooleanExtra("enable long", false);
        mTogglePause = i.getBooleanExtra("enable pause", false);
        mToggleAnimate = i.getBooleanExtra("enable animate", false);
        mToggleDisplay = i.getBooleanExtra("enable display", false);
        mBitmapWidth = i.getIntExtra("resolution X", 0);
        mBitmapHeight = i.getIntExtra("resolution Y", 0);
        mDemoMode = i.getBooleanExtra("demo", false);

        mTestResults = new float[mTestList.length];

        startProcessor();
    }

    protected void onDestroy() {
        super.onDestroy();
    }


    @Override
    public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
        mProcessor.setSurface(new Surface(surface));
    }

    @Override
    public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {
        mProcessor.setSurface(new Surface(surface));
    }

    @Override
    public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
        mProcessor.setSurface(null);
        return true;
    }

    @Override
    public void onSurfaceTextureUpdated(SurfaceTexture surface) {
    }
}