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

Commit 84b9cbd

Browse files
MortimerGorobluemarvin
authored andcommitted
Update SurfaceChanged callback target when a Surface is moved to a different layer (#1540)
1 parent d3500aa commit 84b9cbd

1 file changed

Lines changed: 39 additions & 4 deletions

File tree

app/src/oculusvr/cpp/DeviceDelegateOculusVR.cpp

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,14 @@ struct OculusEyeSwapChain {
124124
class OculusLayer;
125125
typedef std::shared_ptr<OculusLayer> OculusLayerPtr;
126126

127+
struct SurfaceChangedTarget {
128+
OculusLayer * layer;
129+
SurfaceChangedTarget(OculusLayer * aLayer): layer(aLayer) {};
130+
};
131+
132+
typedef std::shared_ptr<SurfaceChangedTarget> SurfaceChangedTargetPtr;
133+
typedef std::weak_ptr<SurfaceChangedTarget> SurfaceChangedTargetWeakPtr;
134+
127135
class OculusLayer {
128136
public:
129137
virtual void Init(JNIEnv * aEnv, vrb::RenderContextPtr& aContext) = 0;
@@ -135,10 +143,13 @@ class OculusLayer {
135143
virtual bool GetDrawInFront() const = 0;
136144
virtual void ClearRequestDraw() = 0;
137145
virtual bool IsComposited() const = 0;
146+
virtual void SetComposited(bool aValue) = 0;
138147
virtual VRLayerPtr GetLayer() const = 0;
139148
virtual void Destroy() = 0;
140149
typedef std::function<void(const vrb::FBOPtr&, GLenum aTarget, bool aBound)> BindDelegate;
141150
virtual void SetBindDelegate(const BindDelegate& aDelegate) = 0;
151+
virtual jobject GetSurface() const = 0;
152+
virtual SurfaceChangedTargetPtr GetSurfaceChangedTarget() const = 0;
142153
virtual ~OculusLayer() {}
143154
};
144155

@@ -147,13 +158,19 @@ class OculusLayerBase: public OculusLayer {
147158
public:
148159
ovrTextureSwapChain * swapChain = nullptr;
149160
bool composited = false;
161+
SurfaceChangedTargetPtr surfaceChangedTarget;
150162
T layer;
151163
U ovrLayer;
152164

153165
void Init(JNIEnv * aEnv, vrb::RenderContextPtr& aContext) override {
154166
layer->SetInitialized(true);
167+
surfaceChangedTarget = std::make_shared<SurfaceChangedTarget>(this);
168+
SurfaceChangedTargetWeakPtr weakTarget = surfaceChangedTarget;
155169
layer->NotifySurfaceChanged(VRLayer::SurfaceChange::Create, [=]() {
156-
composited = true;
170+
SurfaceChangedTargetPtr target = weakTarget.lock();
171+
if (target) {
172+
target->layer->SetComposited(true);
173+
}
157174
});
158175
}
159176

@@ -193,6 +210,10 @@ class OculusLayerBase: public OculusLayer {
193210
return composited;
194211
}
195212

213+
void SetComposited(bool aValue) override {
214+
composited = aValue;
215+
}
216+
196217
VRLayerPtr GetLayer() const override {
197218
return layer;
198219
}
@@ -217,6 +238,14 @@ class OculusLayerBase: public OculusLayer {
217238

218239
void SetBindDelegate(const BindDelegate& aDelegate) override {}
219240

241+
jobject GetSurface() const override {
242+
return nullptr;
243+
}
244+
245+
SurfaceChangedTargetPtr GetSurfaceChangedTarget() const override {
246+
return surfaceChangedTarget;
247+
}
248+
220249
virtual ~OculusLayerBase() {}
221250
};
222251

@@ -290,12 +319,18 @@ class OculusLayerSurface: public OculusLayerBase<T, U> {
290319
});
291320
}
292321

322+
virtual jobject GetSurface() const override {
323+
return surface;
324+
}
325+
293326
protected:
294327
void TakeSurface(const OculusLayerPtr& aSource) {
295328
this->swapChain = aSource->GetSwapChain();
296-
VRLayerSurfacePtr sourceLayer = std::dynamic_pointer_cast<VRLayerSurface>(aSource->GetLayer());
297-
if (sourceLayer) {
298-
this->surface = sourceLayer->GetSurface();
329+
this->surface = aSource->GetSurface();
330+
this->surfaceChangedTarget = aSource->GetSurfaceChangedTarget();
331+
if (this->surfaceChangedTarget) {
332+
// Indicate that the first composite notification should be notified to this layer.
333+
this->surfaceChangedTarget->layer = this;
299334
}
300335
this->composited = aSource->IsComposited();
301336
this->layer->SetInitialized(aSource->GetLayer()->IsInitialized());

0 commit comments

Comments
 (0)