2018-09-25 05:48:02 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* 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/. */
|
|
|
|
#ifndef _include_mozilla_gfx_ipc_CrossProcessPaint_h_
|
|
|
|
#define _include_mozilla_gfx_ipc_CrossProcessPaint_h_
|
|
|
|
|
|
|
|
#include "nsISupportsImpl.h"
|
|
|
|
|
|
|
|
#include "mozilla/dom/ipc/IdType.h"
|
|
|
|
#include "mozilla/dom/Promise.h"
|
2019-07-10 19:45:46 +03:00
|
|
|
#include "mozilla/dom/DOMRect.h"
|
2018-09-25 05:48:02 +03:00
|
|
|
#include "mozilla/gfx/2D.h"
|
2019-07-10 19:45:46 +03:00
|
|
|
#include "mozilla/Maybe.h"
|
2018-09-25 05:48:02 +03:00
|
|
|
#include "mozilla/ipc/ByteBuf.h"
|
|
|
|
#include "nsDataHashtable.h"
|
|
|
|
#include "nsHashKeys.h"
|
|
|
|
#include "nsRefPtrHashtable.h"
|
|
|
|
#include "nsTHashtable.h"
|
|
|
|
|
|
|
|
namespace IPC {
|
|
|
|
template <typename T>
|
|
|
|
struct ParamTraits;
|
|
|
|
} // namespace IPC
|
|
|
|
|
|
|
|
namespace mozilla {
|
2019-07-10 19:45:46 +03:00
|
|
|
|
|
|
|
namespace dom {
|
|
|
|
class WindowGlobalParent;
|
|
|
|
} // namespace dom
|
|
|
|
|
2018-09-25 05:48:02 +03:00
|
|
|
namespace gfx {
|
|
|
|
|
|
|
|
class CrossProcessPaint;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A fragment of a paint of a cross process document tree.
|
|
|
|
*/
|
2019-04-11 15:36:51 +03:00
|
|
|
class PaintFragment final {
|
2018-09-25 05:48:02 +03:00
|
|
|
public:
|
|
|
|
/// Initializes an empty PaintFragment
|
|
|
|
PaintFragment() = default;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a paint fragment by recording the draw commands and dependent tabs
|
|
|
|
* for an nsIDocShell.
|
|
|
|
*
|
|
|
|
* @param aDocShell The document shell to record.
|
2019-07-10 19:45:46 +03:00
|
|
|
* @param aRect The rectangle relative to the viewport to use. If no
|
|
|
|
* rectangle is specified, then the whole viewport will be used.
|
2018-09-25 05:48:02 +03:00
|
|
|
* @param aScale The coordinate scale to use. The size of the resolved
|
|
|
|
* surface will be `aRect.Size() * aScale`, with aScale clamped to
|
|
|
|
* at least kMinPaintScale.
|
|
|
|
* @param aBackgroundColor The background color to use.
|
|
|
|
*
|
|
|
|
* @return A paint fragment. The paint fragment may be `empty` if rendering
|
|
|
|
* was unable to be accomplished for some reason.
|
|
|
|
*/
|
2019-07-10 19:45:46 +03:00
|
|
|
static PaintFragment Record(nsIDocShell* aDocShell,
|
|
|
|
const Maybe<IntRect>& aRect, float aScale,
|
|
|
|
nscolor aBackgroundColor);
|
2018-09-25 05:48:02 +03:00
|
|
|
|
|
|
|
/// Returns whether this paint fragment contains a valid recording.
|
|
|
|
bool IsEmpty() const;
|
|
|
|
|
|
|
|
PaintFragment(PaintFragment&&) = default;
|
|
|
|
PaintFragment& operator=(PaintFragment&&) = default;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
friend struct IPC::ParamTraits<PaintFragment>;
|
|
|
|
friend CrossProcessPaint;
|
|
|
|
|
|
|
|
typedef mozilla::ipc::ByteBuf ByteBuf;
|
|
|
|
|
|
|
|
PaintFragment(IntSize, ByteBuf&&, nsTHashtable<nsUint64HashKey>&&);
|
|
|
|
|
|
|
|
IntSize mSize;
|
|
|
|
ByteBuf mRecording;
|
|
|
|
nsTHashtable<nsUint64HashKey> mDependencies;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* An object for painting a cross process document tree.
|
|
|
|
*/
|
2019-04-11 15:36:51 +03:00
|
|
|
class CrossProcessPaint final {
|
2018-09-25 05:48:02 +03:00
|
|
|
NS_INLINE_DECL_REFCOUNTING(CrossProcessPaint);
|
|
|
|
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Begin an asynchronous paint of a cross process document tree starting at
|
2019-07-10 19:45:46 +03:00
|
|
|
* a WindowGlobalParent. A maybe-async paint for the root WGP will be done,
|
|
|
|
* then async paints will be recursively queued for remote subframes. Once
|
|
|
|
* all subframes have been recorded, the final image will be resolved, and
|
|
|
|
* the promise will be resolved with a dom::ImageBitmap.
|
2018-09-25 05:48:02 +03:00
|
|
|
*
|
2019-07-10 19:45:46 +03:00
|
|
|
* @param aRoot The WindowGlobalParent to paint.
|
|
|
|
* @param aRect The rectangle relative to the viewport to use, or null to
|
|
|
|
* render the whole viewport.
|
2018-09-25 05:48:02 +03:00
|
|
|
* @param aScale The coordinate scale to use. The size of the resolved
|
|
|
|
* surface will be `aRect.Size() * aScale`, with aScale clamped to
|
|
|
|
* at least kMinPaintScale. See the implementation for the current
|
|
|
|
* minimum value.
|
|
|
|
* @param aBackgroundColor The background color to use.
|
|
|
|
* @param aPromise The promise to resolve with a dom::ImageBitmap.
|
|
|
|
*
|
2019-07-10 19:45:46 +03:00
|
|
|
* @returns Whether the paint was able to be initiated or not.
|
2018-09-25 05:48:02 +03:00
|
|
|
*/
|
2019-07-10 19:45:46 +03:00
|
|
|
static bool Start(dom::WindowGlobalParent* aRoot, const dom::DOMRect* aRect,
|
|
|
|
float aScale, nscolor aBackgroundColor,
|
|
|
|
dom::Promise* aPromise);
|
2018-09-25 05:48:02 +03:00
|
|
|
|
2019-07-10 19:45:46 +03:00
|
|
|
void ReceiveFragment(dom::WindowGlobalParent* aWGP,
|
|
|
|
PaintFragment&& aFragment);
|
|
|
|
void LostFragment(dom::WindowGlobalParent* aWGP);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-09-25 05:48:02 +03:00
|
|
|
private:
|
|
|
|
typedef nsRefPtrHashtable<nsUint64HashKey, SourceSurface> ResolvedSurfaceMap;
|
2019-07-10 19:45:46 +03:00
|
|
|
typedef nsDataHashtable<nsRefPtrHashKey<dom::WindowGlobalParent>,
|
|
|
|
PaintFragment>
|
|
|
|
ReceivedFragmentMap;
|
2018-09-25 05:48:02 +03:00
|
|
|
|
|
|
|
CrossProcessPaint(dom::Promise* aPromise, float aScale,
|
2019-07-11 17:01:15 +03:00
|
|
|
dom::WindowGlobalParent* aRoot);
|
2018-09-25 05:48:02 +03:00
|
|
|
~CrossProcessPaint();
|
|
|
|
|
2019-07-11 17:01:15 +03:00
|
|
|
void QueuePaint(dom::WindowGlobalParent* aWGP, const Maybe<IntRect>& aRect,
|
|
|
|
nscolor aBackgroundColor = NS_RGBA(0, 0, 0, 0));
|
2018-09-25 05:48:02 +03:00
|
|
|
|
|
|
|
/// Clear the state of this paint so that it cannot be resolved or receive
|
|
|
|
/// any paint fragments.
|
|
|
|
void Clear();
|
|
|
|
|
|
|
|
/// Returns if this paint has been cleared.
|
|
|
|
bool IsCleared() const;
|
|
|
|
|
|
|
|
/// Resolves the paint fragments if we have none pending and resolves the
|
|
|
|
/// promise.
|
|
|
|
void MaybeResolve();
|
2019-07-10 19:45:46 +03:00
|
|
|
bool ResolveInternal(dom::WindowGlobalParent* aWGP,
|
|
|
|
ResolvedSurfaceMap* aResolved);
|
2018-09-25 05:48:02 +03:00
|
|
|
|
|
|
|
RefPtr<dom::Promise> mPromise;
|
2019-07-10 19:45:46 +03:00
|
|
|
RefPtr<dom::WindowGlobalParent> mRoot;
|
2018-09-25 05:48:02 +03:00
|
|
|
float mScale;
|
|
|
|
uint32_t mPendingFragments;
|
|
|
|
ReceivedFragmentMap mReceivedFragments;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace gfx
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // _include_mozilla_gfx_ipc_CrossProcessPaint_h_
|