/rs/java/android/renderscript/RSSurfaceView.java

https://github.com/aizuzi/platform_frameworks_base · Java · 173 lines · 72 code · 16 blank · 85 comment · 8 complexity · 16773f6a861c0d0182ca3885703fc9c5 MD5 · raw file

  1. /*
  2. * Copyright (C) 2008-2012 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. package android.renderscript;
  17. import java.io.Writer;
  18. import java.util.ArrayList;
  19. import java.util.concurrent.Semaphore;
  20. import android.content.Context;
  21. import android.os.Handler;
  22. import android.os.Message;
  23. import android.util.AttributeSet;
  24. import android.util.Log;
  25. import android.view.Surface;
  26. import android.view.SurfaceHolder;
  27. import android.view.SurfaceView;
  28. /**
  29. * @hide
  30. * @deprecated in API 16
  31. * The Surface View for a graphics renderscript (RenderScriptGL) to draw on.
  32. *
  33. * <div class="special reference">
  34. * <h3>Developer Guides</h3>
  35. * <p>For more information about creating an application that uses RenderScript, read the
  36. * <a href="{@docRoot}guide/topics/renderscript/index.html">RenderScript</a> developer guide.</p>
  37. * </div>
  38. */
  39. public class RSSurfaceView extends SurfaceView implements SurfaceHolder.Callback {
  40. private SurfaceHolder mSurfaceHolder;
  41. private RenderScriptGL mRS;
  42. /**
  43. * @deprecated in API 16
  44. * Standard View constructor. In order to render something, you
  45. * must call {@link android.opengl.GLSurfaceView#setRenderer} to
  46. * register a renderer.
  47. */
  48. public RSSurfaceView(Context context) {
  49. super(context);
  50. init();
  51. //Log.v(RenderScript.LOG_TAG, "RSSurfaceView");
  52. }
  53. /**
  54. * @deprecated in API 16
  55. * Standard View constructor. In order to render something, you
  56. * must call {@link android.opengl.GLSurfaceView#setRenderer} to
  57. * register a renderer.
  58. */
  59. public RSSurfaceView(Context context, AttributeSet attrs) {
  60. super(context, attrs);
  61. init();
  62. //Log.v(RenderScript.LOG_TAG, "RSSurfaceView");
  63. }
  64. private void init() {
  65. // Install a SurfaceHolder.Callback so we get notified when the
  66. // underlying surface is created and destroyed
  67. SurfaceHolder holder = getHolder();
  68. holder.addCallback(this);
  69. }
  70. /**
  71. * @deprecated in API 16
  72. * This method is part of the SurfaceHolder.Callback interface, and is
  73. * not normally called or subclassed by clients of RSSurfaceView.
  74. */
  75. public void surfaceCreated(SurfaceHolder holder) {
  76. mSurfaceHolder = holder;
  77. }
  78. /**
  79. * @deprecated in API 16
  80. * This method is part of the SurfaceHolder.Callback interface, and is
  81. * not normally called or subclassed by clients of RSSurfaceView.
  82. */
  83. public void surfaceDestroyed(SurfaceHolder holder) {
  84. synchronized (this) {
  85. // Surface will be destroyed when we return
  86. if (mRS != null) {
  87. mRS.setSurface(null, 0, 0);
  88. }
  89. }
  90. }
  91. /**
  92. * @deprecated in API 16
  93. * This method is part of the SurfaceHolder.Callback interface, and is
  94. * not normally called or subclassed by clients of RSSurfaceView.
  95. */
  96. public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
  97. synchronized (this) {
  98. if (mRS != null) {
  99. mRS.setSurface(holder, w, h);
  100. }
  101. }
  102. }
  103. /**
  104. * @deprecated in API 16
  105. * Inform the view that the activity is paused. The owner of this view must
  106. * call this method when the activity is paused. Calling this method will
  107. * pause the rendering thread.
  108. * Must not be called before a renderer has been set.
  109. */
  110. public void pause() {
  111. if(mRS != null) {
  112. mRS.pause();
  113. }
  114. }
  115. /**
  116. * @deprecated in API 16
  117. * Inform the view that the activity is resumed. The owner of this view must
  118. * call this method when the activity is resumed. Calling this method will
  119. * recreate the OpenGL display and resume the rendering
  120. * thread.
  121. * Must not be called before a renderer has been set.
  122. */
  123. public void resume() {
  124. if(mRS != null) {
  125. mRS.resume();
  126. }
  127. }
  128. /**
  129. * @deprecated in API 16
  130. **/
  131. public RenderScriptGL createRenderScriptGL(RenderScriptGL.SurfaceConfig sc) {
  132. RenderScriptGL rs = new RenderScriptGL(this.getContext(), sc);
  133. setRenderScriptGL(rs);
  134. return rs;
  135. }
  136. /**
  137. * @deprecated in API 16
  138. **/
  139. public void destroyRenderScriptGL() {
  140. synchronized (this) {
  141. mRS.destroy();
  142. mRS = null;
  143. }
  144. }
  145. /**
  146. * @deprecated in API 16
  147. **/
  148. public void setRenderScriptGL(RenderScriptGL rs) {
  149. mRS = rs;
  150. }
  151. /**
  152. * @deprecated in API 16
  153. **/
  154. public RenderScriptGL getRenderScriptGL() {
  155. return mRS;
  156. }
  157. }