2012-05-09 19:32:54 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2011-12-12 07:15:57 -08:00
|
|
|
/* vim: set sw=4 ts=8 et tw=80 : */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2011-12-12 07:15:57 -08:00
|
|
|
|
|
|
|
#ifndef mozilla_layers_CompositorParent_h
|
|
|
|
#define mozilla_layers_CompositorParent_h
|
|
|
|
|
2012-02-10 15:06:17 -08:00
|
|
|
// Enable this pref to turn on compositor performance warning.
|
|
|
|
// This will print warnings if the compositor isn't meeting
|
2012-03-12 13:32:02 -07:00
|
|
|
// its responsiveness objectives:
|
2012-02-10 15:06:17 -08:00
|
|
|
// 1) Compose a frame within 15ms of receiving a ScheduleCompositeCall
|
|
|
|
// 2) Unless a frame was composited within the throttle threshold in
|
|
|
|
// which the deadline will be 15ms + throttle threshold
|
|
|
|
#define COMPOSITOR_PERFORMANCE_WARNING
|
|
|
|
|
2011-12-12 07:15:57 -08:00
|
|
|
#include "mozilla/layers/PCompositorParent.h"
|
|
|
|
#include "mozilla/layers/PLayersParent.h"
|
2012-02-03 18:35:58 -08:00
|
|
|
#include "base/thread.h"
|
2012-05-09 19:32:54 -07:00
|
|
|
#include "mozilla/Monitor.h"
|
2012-01-06 14:52:32 -08:00
|
|
|
#include "ShadowLayersManager.h"
|
2011-12-12 07:15:57 -08:00
|
|
|
|
2012-01-06 14:52:32 -08:00
|
|
|
class nsIWidget;
|
2011-12-15 12:07:25 -08:00
|
|
|
|
2011-12-12 07:15:57 -08:00
|
|
|
namespace mozilla {
|
|
|
|
namespace layers {
|
|
|
|
|
2012-01-06 14:52:32 -08:00
|
|
|
class LayerManager;
|
|
|
|
|
2012-02-01 11:31:34 -08:00
|
|
|
// Represents (affine) transforms that are calculated from a content view.
|
|
|
|
struct ViewTransform {
|
|
|
|
ViewTransform(nsIntPoint aTranslation = nsIntPoint(0, 0), float aXScale = 1, float aYScale = 1)
|
|
|
|
: mTranslation(aTranslation)
|
|
|
|
, mXScale(aXScale)
|
|
|
|
, mYScale(aYScale)
|
|
|
|
{}
|
|
|
|
|
|
|
|
operator gfx3DMatrix() const
|
|
|
|
{
|
|
|
|
return
|
|
|
|
gfx3DMatrix::ScalingMatrix(mXScale, mYScale, 1) *
|
|
|
|
gfx3DMatrix::Translation(mTranslation.x, mTranslation.y, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIntPoint mTranslation;
|
|
|
|
float mXScale;
|
|
|
|
float mYScale;
|
|
|
|
};
|
|
|
|
|
2011-12-15 12:20:06 -08:00
|
|
|
class CompositorParent : public PCompositorParent,
|
2012-01-06 14:52:32 -08:00
|
|
|
public ShadowLayersManager
|
2011-12-12 07:15:57 -08:00
|
|
|
{
|
2012-01-06 14:52:32 -08:00
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(CompositorParent)
|
2011-12-12 07:15:57 -08:00
|
|
|
public:
|
2012-05-08 12:40:41 -07:00
|
|
|
CompositorParent(nsIWidget* aWidget, MessageLoop* aMsgLoop,
|
|
|
|
PlatformThreadId aThreadID, bool aRenderToEGLSurface = false,
|
|
|
|
int aSurfaceWidth = -1, int aSurfaceHeight = -1);
|
2012-04-24 06:22:34 -07:00
|
|
|
|
2011-12-15 12:07:19 -08:00
|
|
|
virtual ~CompositorParent();
|
2011-12-12 07:15:57 -08:00
|
|
|
|
2012-03-30 12:43:11 -07:00
|
|
|
virtual bool RecvWillStop() MOZ_OVERRIDE;
|
2012-01-16 07:31:16 -08:00
|
|
|
virtual bool RecvStop() MOZ_OVERRIDE;
|
2012-03-28 15:00:10 -07:00
|
|
|
virtual bool RecvPause() MOZ_OVERRIDE;
|
|
|
|
virtual bool RecvResume() MOZ_OVERRIDE;
|
2011-12-12 07:15:57 -08:00
|
|
|
|
2012-03-12 08:50:15 -07:00
|
|
|
virtual void ShadowLayersUpdated(bool isFirstPaint) MOZ_OVERRIDE;
|
2011-12-22 07:59:53 -08:00
|
|
|
void Destroy();
|
|
|
|
|
2012-01-06 14:52:32 -08:00
|
|
|
LayerManager* GetLayerManager() { return mLayerManager; }
|
2011-12-15 12:07:19 -08:00
|
|
|
|
2012-02-01 11:31:34 -08:00
|
|
|
void SetTransformation(float aScale, nsIntPoint aScrollOffset);
|
|
|
|
void AsyncRender();
|
2012-02-09 14:39:04 -08:00
|
|
|
|
2012-02-06 09:38:23 -08:00
|
|
|
// Can be called from any thread
|
2012-03-12 13:32:02 -07:00
|
|
|
void ScheduleRenderOnCompositorThread();
|
|
|
|
void SchedulePauseOnCompositorThread();
|
2012-04-20 08:46:30 -07:00
|
|
|
void ScheduleResumeOnCompositorThread(int width, int height);
|
2012-02-01 11:31:34 -08:00
|
|
|
|
2012-01-06 14:52:32 -08:00
|
|
|
protected:
|
2012-05-22 16:15:16 -07:00
|
|
|
virtual PLayersParent* AllocPLayers(const LayersBackend& aBackendType, int* aMaxTextureSize);
|
2011-12-15 12:07:19 -08:00
|
|
|
virtual bool DeallocPLayers(PLayersParent* aLayers);
|
2012-04-24 06:22:36 -07:00
|
|
|
virtual void ScheduleTask(CancelableTask*, int);
|
|
|
|
virtual void Composite();
|
|
|
|
virtual void ScheduleComposition();
|
2012-04-30 17:03:26 -07:00
|
|
|
virtual void SetFirstPaintViewport(float aOffsetX, float aOffsetY, float aZoom, float aPageWidth, float aPageHeight,
|
|
|
|
float aCssPageWidth, float aCssPageHeight);
|
|
|
|
virtual void SetPageSize(float aZoom, float aPageWidth, float aPageHeight, float aCssPageWidth, float aCssPageHeight);
|
|
|
|
virtual void SyncViewportInfo(const nsIntRect& aDisplayPort, float aDisplayResolution, bool aLayersUpdated,
|
|
|
|
nsIntPoint& aScrollOffset, float& aScaleX, float& aScaleY);
|
2012-05-08 12:40:41 -07:00
|
|
|
void SetEGLSurfaceSize(int width, int height);
|
2011-12-12 07:15:57 -08:00
|
|
|
|
2011-12-15 12:07:19 -08:00
|
|
|
private:
|
2012-02-14 15:36:33 -08:00
|
|
|
void PauseComposition();
|
|
|
|
void ResumeComposition();
|
2012-04-20 08:46:30 -07:00
|
|
|
void ResumeCompositionAndResize(int width, int height);
|
2012-02-14 15:36:33 -08:00
|
|
|
|
2012-02-17 14:58:03 -08:00
|
|
|
void TransformShadowTree();
|
2011-12-12 07:15:57 -08:00
|
|
|
|
2012-04-24 06:22:34 -07:00
|
|
|
inline MessageLoop* CompositorLoop();
|
|
|
|
inline PlatformThreadId CompositorThreadID();
|
|
|
|
|
2012-01-26 11:23:13 -08:00
|
|
|
// Platform specific functions
|
2012-02-07 22:17:54 -08:00
|
|
|
/**
|
|
|
|
* Does a breadth-first search to find the first layer in the tree with a
|
|
|
|
* displayport set.
|
|
|
|
*/
|
|
|
|
Layer* GetPrimaryScrollableLayer();
|
2012-01-26 11:23:13 -08:00
|
|
|
|
2011-12-20 07:37:27 -08:00
|
|
|
nsRefPtr<LayerManager> mLayerManager;
|
2012-01-06 14:52:32 -08:00
|
|
|
nsIWidget* mWidget;
|
2012-02-06 09:38:23 -08:00
|
|
|
CancelableTask *mCurrentCompositeTask;
|
2012-02-06 10:51:33 -08:00
|
|
|
TimeStamp mLastCompose;
|
2012-02-10 15:06:17 -08:00
|
|
|
#ifdef COMPOSITOR_PERFORMANCE_WARNING
|
|
|
|
TimeStamp mExpectedComposeTime;
|
|
|
|
#endif
|
2012-02-06 09:38:23 -08:00
|
|
|
|
|
|
|
bool mPaused;
|
2012-02-01 11:31:34 -08:00
|
|
|
float mXScale;
|
|
|
|
float mYScale;
|
|
|
|
nsIntPoint mScrollOffset;
|
2012-03-12 08:50:27 -07:00
|
|
|
nsIntSize mContentSize;
|
2011-12-15 12:07:25 -08:00
|
|
|
|
2012-03-12 08:50:15 -07:00
|
|
|
// When this flag is set, the next composition will be the first for a
|
|
|
|
// particular document (i.e. the document displayed on the screen will change).
|
|
|
|
// This happens when loading a new page or switching tabs. We notify the
|
|
|
|
// front-end (e.g. Java on Android) about this so that it take the new page
|
|
|
|
// size and zoom into account when providing us with the next view transform.
|
|
|
|
bool mIsFirstPaint;
|
|
|
|
|
2012-03-19 21:06:56 -07:00
|
|
|
// This flag is set during a layers update, so that the first composition
|
|
|
|
// after a layers update has it set. It is cleared after that first composition.
|
|
|
|
bool mLayersUpdated;
|
|
|
|
|
2012-04-24 06:22:34 -07:00
|
|
|
MessageLoop* mCompositorLoop;
|
|
|
|
PlatformThreadId mThreadID;
|
2012-05-08 12:40:41 -07:00
|
|
|
bool mRenderToEGLSurface;
|
|
|
|
nsIntSize mEGLSurfaceSize;
|
2012-04-24 06:22:34 -07:00
|
|
|
|
2012-05-09 19:32:54 -07:00
|
|
|
mozilla::Monitor mPauseCompositionMonitor;
|
|
|
|
|
2011-12-15 12:07:19 -08:00
|
|
|
DISALLOW_EVIL_CONSTRUCTORS(CompositorParent);
|
2011-12-12 07:15:57 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
} // layers
|
|
|
|
} // mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_layers_CompositorParent_h
|