gecko-dev/gfx/layers/composite/PaintedLayerComposite.cpp

189 строки
5.1 KiB
C++
Исходник Обычный вид История

/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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 "PaintedLayerComposite.h"
#include "CompositableHost.h" // for TiledLayerProperties, etc
#include "FrameMetrics.h" // for FrameMetrics
#include "Units.h" // for CSSRect, LayerPixel, etc
#include "gfx2DGlue.h" // for ToMatrix4x4
#include "gfxUtils.h" // for gfxUtils, etc
#include "mozilla/Assertions.h" // for MOZ_ASSERT, etc
#include "mozilla/gfx/Matrix.h" // for Matrix4x4
#include "mozilla/gfx/Point.h" // for Point
#include "mozilla/gfx/Rect.h" // for RoundedToInt, Rect
#include "mozilla/gfx/Types.h" // for Filter::Filter::LINEAR
#include "mozilla/layers/Compositor.h" // for Compositor
#include "mozilla/layers/ContentHost.h" // for ContentHost
#include "mozilla/layers/Effects.h" // for EffectChain
#include "mozilla/mozalloc.h" // for operator delete
#include "nsAString.h"
#include "nsAutoPtr.h" // for nsRefPtr
#include "nsISupportsImpl.h" // for MOZ_COUNT_CTOR, etc
#include "nsMathUtils.h" // for NS_lround
#include "nsPoint.h" // for nsIntPoint
#include "nsRect.h" // for nsIntRect
#include "nsSize.h" // for nsIntSize
#include "nsString.h" // for nsAutoCString
#include "TextRenderer.h"
#include "GeckoProfiler.h"
namespace mozilla {
namespace layers {
class TiledLayerComposer;
PaintedLayerComposite::PaintedLayerComposite(LayerManagerComposite *aManager)
: PaintedLayer(aManager, nullptr)
, LayerComposite(aManager)
, mBuffer(nullptr)
{
MOZ_COUNT_CTOR(PaintedLayerComposite);
mImplData = static_cast<LayerComposite*>(this);
}
PaintedLayerComposite::~PaintedLayerComposite()
{
MOZ_COUNT_DTOR(PaintedLayerComposite);
CleanupResources();
}
bool
PaintedLayerComposite::SetCompositableHost(CompositableHost* aHost)
{
switch (aHost->GetType()) {
Bug 987311 - 5/6 - Convert the rest of CompositorTypes.h to typed enums, auto regex changes - r=nical find gfx/layers -type f | grep -v CompositorTypes.h | xargs sed -i 's/\(^\|[^A-Za-z0-9_]\)DIAGNOSTIC_\(NONE\|TILE_BORDERS\|LAYER_BORDERS\|BIGIMAGE_BORDERS\|FLASH_BORDERS\)\($\|[^A-Za-z0-9_]\)/\1DiagnosticTypes::\2\3/g' find gfx/layers -type f | grep -v CompositorTypes.h | xargs sed -i 's/DiagnosticTypes\:\:NONE/DiagosticTypes::NO_DIAGNOSTIC/g' find gfx/layers -type f | grep -v CompositorTypes.h | xargs sed -i 's/\(^\|[^A-Za-z0-9_]\)DIAGNOSTIC_\(IMAGE\|CONTENT\|CANVAS\|COLOR\|CONTAINER\|TILE\|BIGIMAGE\|COMPONENT_ALPHA\|REGION_RECT\)\($\|[^A-Za-z0-9_]\)/\1DiagnosticFlags::\2\3/g' find gfx/layers -type f | grep -v CompositorTypes.h | xargs sed -i 's/\(^\|[^A-Za-z0-9_]\)EFFECT_\(MASK\|MAX_SECONDARY\|RGB\|YCBCR\|COMPONENT_ALPHA\|SOLID_COLOR\|RENDER_TARGET\|MAX\)\($\|[^A-Za-z0-9_]\)/\1EffectTypes::\2\3/g' find gfx/layers -type f | grep -v CompositorTypes.h | xargs sed -i 's/\(^\|[^A-Za-z0-9_]\)TEXTURE_\(CONTENT\|SHMEM\|YCBCR\|SHARED_GL\|SHARED_GL_EXTERNAL\|STREAM_GL\|FALLBACK\)\($\|[^A-Za-z0-9_]\)/\1DeprecatedTextureClientType::\2\3/g' find gfx/layers -type f | grep -v CompositorTypes.h | xargs sed -i 's/\(^\|[^A-Za-z0-9_]\)\(BUFFER_UNKNOWN\|BUFFER_IMAGE_SINGLE\|BUFFER_IMAGE_BUFFERED\|BUFFER_BRIDGE\|BUFFER_CONTENT\|BUFFER_CONTENT_DIRECT\|BUFFER_CONTENT_INC\|BUFFER_TILED\|BUFFER_SIMPLE_TILED\|COMPOSITABLE_IMAGE\|COMPOSITABLE_CONTENT_SINGLE\|COMPOSITABLE_CONTENT_DOUBLE\|BUFFER_COUNT\)\($\|[^A-Za-z0-9_]\)/\1CompositableType::\2\3/g' find gfx/layers -type f | grep -v CompositorTypes.h | xargs sed -i 's/CompositableType\:\:COMPOSITABLE_/CompositableType::/g' find gfx/layers -type f | grep -v CompositorTypes.h | xargs sed -i 's/\(^\|[^A-Za-z0-9_]\)TEXTURE_HOST_\(DEFAULT\|TILED\|COPY_PREVIOUS\)\($\|[^A-Za-z0-9_]\)/\1DeprecatedTextureHostFlags::\2\3/g' find gfx/layers -type f | grep -v CompositorTypes.h | xargs sed -i 's/\(^\|[^A-Za-z0-9_]\)Texture\(Front\|Back\|OnWhiteFront\|OnWhiteBack\)\($\|[^A-Za-z0-9_]\)/\1TextureIdentifier::\2\3/g' find gfx/layers -type f | grep -v CompositorTypes.h | xargs sed -i 's/\(^\|[^A-Za-z0-9_]\)\(OPEN_NONE\|OPEN_READ\|OPEN_WRITE\|OPEN_READ_WRITE\|OPEN_READ_ONLY\|OPEN_WRITE_ONLY\)\($\|[^A-Za-z0-9_]\)/\1OpenMode::\2\3/g' find gfx/layers -type f | grep -v CompositorTypes.h | xargs sed -i 's/\(^\|[^A-Za-z0-9_]\)\(MaskNone\|Mask2d\|Mask3d\|NumMaskTypes\)\($\|[^A-Za-z0-9_]\)/\1MaskType::\2\3/g' find gfx -type f | xargs sed -i 's/Diagostic/Diagnostic/g'
2014-04-26 06:34:06 +04:00
case CompositableType::BUFFER_CONTENT_INC:
case CompositableType::BUFFER_TILED:
case CompositableType::CONTENT_SINGLE:
case CompositableType::CONTENT_DOUBLE:
mBuffer = static_cast<ContentHost*>(aHost);
return true;
default:
return false;
}
}
void
PaintedLayerComposite::Disconnect()
{
Destroy();
}
void
PaintedLayerComposite::Destroy()
{
if (!mDestroyed) {
CleanupResources();
mDestroyed = true;
}
}
Layer*
PaintedLayerComposite::GetLayer()
{
return this;
}
TiledLayerComposer*
PaintedLayerComposite::GetTiledLayerComposer()
{
if (!mBuffer) {
return nullptr;
}
MOZ_ASSERT(mBuffer->IsAttached());
return mBuffer->AsTiledLayerComposer();
}
LayerRenderState
PaintedLayerComposite::GetRenderState()
{
if (!mBuffer || !mBuffer->IsAttached() || mDestroyed) {
return LayerRenderState();
}
return mBuffer->GetRenderState();
}
void
PaintedLayerComposite::RenderLayer(const nsIntRect& aClipRect)
{
if (!mBuffer || !mBuffer->IsAttached()) {
return;
}
PROFILER_LABEL("PaintedLayerComposite", "RenderLayer",
js::ProfileEntry::Category::GRAPHICS);
MOZ_ASSERT(mBuffer->GetCompositor() == mCompositeManager->GetCompositor() &&
mBuffer->GetLayer() == this,
"buffer is corrupted");
const nsIntRegion& visibleRegion = GetEffectiveVisibleRegion();
gfx::Rect clipRect(aClipRect.x, aClipRect.y, aClipRect.width, aClipRect.height);
#ifdef MOZ_DUMP_PAINTING
if (gfxUtils::sDumpPainting) {
RefPtr<gfx::DataSourceSurface> surf = mBuffer->GetAsSurface();
if (surf) {
WriteSnapshotToDumpFile(this, surf);
}
}
#endif
EffectChain effectChain(this);
LayerManagerComposite::AutoAddMaskEffect autoMaskEffect(mMaskLayer, effectChain);
AddBlendModeEffect(effectChain);
mBuffer->SetPaintWillResample(MayResample());
mBuffer->Composite(effectChain,
GetEffectiveOpacity(),
GetEffectiveTransform(),
GetEffectFilter(),
clipRect,
&visibleRegion);
mBuffer->BumpFlashCounter();
mCompositeManager->GetCompositor()->MakeCurrent();
}
CompositableHost*
PaintedLayerComposite::GetCompositableHost()
{
if (mBuffer && mBuffer->IsAttached()) {
return mBuffer.get();
}
return nullptr;
}
void
PaintedLayerComposite::CleanupResources()
{
if (mBuffer) {
mBuffer->Detach(this);
}
mBuffer = nullptr;
}
void
PaintedLayerComposite::GenEffectChain(EffectChain& aEffect)
{
aEffect.mLayerRef = this;
aEffect.mPrimaryEffect = mBuffer->GenEffect(GetEffectFilter());
}
void
PaintedLayerComposite::PrintInfo(std::stringstream& aStream, const char* aPrefix)
{
PaintedLayer::PrintInfo(aStream, aPrefix);
if (mBuffer && mBuffer->IsAttached()) {
aStream << "\n";
nsAutoCString pfx(aPrefix);
pfx += " ";
mBuffer->PrintInfo(aStream, pfx.get());
}
}
} /* layers */
} /* mozilla */