Skip to content

Commit

Permalink
Merge pull request mozilla#9 from rainemak/nemo_embedlite_31_screenro…
Browse files Browse the repository at this point in the history
…tation

[xulrunner] Add screen rotation API
  • Loading branch information
tmeshkova committed May 10, 2015
2 parents de63d8c + 682f83e commit 2bc8f34
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 5 deletions.
8 changes: 8 additions & 0 deletions embedding/embedlite/EmbedLiteView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,14 @@ EmbedLiteView::SetGLViewPortSize(int width, int height)
mViewImpl->SetGLViewPortSize(width, height);
}

void
EmbedLiteView::SetScreenRotation(mozilla::ScreenRotation rotation, gfxMatrix matrix)
{
NS_ENSURE_TRUE(mViewImpl, );
gfx::Matrix m(matrix.xx, matrix.yx, matrix.xy, matrix.yy, matrix.x0, matrix.y0);
mViewImpl->SetScreenRotation(rotation, m);
}

void
EmbedLiteView::SuspendRendering()
{
Expand Down
4 changes: 4 additions & 0 deletions embedding/embedlite/EmbedLiteView.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#define MOZ_VIEW_EMBED_H

#include "mozilla/RefPtr.h"
#include "mozilla/WidgetUtils.h"
#include "nsStringGlue.h"
#include "gfxMatrix.h"
#include "nsRect.h"
Expand Down Expand Up @@ -125,6 +126,9 @@ class EmbedLiteView
// Setup renderable GL/EGL window surface size
virtual void SetGLViewPortSize(int width, int height);

// Set screen rotation and GL world transform offset and simple rotation are allowed (orientation change)
virtual void SetScreenRotation(mozilla::ScreenRotation rotation, gfxMatrix matrix);

// Scripting Interface, allow to extend embedding API by creating
// child js scripts and messaging interface.
// and do communication between UI and Content child via json messages.
Expand Down
3 changes: 3 additions & 0 deletions embedding/embedlite/embedhelpers/EmbedLiteViewIface.idl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

%{C++
#include "mozilla/gfx/Matrix.h"
#include "mozilla/WidgetUtils.h"
#include "gfxRect.h"
#include "InputData.h"
%}
Expand All @@ -17,6 +18,7 @@ class nsString;
%}
[ref] native nsStringTArrayRef(nsTArray<nsString>);
[ref] native gfxMatrix(mozilla::gfx::Matrix);
[ref] native ScreenRotation(mozilla::ScreenRotation);
[ref] native gfxRect(gfxRect);
[ref] native nsIntPoint(nsIntPoint);
[ref] native nsIntRect(nsIntRect);
Expand All @@ -30,6 +32,7 @@ interface EmbedLiteViewIface
void RenderToImage(in buffer aData, in int32_t aWidth, in int32_t aHeigth, in int32_t aStride, in int32_t aDepth);
void SetViewSize(in int32_t aWidth, in int32_t aHeight);
void SetGLViewPortSize(in int32_t aWidth, in int32_t aHeight);
void SetScreenRotation([const] in ScreenRotation rotation, [const] in gfxMatrix matrix);
void ReceiveInputEvent([const] in InputData aEvent);
void TextEvent(in string aComposite, in string aPreEdit);
void SendKeyPress(in int32_t aDomKeyCode, in int32_t aModifiers, in int32_t aCharCode);
Expand Down
23 changes: 19 additions & 4 deletions embedding/embedlite/embedthread/EmbedLiteCompositorParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ EmbedLiteCompositorParent::EmbedLiteCompositorParent(nsIWidget* aWidget,
uint32_t id)
: CompositorParent(aWidget, aRenderToEGLSurface, aSurfaceWidth, aSurfaceHeight)
, mId(id)
, mRotation(ROTATION_0)
, mUseScreenRotation(false)
, mCurrentCompositeTask(nullptr)
, mLastViewSize(aSurfaceWidth, aSurfaceHeight)
, mInitialPaintCount(0)
Expand Down Expand Up @@ -114,10 +116,17 @@ EmbedLiteCompositorParent::UpdateTransformState()
const CompositorParent::LayerTreeState* state = CompositorParent::GetIndirectShadowTree(RootLayerTreeId());
NS_ENSURE_TRUE(state && state->mLayerManager, );

GLContext* context = static_cast<CompositorOGL*>(state->mLayerManager->GetCompositor())->gl();

CompositorOGL *compositor = static_cast<CompositorOGL*>(state->mLayerManager->GetCompositor());
NS_ENSURE_TRUE(compositor, );

GLContext* context = compositor->gl();
NS_ENSURE_TRUE(context, );

state->mLayerManager->SetWorldTransform(mWorldTransform);
if (mUseScreenRotation) {
compositor->SetScreenRotation(mRotation);
state->mLayerManager->SetWorldTransform(mWorldTransform);
}

