Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
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/. */
6 #include "RenderTrace.h"
8 // If rendertrace is off let's no compile this code
9 #ifdef MOZ_RENDERTRACE
10 #include "Layers.h"
13 namespace mozilla {
14 namespace layers {
16 static int colorId = 0;
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 }
27 void RenderTraceLayers(Layer *aLayer, const char *aColor, const gfx3DMatrix aRootTransform, bool aReset) {
28 if (!aLayer)
29 return;
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);
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 }
45 colorId++;
47 for (Layer* child = aLayer->GetFirstChild();
48 child; child = child->GetNextSibling()) {
49 RenderTraceLayers(child, aColor, aRootTransform, false);
50 }
52 if (aReset) colorId = 0;
53 }
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);
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 }
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 }
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 }
80 void renderTraceEventEnd(const char *aColor) {
81 renderTraceEventEnd("", aColor);
82 }
84 }
85 }
87 #endif