Revision bc0a685b
Added by Leszek Koltunski almost 8 years ago
src/main/java/org/distorted/examples/plainmonalisa/RenderThread.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2016 Leszek Koltunski // |
|
3 |
// // |
|
4 |
// This file is part of Distorted. // |
|
5 |
// // |
|
6 |
// Distorted is free software: you can redistribute it and/or modify // |
|
7 |
// it under the terms of the GNU General Public License as published by // |
|
8 |
// the Free Software Foundation, either version 2 of the License, or // |
|
9 |
// (at your option) any later version. // |
|
10 |
// // |
|
11 |
// Distorted is distributed in the hope that it will be useful, // |
|
12 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of // |
|
13 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
|
14 |
// GNU General Public License for more details. // |
|
15 |
// // |
|
16 |
// You should have received a copy of the GNU General Public License // |
|
17 |
// along with Distorted. If not, see <http://www.gnu.org/licenses/>. // |
|
18 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
19 |
|
|
1 | 20 |
package org.distorted.examples.plainmonalisa; |
2 | 21 |
|
3 | 22 |
import android.graphics.Bitmap; |
... | ... | |
24 | 43 |
import java.io.InputStream; |
25 | 44 |
|
26 | 45 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
27 |
/** |
|
28 |
* This class handles all OpenGL rendering. |
|
29 |
* <p> |
|
30 |
* Start the render thread after the Surface has been created. |
|
31 |
*/ |
|
46 |
|
|
32 | 47 |
public class RenderThread extends Thread |
33 | 48 |
{ |
34 | 49 |
private static final String TAG = "RenderThread"; |
... | ... | |
55 | 70 |
SurfaceView mView; |
56 | 71 |
|
57 | 72 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
58 |
/** |
|
59 |
* Pass in the SurfaceView's SurfaceHolder. Note the Surface may not yet exist. |
|
60 |
*/ |
|
73 |
|
|
61 | 74 |
public RenderThread(SurfaceHolder holder, SurfaceView view) |
62 | 75 |
{ |
63 | 76 |
mSurfaceHolder = holder; |
... | ... | |
74 | 87 |
} |
75 | 88 |
|
76 | 89 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
77 |
/** |
|
78 |
* Thread entry point. |
|
79 |
* <p> |
|
80 |
* The thread should not be started until the Surface associated with the SurfaceHolder |
|
81 |
* has been created. That way we don't have to wait for a separate "surface created" |
|
82 |
* message to arrive. |
|
83 |
*/ |
|
90 |
|
|
84 | 91 |
@Override |
85 | 92 |
public void run() |
86 | 93 |
{ |
... | ... | |
117 | 124 |
} |
118 | 125 |
|
119 | 126 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
120 |
/** |
|
121 |
* Waits until the render thread is ready to receive messages. |
|
122 |
* <p> |
|
123 |
* Call from the UI thread. |
|
124 |
*/ |
|
127 |
|
|
125 | 128 |
public void waitUntilReady() |
126 | 129 |
{ |
127 | 130 |
synchronized (mStartLock) |
... | ... | |
132 | 135 |
{ |
133 | 136 |
mStartLock.wait(); |
134 | 137 |
} |
135 |
catch (InterruptedException ie) { /* not expected */ }
|
|
138 |
catch (InterruptedException ie) { } |
|
136 | 139 |
} |
137 | 140 |
} |
138 | 141 |
} |
139 | 142 |
|
140 | 143 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
141 |
/** |
|
142 |
* Shuts everything down. |
|
143 |
*/ |
|
144 |
|
|
144 | 145 |
void shutdown() |
145 | 146 |
{ |
146 | 147 |
Log.d(TAG, "shutdown"); |
... | ... | |
148 | 149 |
} |
149 | 150 |
|
150 | 151 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
151 |
/** |
|
152 |
* Returns the render thread's Handler. This may be called from any thread. |
|
153 |
*/ |
|
152 |
|
|
154 | 153 |
public RenderHandler getHandler() |
155 |
{
|
|
156 |
return mHandler;
|
|
157 |
}
|
|
154 |
{ |
|
155 |
return mHandler; |
|
156 |
} |
|
158 | 157 |
|
159 | 158 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
160 |
/** |
|
161 |
* Prepares the surface. |
|
162 |
*/ |
|
159 |
|
|
163 | 160 |
void surfaceCreated() |
164 | 161 |
{ |
165 | 162 |
Surface surface = mSurfaceHolder.getSurface(); |
... | ... | |
253 | 250 |
} |
254 | 251 |
} |
255 | 252 |
} |
256 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
Also available in: Unified diff
Add License