2015-07-29 19:02:40 +03:00
|
|
|
/* -*- 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 "mozilla/layers/SingleTiledContentClient.h"
|
|
|
|
|
2015-12-14 23:09:17 +03:00
|
|
|
#include "ClientTiledPaintedLayer.h"
|
2015-07-29 19:02:40 +03:00
|
|
|
|
2015-12-14 23:09:17 +03:00
|
|
|
namespace mozilla {
|
2015-07-29 19:02:40 +03:00
|
|
|
namespace layers {
|
|
|
|
|
|
|
|
|
|
|
|
SingleTiledContentClient::SingleTiledContentClient(ClientTiledPaintedLayer* aPaintedLayer,
|
|
|
|
ClientLayerManager* aManager)
|
2015-09-14 18:02:11 +03:00
|
|
|
: TiledContentClient(aManager, "Single")
|
2015-07-29 19:02:40 +03:00
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(SingleTiledContentClient);
|
|
|
|
|
|
|
|
mTiledBuffer = new ClientSingleTiledLayerBuffer(aPaintedLayer, this, aManager);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SingleTiledContentClient::ClearCachedResources()
|
|
|
|
{
|
|
|
|
CompositableClient::ClearCachedResources();
|
|
|
|
mTiledBuffer->DiscardBuffers();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SingleTiledContentClient::UpdatedBuffer(TiledBufferType aType)
|
|
|
|
{
|
|
|
|
mForwarder->UseTiledLayerBuffer(this, mTiledBuffer->GetSurfaceDescriptorTiles());
|
|
|
|
mTiledBuffer->ClearPaintedRegion();
|
|
|
|
}
|
|
|
|
|
2015-09-23 13:26:56 +03:00
|
|
|
/* static */ bool
|
2015-12-14 23:09:17 +03:00
|
|
|
SingleTiledContentClient::ClientSupportsLayerSize(const gfx::IntSize& aSize, ClientLayerManager* aManager)
|
2015-09-23 13:26:56 +03:00
|
|
|
{
|
|
|
|
int32_t maxTextureSize = aManager->GetMaxTextureSize();
|
|
|
|
return aSize.width <= maxTextureSize && aSize.height <= maxTextureSize;
|
|
|
|
}
|
|
|
|
|
2015-07-29 19:02:40 +03:00
|
|
|
ClientSingleTiledLayerBuffer::ClientSingleTiledLayerBuffer(ClientTiledPaintedLayer* aPaintedLayer,
|
|
|
|
CompositableClient* aCompositableClient,
|
|
|
|
ClientLayerManager* aManager)
|
|
|
|
: ClientTiledLayerBuffer(aPaintedLayer, aCompositableClient)
|
|
|
|
, mManager(aManager)
|
2015-09-04 23:21:37 +03:00
|
|
|
, mWasLastPaintProgressive(false)
|
2016-01-19 22:14:22 +03:00
|
|
|
, mFormat(gfx::SurfaceFormat::UNKNOWN)
|
2015-07-29 19:02:40 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ClientSingleTiledLayerBuffer::ReleaseTiles()
|
|
|
|
{
|
|
|
|
if (!mTile.IsPlaceholderTile()) {
|
|
|
|
mTile.DiscardBuffers();
|
|
|
|
}
|
|
|
|
mTile.SetTextureAllocator(nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ClientSingleTiledLayerBuffer::DiscardBuffers()
|
|
|
|
{
|
|
|
|
if (!mTile.IsPlaceholderTile()) {
|
|
|
|
mTile.DiscardFrontBuffer();
|
|
|
|
mTile.DiscardBackBuffer();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SurfaceDescriptorTiles
|
|
|
|
ClientSingleTiledLayerBuffer::GetSurfaceDescriptorTiles()
|
|
|
|
{
|
|
|
|
InfallibleTArray<TileDescriptor> tiles;
|
|
|
|
|
|
|
|
TileDescriptor tileDesc = mTile.GetTileDescriptor();
|
|
|
|
tiles.AppendElement(tileDesc);
|
2015-12-14 23:09:17 +03:00
|
|
|
mTile.mUpdateRect = gfx::IntRect();
|
2015-07-29 19:02:40 +03:00
|
|
|
|
|
|
|
return SurfaceDescriptorTiles(mValidRegion,
|
|
|
|
tiles,
|
|
|
|
mTilingOrigin,
|
|
|
|
mSize,
|
|
|
|
0, 0, 1, 1,
|
|
|
|
1.0,
|
|
|
|
mFrameResolution.xScale,
|
2015-09-04 23:21:37 +03:00
|
|
|
mFrameResolution.yScale,
|
|
|
|
mWasLastPaintProgressive);
|
2015-07-29 19:02:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<TextureClient>
|
|
|
|
ClientSingleTiledLayerBuffer::GetTextureClient()
|
|
|
|
{
|
2016-01-19 22:14:22 +03:00
|
|
|
MOZ_ASSERT(mFormat != gfx::SurfaceFormat::UNKNOWN);
|
2015-07-29 19:02:40 +03:00
|
|
|
return mCompositableClient->CreateTextureClientForDrawing(
|
2015-08-07 03:27:36 +03:00
|
|
|
gfx::ImageFormatToSurfaceFormat(mFormat), mSize, BackendSelector::Content,
|
2015-10-14 09:02:44 +03:00
|
|
|
TextureFlags::DISALLOW_BIGIMAGE | TextureFlags::IMMEDIATE_UPLOAD);
|
2015-07-29 19:02:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ClientSingleTiledLayerBuffer::PaintThebes(const nsIntRegion& aNewValidRegion,
|
|
|
|
const nsIntRegion& aPaintRegion,
|
|
|
|
const nsIntRegion& aDirtyRegion,
|
|
|
|
LayerManager::DrawPaintedLayerCallback aCallback,
|
2015-09-04 23:21:37 +03:00
|
|
|
void* aCallbackData,
|
|
|
|
bool aIsProgressive)
|
2015-07-29 19:02:40 +03:00
|
|
|
{
|
2015-09-04 23:21:37 +03:00
|
|
|
mWasLastPaintProgressive = aIsProgressive;
|
|
|
|
|
2015-11-17 01:36:38 +03:00
|
|
|
// Compare layer valid region size to current backbuffer size, discard if not matching.
|
2015-12-14 23:09:17 +03:00
|
|
|
gfx::IntSize size = aNewValidRegion.GetBounds().Size();
|
|
|
|
gfx::IntPoint origin = aNewValidRegion.GetBounds().TopLeft();
|
2015-07-29 19:02:40 +03:00
|
|
|
nsIntRegion paintRegion = aPaintRegion;
|
|
|
|
if (mSize != size ||
|
|
|
|
mTilingOrigin != origin) {
|
|
|
|
ResetPaintedAndValidState();
|
|
|
|
mSize = size;
|
|
|
|
mTilingOrigin = origin;
|
|
|
|
paintRegion = aNewValidRegion;
|
|
|
|
}
|
|
|
|
|
|
|
|
SurfaceMode mode;
|
|
|
|
gfxContentType content = GetContentType(&mode);
|
|
|
|
mFormat = gfxPlatform::GetPlatform()->OptimalFormatForContent(content);
|
|
|
|
|
|
|
|
if (mTile.IsPlaceholderTile()) {
|
|
|
|
mTile.SetLayerManager(mManager);
|
|
|
|
mTile.SetTextureAllocator(this);
|
|
|
|
}
|
|
|
|
mTile.SetCompositableClient(mCompositableClient);
|
|
|
|
|
|
|
|
// The dirty region relative to the top-left of the tile.
|
|
|
|
nsIntRegion tileDirtyRegion = paintRegion.MovedBy(-mTilingOrigin);
|
|
|
|
|
|
|
|
nsIntRegion extraPainted;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<TextureClient> backBufferOnWhite;
|
|
|
|
RefPtr<TextureClient> backBuffer =
|
2015-07-29 19:02:40 +03:00
|
|
|
mTile.GetBackBuffer(tileDirtyRegion,
|
|
|
|
content, mode,
|
|
|
|
extraPainted,
|
|
|
|
&backBufferOnWhite);
|
|
|
|
|
|
|
|
mTile.mUpdateRect = tileDirtyRegion.GetBounds().Union(extraPainted.GetBounds());
|
|
|
|
|
|
|
|
extraPainted.MoveBy(mTilingOrigin);
|
|
|
|
extraPainted.And(extraPainted, aNewValidRegion);
|
|
|
|
mPaintedRegion.OrWith(paintRegion);
|
|
|
|
mPaintedRegion.OrWith(extraPainted);
|
|
|
|
|
|
|
|
if (!backBuffer) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-12-14 23:09:17 +03:00
|
|
|
RefPtr<gfx::DrawTarget> dt = backBuffer->BorrowDrawTarget();
|
|
|
|
RefPtr<gfx::DrawTarget> dtOnWhite;
|
2015-07-29 19:02:40 +03:00
|
|
|
if (backBufferOnWhite) {
|
|
|
|
dtOnWhite = backBufferOnWhite->BorrowDrawTarget();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mode != SurfaceMode::SURFACE_OPAQUE) {
|
2016-01-19 04:20:58 +03:00
|
|
|
for (auto iter = tileDirtyRegion.RectIter(); !iter.Done(); iter.Next()) {
|
|
|
|
const gfx::IntRect& rect = iter.Get();
|
2015-07-29 19:02:40 +03:00
|
|
|
if (dtOnWhite) {
|
2016-01-19 04:20:58 +03:00
|
|
|
dt->FillRect(gfx::Rect(rect.x, rect.y, rect.width, rect.height),
|
2015-12-14 23:09:17 +03:00
|
|
|
gfx::ColorPattern(gfx::Color(0.0, 0.0, 0.0, 1.0)));
|
2016-01-19 04:20:58 +03:00
|
|
|
dtOnWhite->FillRect(gfx::Rect(rect.x, rect.y, rect.width, rect.height),
|
2015-12-14 23:09:17 +03:00
|
|
|
gfx::ColorPattern(gfx::Color(1.0, 1.0, 1.0, 1.0)));
|
2015-07-29 19:02:40 +03:00
|
|
|
} else {
|
2016-01-19 04:20:58 +03:00
|
|
|
dt->ClearRect(gfx::Rect(rect.x, rect.y, rect.width, rect.height));
|
2015-07-29 19:02:40 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dtOnWhite) {
|
2015-12-14 23:09:17 +03:00
|
|
|
dt = gfx::Factory::CreateDualDrawTarget(dt, dtOnWhite);
|
2015-07-29 19:02:40 +03:00
|
|
|
dtOnWhite = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2016-06-07 02:39:56 +03:00
|
|
|
RefPtr<gfxContext> ctx = gfxContext::CreateOrNull(dt);
|
2016-04-12 22:18:11 +03:00
|
|
|
if (!ctx) {
|
2016-05-03 22:04:06 +03:00
|
|
|
gfxDevCrash(gfx::LogReason::InvalidContext) << "SingleTiledContextClient context problem " << gfx::hexa(dt);
|
2016-04-12 22:18:11 +03:00
|
|
|
return;
|
|
|
|
}
|
2015-07-29 19:02:40 +03:00
|
|
|
ctx->SetMatrix(ctx->CurrentMatrix().Translate(-mTilingOrigin.x, -mTilingOrigin.y));
|
|
|
|
|
2015-09-15 16:41:42 +03:00
|
|
|
aCallback(mPaintedLayer, ctx, paintRegion, paintRegion, DrawRegionClip::DRAW, nsIntRegion(), aCallbackData);
|
2015-07-29 19:02:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Mark the area we just drew into the back buffer as invalid in the front buffer as they're
|
|
|
|
// now out of sync.
|
2015-08-01 00:03:58 +03:00
|
|
|
mTile.mInvalidFront.OrWith(tileDirtyRegion);
|
2015-07-29 19:02:40 +03:00
|
|
|
|
|
|
|
// The new buffer is now validated, remove the dirty region from it.
|
|
|
|
mTile.mInvalidBack.SubOut(tileDirtyRegion);
|
|
|
|
|
|
|
|
dt = nullptr;
|
|
|
|
|
|
|
|
mTile.Flip();
|
|
|
|
UnlockTile(mTile);
|
|
|
|
|
2016-02-25 16:15:58 +03:00
|
|
|
if (backBuffer->HasIntermediateBuffer()) {
|
2015-07-29 19:02:40 +03:00
|
|
|
// If our new buffer has an internal buffer, we don't want to keep another
|
|
|
|
// TextureClient around unnecessarily, so discard the back-buffer.
|
|
|
|
mTile.DiscardBackBuffer();
|
|
|
|
}
|
|
|
|
|
|
|
|
mValidRegion = aNewValidRegion;
|
|
|
|
mLastPaintSurfaceMode = mode;
|
|
|
|
mLastPaintContentType = content;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace layers
|
|
|
|
} // namespace mozilla
|