widget/CompositorWidgetProxy.cpp
author Phil Ringnalda <philringnalda@gmail.com>
Wed, 29 Jun 2016 19:35:24 -0700
changeset 303220 48bd14a01b55464215c0bfe973f5657a7b5b7f9c
parent 303197 widget/CompositorWidget.cpp@54a0e73f69069c1b5c180a88ead3e9e06f1ce72c
child 303238 bcf4ff0c3eef498cd853a88270c75c161e524549
permissions -rw-r--r--
Back out 7 changesets (bug 1281998) for Windows Marionette crashes Backed out changeset d806fac2c856 (bug 1281998) Backed out changeset b8d4fedfd7eb (bug 1281998) Backed out changeset a72929c0c3ec (bug 1281998) Backed out changeset 74198f88fa37 (bug 1281998) Backed out changeset 54a0e73f6906 (bug 1281998) Backed out changeset 99d1da1293b7 (bug 1281998) Backed out changeset a5a9585754b1 (bug 1281998)

/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "CompositorWidgetProxy.h"
#include "GLConsts.h"
#include "nsBaseWidget.h"
#include "VsyncDispatcher.h"

namespace mozilla {
namespace widget {

CompositorWidgetProxy::~CompositorWidgetProxy()
{
}

already_AddRefed<gfx::DrawTarget>
CompositorWidgetProxy::StartRemoteDrawing()
{
  return nullptr;
}

void
CompositorWidgetProxy::CleanupRemoteDrawing()
{
  mLastBackBuffer = nullptr;
}

already_AddRefed<gfx::DrawTarget>
CompositorWidgetProxy::GetBackBufferDrawTarget(gfx::DrawTarget* aScreenTarget,
                                               const LayoutDeviceIntRect& aRect,
                                               const LayoutDeviceIntRect& aClearRect)
{
  MOZ_ASSERT(aScreenTarget);
  gfx::SurfaceFormat format =
    aScreenTarget->GetFormat() == gfx::SurfaceFormat::B8G8R8X8 ? gfx::SurfaceFormat::B8G8R8X8 : gfx::SurfaceFormat::B8G8R8A8;
  gfx::IntSize size = aRect.ToUnknownRect().Size();
  gfx::IntSize clientSize(GetClientSize().ToUnknownSize());

  RefPtr<gfx::DrawTarget> target;
  // Re-use back buffer if possible
  if (mLastBackBuffer &&
      mLastBackBuffer->GetBackendType() == aScreenTarget->GetBackendType() &&
      mLastBackBuffer->GetFormat() == format &&
      size <= mLastBackBuffer->GetSize() &&
      mLastBackBuffer->GetSize() <= clientSize) {
    target = mLastBackBuffer;
    target->SetTransform(gfx::Matrix());
    if (!aClearRect.IsEmpty()) {
      gfx::IntRect clearRect = aClearRect.ToUnknownRect() - aRect.ToUnknownRect().TopLeft();
      target->ClearRect(gfx::Rect(clearRect.x, clearRect.y, clearRect.width, clearRect.height));
    }
  } else {
    target = aScreenTarget->CreateSimilarDrawTarget(size, format);
    mLastBackBuffer = target;
  }
  return target.forget();
}

already_AddRefed<gfx::SourceSurface>
CompositorWidgetProxy::EndBackBufferDrawing()
{
  RefPtr<gfx::SourceSurface> surface = mLastBackBuffer ? mLastBackBuffer->Snapshot() : nullptr;
  return surface.forget();
}

uint32_t
CompositorWidgetProxy::GetGLFrameBufferFormat()
{
  return LOCAL_GL_RGBA;
}

CompositorWidgetProxyWrapper::CompositorWidgetProxyWrapper(nsBaseWidget* aWidget)
 : mWidget(aWidget)
{
}

bool
CompositorWidgetProxyWrapper::PreRender(layers::LayerManagerComposite* aManager)
{
  return mWidget->PreRender(aManager);
}

void
CompositorWidgetProxyWrapper::PostRender(layers::LayerManagerComposite* aManager)
{
  mWidget->PostRender(aManager);
}

void
CompositorWidgetProxyWrapper::DrawWindowUnderlay(layers::LayerManagerComposite* aManager,
                                                 LayoutDeviceIntRect aRect)
{
  mWidget->DrawWindowUnderlay(aManager, aRect);
}

void
CompositorWidgetProxyWrapper::DrawWindowOverlay(layers::LayerManagerComposite* aManager,
                                                LayoutDeviceIntRect aRect)
{
  mWidget->DrawWindowOverlay(aManager, aRect);
}

already_AddRefed<gfx::DrawTarget>
CompositorWidgetProxyWrapper::StartRemoteDrawing()
{
  return mWidget->StartRemoteDrawing();
}

already_AddRefed<gfx::DrawTarget>
CompositorWidgetProxyWrapper::StartRemoteDrawingInRegion(LayoutDeviceIntRegion& aInvalidRegion,
                                                         layers::BufferMode* aBufferMode)
{
  return mWidget->StartRemoteDrawingInRegion(aInvalidRegion, aBufferMode);
}

void
CompositorWidgetProxyWrapper::EndRemoteDrawing()
{
  mWidget->EndRemoteDrawing();
}

void
CompositorWidgetProxyWrapper::EndRemoteDrawingInRegion(gfx::DrawTarget* aDrawTarget,
                                                       LayoutDeviceIntRegion& aInvalidRegion)
{
  mWidget->EndRemoteDrawingInRegion(aDrawTarget, aInvalidRegion);
}

void
CompositorWidgetProxyWrapper::CleanupRemoteDrawing()
{
  mWidget->CleanupRemoteDrawing();
}

void
CompositorWidgetProxyWrapper::CleanupWindowEffects()
{
  mWidget->CleanupWindowEffects();
}

bool
CompositorWidgetProxyWrapper::InitCompositor(layers::Compositor* aCompositor)
{
  return mWidget->InitCompositor(aCompositor);
}

LayoutDeviceIntSize
CompositorWidgetProxyWrapper::GetClientSize()
{
  return mWidget->GetClientSize();
}

uint32_t
CompositorWidgetProxyWrapper::GetGLFrameBufferFormat()
{
  return mWidget->GetGLFrameBufferFormat();
}

layers::Composer2D*
CompositorWidgetProxyWrapper::GetComposer2D()
{
  return mWidget->GetComposer2D();
}

uintptr_t
CompositorWidgetProxyWrapper::GetWidgetKey()
{
  return reinterpret_cast<uintptr_t>(mWidget);
}

nsIWidget*
CompositorWidgetProxyWrapper::RealWidget()
{
  return mWidget;
}

already_AddRefed<CompositorVsyncDispatcher>
CompositorWidgetProxyWrapper::GetCompositorVsyncDispatcher()
{
  RefPtr<CompositorVsyncDispatcher> cvd = mWidget->GetCompositorVsyncDispatcher();
  return cvd.forget();
}

} // namespace widget
} // namespace mozilla