Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Commit

Permalink
Correctly handle surface resize after the surface is taken by another…
Browse files Browse the repository at this point in the history
… layer (#1639)
  • Loading branch information
MortimerGoro authored Aug 26, 2019
1 parent 05fb61d commit ac81e6a
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions app/src/oculusvr/cpp/DeviceDelegateOculusVR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ class OculusLayer {
virtual void SetBindDelegate(const BindDelegate& aDelegate) = 0;
virtual jobject GetSurface() const = 0;
virtual SurfaceChangedTargetPtr GetSurfaceChangedTarget() const = 0;
virtual void HandleResize(ovrTextureSwapChain * newSwapChain, jobject newSurface, vrb::FBOPtr newFBO) = 0;
virtual ~OculusLayer() {}
};

Expand Down Expand Up @@ -246,6 +247,8 @@ class OculusLayerBase: public OculusLayer {
return surfaceChangedTarget;
}

void HandleResize(ovrTextureSwapChain * newSwapChain, jobject newSurface, vrb::FBOPtr newFBO) override {}

virtual ~OculusLayerBase() {}
};

Expand Down Expand Up @@ -286,20 +289,29 @@ class OculusLayerSurface: public OculusLayerBase<T, U> {
vrb::FBOPtr newFBO;
InitSwapChain(newSwapChain, newSurface, newFBO);
this->layer->SetSurface(newSurface);

SurfaceChangedTargetWeakPtr weakTarget = this->surfaceChangedTarget;
this->layer->NotifySurfaceChanged(VRLayer::SurfaceChange::Create, [=]() {
if (this->swapChain) {
vrapi_DestroyTextureSwapChain(this->swapChain);
}
if (this->surface) {
jniEnv->DeleteGlobalRef(this->surface);
SurfaceChangedTargetPtr target = weakTarget.lock();
if (target && target->layer) {
target->layer->HandleResize(newSwapChain, newSurface, newFBO);
}
this->swapChain = newSwapChain;
this->surface = newSurface;
this->fbo = newFBO;
this->composited = true;
});
}

void HandleResize(ovrTextureSwapChain * newSwapChain, jobject newSurface, vrb::FBOPtr newFBO) override {
if (this->swapChain) {
vrapi_DestroyTextureSwapChain(this->swapChain);
}
if (this->surface) {
jniEnv->DeleteGlobalRef(this->surface);
}
this->swapChain = newSwapChain;
this->surface = newSurface;
this->fbo = newFBO;
this->composited = true;
}

void Destroy() override {
this->fbo = nullptr;
if (this->surface) {
Expand Down

0 comments on commit ac81e6a

Please sign in to comment.