From 94c1a83c68ebe6860c990b5877c91dbb3b51acb9 Mon Sep 17 00:00:00 2001 From: Sotaro Ikeda Date: Fri, 24 Jul 2015 10:56:05 -0700 Subject: [PATCH] Bug 1187048 - Code clean up around nsScreenGonk's EGLSurface handling r=mwu --- gfx/layers/opengl/CompositorOGL.cpp | 5 +++++ widget/gonk/HwcComposer2D.cpp | 8 ++++---- widget/gonk/hwchal/HwcHALBase.h | 4 ++-- widget/gonk/hwchal/HwcICS.cpp | 14 +++++++------- widget/gonk/hwchal/HwcICS.h | 8 ++++---- widget/gonk/nsScreenManagerGonk.cpp | 21 +++++++++++++-------- widget/gonk/nsScreenManagerGonk.h | 12 +++++++----- widget/gonk/nsWindow.cpp | 7 ++++++- 8 files changed, 48 insertions(+), 31 deletions(-) diff --git a/gfx/layers/opengl/CompositorOGL.cpp b/gfx/layers/opengl/CompositorOGL.cpp index c1447cfebde4..9c9ab080f9bd 100644 --- a/gfx/layers/opengl/CompositorOGL.cpp +++ b/gfx/layers/opengl/CompositorOGL.cpp @@ -167,6 +167,11 @@ CompositorOGL::CleanupResources() if (!mGLContext) return; +#ifdef MOZ_WIDGET_GONK + mWidget->SetNativeData(NS_NATIVE_OPENGL_CONTEXT, + reinterpret_cast(nullptr)); +#endif + nsRefPtr ctx = mGLContext->GetSharedContext(); if (!ctx) { ctx = mGLContext; diff --git a/widget/gonk/HwcComposer2D.cpp b/widget/gonk/HwcComposer2D.cpp index 334adace3fee..d20a12d2f07b 100644 --- a/widget/gonk/HwcComposer2D.cpp +++ b/widget/gonk/HwcComposer2D.cpp @@ -709,7 +709,7 @@ HwcComposer2D::TryHwComposition(nsScreenGonk* aScreen) return false; } else if (blitComposite) { // BLIT Composition, flip DispSurface target - GetGonkDisplay()->UpdateDispSurface(aScreen->GetDpy(), aScreen->GetSur()); + GetGonkDisplay()->UpdateDispSurface(aScreen->GetEGLDisplay(), aScreen->GetEGLSurface()); DisplaySurface* dispSurface = aScreen->GetDisplaySurface(); if (!dispSurface) { LOGE("H/W Composition failed. NULL DispSurface."); @@ -731,7 +731,7 @@ HwcComposer2D::Render(nsIWidget* aWidget) // HWC module does not exist or mList is not created yet. if (!mHal->HasHwc() || !mList) { - return GetGonkDisplay()->SwapBuffers(screen->GetDpy(), screen->GetSur()); + return GetGonkDisplay()->SwapBuffers(screen->GetEGLDisplay(), screen->GetEGLSurface()); } else if (!mList && !ReallocLayerList()) { LOGE("Cannot realloc layer list"); return false; @@ -829,7 +829,7 @@ HwcComposer2D::Commit(nsScreenGonk* aScreen) bool HwcComposer2D::TryHwComposition(nsScreenGonk* aScreen) { - mHal->SetEGLInfo(aScreen->GetDpy(), aScreen->GetSur()); + mHal->SetEGLInfo(aScreen->GetEGLDisplay(), aScreen->GetEGLSurface()); return !mHal->Set(mList, aScreen->GetDisplayType()); } @@ -837,7 +837,7 @@ bool HwcComposer2D::Render(nsIWidget* aWidget) { nsScreenGonk* screen = static_cast(aWidget)->GetScreen(); - GetGonkDisplay()->SwapBuffers(screen->GetDpy(), screen->GetSur()); + GetGonkDisplay()->SwapBuffers(screen->GetEGLDisplay(), screen->GetEGLSurface()); if (!mHal->HasHwc()) { return true; diff --git a/widget/gonk/hwchal/HwcHALBase.h b/widget/gonk/hwchal/HwcHALBase.h index 8257c96f5159..6a07ddd91574 100644 --- a/widget/gonk/hwchal/HwcHALBase.h +++ b/widget/gonk/hwchal/HwcHALBase.h @@ -89,8 +89,8 @@ public: virtual const hwc_rect_t GetHwcRect() const = 0; // Set EGL info (only ICS need this info) - virtual void SetEGLInfo(hwc_display_t aDpy, - hwc_surface_t aSur) = 0; + virtual void SetEGLInfo(hwc_display_t aEGLDisplay, + hwc_surface_t aEGLSurface) = 0; // HwcDevice query properties virtual bool Query(QueryType aType) = 0; diff --git a/widget/gonk/hwchal/HwcICS.cpp b/widget/gonk/hwchal/HwcICS.cpp index c37f94dbc61f..92e953555de1 100644 --- a/widget/gonk/hwchal/HwcICS.cpp +++ b/widget/gonk/hwchal/HwcICS.cpp @@ -34,16 +34,16 @@ HwcICS::HwcICS() HwcICS::~HwcICS() { mHwc = nullptr; - mDpy = nullptr; - mSur = nullptr; + mEGLDisplay = nullptr; + mEGLSurface = nullptr; } void -HwcICS::SetEGLInfo(hwc_display_t aDpy, - hwc_surface_t aSur) +HwcICS::SetEGLInfo(hwc_display_t aEGLDisplay, + hwc_surface_t aEGLSurface) { - mDpy = aDpy; - mSur = aSur; + mEGLDisplay = aEGLDisplay; + mEGLSurface = aEGLSurface; } bool @@ -74,7 +74,7 @@ HwcICS::Set(HwcList* aList, if (!mHwc) { return -1; } - return mHwc->set(mHwc, mDpy, mSur, aList); + return mHwc->set(mHwc, mEGLDisplay, mEGLSurface, aList); } int diff --git a/widget/gonk/hwchal/HwcICS.h b/widget/gonk/hwchal/HwcICS.h index 97d149959995..015b79a410dc 100644 --- a/widget/gonk/hwchal/HwcICS.h +++ b/widget/gonk/hwchal/HwcICS.h @@ -33,8 +33,8 @@ public: virtual const hwc_rect_t GetHwcRect() const override { return {0}; } - virtual void SetEGLInfo(hwc_display_t aDpy, - hwc_surface_t aSur) override; + virtual void SetEGLInfo(hwc_display_t aEGLDisplay, + hwc_surface_t aEGLSurface) override; virtual bool Query(QueryType aType) override; @@ -61,8 +61,8 @@ public: private: HwcDevice *mHwc = nullptr; - hwc_display_t mDpy = nullptr; - hwc_surface_t mSur = nullptr; + hwc_display_t mEGLDisplay = nullptr; + hwc_surface_t mEGLSurface = nullptr; }; } // namespace mozilla diff --git a/widget/gonk/nsScreenManagerGonk.cpp b/widget/gonk/nsScreenManagerGonk.cpp index 8165d312764f..607e7c729707 100644 --- a/widget/gonk/nsScreenManagerGonk.cpp +++ b/widget/gonk/nsScreenManagerGonk.cpp @@ -26,6 +26,7 @@ #include "HwcComposer2D.h" #include "VsyncSource.h" #include "nsWindow.h" +#include "mozilla/layers/CompositorParent.h" #include "mozilla/Services.h" #include "mozilla/ProcessPriorityManager.h" #include "nsIdleService.h" @@ -47,6 +48,7 @@ using namespace mozilla; using namespace mozilla::hal; using namespace mozilla::gfx; using namespace mozilla::gl; +using namespace mozilla::layers; using namespace mozilla::dom; namespace { @@ -120,8 +122,8 @@ nsScreenGonk::nsScreenGonk(uint32_t aId, , mDisplaySurface(aNativeData.mDisplaySurface) #endif , mDisplayType(aDisplayType) - , mDpy(EGL_NO_DISPLAY) - , mSur(EGL_NO_SURFACE) + , mEGLDisplay(EGL_NO_DISPLAY) + , mEGLSurface(EGL_NO_SURFACE) , mGLContext(nullptr) { if (mNativeWindow->query(mNativeWindow.get(), NATIVE_WINDOW_WIDTH, &mVirtualBounds.width) || @@ -360,21 +362,24 @@ void nsScreenGonk::SetEGLInfo(hwc_display_t aDisplay, hwc_surface_t aSurface, gl::GLContext* aGLContext) { - mDpy = aDisplay; - mSur = aSurface; + MOZ_ASSERT(CompositorParent::IsInCompositorThread()); + mEGLDisplay = aDisplay; + mEGLSurface = aSurface; mGLContext = aGLContext; } hwc_display_t -nsScreenGonk::GetDpy() +nsScreenGonk::GetEGLDisplay() { - return mDpy; + MOZ_ASSERT(CompositorParent::IsInCompositorThread()); + return mEGLDisplay; } hwc_surface_t -nsScreenGonk::GetSur() +nsScreenGonk::GetEGLSurface() { - return mSur; + MOZ_ASSERT(CompositorParent::IsInCompositorThread()); + return mEGLSurface; } NS_IMPL_ISUPPORTS(nsScreenManagerGonk, nsIScreenManager) diff --git a/widget/gonk/nsScreenManagerGonk.h b/widget/gonk/nsScreenManagerGonk.h index eccb9fb4a75d..247c6874b473 100644 --- a/widget/gonk/nsScreenManagerGonk.h +++ b/widget/gonk/nsScreenManagerGonk.h @@ -90,8 +90,8 @@ public: // Set EGL info of primary display. Used for BLIT Composition. void SetEGLInfo(hwc_display_t aDisplay, hwc_surface_t aSurface, mozilla::gl::GLContext* aGLContext); - hwc_display_t GetDpy(); - hwc_surface_t GetSur(); + hwc_display_t GetEGLDisplay(); + hwc_surface_t GetEGLSurface(); protected: uint32_t mId; @@ -107,10 +107,12 @@ protected: #if ANDROID_VERSION >= 17 android::sp mDisplaySurface; #endif + + // Accessed and updated only on compositor thread GonkDisplay::DisplayType mDisplayType; - hwc_display_t mDpy; // Store for BLIT Composition and GonkDisplayICS - hwc_surface_t mSur; // Store for BLIT Composition and GonkDisplayICS - mozilla::gl::GLContext* mGLContext; // Store for BLIT Composition + hwc_display_t mEGLDisplay; + hwc_surface_t mEGLSurface; + mozilla::gl::GLContext* mGLContext; }; class nsScreenManagerGonk final : public nsIScreenManager diff --git a/widget/gonk/nsWindow.cpp b/widget/gonk/nsWindow.cpp index bc2c5c603dd5..c182f9d73c32 100644 --- a/widget/gonk/nsWindow.cpp +++ b/widget/gonk/nsWindow.cpp @@ -546,8 +546,13 @@ nsWindow::SetNativeData(uint32_t aDataType, uintptr_t aVal) { switch (aDataType) { case NS_NATIVE_OPENGL_CONTEXT: - // Called after primary display's GLContextEGL creation. GLContext* context = reinterpret_cast(aVal); + if (!context) { + mScreen->SetEGLInfo(EGL_NO_DISPLAY, + EGL_NO_SURFACE, + nullptr); + return; + } mScreen->SetEGLInfo(GLContextEGL::Cast(context)->GetEGLDisplay(), GLContextEGL::Cast(context)->GetEGLSurface(), context);