Exemple #1
0
void
LayerManagerComposite::RenderDebugOverlay(const Rect& aBounds)
{
  bool drawFps = gfxPrefs::LayersDrawFPS();
  bool drawFrameCounter = gfxPrefs::DrawFrameCounter();
  bool drawFrameColorBars = gfxPrefs::CompositorDrawColorBars();

  if (drawFps) {
    if (!mFPS) {
      mFPS = new FPSState();
    }

    float fillRatio = mCompositor->GetFillRatio();
    mFPS->DrawFPS(TimeStamp::Now(), drawFrameColorBars ? 10 : 0, 0, unsigned(fillRatio), mCompositor);
  } else {
    mFPS = nullptr;
  }

  if (drawFrameColorBars) {
    gfx::Rect sideRect(0, 0, 10, aBounds.height);

    EffectChain effects;
    effects.mPrimaryEffect = new EffectSolidColor(gfxUtils::GetColorForFrameNumber(sFrameCount));
    mCompositor->DrawQuad(sideRect,
                          sideRect,
                          effects,
                          1.0,
                          gfx::Matrix4x4());
  }

#ifdef MOZ_PROFILING
  if (drawFrameCounter) {
    profiler_set_frame_number(sFrameCount);
    const char* qr = sQRCodeTable[sFrameCount%256];

    int size = 21;
    int padding = 2;
    float opacity = 1.0;
    const uint16_t bitWidth = 5;
    gfx::Rect clip(0,0, bitWidth*640, bitWidth*640);

    // Draw the white squares at once
    gfx::Color bitColor(1.0, 1.0, 1.0, 1.0);
    EffectChain effects;
    effects.mPrimaryEffect = new EffectSolidColor(bitColor);
    int totalSize = (size + padding * 2) * bitWidth;
    mCompositor->DrawQuad(gfx::Rect(0, 0, totalSize, totalSize),
                          clip,
                          effects,
                          opacity,
                          gfx::Matrix4x4());

    // Draw a black square for every bit set in qr[index]
    effects.mPrimaryEffect = new EffectSolidColor(gfx::Color(0, 0, 0, 1.0));
    for (int y = 0; y < size; y++) {
      for (int x = 0; x < size; x++) {
        // Select the right bit from the binary encoding
        int currBit = 128 >> ((x + y * 21) % 8);
        int i = (x + y * 21) / 8;
        if (qr[i] & currBit) {
          mCompositor->DrawQuad(gfx::Rect(bitWidth * (x + padding),
                                          bitWidth * (y + padding),
                                          bitWidth, bitWidth),
                                clip,
                                effects,
                                opacity,
                                gfx::Matrix4x4());
        }
      }
    }
  }
#endif

  if (drawFrameColorBars || drawFrameCounter) {
    // We intentionally overflow at 2^16.
    sFrameCount++;
  }
}
void
LayerManagerComposite::RenderDebugOverlay(const Rect& aBounds)
{
  bool drawFps = gfxPrefs::LayersDrawFPS();
  bool drawFrameCounter = gfxPrefs::DrawFrameCounter();
  bool drawFrameColorBars = gfxPrefs::CompositorDrawColorBars();

  TimeStamp now = TimeStamp::Now();

  if (drawFps) {
    if (!mFPS) {
      mFPS = MakeUnique<FPSState>();
    }

    float alpha = 1;
#ifdef ANDROID
    // Draw a translation delay warning overlay
    int width;
    int border;
    if (!mWarnTime.IsNull() && (now - mWarnTime).ToMilliseconds() < kVisualWarningDuration) {
      EffectChain effects;

      // Black blorder
      border = 4;
      width = 6;
      effects.mPrimaryEffect = new EffectSolidColor(gfx::Color(0, 0, 0, 1));
      mCompositor->DrawQuad(gfx::Rect(border, border, aBounds.width - 2 * border, width),
                            aBounds, effects, alpha, gfx::Matrix4x4());
      mCompositor->DrawQuad(gfx::Rect(border, aBounds.height - border - width, aBounds.width - 2 * border, width),
                            aBounds, effects, alpha, gfx::Matrix4x4());
      mCompositor->DrawQuad(gfx::Rect(border, border + width, width, aBounds.height - 2 * border - width * 2),
                            aBounds, effects, alpha, gfx::Matrix4x4());
      mCompositor->DrawQuad(gfx::Rect(aBounds.width - border - width, border + width, width, aBounds.height - 2 * border - 2 * width),
                            aBounds, effects, alpha, gfx::Matrix4x4());

      // Content
      border = 5;
      width = 4;
      effects.mPrimaryEffect = new EffectSolidColor(gfx::Color(1, 1.f - mWarningLevel, 0, 1));
      mCompositor->DrawQuad(gfx::Rect(border, border, aBounds.width - 2 * border, width),
                            aBounds, effects, alpha, gfx::Matrix4x4());
      mCompositor->DrawQuad(gfx::Rect(border, aBounds.height - border - width, aBounds.width - 2 * border, width),
                            aBounds, effects, alpha, gfx::Matrix4x4());
      mCompositor->DrawQuad(gfx::Rect(border, border + width, width, aBounds.height - 2 * border - width * 2),
                            aBounds, effects, alpha, gfx::Matrix4x4());
      mCompositor->DrawQuad(gfx::Rect(aBounds.width - border - width, border + width, width, aBounds.height - 2 * border - 2 * width),
                            aBounds, effects, alpha, gfx::Matrix4x4());
      SetDebugOverlayWantsNextFrame(true);
    }
#endif

    float fillRatio = mCompositor->GetFillRatio();
    mFPS->DrawFPS(now, drawFrameColorBars ? 10 : 1, 2, unsigned(fillRatio), mCompositor);

    if (mUnusedApzTransformWarning) {
      // If we have an unused APZ transform on this composite, draw a 20x20 red box
      // in the top-right corner
      EffectChain effects;
      effects.mPrimaryEffect = new EffectSolidColor(gfx::Color(1, 0, 0, 1));
      mCompositor->DrawQuad(gfx::Rect(aBounds.width - 20, 0, aBounds.width, 20),
                            aBounds, effects, alpha, gfx::Matrix4x4());

      mUnusedApzTransformWarning = false;
      SetDebugOverlayWantsNextFrame(true);
    }

    // Each frame is invalidate by the previous frame for simplicity
    AddInvalidRegion(nsIntRect(0, 0, 256, 256));
  } else {
    mFPS = nullptr;
  }

  if (drawFrameColorBars) {
    gfx::Rect sideRect(0, 0, 10, aBounds.height);

    EffectChain effects;
    effects.mPrimaryEffect = new EffectSolidColor(gfxUtils::GetColorForFrameNumber(sFrameCount));
    mCompositor->DrawQuad(sideRect,
                          sideRect,
                          effects,
                          1.0,
                          gfx::Matrix4x4());

    // Each frame is invalidate by the previous frame for simplicity
    AddInvalidRegion(nsIntRect(0, 0, sideRect.width, sideRect.height));
  }

#ifdef MOZ_PROFILING
  if (drawFrameCounter) {
    profiler_set_frame_number(sFrameCount);
    const char* qr = sQRCodeTable[sFrameCount%256];

    int size = 21;
    int padding = 2;
    float opacity = 1.0;
    const uint16_t bitWidth = 5;
    gfx::Rect clip(0,0, bitWidth*640, bitWidth*640);

    // Draw the white squares at once
    gfx::Color bitColor(1.0, 1.0, 1.0, 1.0);
    EffectChain effects;
    effects.mPrimaryEffect = new EffectSolidColor(bitColor);
    int totalSize = (size + padding * 2) * bitWidth;
    mCompositor->DrawQuad(gfx::Rect(0, 0, totalSize, totalSize),
                          clip,
                          effects,
                          opacity,
                          gfx::Matrix4x4());

    // Draw a black square for every bit set in qr[index]
    effects.mPrimaryEffect = new EffectSolidColor(gfx::Color(0, 0, 0, 1.0));
    for (int y = 0; y < size; y++) {
      for (int x = 0; x < size; x++) {
        // Select the right bit from the binary encoding
        int currBit = 128 >> ((x + y * 21) % 8);
        int i = (x + y * 21) / 8;
        if (qr[i] & currBit) {
          mCompositor->DrawQuad(gfx::Rect(bitWidth * (x + padding),
                                          bitWidth * (y + padding),
                                          bitWidth, bitWidth),
                                clip,
                                effects,
                                opacity,
                                gfx::Matrix4x4());
        }
      }
    }

    // Each frame is invalidate by the previous frame for simplicity
    AddInvalidRegion(nsIntRect(0, 0, 256, 256));
  }
#endif

  if (drawFrameColorBars || drawFrameCounter) {
    // We intentionally overflow at 2^16.
    sFrameCount++;
  }
}
// -----------------------------------------------------------------------------
// CheckAndDrawFrame
//
// -----------------------------------------------------------------------------
//
static TBool CheckAndDrawFrame( MAknsSkinInstance* aInstance,
    CBitmapContext& aGc, const TRect& aOuterRect, const TRect& aInnerRect,
    const TAknsItemID& aFrameID, const TAknsItemID& aCenterID,
    const TInt aDrawParam )
    {
    if( !aInstance )
        {
        return EFalse;
        }
    
    if( !(aDrawParam & KAknsDrawParamPrepareOnly) )
        {
        // Prepare before drawing
        CheckAndDrawFrame( aInstance, aGc, aOuterRect, aInnerRect,
            aFrameID, aCenterID, aDrawParam|KAknsDrawParamPrepareOnly );
        }

    CAknsImageItemData* rawData = static_cast<CAknsImageItemData*>(
        aInstance->GetCachedItemData( aFrameID, EAknsITImage ) );
    if( !rawData )
        {
        return EFalse;
        }

    if (!(aDrawParam & KAknsDrawParamPrepareOnly))
        {
        aGc.SetPenStyle(CGraphicsContext::ENullPen);
        aGc.SetBrushStyle(CGraphicsContext::ENullBrush);
        }

    TBool retVal = EFalse;

    if( AknsUtils::IsDerivedType( EAknsITImageTable, rawData->Type() ) )
        {
        CAknsImageTableItemData* data =
            static_cast<CAknsImageTableItemData*>(rawData);
        if( data->NumberOfImages() != EAknsFrameElementsN )
            {
            return EFalse;
            }

        // Corners
        retVal |= CheckAndDrawCachedImage( aInstance, aGc,
            TRect( aOuterRect.iTl, aInnerRect.iTl ),
            data->ImageIID( EAknsFrameIndexTl ), aDrawParam );
        retVal |= CheckAndDrawCachedImage( aInstance, aGc,
            TRect( aInnerRect.iBr.iX, aOuterRect.iTl.iY,
            aOuterRect.iBr.iX, aInnerRect.iTl.iY ),
            data->ImageIID( EAknsFrameIndexTr ), aDrawParam );
        retVal |= CheckAndDrawCachedImage( aInstance, aGc,
            TRect( aOuterRect.iTl.iX, aInnerRect.iBr.iY,
            aInnerRect.iTl.iX, aOuterRect.iBr.iY ),
            data->ImageIID( EAknsFrameIndexBl ), aDrawParam );
        retVal |= CheckAndDrawCachedImage( aInstance, aGc,
            TRect( aInnerRect.iBr, aOuterRect.iBr ),
            data->ImageIID( EAknsFrameIndexBr ), aDrawParam );

        // Sides
        TRect sideRect( aInnerRect.iTl.iX, aOuterRect.iTl.iY,
            aInnerRect.iBr.iX, aInnerRect.iTl.iY );
        retVal |= CheckAndDrawCachedImage( aInstance, aGc, sideRect,
            data->ImageIID( EAknsFrameIndexT ), aDrawParam );
        sideRect.SetRect( aInnerRect.iTl.iX, aInnerRect.iBr.iY,
            aInnerRect.iBr.iX, aOuterRect.iBr.iY );
        retVal |= CheckAndDrawCachedImage( aInstance, aGc, sideRect,
            data->ImageIID( EAknsFrameIndexB ), aDrawParam );
        sideRect.SetRect( aOuterRect.iTl.iX, aInnerRect.iTl.iY,
            aInnerRect.iTl.iX, aInnerRect.iBr.iY );
        retVal |= CheckAndDrawCachedImage( aInstance, aGc, sideRect,
            data->ImageIID( EAknsFrameIndexL ), aDrawParam );
        sideRect.SetRect( aInnerRect.iBr.iX, aInnerRect.iTl.iY,
            aOuterRect.iBr.iX, aInnerRect.iBr.iY );
        retVal |= CheckAndDrawCachedImage( aInstance, aGc, sideRect,
            data->ImageIID( EAknsFrameIndexR ), aDrawParam );

        // Center
        //lint --e{961} Valid logic
        if( aCenterID == KAknsIIDDefault )
            {
            retVal |= CheckAndDrawCachedImage( aInstance, aGc, aInnerRect,
                data->ImageIID( EAknsFrameIndexCenter ), aDrawParam );
            }
        else if( aCenterID != KAknsIIDNone )
            {
            retVal |= CheckAndDrawCachedImage( aInstance, aGc, aInnerRect,
                aCenterID, aDrawParam );
            }
        }
    else if( AknsUtils::IsDerivedType( EAknsITBitmap, rawData->Type() ) )
        {
        // Center only
        retVal |= CheckAndDrawCachedImage( aInstance, aGc, aOuterRect,
            aFrameID, aDrawParam );
        }

    if (!(aDrawParam & KAknsDrawParamPrepareOnly))
        {
        aGc.SetPenStyle(CGraphicsContext::ESolidPen); //lint !e961 Intentional
        aGc.SetBrushStyle(CGraphicsContext::ENullBrush);
        }
    return retVal;
    }