/* 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"namespacemozilla{namespacewidget{CompositorWidget::CompositorWidget(constlayers::CompositorOptions&aOptions):mOptions(aOptions){}CompositorWidget::~CompositorWidget(){}already_AddRefed<gfx::DrawTarget>CompositorWidget::StartRemoteDrawing(){returnnullptr;}voidCompositorWidget::CleanupRemoteDrawing(){mLastBackBuffer=nullptr;}already_AddRefed<gfx::DrawTarget>CompositorWidget::GetBackBufferDrawTarget(gfx::DrawTarget*aScreenTarget,constLayoutDeviceIntRect&aRect,constLayoutDeviceIntRect&aClearRect){MOZ_ASSERT(aScreenTarget);gfx::SurfaceFormatformat=aScreenTarget->GetFormat()==gfx::SurfaceFormat::B8G8R8X8?gfx::SurfaceFormat::B8G8R8X8:gfx::SurfaceFormat::B8G8R8A8;gfx::IntSizesize=aRect.ToUnknownRect().Size();gfx::IntSizeclientSize(GetClientSize().ToUnknownSize());RefPtr<gfx::DrawTarget>target;// Re-use back buffer if possibleif(mLastBackBuffer&&mLastBackBuffer->GetBackendType()==aScreenTarget->GetBackendType()&&mLastBackBuffer->GetFormat()==format&&size<=mLastBackBuffer->GetSize()&&mLastBackBuffer->GetSize()<=clientSize){target=mLastBackBuffer;target->SetTransform(gfx::Matrix());if(!aClearRect.IsEmpty()){gfx::IntRectclearRect=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;}returntarget.forget();}already_AddRefed<gfx::SourceSurface>CompositorWidget::EndBackBufferDrawing(){RefPtr<gfx::SourceSurface>surface=mLastBackBuffer?mLastBackBuffer->Snapshot():nullptr;returnsurface.forget();}uint32_tCompositorWidget::GetGLFrameBufferFormat(){returnLOCAL_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");returnnullptr;}}// namespace widget}// namespace mozilla