Bug 1297836 - Get surface when creating or resuming compositor; r=snorp

Get rid of LayerView.Compositor.getSurface and just pass in the surface
when creating or resuming the compositor. That also lets us get rid of
some synchronization required for getSurface.
This commit is contained in:
Jim Chen 2016-08-26 12:25:57 -04:00
parent 4c8cec0df5
commit d924b1c615
4 changed files with 23 additions and 57 deletions

View File

@ -93,7 +93,7 @@ public class LayerView extends ScrollView implements Tabs.OnTabsChangedListener
// Gecko thread creates compositor; blocks UI thread.
@WrapForJNI(calledFrom = "ui", dispatchTo = "proxy")
/* package */ native void createCompositor(int width, int height);
/* package */ native void createCompositor(int width, int height, Object surface);
// Gecko thread pauses compositor; blocks UI thread.
@WrapForJNI(calledFrom = "ui", dispatchTo = "current")
@ -101,21 +101,11 @@ public class LayerView extends ScrollView implements Tabs.OnTabsChangedListener
// UI thread resumes compositor and notifies Gecko thread; does not block UI thread.
@WrapForJNI(calledFrom = "ui", dispatchTo = "current")
/* package */ native void syncResumeResizeCompositor(int width, int height);
/* package */ native void syncResumeResizeCompositor(int width, int height, Object surface);
@WrapForJNI(calledFrom = "any", dispatchTo = "current")
/* package */ native void syncInvalidateAndScheduleComposite();
@WrapForJNI
private Object getSurface() {
synchronized (LayerView.this) {
if (LayerView.this.mServerSurfaceValid) {
return LayerView.this.getSurface();
}
}
return null;
}
@WrapForJNI(calledFrom = "gecko")
private void reattach() {
mCompositorCreated = true;
@ -459,11 +449,9 @@ public class LayerView extends ScrollView implements Tabs.OnTabsChangedListener
void serverSurfaceChanged(int newWidth, int newHeight) {
ThreadUtils.assertOnUiThread();
synchronized (this) {
mWidth = newWidth;
mHeight = newHeight;
mServerSurfaceValid = true;
}
mWidth = newWidth;
mHeight = newHeight;
mServerSurfaceValid = true;
updateCompositor();
}
@ -484,7 +472,7 @@ public class LayerView extends ScrollView implements Tabs.OnTabsChangedListener
// the compositor resuming, so that Gecko knows that it can now draw.
// It is important to not notify Gecko until after the compositor has
// been resumed, otherwise Gecko may send updates that get dropped.
mCompositor.syncResumeResizeCompositor(mWidth, mHeight);
mCompositor.syncResumeResizeCompositor(mWidth, mHeight, getSurface());
return;
}
@ -493,7 +481,7 @@ public class LayerView extends ScrollView implements Tabs.OnTabsChangedListener
// happen without needing to block anywhere.
if (mServerSurfaceValid && getLayerClient().isGeckoReady()) {
mCompositorCreated = true;
mCompositor.createCompositor(mWidth, mHeight);
mCompositor.createCompositor(mWidth, mHeight, getSurface());
}
}
@ -522,7 +510,7 @@ public class LayerView extends ScrollView implements Tabs.OnTabsChangedListener
}
if (mCompositorCreated) {
mCompositor.syncResumeResizeCompositor(width, height);
mCompositor.syncResumeResizeCompositor(width, height, getSurface());
}
if (mOverscroll != null) {
@ -561,9 +549,7 @@ public class LayerView extends ScrollView implements Tabs.OnTabsChangedListener
mCompositor.syncPauseCompositor();
}
synchronized (this) {
mServerSurfaceValid = false;
}
mServerSurfaceValid = false;
}
private void onDestroyed() {

View File

@ -1441,14 +1441,6 @@ auto LayerView::Compositor::Destroy() const -> void
constexpr char LayerView::Compositor::DisposeNative_t::name[];
constexpr char LayerView::Compositor::DisposeNative_t::signature[];
constexpr char LayerView::Compositor::GetSurface_t::name[];
constexpr char LayerView::Compositor::GetSurface_t::signature[];
auto LayerView::Compositor::GetSurface() const -> mozilla::jni::Object::LocalRef
{
return mozilla::jni::Method<GetSurface_t>::Call(Compositor::mCtx, nullptr);
}
constexpr char LayerView::Compositor::OnSizeChanged_t::name[];
constexpr char LayerView::Compositor::OnSizeChanged_t::signature[];

View File

@ -4633,10 +4633,11 @@ public:
typedef void SetterType;
typedef mozilla::jni::Args<
int32_t,
int32_t> Args;
int32_t,
mozilla::jni::Object::Param> Args;
static constexpr char name[] = "createCompositor";
static constexpr char signature[] =
"(II)V";
"(IILjava/lang/Object;)V";
static const bool isStatic = false;
static const mozilla::jni::ExceptionMode exceptionMode =
mozilla::jni::ExceptionMode::ABORT;
@ -4682,25 +4683,6 @@ public:
mozilla::jni::DispatchTarget::GECKO;
};
struct GetSurface_t {
typedef Compositor Owner;
typedef mozilla::jni::Object::LocalRef ReturnType;
typedef mozilla::jni::Object::Param SetterType;
typedef mozilla::jni::Args<> Args;
static constexpr char name[] = "getSurface";
static constexpr char signature[] =
"()Ljava/lang/Object;";
static const bool isStatic = false;
static const mozilla::jni::ExceptionMode exceptionMode =
mozilla::jni::ExceptionMode::ABORT;
static const mozilla::jni::CallingThread callingThread =
mozilla::jni::CallingThread::ANY;
static const mozilla::jni::DispatchTarget dispatchTarget =
mozilla::jni::DispatchTarget::CURRENT;
};
auto GetSurface() const -> mozilla::jni::Object::LocalRef;
struct OnSizeChanged_t {
typedef Compositor Owner;
typedef void ReturnType;
@ -4781,10 +4763,11 @@ public:
typedef void SetterType;
typedef mozilla::jni::Args<
int32_t,
int32_t> Args;
int32_t,
mozilla::jni::Object::Param> Args;
static constexpr char name[] = "syncResumeResizeCompositor";
static constexpr char signature[] =
"(II)V";
"(IILjava/lang/Object;)V";
static const bool isStatic = false;
static const mozilla::jni::ExceptionMode exceptionMode =
mozilla::jni::ExceptionMode::ABORT;

View File

@ -1029,7 +1029,6 @@ public:
jni::Object::Param GetSurface()
{
mSurface = mCompositor->GetSurface();
return mSurface;
}
@ -1105,12 +1104,15 @@ public:
}
}
void CreateCompositor(int32_t aWidth, int32_t aHeight)
void CreateCompositor(int32_t aWidth, int32_t aHeight,
jni::Object::Param aSurface)
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(mWindow);
mSurface = aSurface;
mWindow->CreateLayerManager(aWidth, aHeight);
mCompositorPaused = false;
OnResumedCompositor();
}
@ -1147,7 +1149,8 @@ public:
}
void SyncResumeResizeCompositor(const LayerView::Compositor::LocalRef& aObj,
int32_t aWidth, int32_t aHeight)
int32_t aWidth, int32_t aHeight,
jni::Object::Param aSurface)
{
MOZ_ASSERT(AndroidBridge::IsJavaUiThread());
@ -1157,6 +1160,8 @@ public:
bridge = window->GetCompositorBridgeParent();
}
mSurface = aSurface;
if (!bridge || !bridge->ScheduleResumeOnCompositorThread(aWidth,
aHeight)) {
return;