widget/CompositorWidget.cpp
author Henrik Skupin <mail@hskupin.info>
Tue, 01 Nov 2016 10:48:25 +0100
changeset 321556 e7aa936d8b6e3707a29665d9eb6623d21ff5deea
parent 305745 3fdb8ca3e6ffbd310daf342eb8febb1c17938dd0
child 329206 25254cf7bd3f3273e6d0a198e05e48dabb7c825c
permissions -rw-r--r--
Bug 1299216 - Wait for process exit first before checking for crashes. r=automatedtester MozReview-Commit-ID: 8U48dNHoFmi

/* 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 "CompositorWidget.h"
#include "GLConsts.h"
#include "nsBaseWidget.h"
#include "VsyncDispatcher.h"

namespace mozilla {
namespace widget {

CompositorWidget::~CompositorWidget()
{
}

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

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

already_AddRefed<gfx::DrawTarget>
CompositorWidget::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>
CompositorWidget::EndBackBufferDrawing()
{
  RefPtr<gfx::SourceSurface> surface = mLastBackBuffer ? mLastBackBuffer->Snapshot() : nullptr;
  return surface.forget();
}

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

RefPtr<VsyncObserver>
CompositorWidget::GetVsyncObserver() const
{
  // This should only used when the widget is in the GPU process, and should be
  // implemented by IPDL-enabled CompositorWidgets.
  // GPU process does not have a CompositorVsyncDispatcher.
  MOZ_ASSERT_UNREACHABLE("Must be implemented by derived class");
  return nullptr;
}

} // namespace widget
} // namespace mozilla