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 #include "LayersHelpers.h"
14 gfx::IntRect
ComputeBackdropCopyRect(const gfx::Rect
& aRect
,
15 const gfx::IntRect
& aClipRect
,
16 const gfx::Matrix4x4
& aTransform
,
17 const gfx::IntRect
& aRenderTargetRect
,
18 gfx::Matrix4x4
* aOutTransform
,
19 gfx::Rect
* aOutLayerQuad
) {
21 IntPoint rtOffset
= aRenderTargetRect
.TopLeft();
22 IntSize rtSize
= aRenderTargetRect
.Size();
24 gfx::IntRect
renderBounds(0, 0, rtSize
.width
, rtSize
.height
);
25 renderBounds
.IntersectRect(renderBounds
, aClipRect
);
26 renderBounds
.MoveBy(rtOffset
);
28 // Apply the layer transform.
29 RectDouble dest
= aTransform
.TransformAndClipBounds(
30 RectDouble(aRect
.X(), aRect
.Y(), aRect
.Width(), aRect
.Height()),
31 RectDouble(renderBounds
.X(), renderBounds
.Y(), renderBounds
.Width(),
32 renderBounds
.Height()));
35 // Ensure we don't round out to -1, which trips up Direct3D.
36 dest
.IntersectRect(dest
, RectDouble(0, 0, rtSize
.width
, rtSize
.height
));
39 *aOutLayerQuad
= Rect(dest
.X(), dest
.Y(), dest
.Width(), dest
.Height());
42 // Round out to integer.
45 dest
.ToIntRect(&result
);
47 // Create a transform from adjusted clip space to render target space,
48 // translate it for the backdrop rect, then transform it into the backdrop's
51 transform
.PostScale(rtSize
.width
, rtSize
.height
, 1.0);
52 transform
.PostTranslate(-result
.X(), -result
.Y(), 0.0);
53 transform
.PostScale(1 / float(result
.Width()), 1 / float(result
.Height()),
55 *aOutTransform
= transform
;
60 } // namespace mozilla