Bug 1632310 [wpt PR 23186] - Add test for computed versus resolved style., a=testonly
[gecko.git] / gfx / layers / LayersHelpers.cpp
blob72f194aa48172d0cf88fdf8ce4aa93fa0971278a
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"
9 namespace mozilla {
10 namespace layers {
12 using namespace gfx;
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) {
20 // Compute the clip.
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()));
33 dest -= rtOffset;
35 // Ensure we don't round out to -1, which trips up Direct3D.
36 dest.IntersectRect(dest, RectDouble(0, 0, rtSize.width, rtSize.height));
38 if (aOutLayerQuad) {
39 *aOutLayerQuad = Rect(dest.X(), dest.Y(), dest.Width(), dest.Height());
42 // Round out to integer.
43 IntRect result;
44 dest.RoundOut();
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
49 // uv-space.
50 Matrix4x4 transform;
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()),
54 1.0);
55 *aOutTransform = transform;
56 return result;
59 } // namespace layers
60 } // namespace mozilla