1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef MOZILLA_GFX_COMPOSITOR_H
8 #define MOZILLA_GFX_COMPOSITOR_H
10 #include "Units.h" // for ScreenPoint
11 #include "mozilla/Assertions.h" // for MOZ_ASSERT, etc
12 #include "mozilla/RefPtr.h" // for already_AddRefed, RefCounted
13 #include "mozilla/gfx/2D.h" // for DrawTarget
14 #include "mozilla/gfx/MatrixFwd.h" // for Matrix, Matrix4x4
15 #include "mozilla/gfx/Point.h" // for IntSize, Point
16 #include "mozilla/gfx/Polygon.h" // for Polygon
17 #include "mozilla/gfx/Rect.h" // for Rect, IntRect
18 #include "mozilla/gfx/Types.h" // for Float
19 #include "mozilla/gfx/Triangle.h" // for Triangle, TexturedTriangle
20 #include "mozilla/layers/CompositorTypes.h" // for DiagnosticTypes, etc
21 #include "mozilla/layers/LayersTypes.h" // for LayersBackend
22 #include "mozilla/layers/SurfacePool.h" // for SurfacePoolHandle
23 #include "mozilla/layers/TextureSourceProvider.h"
24 #include "mozilla/widget/CompositorWidget.h"
25 #include "nsISupportsImpl.h" // for MOZ_COUNT_CTOR, etc
28 #include "mozilla/WidgetUtils.h"
31 * Different elements of a web pages are rendered into separate "layers" before
32 * they are flattened into the final image that is brought to the screen.
33 * See Layers.h for more informations about layers and why we use retained
35 * Most of the documentation for layers is directly in the source code in the
36 * form of doc comments. An overview can also be found in the the wiki:
37 * https://wiki.mozilla.org/Gecko:Overview#Graphics
40 * # Main interfaces and abstractions
42 * - Layer, ShadowableLayer and LayerComposite
43 * (see Layers.h and ipc/ShadowLayers.h)
44 * - CompositableClient and CompositableHost
45 * (client/CompositableClient.h composite/CompositableHost.h)
46 * - TextureClient and TextureHost
47 * (client/TextureClient.h composite/TextureHost.h)
49 * (composite/TextureHost.h)
51 * (ipc/CompositableForwarder.h ipc/ShadowLayers.h)
55 * (.ipdl files under the gfx/layers/ipc directory)
57 * The *Client and Shadowable* classes are always used on the content thread.
58 * Forwarders are always used on the content thread.
59 * The *Host and Shadow* classes are always used on the compositor thread.
60 * Compositors, TextureSource, and Effects are always used on the compositor
62 * Most enums and constants are declared in LayersTypes.h and CompositorTypes.h.
67 * Most layer classes own a Compositable plus some extra information like
68 * transforms and clip rects. They are platform independent.
69 * Compositable classes manipulate Texture objects and are reponsible for
70 * things like tiling, buffer rotation or double buffering. Compositables
71 * are also platform-independent. Examples of compositable classes are:
76 * Texture classes (TextureClient and TextureHost) are thin abstractions over
77 * platform-dependent texture memory. They are maniplulated by compositables
78 * and don't know about buffer rotations and such. The purposes of TextureClient
79 * and TextureHost are to synchronize, serialize and deserialize texture data.
80 * TextureHosts provide access to TextureSources that are views on the
81 * Texture data providing the necessary api for Compositor backend to composite
84 * Compositable and Texture clients and hosts are created using factory methods.
85 * They should only be created by using their constructor in exceptional
86 * circumstances. The factory methods are located:
87 * TextureClient - CompositableClient::CreateTextureClient
88 * TextureHost - TextureHost::CreateTextureHost, which calls a
89 * platform-specific function, e.g.,
90 * CreateTextureHostOGL CompositableClient - in the appropriate subclass, e.g.,
91 * CanvasClient::CreateCanvasClient
92 * CompositableHost - CompositableHost::Create
97 * If off-main-thread compositing (OMTC) is enabled, compositing is performed
98 * in a dedicated thread. In some setups compositing happens in a dedicated
99 * process. Documentation may refer to either the compositor thread or the
100 * compositor process.
101 * See explanations in ShadowLayers.h.
104 * # Backend implementations
106 * Compositor backends like OpenGL or flavours of D3D live in their own
107 * directory under gfx/layers/. To add a new backend, implement at least the
108 * following interfaces:
109 * - Compositor (ex. CompositorOGL)
110 * - TextureHost (ex. SurfaceTextureHost)
111 * Depending on the type of data that needs to be serialized, you may need to
112 * add specific TextureClient implementations.
120 class DataSourceSurface
;
130 class DataTextureSource
;
131 class CompositingRenderTarget
;
132 class CompositorBridgeParent
;
133 class LayerManagerComposite
;
136 class CompositorD3D11
;
137 class BasicCompositor
;
138 class TextureReadLock
;
140 class AsyncReadbackBuffer
;
143 enum SurfaceInitMode
{ INIT_MODE_NONE
, INIT_MODE_CLEAR
};
146 * Common interface for compositor backends.
148 * Compositor provides a cross-platform interface to a set of operations for
149 * compositing quads. Compositor knows nothing about the layer tree. It must be
150 * told everything about each composited quad - contents, location, transform,
153 * In theory it should be possible for different widgets to use the same
154 * compositor. In practice, we use one compositor per window.
158 * For an example of a user of Compositor, see LayerManagerComposite.
160 * Initialization: create a Compositor object, call Initialize().
162 * Destruction: destroy any resources associated with the compositor, call
163 * Destroy(), delete the Compositor object.
167 * for each quad to be composited:
168 * call MakeCurrent if necessary (not necessary if no other context has been
170 * take care of any texture upload required to composite the quad, this step
171 * is backend-dependent,
172 * construct an EffectChain for the quad,
176 * By default, the compositor will render to the screen if BeginFrameForWindow
177 * is called. To render to a target, call BeginFrameForTarget or
178 * or SetRenderTarget, the latter with a target created
179 * by CreateRenderTarget or CreateRenderTargetFromSource.
181 * The target and viewport methods can be called before any DrawQuad call and
182 * affect any subsequent DrawQuad calls.
184 class Compositor
: public TextureSourceProvider
{
186 virtual ~Compositor();
189 explicit Compositor(widget::CompositorWidget
* aWidget
,
190 CompositorBridgeParent
* aParent
= nullptr);
192 virtual bool Initialize(nsCString
* const out_failureReason
) = 0;
193 void Destroy() override
;
194 bool IsDestroyed() const { return mIsDestroyed
; }
197 * Request a texture host identifier that may be used for creating textures
198 * across process or thread boundaries that are compatible with this
201 virtual TextureFactoryIdentifier
GetTextureFactoryIdentifier() = 0;
204 * Properties of the compositor.
206 virtual bool CanUseCanvasLayerForSize(const gfx::IntSize
& aSize
) = 0;
208 typedef uint32_t MakeCurrentFlags
;
209 static const MakeCurrentFlags ForceMakeCurrent
= 0x1;
211 * Make this compositor's rendering context the current context for the
212 * underlying graphics API. This may be a global operation, depending on the
213 * API. Our context will remain the current one until someone else changes it.
215 * Clients of the compositor should call this at the start of the compositing
216 * process, it might be required by texture uploads etc.
218 * If aFlags == ForceMakeCurrent then we will (re-)set our context on the
219 * underlying API even if it is already the current context.
221 virtual void MakeCurrent(MakeCurrentFlags aFlags
= 0) = 0;
224 * Creates a Surface that can be used as a rendering target by this
227 virtual already_AddRefed
<CompositingRenderTarget
> CreateRenderTarget(
228 const gfx::IntRect
& aRect
, SurfaceInitMode aInit
) = 0;
231 * Creates a Surface that can be used as a rendering target by this
232 * compositor, and initializes the surface by copying from aSource.
233 * If aSource is null, then the current screen buffer is used as source.
235 * aSourcePoint specifies the point in aSource to copy data from.
237 virtual already_AddRefed
<CompositingRenderTarget
>
238 CreateRenderTargetFromSource(const gfx::IntRect
& aRect
,
239 const CompositingRenderTarget
* aSource
,
240 const gfx::IntPoint
& aSourcePoint
) = 0;
243 * Grab a snapshot of aSource and store it in aDest, so that the pixels can
244 * be read on the CPU by mapping aDest at some point in the future.
245 * aSource and aDest must have the same size.
246 * If this is a GPU compositor, this call must not block on the GPU.
247 * Returns whether the operation was successful.
249 virtual bool ReadbackRenderTarget(CompositingRenderTarget
* aSource
,
250 AsyncReadbackBuffer
* aDest
) {
255 * Create an AsyncReadbackBuffer of the specified size. Can return null.
257 virtual already_AddRefed
<AsyncReadbackBuffer
> CreateAsyncReadbackBuffer(
258 const gfx::IntSize
& aSize
) {
263 * Draw a part of aSource into the current render target.
264 * Scaling is done with linear filtering.
265 * Returns whether the operation was successful.
267 virtual bool BlitRenderTarget(CompositingRenderTarget
* aSource
,
268 const gfx::IntSize
& aSourceSize
,
269 const gfx::IntSize
& aDestSize
) {
274 * Sets the given surface as the target for subsequent calls to DrawQuad.
275 * Passing null as aSurface sets the screen as the target.
277 virtual void SetRenderTarget(CompositingRenderTarget
* aSurface
) = 0;
280 * Returns the current target for rendering. Will return null if we are
281 * rendering to the screen.
283 virtual already_AddRefed
<CompositingRenderTarget
> GetCurrentRenderTarget()
287 * Returns a render target which contains the entire window's drawing.
288 * On platforms where no such render target is used during compositing (e.g.
289 * with buffered BasicCompositor, where only the invalid area is drawn to a
290 * render target), this will return null.
292 virtual already_AddRefed
<CompositingRenderTarget
> GetWindowRenderTarget()
298 * Mostly the compositor will pull the size from a widget and this method will
299 * be ignored, but compositor implementations are free to use it if they like.
301 virtual void SetDestinationSurfaceSize(const gfx::IntSize
& aSize
) = 0;
303 void DrawGeometry(const gfx::Rect
& aRect
, const gfx::IntRect
& aClipRect
,
304 const EffectChain
& aEffectChain
, gfx::Float aOpacity
,
305 const gfx::Matrix4x4
& aTransform
,
306 const gfx::Rect
& aVisibleRect
,
307 const Maybe
<gfx::Polygon
>& aGeometry
);
309 void DrawGeometry(const gfx::Rect
& aRect
, const gfx::IntRect
& aClipRect
,
310 const EffectChain
& aEffectChain
, gfx::Float aOpacity
,
311 const gfx::Matrix4x4
& aTransform
,
312 const Maybe
<gfx::Polygon
>& aGeometry
) {
313 DrawGeometry(aRect
, aClipRect
, aEffectChain
, aOpacity
, aTransform
, aRect
,
318 * Tell the compositor to draw a quad. What to do draw and how it is
319 * drawn is specified by aEffectChain. aRect is the quad to draw, in user
320 * space. aTransform transforms from user space to screen space. If texture
321 * coords are required, these will be in the primary effect in the effect
322 * chain. aVisibleRect is used to determine which edges should be antialiased,
323 * without applying the effect to the inner edges of a tiled layer.
325 virtual void DrawQuad(const gfx::Rect
& aRect
, const gfx::IntRect
& aClipRect
,
326 const EffectChain
& aEffectChain
, gfx::Float aOpacity
,
327 const gfx::Matrix4x4
& aTransform
,
328 const gfx::Rect
& aVisibleRect
) = 0;
331 * Overload of DrawQuad, with aVisibleRect defaulted to the value of aRect.
332 * Use this when you are drawing a single quad that is not part of a tiled
335 void DrawQuad(const gfx::Rect
& aRect
, const gfx::IntRect
& aClipRect
,
336 const EffectChain
& aEffectChain
, gfx::Float aOpacity
,
337 const gfx::Matrix4x4
& aTransform
) {
338 DrawQuad(aRect
, aClipRect
, aEffectChain
, aOpacity
, aTransform
, aRect
);
341 virtual void DrawTriangle(const gfx::TexturedTriangle
& aTriangle
,
342 const gfx::IntRect
& aClipRect
,
343 const EffectChain
& aEffectChain
,
345 const gfx::Matrix4x4
& aTransform
,
346 const gfx::Rect
& aVisibleRect
) {
348 "Compositor::DrawTriangle is not implemented for the current "
352 virtual bool SupportsLayerGeometry() const { return false; }
355 * Draw an unfilled solid color rect. Typically used for debugging overlays.
357 void SlowDrawRect(const gfx::Rect
& aRect
, const gfx::DeviceColor
& color
,
358 const gfx::IntRect
& aClipRect
= gfx::IntRect(),
359 const gfx::Matrix4x4
& aTransform
= gfx::Matrix4x4(),
360 int aStrokeWidth
= 1);
363 * Draw a solid color filled rect. This is a simple DrawQuad helper.
365 void FillRect(const gfx::Rect
& aRect
, const gfx::DeviceColor
& color
,
366 const gfx::IntRect
& aClipRect
= gfx::IntRect(),
367 const gfx::Matrix4x4
& aTransform
= gfx::Matrix4x4());
369 void SetClearColor(const gfx::DeviceColor
& aColor
) { mClearColor
= aColor
; }
371 void SetDefaultClearColor(const gfx::DeviceColor
& aColor
) {
372 mDefaultClearColor
= aColor
;
375 void SetClearColorToDefault() { mClearColor
= mDefaultClearColor
; }
378 * Clear aRect on current render target.
380 virtual void ClearRect(const gfx::Rect
& aRect
) = 0;
383 * Start a new frame for rendering to the window.
384 * Needs to be paired with a call to EndFrame() if the return value is not
387 * aInvalidRegion is the invalid region of the window.
388 * aClipRect is the clip rect for all drawing (optional).
389 * aRenderBounds is the bounding rect for rendering.
390 * aOpaqueRegion is the area that contains opaque content.
391 * All coordinates are in window space.
393 * Returns the non-empty render bounds actually used by the compositor in
394 * window space, or Nothing() if composition should be aborted.
396 virtual Maybe
<gfx::IntRect
> BeginFrameForWindow(
397 const nsIntRegion
& aInvalidRegion
, const Maybe
<gfx::IntRect
>& aClipRect
,
398 const gfx::IntRect
& aRenderBounds
, const nsIntRegion
& aOpaqueRegion
) = 0;
401 * Start a new frame for rendering to a DrawTarget. Rendering can happen
402 * directly into the DrawTarget, or it can happen in an offscreen GPU buffer
403 * and read back into the DrawTarget in EndFrame, or it can happen inside the
404 * window and read back into the DrawTarget in EndFrame.
405 * Needs to be paired with a call to EndFrame() if the return value is not
408 * aInvalidRegion is the invalid region in the target.
409 * aClipRect is the clip rect for all drawing (optional).
410 * aRenderBounds is the bounding rect for rendering.
411 * aOpaqueRegion is the area that contains opaque content.
412 * aTarget is the DrawTarget which should contain the rendering after
413 * EndFrame() has been called.
414 * aTargetBounds are the DrawTarget's bounds.
415 * All coordinates are in window space.
417 * Returns the non-empty render bounds actually used by the compositor in
418 * window space, or Nothing() if composition should be aborted.
420 * If BeginFrame succeeds, the compositor keeps a reference to aTarget until
421 * EndFrame is called.
423 virtual Maybe
<gfx::IntRect
> BeginFrameForTarget(
424 const nsIntRegion
& aInvalidRegion
, const Maybe
<gfx::IntRect
>& aClipRect
,
425 const gfx::IntRect
& aRenderBounds
, const nsIntRegion
& aOpaqueRegion
,
426 gfx::DrawTarget
* aTarget
, const gfx::IntRect
& aTargetBounds
) = 0;
429 * Start a new frame for rendering to one or more native layers. Needs to be
430 * paired with a call to EndFrame().
432 * This puts the compositor in a state where offscreen rendering is allowed.
433 * Rendering an actual native layer is only possible via a call to
434 * BeginRenderingToNativeLayer(), after BeginFrameForNativeLayers() has run.
436 * The following is true for the entire time between
437 * BeginFrameForNativeLayers() and EndFrame(), even outside pairs of calls to
438 * Begin/EndRenderingToNativeLayer():
439 * - GetCurrentRenderTarget() will return something non-null.
440 * - CreateRenderTarget() and SetRenderTarget() can be called, in order to
441 * facilitate offscreen rendering.
442 * The render target that this method sets as the current render target is not
443 * useful. Do not render to it. It exists so that calls of the form
444 * SetRenderTarget(previousTarget) do not crash.
446 * Do not call on platforms that do not support native layers.
448 virtual void BeginFrameForNativeLayers() = 0;
451 * Start rendering into aNativeLayer.
452 * Needs to be paired with a call to EndRenderingToNativeLayer() if the return
453 * value is not Nothing().
455 * Must be called between BeginFrameForNativeLayers() and EndFrame().
457 * aInvalidRegion is the invalid region in the native layer.
458 * aClipRect is the clip rect for all drawing (optional).
459 * aOpaqueRegion is the area that contains opaque content.
460 * aNativeLayer is the native layer.
461 * All coordinates, including aNativeLayer->GetRect(), are in window space.
463 * Returns the non-empty layer rect, or Nothing() if rendering to this layer
466 * If BeginRenderingToNativeLayer succeeds, the compositor keeps a reference
467 * to aNativeLayer until EndRenderingToNativeLayer is called.
469 * Do not call on platforms that do not support native layers.
471 virtual Maybe
<gfx::IntRect
> BeginRenderingToNativeLayer(
472 const nsIntRegion
& aInvalidRegion
, const Maybe
<gfx::IntRect
>& aClipRect
,
473 const nsIntRegion
& aOpaqueRegion
, NativeLayer
* aNativeLayer
) = 0;
476 * Stop rendering to the native layer and submit the rendering as the layer's
479 * Do not call on platforms that do not support native layers.
481 virtual void EndRenderingToNativeLayer() = 0;
484 * Notification that we've finished issuing draw commands for normal
485 * layers (as opposed to the diagnostic overlay which comes after).
486 * This is called between BeginFrame* and EndFrame, and it's called before
487 * GetWindowRenderTarget() is called for the purposes of screenshot capturing.
488 * That next call to GetWindowRenderTarget() expects up-to-date contents for
490 * When rendering to native layers, this should be called for every layer,
491 * between BeginRenderingToNativeLayer and EndRenderingToNativeLayer, at a
492 * time at which the current render target is the one that
493 * BeginRenderingToNativeLayer has put in place.
494 * When not rendering to native layers, this should be called at a time when
495 * the current render target is the one that BeginFrameForWindow put in place.
497 virtual void NormalDrawingDone() {}
500 * Flush the current frame to the screen and tidy up.
502 * Derived class overriding this should call Compositor::EndFrame.
504 virtual void EndFrame();
506 virtual void CancelFrame(bool aNeedFlush
= true) { ReadUnlockTextures(); }
508 virtual void WaitForGPU() {}
510 virtual RefPtr
<SurfacePoolHandle
> GetSurfacePoolHandle() { return nullptr; }
513 * Whether textures created by this compositor can receive partial updates.
515 virtual bool SupportsPartialTextureUpdate() = 0;
517 void SetDiagnosticTypes(DiagnosticTypes aDiagnostics
) {
518 mDiagnosticTypes
= aDiagnostics
;
521 DiagnosticTypes
GetDiagnosticTypes() const { return mDiagnosticTypes
; }
523 void DrawDiagnostics(DiagnosticFlags aFlags
, const gfx::Rect
& visibleRect
,
524 const gfx::IntRect
& aClipRect
,
525 const gfx::Matrix4x4
& transform
,
526 uint32_t aFlashCounter
= DIAGNOSTIC_FLASH_COUNTER_MAX
);
528 void DrawDiagnostics(DiagnosticFlags aFlags
, const nsIntRegion
& visibleRegion
,
529 const gfx::IntRect
& aClipRect
,
530 const gfx::Matrix4x4
& transform
,
531 uint32_t aFlashCounter
= DIAGNOSTIC_FLASH_COUNTER_MAX
);
533 #ifdef MOZ_DUMP_PAINTING
534 virtual const char* Name() const = 0;
535 #endif // MOZ_DUMP_PAINTING
537 virtual LayersBackend
GetBackendType() const = 0;
539 virtual CompositorD3D11
* AsCompositorD3D11() { return nullptr; }
541 Compositor
* AsCompositor() override
{ return this; }
543 TimeStamp
GetLastCompositionEndTime() const override
{
544 return mLastCompositionEndTime
;
547 void UnlockAfterComposition(TextureHost
* aTexture
) override
;
548 bool NotifyNotUsedAfterComposition(TextureHost
* aTextureHost
) override
;
551 * Notify the compositor that composition is being paused. This allows the
552 * compositor to temporarily release any resources.
553 * Between calling Pause and Resume, compositing may fail.
555 virtual void Pause() {}
557 * Notify the compositor that composition is being resumed. The compositor
558 * regain any resources it requires for compositing.
559 * Returns true if succeeded.
561 virtual bool Resume() { return true; }
564 * Call before rendering begins to ensure the compositor is ready to
565 * composite. Returns false if rendering should be aborted.
567 virtual bool Ready() { return true; }
569 virtual void ForcePresent() {}
571 virtual bool IsPendingComposite() { return false; }
573 virtual void FinishPendingComposite() {}
575 widget::CompositorWidget
* GetWidget() const { return mWidget
; }
577 // Return statistics for the most recent frame we computed statistics for.
578 virtual void GetFrameStats(GPUStats
* aStats
);
580 ScreenRotation
GetScreenRotation() const { return mScreenRotation
; }
581 void SetScreenRotation(ScreenRotation aRotation
) {
582 mScreenRotation
= aRotation
;
585 // A stale Compositor has no CompositorBridgeParent; it will not process
586 // frames and should not be used.
588 bool IsValid() const override
;
589 CompositorBridgeParent
* GetCompositorBridgeParent() const { return mParent
; }
592 * Request the compositor to allow recording its frames.
594 * This is a noop on |CompositorOGL|.
596 virtual void RequestAllowFrameRecording(bool aWillRecord
) {
597 mRecordFrames
= aWillRecord
;
601 * Record the current frame for readback by the |CompositionRecorder|.
603 * If this compositor does not support this feature, a null pointer is
606 already_AddRefed
<RecordedFrame
> RecordFrame(const TimeStamp
& aTimeStamp
);
609 void DrawDiagnosticsInternal(DiagnosticFlags aFlags
,
610 const gfx::Rect
& aVisibleRect
,
611 const gfx::IntRect
& aClipRect
,
612 const gfx::Matrix4x4
& transform
,
613 uint32_t aFlashCounter
);
615 bool ShouldDrawDiagnostics(DiagnosticFlags
);
618 * Given a layer rect, clip, and transform, compute the area of the backdrop
619 * that needs to be copied for mix-blending. The output transform translates
620 * from 0..1 space into the backdrop rect space.
622 * The transformed layer quad is also optionally returned - this is the same
623 * as the result rect, before rounding.
625 gfx::IntRect
ComputeBackdropCopyRect(const gfx::Rect
& aRect
,
626 const gfx::IntRect
& aClipRect
,
627 const gfx::Matrix4x4
& aTransform
,
628 gfx::Matrix4x4
* aOutTransform
,
629 gfx::Rect
* aOutLayerQuad
= nullptr);
631 gfx::IntRect
ComputeBackdropCopyRect(const gfx::Triangle
& aTriangle
,
632 const gfx::IntRect
& aClipRect
,
633 const gfx::Matrix4x4
& aTransform
,
634 gfx::Matrix4x4
* aOutTransform
,
635 gfx::Rect
* aOutLayerQuad
= nullptr);
637 virtual void DrawTriangles(const nsTArray
<gfx::TexturedTriangle
>& aTriangles
,
638 const gfx::Rect
& aRect
,
639 const gfx::IntRect
& aClipRect
,
640 const EffectChain
& aEffectChain
,
642 const gfx::Matrix4x4
& aTransform
,
643 const gfx::Rect
& aVisibleRect
);
645 virtual void DrawPolygon(const gfx::Polygon
& aPolygon
, const gfx::Rect
& aRect
,
646 const gfx::IntRect
& aClipRect
,
647 const EffectChain
& aEffectChain
, gfx::Float aOpacity
,
648 const gfx::Matrix4x4
& aTransform
,
649 const gfx::Rect
& aVisibleRect
);
652 * Whether or not the compositor should be prepared to record frames. While
653 * this returns true, compositors are expected to maintain a full window
654 * render target that they return from GetWindowRenderTarget() between
655 * NormalDrawingDone() and EndFrame().
657 * This will be true when either we are recording a profile with screenshots
658 * enabled or the |LayerManagerComposite| has requested us to record frames
659 * for the |CompositionRecorder|.
661 bool ShouldRecordFrames() const;
664 * Last Composition end time.
666 TimeStamp mLastCompositionEndTime
;
668 DiagnosticTypes mDiagnosticTypes
;
669 CompositorBridgeParent
* mParent
;
672 * We keep track of the total number of pixels filled as we composite the
673 * current frame. This value is an approximation and is not accurate,
674 * especially in the presence of transforms.
676 size_t mPixelsPerFrame
;
677 size_t mPixelsFilled
;
679 ScreenRotation mScreenRotation
;
681 widget::CompositorWidget
* mWidget
;
685 gfx::DeviceColor mClearColor
;
686 gfx::DeviceColor mDefaultClearColor
;
688 bool mRecordFrames
= false;
691 static LayersBackend sBackend
;
694 // Returns the number of rects. (Up to 4)
695 typedef gfx::Rect decomposedRectArrayT
[4];
696 size_t DecomposeIntoNoRepeatRects(const gfx::Rect
& aRect
,
697 const gfx::Rect
& aTexCoordRect
,
698 decomposedRectArrayT
* aLayerRects
,
699 decomposedRectArrayT
* aTextureRects
);
701 static inline bool BlendOpIsMixBlendMode(gfx::CompositionOp aOp
) {
703 case gfx::CompositionOp::OP_MULTIPLY
:
704 case gfx::CompositionOp::OP_SCREEN
:
705 case gfx::CompositionOp::OP_OVERLAY
:
706 case gfx::CompositionOp::OP_DARKEN
:
707 case gfx::CompositionOp::OP_LIGHTEN
:
708 case gfx::CompositionOp::OP_COLOR_DODGE
:
709 case gfx::CompositionOp::OP_COLOR_BURN
:
710 case gfx::CompositionOp::OP_HARD_LIGHT
:
711 case gfx::CompositionOp::OP_SOFT_LIGHT
:
712 case gfx::CompositionOp::OP_DIFFERENCE
:
713 case gfx::CompositionOp::OP_EXCLUSION
:
714 case gfx::CompositionOp::OP_HUE
:
715 case gfx::CompositionOp::OP_SATURATION
:
716 case gfx::CompositionOp::OP_COLOR
:
717 case gfx::CompositionOp::OP_LUMINOSITY
:
724 class AsyncReadbackBuffer
{
726 NS_INLINE_DECL_REFCOUNTING(AsyncReadbackBuffer
)
728 gfx::IntSize
GetSize() const { return mSize
; }
729 virtual bool MapAndCopyInto(gfx::DataSourceSurface
* aSurface
,
730 const gfx::IntSize
& aReadSize
) const = 0;
733 explicit AsyncReadbackBuffer(const gfx::IntSize
& aSize
) : mSize(aSize
) {}
734 virtual ~AsyncReadbackBuffer() = default;
739 struct TexturedVertex
{
744 nsTArray
<TexturedVertex
> TexturedTrianglesToVertexArray(
745 const nsTArray
<gfx::TexturedTriangle
>& aTriangles
);
747 } // namespace layers
748 } // namespace mozilla
750 #endif /* MOZILLA_GFX_COMPOSITOR_H */