|
1 /* -*- Mode: C++; tab-width: 2; 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 "RenderTrace.h" |
|
7 |
|
8 // If rendertrace is off let's no compile this code |
|
9 #ifdef MOZ_RENDERTRACE |
|
10 #include "Layers.h" |
|
11 |
|
12 |
|
13 namespace mozilla { |
|
14 namespace layers { |
|
15 |
|
16 static int colorId = 0; |
|
17 |
|
18 static gfx3DMatrix GetRootTransform(Layer *aLayer) { |
|
19 gfx3DMatrix layerTrans = aLayer->GetTransform(); |
|
20 layerTrans.ProjectTo2D(); |
|
21 if (aLayer->GetParent() != nullptr) { |
|
22 return GetRootTransform(aLayer->GetParent()) * layerTrans; |
|
23 } |
|
24 return layerTrans; |
|
25 } |
|
26 |
|
27 void RenderTraceLayers(Layer *aLayer, const char *aColor, const gfx3DMatrix aRootTransform, bool aReset) { |
|
28 if (!aLayer) |
|
29 return; |
|
30 |
|
31 gfx3DMatrix trans = aRootTransform * aLayer->GetTransform(); |
|
32 trans.ProjectTo2D(); |
|
33 nsIntRect clipRect = aLayer->GetEffectiveVisibleRegion().GetBounds(); |
|
34 gfxRect rect(clipRect.x, clipRect.y, clipRect.width, clipRect.height); |
|
35 trans.TransformBounds(rect); |
|
36 |
|
37 if (strcmp(aLayer->Name(), "ContainerLayer") != 0 && |
|
38 strcmp(aLayer->Name(), "ContainerLayerComposite") != 0) { |
|
39 printf_stderr("%s RENDERTRACE %u rect #%02X%s %i %i %i %i\n", |
|
40 aLayer->Name(), (int)PR_IntervalNow(), |
|
41 colorId, aColor, |
|
42 (int)rect.x, (int)rect.y, (int)rect.width, (int)rect.height); |
|
43 } |
|
44 |
|
45 colorId++; |
|
46 |
|
47 for (Layer* child = aLayer->GetFirstChild(); |
|
48 child; child = child->GetNextSibling()) { |
|
49 RenderTraceLayers(child, aColor, aRootTransform, false); |
|
50 } |
|
51 |
|
52 if (aReset) colorId = 0; |
|
53 } |
|
54 |
|
55 void RenderTraceInvalidateStart(Layer *aLayer, const char *aColor, const nsIntRect aRect) { |
|
56 gfx3DMatrix trans = GetRootTransform(aLayer); |
|
57 gfxRect rect(aRect.x, aRect.y, aRect.width, aRect.height); |
|
58 trans.TransformBounds(rect); |
|
59 |
|
60 printf_stderr("%s RENDERTRACE %u fillrect #%s %i %i %i %i\n", |
|
61 aLayer->Name(), (int)PR_IntervalNow(), |
|
62 aColor, |
|
63 (int)rect.x, (int)rect.y, (int)rect.width, (int)rect.height); |
|
64 } |
|
65 void RenderTraceInvalidateEnd(Layer *aLayer, const char *aColor) { |
|
66 // Clear with an empty rect |
|
67 RenderTraceInvalidateStart(aLayer, aColor, nsIntRect()); |
|
68 } |
|
69 |
|
70 void renderTraceEventStart(const char *aComment, const char *aColor) { |
|
71 printf_stderr("%s RENDERTRACE %u fillrect #%s 0 0 10 10\n", |
|
72 aComment, (int)PR_IntervalNow(), aColor); |
|
73 } |
|
74 |
|
75 void renderTraceEventEnd(const char *aComment, const char *aColor) { |
|
76 printf_stderr("%s RENDERTRACE %u fillrect #%s 0 0 0 0\n", |
|
77 aComment, (int)PR_IntervalNow(), aColor); |
|
78 } |
|
79 |
|
80 void renderTraceEventEnd(const char *aColor) { |
|
81 renderTraceEventEnd("", aColor); |
|
82 } |
|
83 |
|
84 } |
|
85 } |
|
86 |
|
87 #endif |
|
88 |