Line data Source code
1 : /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 : * This Source Code Form is subject to the terms of the Mozilla Public
3 : * License, v. 2.0. If a copy of the MPL was not distributed with this
4 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 :
6 : #include "LayersHelpers.h"
7 :
8 : namespace mozilla {
9 : namespace layers {
10 :
11 : using namespace gfx;
12 :
13 : gfx::IntRect
14 0 : 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 : {
21 : // Compute the clip.
22 0 : IntPoint rtOffset = aRenderTargetRect.TopLeft();
23 0 : IntSize rtSize = aRenderTargetRect.Size();
24 :
25 0 : gfx::IntRect renderBounds(0, 0, rtSize.width, rtSize.height);
26 0 : renderBounds.IntersectRect(renderBounds, aClipRect);
27 0 : renderBounds.MoveBy(rtOffset);
28 :
29 : // Apply the layer transform.
30 : RectDouble dest = aTransform.TransformAndClipBounds(
31 0 : RectDouble(aRect.x, aRect.y, aRect.width, aRect.height),
32 0 : RectDouble(renderBounds.x, renderBounds.y, renderBounds.width, renderBounds.height));
33 0 : dest -= rtOffset;
34 :
35 : // Ensure we don't round out to -1, which trips up Direct3D.
36 0 : dest.IntersectRect(dest, RectDouble(0, 0, rtSize.width, rtSize.height));
37 :
38 0 : if (aOutLayerQuad) {
39 0 : *aOutLayerQuad = Rect(dest.x, dest.y, dest.width, dest.height);
40 : }
41 :
42 : // Round out to integer.
43 0 : IntRect result;
44 0 : dest.RoundOut();
45 0 : dest.ToIntRect(&result);
46 :
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 0 : Matrix4x4 transform;
51 0 : transform.PostScale(rtSize.width, rtSize.height, 1.0);
52 0 : transform.PostTranslate(-result.x, -result.y, 0.0);
53 0 : transform.PostScale(1 / float(result.width), 1 / float(result.height), 1.0);
54 0 : *aOutTransform = transform;
55 0 : return result;
56 : }
57 :
58 : } // namespace layers
59 : } // namespace mozilla
|