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