2014-10-18 03:34:01 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
// vim:set ts=2 sts=2 sw=2 et cin:
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2014-10-21 17:53:00 +04:00
|
|
|
#ifndef AndroidSurfaceTexture_h__
|
|
|
|
#define AndroidSurfaceTexture_h__
|
2014-10-18 03:34:01 +04:00
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
|
|
|
|
|
|
|
#include <jni.h>
|
|
|
|
#include "nsIRunnable.h"
|
|
|
|
#include "gfxPlatform.h"
|
|
|
|
#include "GLDefs.h"
|
2014-10-21 17:53:01 +04:00
|
|
|
#include "mozilla/gfx/2D.h"
|
2015-12-03 02:52:00 +03:00
|
|
|
#include "mozilla/gfx/MatrixFwd.h"
|
2014-10-21 17:53:01 +04:00
|
|
|
#include "mozilla/Monitor.h"
|
2014-10-18 03:34:01 +04:00
|
|
|
|
2014-11-13 21:47:24 +03:00
|
|
|
#include "SurfaceTexture.h"
|
2014-10-21 17:53:00 +04:00
|
|
|
#include "AndroidNativeWindow.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace gl {
|
|
|
|
|
2014-10-21 17:53:01 +04:00
|
|
|
class GLContext;
|
|
|
|
|
2014-10-18 03:34:01 +04:00
|
|
|
/**
|
|
|
|
* This class is a wrapper around Android's SurfaceTexture class.
|
|
|
|
* Usage is pretty much exactly like the Java class, so see
|
|
|
|
* the Android documentation for details.
|
|
|
|
*/
|
2014-10-21 17:53:00 +04:00
|
|
|
class AndroidSurfaceTexture {
|
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(AndroidSurfaceTexture)
|
2014-10-18 03:34:01 +04:00
|
|
|
|
|
|
|
public:
|
2014-10-21 17:53:01 +04:00
|
|
|
|
|
|
|
// The SurfaceTexture is created in an attached state. This method requires
|
|
|
|
// Android Ice Cream Sandwich.
|
2015-06-17 17:00:52 +03:00
|
|
|
static already_AddRefed<AndroidSurfaceTexture> Create(GLContext* aGLContext, GLuint aTexture);
|
2014-10-21 17:53:01 +04:00
|
|
|
|
|
|
|
// Here the SurfaceTexture will be created in a detached state. You must call
|
|
|
|
// Attach() with the GLContext you wish to composite with. It must be done
|
|
|
|
// on the thread where that GLContext is current. This method requires
|
|
|
|
// Android Jelly Bean.
|
2015-06-17 17:00:52 +03:00
|
|
|
static already_AddRefed<AndroidSurfaceTexture> Create();
|
2014-10-21 17:53:01 +04:00
|
|
|
|
2016-02-19 01:55:15 +03:00
|
|
|
static AndroidSurfaceTexture* Find(int aId);
|
2014-10-18 03:34:01 +04:00
|
|
|
|
2014-10-21 17:53:01 +04:00
|
|
|
// If we are on Jelly Bean, the SurfaceTexture can be detached and reattached
|
|
|
|
// to allow consumption from different GLContexts. It is recommended to only
|
|
|
|
// attach while you are consuming in order to allow this.
|
|
|
|
//
|
|
|
|
// Only one GLContext may be attached at any given time. If another is already
|
|
|
|
// attached, we try to wait for it to become detached.
|
2014-11-13 21:47:24 +03:00
|
|
|
nsresult Attach(GLContext* aContext, PRIntervalTime aTiemout = PR_INTERVAL_NO_TIMEOUT);
|
2014-10-21 17:53:01 +04:00
|
|
|
|
2014-11-13 21:47:24 +03:00
|
|
|
nsresult Detach();
|
2014-10-21 17:53:01 +04:00
|
|
|
|
2016-03-02 19:29:10 +03:00
|
|
|
// Ability to detach is based on API version (16+), and we also block PowerVR
|
|
|
|
// since it has some type of fencing problem. Bug 1100126.
|
|
|
|
bool CanDetach() const;
|
2015-02-03 00:25:22 +03:00
|
|
|
|
2016-02-19 01:56:31 +03:00
|
|
|
GLContext* AttachedContext() const { return mAttachedContext; }
|
2014-10-21 17:53:01 +04:00
|
|
|
|
2016-02-19 01:56:31 +03:00
|
|
|
AndroidNativeWindow* NativeWindow() const {
|
2014-10-21 17:53:00 +04:00
|
|
|
return mNativeWindow;
|
|
|
|
}
|
|
|
|
|
2014-10-18 03:34:01 +04:00
|
|
|
// This attaches the updated data to the TEXTURE_EXTERNAL target
|
|
|
|
void UpdateTexImage();
|
|
|
|
|
2016-02-19 01:56:31 +03:00
|
|
|
void GetTransformMatrix(mozilla::gfx::Matrix4x4& aMatrix) const;
|
|
|
|
int ID() const { return mID; }
|
2014-10-18 03:34:01 +04:00
|
|
|
|
2014-10-21 17:53:00 +04:00
|
|
|
void SetDefaultSize(mozilla::gfx::IntSize size);
|
|
|
|
|
2014-10-18 03:34:01 +04:00
|
|
|
// The callback is guaranteed to be called on the main thread even
|
|
|
|
// if the upstream callback is received on a different thread
|
|
|
|
void SetFrameAvailableCallback(nsIRunnable* aRunnable);
|
|
|
|
|
|
|
|
// Only should be called by AndroidJNI when we get a
|
|
|
|
// callback from the underlying SurfaceTexture instance
|
|
|
|
void NotifyFrameAvailable();
|
|
|
|
|
2016-02-19 01:56:31 +03:00
|
|
|
GLuint Texture() const { return mTexture; }
|
|
|
|
const widget::sdk::Surface::Ref& JavaSurface() const { return mSurface; }
|
2015-01-10 03:33:57 +03:00
|
|
|
|
2014-10-21 17:53:00 +04:00
|
|
|
private:
|
|
|
|
AndroidSurfaceTexture();
|
2014-10-21 17:53:00 +04:00
|
|
|
~AndroidSurfaceTexture();
|
2014-10-18 03:34:01 +04:00
|
|
|
|
2014-10-21 17:53:01 +04:00
|
|
|
bool Init(GLContext* aContext, GLuint aTexture);
|
2014-10-18 03:34:01 +04:00
|
|
|
|
2014-10-21 17:53:00 +04:00
|
|
|
GLuint mTexture;
|
2015-01-10 03:33:57 +03:00
|
|
|
widget::sdk::SurfaceTexture::GlobalRef mSurfaceTexture;
|
|
|
|
widget::sdk::Surface::GlobalRef mSurface;
|
2014-10-21 17:53:00 +04:00
|
|
|
|
2014-10-21 17:53:01 +04:00
|
|
|
GLContext* mAttachedContext;
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<AndroidNativeWindow> mNativeWindow;
|
2014-10-18 03:34:01 +04:00
|
|
|
int mID;
|
2015-03-17 19:29:17 +03:00
|
|
|
nsCOMPtr<nsIRunnable> mFrameAvailableCallback;
|
2016-02-19 01:56:31 +03:00
|
|
|
|
|
|
|
mutable Monitor mMonitor;
|
2014-10-18 03:34:01 +04:00
|
|
|
};
|
2014-10-21 17:53:01 +04:00
|
|
|
|
2014-10-21 17:53:00 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-18 03:34:01 +04:00
|
|
|
|
|
|
|
#endif
|
|
|
|
#endif
|