gfx/layers/RenderTrace.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/layers/RenderTrace.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,88 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
     1.5 + * This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#include "RenderTrace.h"
    1.10 +
    1.11 +// If rendertrace is off let's no compile this code
    1.12 +#ifdef MOZ_RENDERTRACE
    1.13 +#include "Layers.h"
    1.14 +
    1.15 +
    1.16 +namespace mozilla {
    1.17 +namespace layers {
    1.18 +
    1.19 +static int colorId = 0;
    1.20 +
    1.21 +static gfx3DMatrix GetRootTransform(Layer *aLayer) {
    1.22 +  gfx3DMatrix layerTrans = aLayer->GetTransform();
    1.23 +  layerTrans.ProjectTo2D();
    1.24 +  if (aLayer->GetParent() != nullptr) {
    1.25 +    return GetRootTransform(aLayer->GetParent()) * layerTrans;
    1.26 +  }
    1.27 +  return layerTrans;
    1.28 +}
    1.29 +
    1.30 +void RenderTraceLayers(Layer *aLayer, const char *aColor, const gfx3DMatrix aRootTransform, bool aReset) {
    1.31 +  if (!aLayer)
    1.32 +    return;
    1.33 +
    1.34 +  gfx3DMatrix trans = aRootTransform * aLayer->GetTransform();
    1.35 +  trans.ProjectTo2D();
    1.36 +  nsIntRect clipRect = aLayer->GetEffectiveVisibleRegion().GetBounds();
    1.37 +  gfxRect rect(clipRect.x, clipRect.y, clipRect.width, clipRect.height);
    1.38 +  trans.TransformBounds(rect);
    1.39 +
    1.40 +  if (strcmp(aLayer->Name(), "ContainerLayer") != 0 &&
    1.41 +      strcmp(aLayer->Name(), "ContainerLayerComposite") != 0) {
    1.42 +    printf_stderr("%s RENDERTRACE %u rect #%02X%s %i %i %i %i\n",
    1.43 +      aLayer->Name(), (int)PR_IntervalNow(),
    1.44 +      colorId, aColor,
    1.45 +      (int)rect.x, (int)rect.y, (int)rect.width, (int)rect.height);
    1.46 +  }
    1.47 +
    1.48 +  colorId++;
    1.49 +
    1.50 +  for (Layer* child = aLayer->GetFirstChild();
    1.51 +        child; child = child->GetNextSibling()) {
    1.52 +    RenderTraceLayers(child, aColor, aRootTransform, false);
    1.53 +  }
    1.54 +
    1.55 +  if (aReset) colorId = 0;
    1.56 +}
    1.57 +
    1.58 +void RenderTraceInvalidateStart(Layer *aLayer, const char *aColor, const nsIntRect aRect) {
    1.59 +  gfx3DMatrix trans = GetRootTransform(aLayer);
    1.60 +  gfxRect rect(aRect.x, aRect.y, aRect.width, aRect.height);
    1.61 +  trans.TransformBounds(rect);
    1.62 +
    1.63 +  printf_stderr("%s RENDERTRACE %u fillrect #%s %i %i %i %i\n",
    1.64 +    aLayer->Name(), (int)PR_IntervalNow(),
    1.65 +    aColor,
    1.66 +    (int)rect.x, (int)rect.y, (int)rect.width, (int)rect.height);
    1.67 +}
    1.68 +void RenderTraceInvalidateEnd(Layer *aLayer, const char *aColor) {
    1.69 +  // Clear with an empty rect
    1.70 +  RenderTraceInvalidateStart(aLayer, aColor, nsIntRect());
    1.71 +}
    1.72 +
    1.73 +void renderTraceEventStart(const char *aComment, const char *aColor) {
    1.74 +  printf_stderr("%s RENDERTRACE %u fillrect #%s 0 0 10 10\n",
    1.75 +    aComment, (int)PR_IntervalNow(), aColor);
    1.76 +}
    1.77 +
    1.78 +void renderTraceEventEnd(const char *aComment, const char *aColor) {
    1.79 +  printf_stderr("%s RENDERTRACE %u fillrect #%s 0 0 0 0\n",
    1.80 +    aComment, (int)PR_IntervalNow(), aColor);
    1.81 +}
    1.82 +
    1.83 +void renderTraceEventEnd(const char *aColor) {
    1.84 +  renderTraceEventEnd("", aColor);
    1.85 +}
    1.86 +
    1.87 +}
    1.88 +}
    1.89 +
    1.90 +#endif
    1.91 +

mercurial