if (!mActiveClipping.IsEmpty() && state->mLayerManager->GetRoot()) {
state->mLayerManager->GetRoot()->SetClipRect(&mActiveClipping);
Expand Down Expand Up @@ -228,9 +237,15 @@ void EmbedLiteCompositorParent::SetSurfaceSize(int width, int height)
SetEGLSurfaceSize(width, height);
}

void EmbedLiteCompositorParent::SetWorldTransform(gfx::Matrix aMatrix)
void EmbedLiteCompositorParent::SetScreenRotation(const mozilla::ScreenRotation &rotation, const gfx::Matrix &matrix)
{
mWorldTransform = aMatrix;
if (mRotation != rotation) {
mWorldTransform = matrix;
mRotation = rotation;
mUseScreenRotation = true;
CancelCurrentCompositeTask();
ScheduleRenderOnCompositorThread();
}
}

void EmbedLiteCompositorParent::SetClipping(const gfxRect& aClipRect)
Expand Down
5 changes: 4 additions & 1 deletion embedding/embedlite/embedthread/EmbedLiteCompositorParent.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#define COMPOSITOR_PERFORMANCE_WARNING

#include "mozilla/WidgetUtils.h"
#include "mozilla/layers/CompositorParent.h"
#include "mozilla/layers/CompositorChild.h"
#include "Layers.h"
Expand All @@ -32,7 +33,7 @@ class EmbedLiteCompositorParent : public mozilla::layers::CompositorParent
bool RenderToContext(gfx::DrawTarget* aTarget);
bool RenderGL();
void SetSurfaceSize(int width, int height);
void SetWorldTransform(gfx::Matrix);
void SetScreenRotation(const mozilla::ScreenRotation& rotation, const gfx::Matrix& matrix);
void SetClipping(const gfxRect& aClipRect);
void* GetPlatformImage(int* width, int* height);
virtual void SuspendRendering();
Expand All @@ -58,6 +59,8 @@ class EmbedLiteCompositorParent : public mozilla::layers::CompositorParent

uint32_t mId;
gfx::Matrix mWorldTransform;
mozilla::ScreenRotation mRotation;
bool mUseScreenRotation;
nsIntRect mActiveClipping;
CancelableTask* mCurrentCompositeTask;
gfx::IntSize mLastViewSize;
Expand Down
20 changes: 20 additions & 0 deletions embedding/embedlite/embedthread/EmbedLiteViewThreadParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ EmbedLiteViewThreadParent::EmbedLiteViewThreadParent(const uint32_t& id, const u
: mId(id)
, mViewAPIDestroyed(false)
, mCompositor(nullptr)
, mRotation(ROTATION_0)
, mPendingRotation(false)
, mUILoop(MessageLoop::current())
, mLastIMEState(0)
, mUploadTexture(0)
Expand Down Expand Up @@ -65,6 +67,10 @@ EmbedLiteViewThreadParent::SetCompositor(EmbedLiteCompositorParent* aCompositor)
mCompositor = aCompositor;
UpdateScrollController();
if (mCompositor)
if (mPendingRotation) {
mCompositor->SetScreenRotation(mRotation, mWorldTransform);
mPendingRotation = false;
}
mCompositor->SetSurfaceSize(mGLViewPortSize.width, mGLViewPortSize.height);
}

Expand Down Expand Up @@ -399,6 +405,20 @@ EmbedLiteViewThreadParent::SetGLViewPortSize(int width, int height)
return NS_OK;
}

NS_IMETHODIMP
EmbedLiteViewThreadParent::SetScreenRotation(const mozilla::ScreenRotation& rotation, const gfx::Matrix& matrix)
{
mWorldTransform = matrix;
mRotation = rotation;

if (mCompositor) {
mCompositor->SetScreenRotation(rotation, matrix);
} else {
mPendingRotation = true;
}
return NS_OK;
}

NS_IMETHODIMP
EmbedLiteViewThreadParent::ResumeRendering()
{
Expand Down
7 changes: 7 additions & 0 deletions embedding/embedlite/embedthread/EmbedLiteViewThreadParent.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#define MOZ_VIEW_EMBED_THREAD_PARENT_H

#include "mozilla/embedlite/PEmbedLiteViewParent.h"
#include "mozilla/WidgetUtils.h"
#include "EmbedLiteViewIface.h"
#include "GLDefs.h"

Expand Down Expand Up @@ -120,6 +121,12 @@ class EmbedLiteViewThreadParent : public PEmbedLiteViewParent,

ScreenIntSize mViewSize;
gfxSize mGLViewPortSize;

// Cache initial values.
gfx::Matrix mWorldTransform;
mozilla::ScreenRotation mRotation;
bool mPendingRotation;

MessageLoop* mUILoop;
int mLastIMEState;

Expand Down

0 comments on commit 2bc8f34

Please sign in to comment.