/src/mozilla-central/gfx/layers/LayersHelpers.cpp
Line | Count | Source (jump to first uncovered line) |
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/. */ |
6 | | |
7 | | #include "LayersHelpers.h" |
8 | | |
9 | | namespace mozilla { |
10 | | namespace layers { |
11 | | |
12 | | using namespace gfx; |
13 | | |
14 | | gfx::IntRect |
15 | | ComputeBackdropCopyRect(const gfx::Rect& aRect, |
16 | | const gfx::IntRect& aClipRect, |
17 | | const gfx::Matrix4x4& aTransform, |
18 | | const gfx::IntRect& aRenderTargetRect, |
19 | | gfx::Matrix4x4* aOutTransform, |
20 | | gfx::Rect* aOutLayerQuad) |
21 | 0 | { |
22 | 0 | // Compute the clip. |
23 | 0 | IntPoint rtOffset = aRenderTargetRect.TopLeft(); |
24 | 0 | IntSize rtSize = aRenderTargetRect.Size(); |
25 | 0 |
|
26 | 0 | gfx::IntRect renderBounds(0, 0, rtSize.width, rtSize.height); |
27 | 0 | renderBounds.IntersectRect(renderBounds, aClipRect); |
28 | 0 | renderBounds.MoveBy(rtOffset); |
29 | 0 |
|
30 | 0 | // Apply the layer transform. |
31 | 0 | RectDouble dest = aTransform.TransformAndClipBounds( |
32 | 0 | RectDouble(aRect.X(), aRect.Y(), aRect.Width(), aRect.Height()), |
33 | 0 | RectDouble(renderBounds.X(), renderBounds.Y(), renderBounds.Width(), renderBounds.Height())); |
34 | 0 | dest -= rtOffset; |
35 | 0 |
|
36 | 0 | // Ensure we don't round out to -1, which trips up Direct3D. |
37 | 0 | dest.IntersectRect(dest, RectDouble(0, 0, rtSize.width, rtSize.height)); |
38 | 0 |
|
39 | 0 | if (aOutLayerQuad) { |
40 | 0 | *aOutLayerQuad = Rect(dest.X(), dest.Y(), dest.Width(), dest.Height()); |
41 | 0 | } |
42 | 0 |
|
43 | 0 | // Round out to integer. |
44 | 0 | IntRect result; |
45 | 0 | dest.RoundOut(); |
46 | 0 | dest.ToIntRect(&result); |
47 | 0 |
|
48 | 0 | // Create a transform from adjusted clip space to render target space, |
49 | 0 | // translate it for the backdrop rect, then transform it into the backdrop's |
50 | 0 | // uv-space. |
51 | 0 | Matrix4x4 transform; |
52 | 0 | transform.PostScale(rtSize.width, rtSize.height, 1.0); |
53 | 0 | transform.PostTranslate(-result.X(), -result.Y(), 0.0); |
54 | 0 | transform.PostScale(1 / float(result.Width()), 1 / float(result.Height()), 1.0); |
55 | 0 | *aOutTransform = transform; |
56 | 0 | return result; |
57 | 0 | } |
58 | | |
59 | | } // namespace layers |
60 | | } // namespace mozilla |