Example #1
0
void
CanvasLayerD3D9::UpdateSurface()
{
  if (!IsDirty() && mTexture)
    return;
  Painted();

  if (!mTexture) {
    CreateTexture();

    if (!mTexture) {
      NS_WARNING("CanvasLayerD3D9::Updated called but no texture present and creation failed!");
      return;
    }
  }

  // WebGL reads entire surface.
  LockTextureRectD3D9 textureLock(mTexture);
  if (!textureLock.HasLock()) {
    NS_WARNING("Failed to lock CanvasLayer texture.");
    return;
  }

  D3DLOCKED_RECT rect = textureLock.GetLockRect();
  IntSize boundsSize(mBounds.width, mBounds.height);
  RefPtr<DrawTarget> rectDt = Factory::CreateDrawTargetForData(BackendType::CAIRO,
                                                               (uint8_t*)rect.pBits,
                                                               boundsSize,
                                                               rect.Pitch,
                                                               SurfaceFormat::B8G8R8A8);

  if (mGLContext) {
    auto screen = mGLContext->Screen();
    MOZ_ASSERT(screen);

    SharedSurface* surf = screen->Front()->Surf();
    if (!surf)
      return;
    surf->WaitSync();

    if (!ReadbackSharedSurface(surf, rectDt)) {
      NS_WARNING("Failed to readback into texture.");
    }
  } else {
    RefPtr<SourceSurface> surface = mDrawTarget->Snapshot();

    Rect drawRect(0, 0, surface->GetSize().width, surface->GetSize().height);
    rectDt->DrawSurface(surface, drawRect, drawRect,
                        DrawSurfaceOptions(),  DrawOptions(1.0F, CompositionOp::OP_SOURCE));

    rectDt->Flush();
  }
}
SharedSurface*
SurfaceStream::SwapConsumer()
{
    MOZ_ASSERT(mIsAlive);

    SharedSurface* ret = SwapConsumer_NoWait();
    if (!ret)
        return nullptr;

    if (!ret->WaitSync()) {
        return nullptr;
    }

    return ret;
}