Skip to content

Commit

Permalink
Redesign nsScreenManagerGonk/nsScreenGonk and the use of it. Not comp…
Browse files Browse the repository at this point in the history
…iled yet.
  • Loading branch information
elefant committed Apr 20, 2015
1 parent 0d4bac4 commit 34db0c0
Show file tree
Hide file tree
Showing 8 changed files with 340 additions and 174 deletions.
4 changes: 2 additions & 2 deletions dom/wifi/WifiDisplayManager.cpp
Expand Up @@ -46,13 +46,13 @@ class NativeRemoteDisplayClient : public BnRemoteDisplayClient {
virtual void onDisplayConnected(const sp<IGraphicBufferProducer>& bufferProducer,
uint32_t width, uint32_t height, uint32_t flags, uint32_t session) {
ALOGI("Callback onDisplayConnected");
mozilla::GetGonkDisplay()->AddDisplay(GonkDisplay::DISPLAY_VIRTUAL, bufferProducer);
mozilla::GetScreenManager()->AddScreen(GonkDisplay::DISPLAY_VIRTUAL, bufferProducer);
}

virtual void onDisplayDisconnected() {
ALOGI("Callback onDisplayDisconnected");
enableAudioSubmix(false);
mozilla::GetGonkDisplay()->RemoveDisplay(GonkDisplay::DISPLAY_VIRTUAL);
mozilla::GetScreenManager()->RemoveScreen(GonkDisplay::DISPLAY_VIRTUAL);
}

virtual void onDisplayError(int32_t error) {
Expand Down
4 changes: 2 additions & 2 deletions widget/gonk/HwcComposer2D.cpp
Expand Up @@ -266,7 +266,7 @@ void
HwcComposer2D::Hotplug(int aDisplay, int aConnected)
{
if (aConnected) {
GetGonkDisplay()->AddDisplay(GonkDisplay::DISPLAY_EXTERNAL);
GetScreenManager()->AddScreen(GonkDisplay::DISPLAY_EXTERNAL);
nsIntSize screenSize;
ANativeWindow *win = GetGonkDisplay()->GetNativeWindow(GonkDisplay::DISPLAY_EXTERNAL);
if (win) {
Expand All @@ -285,7 +285,7 @@ HwcComposer2D::Hotplug(int aDisplay, int aConnected)
mLists[GonkDisplay::DISPLAY_EXTERNAL] = listrealloc;
}
} else {
GetGonkDisplay()->RemoveDisplay(GonkDisplay::DISPLAY_EXTERNAL);
GetScreenManager()->RemoveDisplay(GonkDisplay::DISPLAY_EXTERNAL);
}
}
#endif
Expand Down
2 changes: 1 addition & 1 deletion widget/gonk/libdisplay/GonkDisplay.h
Expand Up @@ -65,7 +65,7 @@ class MOZ_EXPORT GonkDisplay {
/**
*
*/
virtual void AddDisplay(
virtual uint32_t AddDisplay(
const uint32_t aType,
const android::sp<android::IGraphicBufferProducer>& aProducer = nullptr)
{}
Expand Down
44 changes: 3 additions & 41 deletions widget/gonk/libdisplay/GonkDisplayJB.cpp
Expand Up @@ -30,9 +30,6 @@
#include "GraphicBufferAlloc.h"
#endif
#include "BootAnimation.h"
#include "nsIObserverService.h"
#include "nsServiceManagerUtils.h"
#include "nsThreadUtils.h"

using namespace android;

Expand Down Expand Up @@ -418,42 +415,7 @@ GonkDisplayJB::GetSurfaceformat(const uint32_t aType)
return 0;
}

namespace
{
class NotifyTask : public nsIRunnable
{
public:
NS_DECL_ISUPPORTS

public:
NotifyTask(nsIDisplayDevice* aDisplayDevice)
: mDisplayDevice(aDisplayDevice)
{
}

NS_IMETHOD Run()
{
nsCOMPtr<nsIObserverService> os(do_GetService("@mozilla.org/observer-service;1"));
if (!os) {
return NS_ERROR_FAILURE;
}

return os->NotifyObservers(mDisplayDevice, "display-change", nullptr);
}
private:
nsCOMPtr<nsIDisplayDevice> mDisplayDevice;
};

NS_IMPL_ISUPPORTS(NotifyTask, nsIRunnable)
} // end of unnamed namespace

void
GonkDisplayJB::NotifyDisplayChange(nsIDisplayDevice* aDisplayDevice)
{
NS_DispatchToMainThread(new NotifyTask(aDisplayDevice));
}

void
uint32_t
GonkDisplayJB::AddDisplay(const uint32_t aType,
const sp<IGraphicBufferProducer>& aProducer)
{
Expand Down Expand Up @@ -503,10 +465,10 @@ GonkDisplayJB::AddDisplay(const uint32_t aType,
GRALLOC_USAGE_HW_RENDER |
GRALLOC_USAGE_HW_COMPOSER);

NotifyDisplayChange(new DisplayDevice(*device));

ALOGI("Add a new DisplayDevice of type:%d, w:%d, h:%d", device->mType,
device->mWidth, device->mHeight);

return aType;
}

void
Expand Down
2 changes: 1 addition & 1 deletion widget/gonk/libdisplay/GonkDisplayJB.h
Expand Up @@ -56,7 +56,7 @@ class MOZ_EXPORT GonkDisplayJB : public GonkDisplay {

bool Post(buffer_handle_t buf, int fence);

virtual void AddDisplay(
virtual uint32_t AddDisplay(
const uint32_t aType,
const android::sp<android::IGraphicBufferProducer>& aProducer = nullptr);

Expand Down
39 changes: 37 additions & 2 deletions widget/gonk/nsScreenManagerGonk.h
Expand Up @@ -28,7 +28,9 @@ class nsScreenGonk : public nsBaseScreen
typedef mozilla::hal::ScreenConfiguration ScreenConfiguration;

public:
nsScreenGonk(void* nativeScreen);
nsScreenGonk::nsScreenGonk(const ScreenConfiguration& aConfig,
uint32_t aId,
void* aNativeWidget);
~nsScreenGonk();

NS_IMETHOD GetId(uint32_t* aId);
Expand All @@ -39,8 +41,29 @@ class nsScreenGonk : public nsBaseScreen
NS_IMETHOD GetRotation(uint32_t* aRotation);
NS_IMETHOD SetRotation(uint32_t aRotation);

uint32_t GetId();
nsIntRect GetRect();

nsIntRect GetNaturalRect();
uint32_t GetEffectiveScreenRotation();
ScreenConfiguration GetScreenConfiguration();

bool IsPrimaryScreen();

static uint32_t GetRotation();
static ScreenConfiguration GetConfiguration();

private:
uint32_t mId;
int32_t mWidth;
int32_t mHeight;
int32_t mPixelDepth;
uint32_t mRotation;
void* mNativeWidget;
uint32_t mPhyisicalRotation;

uint32_t mNaturalWidth;
uint32_t mNaturalHeight;
};

class nsScreenManagerGonk final : public nsIScreenManager
Expand All @@ -51,10 +74,22 @@ class nsScreenManagerGonk final : public nsIScreenManager
NS_DECL_ISUPPORTS
NS_DECL_NSISCREENMANAGER

nsCOMPtr<nsScreenGonk> GetPrimaryScreen();

// The following three functions are "display type" based.
// Other than these functions, we should use screen id to
// manipulate on nsWindow and GonkDisplay devices.
nsCOMPtr<nsScreenGonk> ScreenForType(uint32_t aDisplayType);

void AddScreen(uint32_t aDisplayType,
const android::sp<android::IGraphicBufferProducer>& aProducer = nullptr);

void RemoveScreen(uint32_t aDisplayType);

protected:
~nsScreenManagerGonk();

nsCOMPtr<nsIScreen> mOneScreen;
nsTArray<nsCOMPtr<nsScreenGonk>> mScreens;
};

#endif /* nsScreenManagerGonk_h___ */

0 comments on commit 34db0c0

Please sign in to comment.