Bug 1186159 - Add an APZ minimap. r=kats
This commit is contained in:
@@ -121,7 +121,6 @@ Compositor::DrawDiagnosticsInternal(DiagnosticFlags aFlags,
|
|||||||
#else
|
#else
|
||||||
int lWidth = 2;
|
int lWidth = 2;
|
||||||
#endif
|
#endif
|
||||||
float opacity = 0.7f;
|
|
||||||
|
|
||||||
gfx::Color color;
|
gfx::Color color;
|
||||||
if (aFlags & DiagnosticFlags::CONTENT) {
|
if (aFlags & DiagnosticFlags::CONTENT) {
|
||||||
@@ -142,12 +141,15 @@ Compositor::DrawDiagnosticsInternal(DiagnosticFlags aFlags,
|
|||||||
aFlags & DiagnosticFlags::BIGIMAGE ||
|
aFlags & DiagnosticFlags::BIGIMAGE ||
|
||||||
aFlags & DiagnosticFlags::REGION_RECT) {
|
aFlags & DiagnosticFlags::REGION_RECT) {
|
||||||
lWidth = 1;
|
lWidth = 1;
|
||||||
opacity = 0.5f;
|
|
||||||
color.r *= 0.7f;
|
color.r *= 0.7f;
|
||||||
color.g *= 0.7f;
|
color.g *= 0.7f;
|
||||||
color.b *= 0.7f;
|
color.b *= 0.7f;
|
||||||
|
color.a = color.a * 0.5f;
|
||||||
|
} else {
|
||||||
|
color.a = color.a * 0.7f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (mDiagnosticTypes & DiagnosticTypes::FLASH_BORDERS) {
|
if (mDiagnosticTypes & DiagnosticTypes::FLASH_BORDERS) {
|
||||||
float flash = (float)aFlashCounter / (float)DIAGNOSTIC_FLASH_COUNTER_MAX;
|
float flash = (float)aFlashCounter / (float)DIAGNOSTIC_FLASH_COUNTER_MAX;
|
||||||
color.r *= flash;
|
color.r *= flash;
|
||||||
@@ -155,31 +157,57 @@ Compositor::DrawDiagnosticsInternal(DiagnosticFlags aFlags,
|
|||||||
color.b *= flash;
|
color.b *= flash;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SlowDrawRect(aVisibleRect, color, aClipRect, aTransform, lWidth);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Compositor::SlowDrawRect(const gfx::Rect& aRect, const gfx::Color& aColor,
|
||||||
|
const gfx::Rect& aClipRect,
|
||||||
|
const gfx::Matrix4x4& aTransform, int aStrokeWidth)
|
||||||
|
{
|
||||||
|
// TODO This should draw a rect using a single draw call but since
|
||||||
|
// this is only used for debugging overlays it's not worth optimizing ATM.
|
||||||
|
float opacity = 1.0f;
|
||||||
EffectChain effects;
|
EffectChain effects;
|
||||||
|
|
||||||
effects.mPrimaryEffect = new EffectSolidColor(color);
|
effects.mPrimaryEffect = new EffectSolidColor(aColor);
|
||||||
// left
|
// left
|
||||||
this->DrawQuad(gfx::Rect(aVisibleRect.x, aVisibleRect.y,
|
this->DrawQuad(gfx::Rect(aRect.x, aRect.y,
|
||||||
lWidth, aVisibleRect.height),
|
aStrokeWidth, aRect.height),
|
||||||
aClipRect, effects, opacity,
|
aClipRect, effects, opacity,
|
||||||
aTransform);
|
aTransform);
|
||||||
// top
|
// top
|
||||||
this->DrawQuad(gfx::Rect(aVisibleRect.x + lWidth, aVisibleRect.y,
|
this->DrawQuad(gfx::Rect(aRect.x + aStrokeWidth, aRect.y,
|
||||||
aVisibleRect.width - 2 * lWidth, lWidth),
|
aRect.width - 2 * aStrokeWidth, aStrokeWidth),
|
||||||
aClipRect, effects, opacity,
|
aClipRect, effects, opacity,
|
||||||
aTransform);
|
aTransform);
|
||||||
// right
|
// right
|
||||||
this->DrawQuad(gfx::Rect(aVisibleRect.x + aVisibleRect.width - lWidth, aVisibleRect.y,
|
this->DrawQuad(gfx::Rect(aRect.x + aRect.width - aStrokeWidth, aRect.y,
|
||||||
lWidth, aVisibleRect.height),
|
aStrokeWidth, aRect.height),
|
||||||
aClipRect, effects, opacity,
|
aClipRect, effects, opacity,
|
||||||
aTransform);
|
aTransform);
|
||||||
// bottom
|
// bottom
|
||||||
this->DrawQuad(gfx::Rect(aVisibleRect.x + lWidth, aVisibleRect.y + aVisibleRect.height-lWidth,
|
this->DrawQuad(gfx::Rect(aRect.x + aStrokeWidth, aRect.y + aRect.height - aStrokeWidth,
|
||||||
aVisibleRect.width - 2 * lWidth, lWidth),
|
aRect.width - 2 * aStrokeWidth, aStrokeWidth),
|
||||||
aClipRect, effects, opacity,
|
aClipRect, effects, opacity,
|
||||||
aTransform);
|
aTransform);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Compositor::FillRect(const gfx::Rect& aRect, const gfx::Color& aColor,
|
||||||
|
const gfx::Rect& aClipRect,
|
||||||
|
const gfx::Matrix4x4& aTransform)
|
||||||
|
{
|
||||||
|
float opacity = 1.0f;
|
||||||
|
EffectChain effects;
|
||||||
|
|
||||||
|
effects.mPrimaryEffect = new EffectSolidColor(aColor);
|
||||||
|
this->DrawQuad(aRect,
|
||||||
|
aClipRect, effects, opacity,
|
||||||
|
aTransform);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static float
|
static float
|
||||||
WrapTexCoord(float v)
|
WrapTexCoord(float v)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -320,6 +320,21 @@ public:
|
|||||||
DrawQuad(aRect, aClipRect, aEffectChain, aOpacity, aTransform, aRect);
|
DrawQuad(aRect, aClipRect, aEffectChain, aOpacity, aTransform, aRect);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Draw an unfilled solid color rect. Typically used for debugging overlays.
|
||||||
|
*/
|
||||||
|
void SlowDrawRect(const gfx::Rect& aRect, const gfx::Color& color,
|
||||||
|
const gfx::Rect& aClipRect = gfx::Rect(),
|
||||||
|
const gfx::Matrix4x4& aTransform = gfx::Matrix4x4(),
|
||||||
|
int aStrokeWidth = 1);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Draw a solid color filled rect. This is a simple DrawQuad helper.
|
||||||
|
*/
|
||||||
|
void FillRect(const gfx::Rect& aRect, const gfx::Color& color,
|
||||||
|
const gfx::Rect& aClipRect = gfx::Rect(),
|
||||||
|
const gfx::Matrix4x4& aTransform = gfx::Matrix4x4());
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Clear aRect on current render target.
|
* Clear aRect on current render target.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -329,6 +329,86 @@ ContainerPrepare(ContainerT* aContainer,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<class ContainerT> void
|
||||||
|
RenderMinimap(ContainerT* aContainer, LayerManagerComposite* aManager,
|
||||||
|
const RenderTargetIntRect& aClipRect, Layer* aLayer)
|
||||||
|
{
|
||||||
|
Compositor* compositor = aManager->GetCompositor();
|
||||||
|
|
||||||
|
if (aLayer->GetFrameMetricsCount() < 1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
AsyncPanZoomController* controller = aLayer->GetAsyncPanZoomController(0);
|
||||||
|
if (!controller) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ViewTransform asyncTransformWithoutOverscroll;
|
||||||
|
ParentLayerPoint scrollOffset;
|
||||||
|
controller->SampleContentTransformForFrame(&asyncTransformWithoutOverscroll,
|
||||||
|
scrollOffset);
|
||||||
|
|
||||||
|
// Options
|
||||||
|
const int verticalPadding = 10;
|
||||||
|
const int horizontalPadding = 5;
|
||||||
|
gfx::Color backgroundColor(0.3f, 0.3f, 0.3f, 0.3f);
|
||||||
|
gfx::Color tileActiveColor(1, 1, 1, 0.5f);
|
||||||
|
gfx::Color tileBorderColor(0, 0, 0, 0.1f);
|
||||||
|
gfx::Color pageBorderColor(0, 0, 0);
|
||||||
|
gfx::Color displayPortColor(0, 1.f, 0);
|
||||||
|
gfx::Color viewPortColor(0, 0, 1.f);
|
||||||
|
|
||||||
|
// Rects
|
||||||
|
const FrameMetrics& fm = aLayer->GetFrameMetrics(0);
|
||||||
|
LayerRect scrollRect = fm.GetScrollableRect() * fm.LayersPixelsPerCSSPixel();
|
||||||
|
LayerRect viewRect = ParentLayerRect(scrollOffset, fm.GetCompositionBounds().Size()) / LayerToParentLayerScale(1);
|
||||||
|
LayerRect dp = (fm.GetDisplayPort() + fm.GetScrollOffset()) * fm.LayersPixelsPerCSSPixel();
|
||||||
|
|
||||||
|
// Compute a scale with an appropriate aspect ratio
|
||||||
|
// We allocate up to 100px of width and the height of this layer.
|
||||||
|
float scaleFactor;
|
||||||
|
float scaleFactorX;
|
||||||
|
float scaleFactorY;
|
||||||
|
scaleFactorX = 100.f / scrollRect.width;
|
||||||
|
scaleFactorY = ((viewRect.height) - 2 * verticalPadding) / scrollRect.height;
|
||||||
|
scaleFactor = std::min(scaleFactorX, scaleFactorY);
|
||||||
|
|
||||||
|
Matrix4x4 transform = Matrix4x4::Scaling(scaleFactor, scaleFactor, 1);
|
||||||
|
transform.PostTranslate(horizontalPadding, verticalPadding, 0);
|
||||||
|
|
||||||
|
Rect clipRect = aContainer->GetEffectiveTransform().TransformBounds(
|
||||||
|
transform.TransformBounds(scrollRect.ToUnknownRect()));
|
||||||
|
clipRect.width++;
|
||||||
|
clipRect.height++;
|
||||||
|
|
||||||
|
Rect r;
|
||||||
|
r = transform.TransformBounds(scrollRect.ToUnknownRect());
|
||||||
|
compositor->FillRect(r, backgroundColor, clipRect, aContainer->GetEffectiveTransform());
|
||||||
|
|
||||||
|
int tileW = gfxPrefs::LayersTileWidth();
|
||||||
|
int tileH = gfxPrefs::LayersTileHeight();
|
||||||
|
|
||||||
|
for (int x = scrollRect.x; x < scrollRect.XMost(); x += tileW) {
|
||||||
|
for (int y = scrollRect.y; y < scrollRect.YMost(); y += tileH) {
|
||||||
|
LayerRect tileRect = LayerRect(x - x % tileW, y - y % tileH, tileW, tileH);
|
||||||
|
r = transform.TransformBounds(tileRect.ToUnknownRect());
|
||||||
|
if (tileRect.Intersects(dp)) {
|
||||||
|
compositor->FillRect(r, tileActiveColor, clipRect, aContainer->GetEffectiveTransform());
|
||||||
|
}
|
||||||
|
compositor->SlowDrawRect(r, tileBorderColor, clipRect, aContainer->GetEffectiveTransform());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
r = transform.TransformBounds(scrollRect.ToUnknownRect());
|
||||||
|
compositor->SlowDrawRect(r, pageBorderColor, clipRect, aContainer->GetEffectiveTransform());
|
||||||
|
r = transform.TransformBounds(dp.ToUnknownRect());
|
||||||
|
compositor->SlowDrawRect(r, displayPortColor, clipRect, aContainer->GetEffectiveTransform());
|
||||||
|
r = transform.TransformBounds(viewRect.ToUnknownRect());
|
||||||
|
compositor->SlowDrawRect(r, viewPortColor, clipRect, aContainer->GetEffectiveTransform());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
template<class ContainerT> void
|
template<class ContainerT> void
|
||||||
RenderLayers(ContainerT* aContainer,
|
RenderLayers(ContainerT* aContainer,
|
||||||
LayerManagerComposite* aManager,
|
LayerManagerComposite* aManager,
|
||||||
@@ -407,6 +487,10 @@ RenderLayers(ContainerT* aContainer,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (gfxPrefs::APZMinimap()) {
|
||||||
|
RenderMinimap(aContainer, aManager, aClipRect, layer);
|
||||||
|
}
|
||||||
|
|
||||||
// invariant: our GL context should be current here, I don't think we can
|
// invariant: our GL context should be current here, I don't think we can
|
||||||
// assert it though
|
// assert it though
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,6 +50,9 @@ class ContainerLayerComposite : public ContainerLayer,
|
|||||||
LayerManagerComposite* aManager,
|
LayerManagerComposite* aManager,
|
||||||
const RenderTargetIntRect& aClipRect);
|
const RenderTargetIntRect& aClipRect);
|
||||||
|
|
||||||
|
template<class ContainerT>
|
||||||
|
void RenderMinimap(ContainerT* aContainer, LayerManagerComposite* aManager,
|
||||||
|
const RenderTargetIntRect& aClipRect, Layer* aLayer);
|
||||||
public:
|
public:
|
||||||
explicit ContainerLayerComposite(LayerManagerComposite *aManager);
|
explicit ContainerLayerComposite(LayerManagerComposite *aManager);
|
||||||
|
|
||||||
|
|||||||
@@ -163,6 +163,7 @@ private:
|
|||||||
DECL_GFX_PREF(Once, "apz.max_velocity_inches_per_ms", APZMaxVelocity, float, -1.0f);
|
DECL_GFX_PREF(Once, "apz.max_velocity_inches_per_ms", APZMaxVelocity, float, -1.0f);
|
||||||
DECL_GFX_PREF(Once, "apz.max_velocity_queue_size", APZMaxVelocityQueueSize, uint32_t, 5);
|
DECL_GFX_PREF(Once, "apz.max_velocity_queue_size", APZMaxVelocityQueueSize, uint32_t, 5);
|
||||||
DECL_GFX_PREF(Live, "apz.min_skate_speed", APZMinSkateSpeed, float, 1.0f);
|
DECL_GFX_PREF(Live, "apz.min_skate_speed", APZMinSkateSpeed, float, 1.0f);
|
||||||
|
DECL_GFX_PREF(Live, "apz.minimap.enabled", APZMinimap, bool, false);
|
||||||
DECL_GFX_PREF(Live, "apz.num_paint_duration_samples", APZNumPaintDurationSamples, int32_t, 3);
|
DECL_GFX_PREF(Live, "apz.num_paint_duration_samples", APZNumPaintDurationSamples, int32_t, 3);
|
||||||
DECL_GFX_PREF(Live, "apz.overscroll.enabled", APZOverscrollEnabled, bool, false);
|
DECL_GFX_PREF(Live, "apz.overscroll.enabled", APZOverscrollEnabled, bool, false);
|
||||||
DECL_GFX_PREF(Live, "apz.overscroll.min_pan_distance_ratio", APZMinPanDistanceRatio, float, 1.0f);
|
DECL_GFX_PREF(Live, "apz.overscroll.min_pan_distance_ratio", APZMinPanDistanceRatio, float, 1.0f);
|
||||||
|
|||||||
@@ -548,6 +548,7 @@ pref("apz.fling_stopped_threshold", "0.01");
|
|||||||
pref("apz.max_velocity_inches_per_ms", "-1.0");
|
pref("apz.max_velocity_inches_per_ms", "-1.0");
|
||||||
pref("apz.max_velocity_queue_size", 5);
|
pref("apz.max_velocity_queue_size", 5);
|
||||||
pref("apz.min_skate_speed", "1.0");
|
pref("apz.min_skate_speed", "1.0");
|
||||||
|
pref("apz.minimap.enabled", false);
|
||||||
pref("apz.num_paint_duration_samples", 3);
|
pref("apz.num_paint_duration_samples", 3);
|
||||||
pref("apz.overscroll.enabled", false);
|
pref("apz.overscroll.enabled", false);
|
||||||
pref("apz.overscroll.min_pan_distance_ratio", "1.0");
|
pref("apz.overscroll.min_pan_distance_ratio", "1.0");
|
||||||
|
|||||||
Reference in New Issue
Block a user