From b2b52ae04e80a2c4b44ec3f45262a8ecf9d50c8d Mon Sep 17 00:00:00 2001 From: Bas Schouten Date: Wed, 12 Mar 2014 03:27:33 +0100 Subject: [PATCH] Bug 982275 - Part 2: Add a pref for drawing layer-info inside layers. r=jrmuizel --- gfx/layers/Layers.h | 14 ++++----- .../composite/ContainerLayerComposite.cpp | 31 +++++++++++++++++++ .../composite/LayerManagerComposite.cpp | 2 +- gfx/thebes/gfxPrefs.h | 1 + 4 files changed, 40 insertions(+), 8 deletions(-) diff --git a/gfx/layers/Layers.h b/gfx/layers/Layers.h index 5038252bc4ee..5d6187ecdefe 100644 --- a/gfx/layers/Layers.h +++ b/gfx/layers/Layers.h @@ -1308,6 +1308,13 @@ public: */ void LogSelf(const char* aPrefix=""); + // Print interesting information about this into aTo. Internally + // used to implement Dump*() and Log*(). If subclasses have + // additional interesting properties, they should override this with + // an implementation that first calls the base implementation then + // appends additional info to aTo. + virtual nsACString& PrintInfo(nsACString& aTo, const char* aPrefix); + static bool IsLogEnabled() { return LayerManager::IsLogEnabled(); } /** @@ -1351,13 +1358,6 @@ public: protected: Layer(LayerManager* aManager, void* aImplData); - // Print interesting information about this into aTo. Internally - // used to implement Dump*() and Log*(). If subclasses have - // additional interesting properties, they should override this with - // an implementation that first calls the base implementation then - // appends additional info to aTo. - virtual nsACString& PrintInfo(nsACString& aTo, const char* aPrefix); - /** * We can snap layer transforms for two reasons: * 1) To avoid unnecessary resampling when a transform is a translation diff --git a/gfx/layers/composite/ContainerLayerComposite.cpp b/gfx/layers/composite/ContainerLayerComposite.cpp index 0103c4186845..58f4a8cbf962 100644 --- a/gfx/layers/composite/ContainerLayerComposite.cpp +++ b/gfx/layers/composite/ContainerLayerComposite.cpp @@ -31,6 +31,7 @@ #include "nsRect.h" // for nsIntRect #include "nsRegion.h" // for nsIntRegion #include "nsTArray.h" // for nsAutoTArray +#include "TextRenderer.h" // for TextRenderer #include namespace mozilla { @@ -120,6 +121,32 @@ static gfx::Point GetScrollData(Layer* aLayer) { return origin; } +static void DrawLayerInfo(const nsIntRect& aClipRect, + LayerManagerComposite* aManager, + Layer* aLayer) +{ + + if (aLayer->GetType() == Layer::LayerType::TYPE_CONTAINER) { + // XXX - should figure out a way to render this, but for now this + // is hard to do, since it will often get superimposed over the first + // child of the layer, which is bad. + return; + } + + nsAutoCString layerInfo; + aLayer->PrintInfo(layerInfo, ""); + + nsIntRegion visibleRegion = aLayer->GetVisibleRegion(); + + uint32_t maxWidth = visibleRegion.GetBounds().width < 500 ? visibleRegion.GetBounds().width : 500; + + nsIntPoint topLeft = visibleRegion.GetBounds().TopLeft(); + aManager->GetTextRenderer()->RenderText(layerInfo.get(), gfx::IntPoint(topLeft.x, topLeft.y), + aLayer->GetEffectiveTransform(), 16, + maxWidth); + +} + static LayerVelocityUserData* GetVelocityData(Layer* aLayer) { static char sLayerVelocityUserDataKey; void* key = reinterpret_cast(&sLayerVelocityUserDataKey); @@ -361,6 +388,10 @@ ContainerRender(ContainerT* aContainer, if (gfxPrefs::LayersScrollGraph()) { DrawVelGraph(clipRect, aManager, layerToRender->GetLayer()); } + + if (gfxPrefs::DrawLayerInfo()) { + DrawLayerInfo(clipRect, aManager, layerToRender->GetLayer()); + } // invariant: our GL context should be current here, I don't think we can // assert it though } diff --git a/gfx/layers/composite/LayerManagerComposite.cpp b/gfx/layers/composite/LayerManagerComposite.cpp index 31067de78d97..9a19438de0ab 100644 --- a/gfx/layers/composite/LayerManagerComposite.cpp +++ b/gfx/layers/composite/LayerManagerComposite.cpp @@ -51,7 +51,7 @@ #include #endif #include "GeckoProfiler.h" -#include "TextRenderer.h" +#include "TextRenderer.h" // for TextRenderer class gfxASurface; class gfxContext; diff --git a/gfx/thebes/gfxPrefs.h b/gfx/thebes/gfxPrefs.h index e2d7bbe29368..63ac3bdac75a 100644 --- a/gfx/thebes/gfxPrefs.h +++ b/gfx/thebes/gfxPrefs.h @@ -154,6 +154,7 @@ private: DECL_GFX_PREF(Live, "layers.draw-bigimage-borders", DrawBigImageBorders, bool, false); DECL_GFX_PREF(Live, "layers.draw-borders", DrawLayerBorders, bool, false); DECL_GFX_PREF(Live, "layers.draw-tile-borders", DrawTileBorders, bool, false); + DECL_GFX_PREF(Live, "layers.draw-layer-info", DrawLayerInfo, bool, false); DECL_GFX_PREF(Once, "layers.dump", LayersDump, bool, false); DECL_GFX_PREF(Once, "layers.enable-tiles", LayersTilesEnabled, bool, false); DECL_GFX_PREF(Once, "layers.simple-tiles", LayersUseSimpleTiles, bool, false);