Project

General

Profile

« Previous | Next » 

Revision bc0a685b

Added by Leszek Koltunski almost 8 years ago

Add License

View differences:

src/main/java/org/distorted/examples/plainmonalisa/RenderHandler.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.os.Handler;
......
7 26
import java.lang.ref.WeakReference;
8 27

  
9 28
///////////////////////////////////////////////////////////////////////////////////////////////////
29
// Used for messages sent from the UI thread to the render thread.
10 30

  
11
/**
12
 * Handler for RenderThread.  Used for messages sent from the UI thread to the render thread.
13
 * <p>
14
 * The object is created on the render thread, and the various "send" methods are called
15
 * from the UI thread.
16
 */
17 31
public class RenderHandler extends Handler
18 32
  {
19 33
  private static final String TAG = "RenderHandler";
......
23 37
  private static final int MSG_DO_FRAME = 2;
24 38
  private static final int MSG_SHUTDOWN = 4;
25 39

  
26
  // This shouldn't need to be a weak ref, since we'll go away when the Looper quits,
27
  // but no real harm in it.
28 40
  private WeakReference<RenderThread> mWeakRenderThread;
29 41

  
30 42
///////////////////////////////////////////////////////////////////////////////////////////////////
31
  /**
32
   * Call from render thread.
33
   */
43

  
34 44
  public RenderHandler(RenderThread rt)
35
      {
36
      mWeakRenderThread = new WeakReference<>(rt);
37
      }
45
    {
46
    mWeakRenderThread = new WeakReference<>(rt);
47
    }
38 48

  
39 49
///////////////////////////////////////////////////////////////////////////////////////////////////
40
  /**
41
   * Sends the "surface created" message.
42
   * <p>
43
   * Call from UI thread.
44
   */
50

  
45 51
  public void sendSurfaceCreated()
46 52
    {
47 53
    sendMessage(obtainMessage(RenderHandler.MSG_SURFACE_CREATED));
48 54
    }
49 55

  
50 56
///////////////////////////////////////////////////////////////////////////////////////////////////
51
  /**
52
   * Sends the "surface changed" message, forwarding what we got from the SurfaceHolder.
53
   * <p>
54
   * Call from UI thread.
55
   */
56
  public void sendSurfaceChanged(@SuppressWarnings("unused") int format, int width, int height)
57

  
58
  public void sendSurfaceChanged(int format, int width, int height)
57 59
    {
58 60
    sendMessage(obtainMessage(RenderHandler.MSG_SURFACE_CHANGED, width, height));
59 61
    }
60 62

  
61 63
///////////////////////////////////////////////////////////////////////////////////////////////////
62
  /**
63
   * Sends the "do frame" message, forwarding the Choreographer event.
64
   * <p>
65
   * Call from UI thread.
66
   */
64

  
67 65
  public void sendDoFrame(long frameTimeNanos)
68 66
    {
69 67
    sendMessage(obtainMessage(RenderHandler.MSG_DO_FRAME, (int) (frameTimeNanos >> 32), (int) frameTimeNanos));
70 68
    }
71 69

  
72 70
///////////////////////////////////////////////////////////////////////////////////////////////////
73
  /**
74
   * Sends the "shutdown" message, which tells the render thread to halt.
75
   * <p>
76
   * Call from UI thread.
77
   */
71

  
78 72
  public void sendShutdown()
79
      {
80
      sendMessage(obtainMessage(RenderHandler.MSG_SHUTDOWN));
81
      }
73
    {
74
    sendMessage(obtainMessage(RenderHandler.MSG_SHUTDOWN));
75
    }
82 76

  
83 77
///////////////////////////////////////////////////////////////////////////////////////////////////
84 78
  @Override  // runs on RenderThread
85 79
  public void handleMessage(Message msg)
86 80
    {
87 81
    int what = msg.what;
88
    //Log.d(TAG, "RenderHandler [" + this + "]: what=" + what);
82

  
89 83
    RenderThread renderThread = mWeakRenderThread.get();
90 84

  
91 85
    if (renderThread == null)

Also available in: Unified diff