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
|
2012-05-28 14:28:31 -07:00
|
|
|
//#define COMPOSITOR_PERFORMANCE_WARNING
|
2012-02-10 15:06:17 -08:00
|
|
|
|
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-07-30 17:42:26 -07:00
|
|
|
#include "mozilla/TimeStamp.h"
|
2012-01-06 14:52:32 -08:00
|
|
|
#include "ShadowLayersManager.h"
|
|
|
|
class nsIWidget;
|
2011-12-15 12:07:25 -08:00
|
|
|
|
2012-07-13 08:25:29 -07:00
|
|
|
namespace base {
|
|
|
|
class Thread;
|
|
|
|
}
|
|
|
|
|
2011-12-12 07:15:57 -08:00
|
|
|
namespace mozilla {
|
|
|
|
namespace layers {
|
|
|
|
|
2012-07-19 23:48:27 -07:00
|
|
|
class AsyncPanZoomController;
|
2012-07-30 17:42:26 -07:00
|
|
|
class Layer;
|
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 {
|
2013-03-04 06:37:43 -08:00
|
|
|
ViewTransform(gfxPoint aTranslation = gfxPoint(),
|
|
|
|
gfxSize aScale = gfxSize(1, 1))
|
2012-02-01 11:31:34 -08:00
|
|
|
: mTranslation(aTranslation)
|
2012-12-23 07:51:39 -08:00
|
|
|
, mScale(aScale)
|
2012-02-01 11:31:34 -08:00
|
|
|
{}
|
|
|
|
|
|
|
|
operator gfx3DMatrix() const
|
|
|
|
{
|
|
|
|
return
|
2012-12-23 07:51:39 -08:00
|
|
|
gfx3DMatrix::ScalingMatrix(mScale.width, mScale.height, 1) *
|
2012-02-01 11:31:34 -08:00
|
|
|
gfx3DMatrix::Translation(mTranslation.x, mTranslation.y, 0);
|
|
|
|
}
|
|
|
|
|
2013-03-04 06:37:43 -08:00
|
|
|
gfxPoint mTranslation;
|
|
|
|
gfxSize mScale;
|
2012-02-01 11:31:34 -08:00
|
|
|
};
|
|
|
|
|
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)
|
2012-11-21 18:40:57 -08:00
|
|
|
|
2011-12-12 07:15:57 -08:00
|
|
|
public:
|
2012-07-13 08:25:29 -07:00
|
|
|
CompositorParent(nsIWidget* aWidget,
|
|
|
|
bool aRenderToEGLSurface = false,
|
2012-05-08 12:40:41 -07:00
|
|
|
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;
|
2012-10-04 00:05:24 -07:00
|
|
|
virtual bool RecvMakeSnapshot(const SurfaceDescriptor& aInSnapshot,
|
|
|
|
SurfaceDescriptor* aOutSnapshot);
|
2011-12-12 07:15:57 -08:00
|
|
|
|
2012-07-17 16:59:44 -07:00
|
|
|
virtual void ShadowLayersUpdated(ShadowLayersParent* aLayerTree,
|
2012-07-24 12:01:09 -07:00
|
|
|
const TargetConfig& aTargetConfig,
|
2012-07-17 16:59:44 -07:00
|
|
|
bool isFirstPaint) MOZ_OVERRIDE;
|
2013-02-04 12:13:17 -08:00
|
|
|
/**
|
|
|
|
* This forces the is-first-paint flag to true. This is intended to
|
|
|
|
* be called by the widget code when it loses its viewport information
|
|
|
|
* (or for whatever reason wants to refresh the viewport information).
|
|
|
|
* The information refresh happens because the compositor will call
|
|
|
|
* SetFirstPaintViewport on the next frame of composition.
|
|
|
|
*/
|
|
|
|
void ForceIsFirstPaint() { mIsFirstPaint = true; }
|
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
|
|
|
|
2013-03-04 06:37:43 -08:00
|
|
|
void SetTransformation(float aScale, nsIntPoint aScrollOffset);
|
2012-02-01 11:31:34 -08:00
|
|
|
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();
|
2013-01-10 08:21:10 -08:00
|
|
|
/**
|
|
|
|
* Returns true if a surface was obtained and the resume succeeded; false
|
|
|
|
* otherwise.
|
|
|
|
*/
|
|
|
|
bool ScheduleResumeOnCompositorThread(int width, int height);
|
2012-02-01 11:31:34 -08:00
|
|
|
|
2012-07-13 12:38:09 -07:00
|
|
|
virtual void ScheduleComposition();
|
2012-08-06 19:41:29 -07:00
|
|
|
void NotifyShadowTreeTransaction();
|
|
|
|
|
2012-07-13 12:38:09 -07:00
|
|
|
/**
|
|
|
|
* Returns a pointer to the compositor corresponding to the given ID.
|
|
|
|
*/
|
2012-08-22 08:56:38 -07:00
|
|
|
static CompositorParent* GetCompositor(uint64_t id);
|
2012-07-13 12:38:09 -07:00
|
|
|
|
2012-07-13 08:25:29 -07:00
|
|
|
/**
|
|
|
|
* Returns the compositor thread's message loop.
|
|
|
|
*
|
|
|
|
* This message loop is used by CompositorParent and ImageBridgeParent.
|
|
|
|
*/
|
|
|
|
static MessageLoop* CompositorLoop();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates the compositor thread and the global compositor map.
|
|
|
|
*/
|
|
|
|
static void StartUp();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Destroys the compositor thread and the global compositor map.
|
|
|
|
*/
|
|
|
|
static void ShutDown();
|
|
|
|
|
2012-07-19 23:48:27 -07:00
|
|
|
/**
|
|
|
|
* Allocate an ID that can be used to refer to a layer tree and
|
|
|
|
* associated resources that live only on the compositor thread.
|
|
|
|
*
|
|
|
|
* Must run on the content main thread.
|
|
|
|
*/
|
2012-07-17 16:59:45 -07:00
|
|
|
static uint64_t AllocateLayerTreeId();
|
2012-07-19 23:48:27 -07:00
|
|
|
/**
|
|
|
|
* Release compositor-thread resources referred to by |aID|.
|
|
|
|
*
|
|
|
|
* Must run on the content main thread.
|
|
|
|
*/
|
|
|
|
static void DeallocateLayerTreeId(uint64_t aId);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set aController as the pan/zoom controller for the tree referred
|
|
|
|
* to by aLayersId.
|
|
|
|
*
|
|
|
|
* Must run on content main thread.
|
|
|
|
*/
|
|
|
|
static void SetPanZoomControllerForLayerTree(uint64_t aLayersId,
|
|
|
|
AsyncPanZoomController* aController);
|
2012-07-17 16:59:45 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A new child process has been configured to push transactions
|
|
|
|
* directly to us. Transport is to its thread context.
|
|
|
|
*/
|
|
|
|
static PCompositorParent*
|
|
|
|
Create(Transport* aTransport, ProcessId aOtherProcess);
|
|
|
|
|
2012-07-25 12:47:01 -07:00
|
|
|
/**
|
|
|
|
* Setup external message loop and thread ID for Compositor.
|
|
|
|
* Should be used when CompositorParent should work in existing thread/MessageLoop,
|
|
|
|
* for example moving Compositor into native toolkit main thread will allow to avoid
|
|
|
|
* extra synchronization and call ::Composite() right from toolkit::Paint event
|
|
|
|
*/
|
|
|
|
static void StartUpWithExistingThread(MessageLoop* aMsgLoop,
|
|
|
|
PlatformThreadId aThreadID);
|
|
|
|
|
2012-10-29 15:10:45 -07:00
|
|
|
/**
|
|
|
|
* Release disposable memory. This will clear the tile store (stale tiles).
|
|
|
|
*/
|
|
|
|
bool
|
|
|
|
RecvMemoryPressure();
|
|
|
|
|
2012-01-06 14:52:32 -08:00
|
|
|
protected:
|
2012-07-17 16:59:45 -07:00
|
|
|
virtual PLayersParent* AllocPLayers(const LayersBackend& aBackendHint,
|
|
|
|
const uint64_t& aId,
|
|
|
|
LayersBackend* aBackend,
|
|
|
|
int32_t* 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();
|
2012-10-04 00:05:24 -07:00
|
|
|
virtual void ComposeToTarget(gfxContext* aTarget);
|
2013-03-04 06:37:43 -08:00
|
|
|
virtual void SetFirstPaintViewport(const nsIntPoint& aOffset, float aZoom, const nsIntRect& aPageRect, const gfx::Rect& aCssPageRect);
|
2012-06-13 10:49:40 -07:00
|
|
|
virtual void SetPageRect(const gfx::Rect& aCssPageRect);
|
2013-03-04 06:37:43 -08:00
|
|
|
virtual void SyncViewportInfo(const nsIntRect& aDisplayPort, float aDisplayResolution, bool aLayersUpdated,
|
2013-03-07 02:17:33 -08:00
|
|
|
nsIntPoint& aScrollOffset, float& aScaleX, float& aScaleY,
|
|
|
|
gfx::Margin& aFixedLayerMargins);
|
2012-05-08 12:40:41 -07:00
|
|
|
void SetEGLSurfaceSize(int width, int height);
|
2012-12-20 14:37:20 -08:00
|
|
|
// If SetPanZoomControllerForLayerTree is not set, Compositor will use
|
|
|
|
// derived class AsyncPanZoomController transformations.
|
|
|
|
// Compositor will not own AsyncPanZoomController here.
|
|
|
|
virtual AsyncPanZoomController* GetDefaultPanZoomController() { return nullptr; }
|
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-11-21 18:40:57 -08:00
|
|
|
void ForceComposition();
|
2012-02-14 15:36:33 -08:00
|
|
|
|
2012-07-19 23:48:27 -07:00
|
|
|
// Sample transforms for layer trees. Return true to request
|
|
|
|
// another animation frame.
|
|
|
|
bool TransformShadowTree(TimeStamp aCurrentFrame);
|
2013-01-10 01:10:20 -08:00
|
|
|
void TransformScrollableLayer(Layer* aLayer, const gfx3DMatrix& aRootTransform);
|
2012-07-19 23:48:27 -07:00
|
|
|
// Return true if an AsyncPanZoomController content transform was
|
|
|
|
// applied for |aLayer|. *aWantNextFrame is set to true if the
|
|
|
|
// controller wants another animation frame.
|
|
|
|
bool ApplyAsyncContentTransformToTree(TimeStamp aCurrentFrame, Layer* aLayer,
|
|
|
|
bool* aWantNextFrame);
|
2011-12-12 07:15:57 -08:00
|
|
|
|
2012-04-24 06:22:34 -07:00
|
|
|
inline PlatformThreadId CompositorThreadID();
|
|
|
|
|
2012-07-13 12:38:09 -07:00
|
|
|
/**
|
|
|
|
* Creates a global map referencing each compositor by ID.
|
|
|
|
*
|
|
|
|
* This map is used by the ImageBridge protocol to trigger
|
|
|
|
* compositions without having to keep references to the
|
|
|
|
* compositor
|
|
|
|
*/
|
|
|
|
static void CreateCompositorMap();
|
|
|
|
static void DestroyCompositorMap();
|
|
|
|
|
2012-07-13 08:25:29 -07:00
|
|
|
/**
|
|
|
|
* Creates the compositor thread.
|
|
|
|
*
|
|
|
|
* All compositors live on the same thread.
|
|
|
|
* The thread is not lazily created on first access to avoid dealing with
|
|
|
|
* thread safety. Therefore it's best to create and destroy the thread when
|
|
|
|
* we know we areb't using it (So creating/destroying along with gfxPlatform
|
|
|
|
* looks like a good place).
|
|
|
|
*/
|
|
|
|
static bool CreateThread();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Destroys the compositor thread.
|
|
|
|
*
|
|
|
|
* It is safe to call this fucntion more than once, although the second call
|
|
|
|
* will have no effect.
|
|
|
|
* This function is not thread-safe.
|
|
|
|
*/
|
|
|
|
static void DestroyThread();
|
|
|
|
|
2012-07-13 12:38:09 -07:00
|
|
|
/**
|
|
|
|
* Add a compositor to the global compositor map.
|
|
|
|
*/
|
2012-08-22 08:56:38 -07:00
|
|
|
static void AddCompositor(CompositorParent* compositor, uint64_t* id);
|
2012-07-13 12:38:09 -07:00
|
|
|
/**
|
|
|
|
* Remove a compositor from the global compositor map.
|
|
|
|
*/
|
2012-08-22 08:56:38 -07:00
|
|
|
static CompositorParent* RemoveCompositor(uint64_t id);
|
2012-07-13 12:38:09 -07:00
|
|
|
|
2012-10-04 00:05:24 -07:00
|
|
|
/**
|
|
|
|
* Return true if current state allows compositing, that is
|
|
|
|
* finishing a layers transaction.
|
|
|
|
*/
|
|
|
|
bool CanComposite();
|
2012-07-13 12:38:09 -07:00
|
|
|
|
2012-01-26 11:23:13 -08:00
|
|
|
// Platform specific functions
|
2012-05-23 01:36:39 -07:00
|
|
|
/**
|
2012-06-27 08:44:22 -07:00
|
|
|
* Recursively applies the given translation to all top-level fixed position
|
|
|
|
* layers that are descendants of the given layer.
|
|
|
|
* aScaleDiff is considered to be the scale transformation applied when
|
|
|
|
* displaying the layers, and is used to make sure the anchor points of
|
|
|
|
* fixed position layers remain in the same position.
|
2012-05-23 01:36:39 -07:00
|
|
|
*/
|
2012-06-27 08:44:22 -07:00
|
|
|
void TransformFixedLayers(Layer* aLayer,
|
|
|
|
const gfxPoint& aTranslation,
|
2013-03-07 02:17:33 -08:00
|
|
|
const gfxSize& aScaleDiff,
|
|
|
|
const gfx::Margin& aFixedLayerMargins);
|
2012-05-23 01:36:39 -07:00
|
|
|
|
2012-10-04 00:05:24 -07:00
|
|
|
virtual PGrallocBufferParent* AllocPGrallocBuffer(
|
|
|
|
const gfxIntSize&, const uint32_t&, const uint32_t&,
|
|
|
|
MaybeMagicGrallocBufferHandle*) MOZ_OVERRIDE
|
|
|
|
{ return nullptr; }
|
|
|
|
virtual bool DeallocPGrallocBuffer(PGrallocBufferParent*)
|
|
|
|
{ return false; }
|
|
|
|
|
2011-12-20 07:37:27 -08:00
|
|
|
nsRefPtr<LayerManager> mLayerManager;
|
2012-01-06 14:52:32 -08:00
|
|
|
nsIWidget* mWidget;
|
2012-07-24 12:01:09 -07:00
|
|
|
TargetConfig mTargetConfig;
|
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;
|
2013-03-04 06:37:43 -08:00
|
|
|
nsIntPoint mScrollOffset;
|
|
|
|
nsIntRect mContentRect;
|
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-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;
|
2012-05-29 10:49:03 -07:00
|
|
|
mozilla::Monitor mResumeCompositionMonitor;
|
2012-05-09 19:32:54 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint64_t mCompositorID;
|
2012-07-13 12:38:09 -07:00
|
|
|
|
2012-11-21 18:40:57 -08:00
|
|
|
bool mOverrideComposeReadiness;
|
|
|
|
CancelableTask* mForceCompositionTask;
|
|
|
|
|
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
|