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

Commit

Permalink
Update SurfaceChanged callback target when a Surface is moved to a di…
Browse files Browse the repository at this point in the history
…fferent layer (#1540)
  • Loading branch information
MortimerGoro authored and bluemarvin committed Aug 8, 2019
1 parent d3500aa commit 84b9cbd
Showing 1 changed file with 39 additions and 4 deletions.
43 changes: 39 additions & 4 deletions app/src/oculusvr/cpp/DeviceDelegateOculusVR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,14 @@ struct OculusEyeSwapChain {
class OculusLayer;
typedef std::shared_ptr<OculusLayer> OculusLayerPtr;

struct SurfaceChangedTarget {
OculusLayer * layer;
SurfaceChangedTarget(OculusLayer * aLayer): layer(aLayer) {};
};

typedef std::shared_ptr<SurfaceChangedTarget> SurfaceChangedTargetPtr;
typedef std::weak_ptr<SurfaceChangedTarget> SurfaceChangedTargetWeakPtr;

class OculusLayer {
public:
virtual void Init(JNIEnv * aEnv, vrb::RenderContextPtr& aContext) = 0;
Expand All @@ -135,10 +143,13 @@ class OculusLayer {
virtual bool GetDrawInFront() const = 0;
virtual void ClearRequestDraw() = 0;
virtual bool IsComposited() const = 0;
virtual void SetComposited(bool aValue) = 0;
virtual VRLayerPtr GetLayer() const = 0;
virtual void Destroy() = 0;
typedef std::function<void(const vrb::FBOPtr&, GLenum aTarget, bool aBound)> BindDelegate;
virtual void SetBindDelegate(const BindDelegate& aDelegate) = 0;
virtual jobject GetSurface() const = 0;
virtual SurfaceChangedTargetPtr GetSurfaceChangedTarget() const = 0;
virtual ~OculusLayer() {}
};

Expand All @@ -147,13 +158,19 @@ class OculusLayerBase: public OculusLayer {
public:
ovrTextureSwapChain * swapChain = nullptr;
bool composited = false;
SurfaceChangedTargetPtr surfaceChangedTarget;
T layer;
U ovrLayer;

void Init(JNIEnv * aEnv, vrb::RenderContextPtr& aContext) override {
layer->SetInitialized(true);
surfaceChangedTarget = std::make_shared<SurfaceChangedTarget>(this);
SurfaceChangedTargetWeakPtr weakTarget = surfaceChangedTarget;
layer->NotifySurfaceChanged(VRLayer::SurfaceChange::Create, [=]() {
composited = true;
SurfaceChangedTargetPtr target = weakTarget.lock();
if (target) {
target->layer->SetComposited(true);
}
});
}

Expand Down Expand Up @@ -193,6 +210,10 @@ class OculusLayerBase: public OculusLayer {
return composited;
}

void SetComposited(bool aValue) override {
composited = aValue;
}

VRLayerPtr GetLayer() const override {
return layer;
}
Expand All @@ -217,6 +238,14 @@ class OculusLayerBase: public OculusLayer {

void SetBindDelegate(const BindDelegate& aDelegate) override {}

jobject GetSurface() const override {
return nullptr;
}

SurfaceChangedTargetPtr GetSurfaceChangedTarget() const override {
return surfaceChangedTarget;
}

virtual ~OculusLayerBase() {}
};

Expand Down Expand Up @@ -290,12 +319,18 @@ class OculusLayerSurface: public OculusLayerBase<T, U> {
});
}

virtual jobject GetSurface() const override {
return surface;
}

protected:
void TakeSurface(const OculusLayerPtr& aSource) {
this->swapChain = aSource->GetSwapChain();
VRLayerSurfacePtr sourceLayer = std::dynamic_pointer_cast<VRLayerSurface>(aSource->GetLayer());
if (sourceLayer) {
this->surface = sourceLayer->GetSurface();
this->surface = aSource->GetSurface();
this->surfaceChangedTarget = aSource->GetSurfaceChangedTarget();
if (this->surfaceChangedTarget) {
// Indicate that the first composite notification should be notified to this layer.
this->surfaceChangedTarget->layer = this;
}
this->composited = aSource->IsComposited();
this->layer->SetInitialized(aSource->GetLayer()->IsInitialized());
Expand Down

0 comments on commit 84b9cbd

Please sign in to comment.