зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1186159 - Add an APZ minimap. r=kats
--HG-- extra : commitid : Iqp1Id5IZsI extra : rebase_source : 47afb423bc1d96df97e54f1d23fb8f87cfe0419b
This commit is contained in:
Родитель
1f5f61c880
Коммит
f1dc8b79a7
|
@ -121,7 +121,6 @@ Compositor::DrawDiagnosticsInternal(DiagnosticFlags aFlags,
|
|||
#else
|
||||
int lWidth = 2;
|
||||
#endif
|
||||
float opacity = 0.7f;
|
||||
|
||||
gfx::Color color;
|
||||
if (aFlags & DiagnosticFlags::CONTENT) {
|
||||
|
@ -142,12 +141,15 @@ Compositor::DrawDiagnosticsInternal(DiagnosticFlags aFlags,
|
|||
aFlags & DiagnosticFlags::BIGIMAGE ||
|
||||
aFlags & DiagnosticFlags::REGION_RECT) {
|
||||
lWidth = 1;
|
||||
opacity = 0.5f;
|
||||
color.r *= 0.7f;
|
||||
color.g *= 0.7f;
|
||||
color.b *= 0.7f;
|
||||
color.a = color.a * 0.5f;
|
||||
} else {
|
||||
color.a = color.a * 0.7f;
|
||||
}
|
||||
|
||||
|
||||
if (mDiagnosticTypes & DiagnosticTypes::FLASH_BORDERS) {
|
||||
float flash = (float)aFlashCounter / (float)DIAGNOSTIC_FLASH_COUNTER_MAX;
|
||||
color.r *= flash;
|
||||
|
@ -155,31 +157,57 @@ Compositor::DrawDiagnosticsInternal(DiagnosticFlags aFlags,
|
|||
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;
|
||||
|
||||
effects.mPrimaryEffect = new EffectSolidColor(color);
|
||||
effects.mPrimaryEffect = new EffectSolidColor(aColor);
|
||||
// left
|
||||
this->DrawQuad(gfx::Rect(aVisibleRect.x, aVisibleRect.y,
|
||||
lWidth, aVisibleRect.height),
|
||||
this->DrawQuad(gfx::Rect(aRect.x, aRect.y,
|
||||
aStrokeWidth, aRect.height),
|
||||
aClipRect, effects, opacity,
|
||||
aTransform);
|
||||
// top
|
||||
this->DrawQuad(gfx::Rect(aVisibleRect.x + lWidth, aVisibleRect.y,
|
||||
aVisibleRect.width - 2 * lWidth, lWidth),
|
||||
this->DrawQuad(gfx::Rect(aRect.x + aStrokeWidth, aRect.y,
|
||||
aRect.width - 2 * aStrokeWidth, aStrokeWidth),
|
||||
aClipRect, effects, opacity,
|
||||
aTransform);
|
||||
// right
|
||||
this->DrawQuad(gfx::Rect(aVisibleRect.x + aVisibleRect.width - lWidth, aVisibleRect.y,
|
||||
lWidth, aVisibleRect.height),
|
||||
this->DrawQuad(gfx::Rect(aRect.x + aRect.width - aStrokeWidth, aRect.y,
|
||||
aStrokeWidth, aRect.height),
|
||||
aClipRect, effects, opacity,
|
||||
aTransform);
|
||||
// bottom
|
||||
this->DrawQuad(gfx::Rect(aVisibleRect.x + lWidth, aVisibleRect.y + aVisibleRect.height-lWidth,
|
||||
aVisibleRect.width - 2 * lWidth, lWidth),
|
||||
this->DrawQuad(gfx::Rect(aRect.x + aStrokeWidth, aRect.y + aRect.height - aStrokeWidth,
|
||||
aRect.width - 2 * aStrokeWidth, aStrokeWidth),
|
||||
aClipRect, effects, opacity,
|
||||
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
|
||||
WrapTexCoord(float v)
|
||||
{
|
||||
|
|
|
@ -320,6 +320,21 @@ public:
|
|||
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.
|
||||
*/
|
||||
|
|
|
@ -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
|
||||
RenderLayers(ContainerT* aContainer,
|
||||
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
|
||||
// assert it though
|
||||
}
|
||||
|
|
|
@ -50,6 +50,9 @@ class ContainerLayerComposite : public ContainerLayer,
|
|||
LayerManagerComposite* aManager,
|
||||
const RenderTargetIntRect& aClipRect);
|
||||
|
||||
template<class ContainerT>
|
||||
void RenderMinimap(ContainerT* aContainer, LayerManagerComposite* aManager,
|
||||
const RenderTargetIntRect& aClipRect, Layer* aLayer);
|
||||
public:
|
||||
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_queue_size", APZMaxVelocityQueueSize, uint32_t, 5);
|
||||
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.overscroll.enabled", APZOverscrollEnabled, bool, false);
|
||||
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_queue_size", 5);
|
||||
pref("apz.min_skate_speed", "1.0");
|
||||
pref("apz.minimap.enabled", false);
|
||||
pref("apz.num_paint_duration_samples", 3);
|
||||
pref("apz.overscroll.enabled", false);
|
||||
pref("apz.overscroll.min_pan_distance_ratio", "1.0");
|
||||
|
|
Загрузка…
Ссылка в новой задаче