surface_texture_listener.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // Copyright (c) 2013 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef UI_GL_ANDROID_SURFACE_TEXTURE_LISTENER_H_
  5. #define UI_GL_ANDROID_SURFACE_TEXTURE_LISTENER_H_
  6. #include <jni.h>
  7. #include "base/android/scoped_java_ref.h"
  8. #include "base/callback.h"
  9. #include "base/memory/ref_counted.h"
  10. #include "base/task/sequenced_task_runner_helpers.h"
  11. #include "ui/gl/gl_export.h"
  12. namespace base {
  13. class SingleThreadTaskRunner;
  14. }
  15. namespace gl {
  16. // Listener class for all the callbacks from android SurfaceTexture.
  17. class GL_EXPORT SurfaceTextureListener {
  18. public:
  19. SurfaceTextureListener() = delete;
  20. SurfaceTextureListener(const SurfaceTextureListener&) = delete;
  21. SurfaceTextureListener& operator=(const SurfaceTextureListener&) = delete;
  22. // Destroy this listener.
  23. void Destroy(JNIEnv* env, const base::android::JavaParamRef<jobject>& obj);
  24. // A new frame is available to consume.
  25. void FrameAvailable(JNIEnv* env,
  26. const base::android::JavaParamRef<jobject>& obj);
  27. private:
  28. friend class base::DeleteHelper<SurfaceTextureListener>;
  29. // Native code should not hold any reference to this object, and instead pass
  30. // it up to Java for being referenced by a SurfaceTexture instance.
  31. // If use_any_thread is true, then the FrameAvailable callback will happen
  32. // on whatever thread calls us. Otherwise, we will call it back on the same
  33. // thread that was used to construct us.
  34. SurfaceTextureListener(base::RepeatingClosure callback, bool use_any_thread);
  35. ~SurfaceTextureListener();
  36. friend class SurfaceTexture;
  37. base::RepeatingClosure callback_;
  38. scoped_refptr<base::SingleThreadTaskRunner> browser_loop_;
  39. bool use_any_thread_;
  40. };
  41. } // namespace gl
  42. #endif // UI_GL_ANDROID_SURFACE_TEXTURE_LISTENER_H_