2013-05-01 09:03:25 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; 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/. */
|
|
|
|
|
2015-06-05 02:50:59 +03:00
|
|
|
#include "CopyableCanvasLayer.h"
|
2015-06-05 03:15:38 +03:00
|
|
|
|
|
|
|
#include "BasicLayersImpl.h" // for FillWithMask, etc
|
2013-08-12 03:17:23 +04:00
|
|
|
#include "GLContext.h" // for GLContext
|
|
|
|
#include "GLScreenBuffer.h" // for GLScreenBuffer
|
|
|
|
#include "SharedSurface.h" // for SharedSurface
|
2014-07-12 02:10:49 +04:00
|
|
|
#include "SharedSurfaceGL.h" // for SharedSurface
|
2013-08-12 03:17:23 +04:00
|
|
|
#include "gfxPattern.h" // for gfxPattern, etc
|
|
|
|
#include "gfxPlatform.h" // for gfxPlatform, gfxImageFormat
|
|
|
|
#include "gfxRect.h" // for gfxRect
|
|
|
|
#include "gfxUtils.h" // for gfxUtils
|
2013-12-20 20:46:28 +04:00
|
|
|
#include "gfx2DGlue.h" // for thebes --> moz2d transition
|
2013-08-12 03:17:23 +04:00
|
|
|
#include "mozilla/gfx/BaseSize.h" // for BaseSize
|
2014-05-13 06:20:27 +04:00
|
|
|
#include "mozilla/gfx/Tools.h"
|
2015-05-29 18:01:46 +03:00
|
|
|
#include "mozilla/gfx/Point.h" // for IntSize
|
2016-03-14 18:39:12 +03:00
|
|
|
#include "mozilla/layers/AsyncCanvasRenderer.h"
|
2015-06-19 02:07:21 +03:00
|
|
|
#include "mozilla/layers/PersistentBufferProvider.h"
|
2013-08-12 03:17:23 +04:00
|
|
|
#include "nsDebug.h" // for NS_ASSERTION, NS_WARNING, etc
|
|
|
|
#include "nsISupportsImpl.h" // for gfxContext::AddRef, etc
|
2015-05-07 12:07:53 +03:00
|
|
|
#include "nsRect.h" // for mozilla::gfx::IntRect
|
2014-05-13 06:20:26 +04:00
|
|
|
#include "gfxUtils.h"
|
2015-06-05 03:15:38 +03:00
|
|
|
#include "client/TextureClientSharedSurface.h"
|
2013-05-01 09:03:25 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace layers {
|
|
|
|
|
2014-05-22 14:11:45 +04:00
|
|
|
using namespace mozilla::gfx;
|
|
|
|
using namespace mozilla::gl;
|
|
|
|
|
2013-09-07 06:11:41 +04:00
|
|
|
CopyableCanvasLayer::CopyableCanvasLayer(LayerManager* aLayerManager, void *aImplData) :
|
|
|
|
CanvasLayer(aLayerManager, aImplData)
|
2014-10-08 08:15:39 +04:00
|
|
|
, mGLFrontbuffer(nullptr)
|
2014-06-19 04:04:06 +04:00
|
|
|
, mIsAlphaPremultiplied(true)
|
2014-11-18 04:02:19 +03:00
|
|
|
, mOriginPos(gl::OriginPos::TopLeft)
|
2016-07-04 23:11:07 +03:00
|
|
|
, mIsMirror(false)
|
2013-09-07 06:11:41 +04:00
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(CopyableCanvasLayer);
|
|
|
|
}
|
|
|
|
|
|
|
|
CopyableCanvasLayer::~CopyableCanvasLayer()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(CopyableCanvasLayer);
|
|
|
|
}
|
|
|
|
|
2013-05-01 09:03:25 +04:00
|
|
|
void
|
|
|
|
CopyableCanvasLayer::Initialize(const Data& aData)
|
|
|
|
{
|
2014-02-06 18:46:30 +04:00
|
|
|
if (aData.mGLContext) {
|
2013-05-01 09:03:25 +04:00
|
|
|
mGLContext = aData.mGLContext;
|
2014-06-19 04:04:06 +04:00
|
|
|
mIsAlphaPremultiplied = aData.mIsGLAlphaPremult;
|
2014-11-18 04:02:19 +03:00
|
|
|
mOriginPos = gl::OriginPos::BottomLeft;
|
2016-07-04 23:11:07 +03:00
|
|
|
mIsMirror = aData.mIsMirror;
|
2014-11-18 04:02:19 +03:00
|
|
|
|
2013-05-01 09:03:25 +04:00
|
|
|
MOZ_ASSERT(mGLContext->IsOffscreen(), "canvas gl context isn't offscreen");
|
|
|
|
|
2014-10-08 08:15:39 +04:00
|
|
|
if (aData.mFrontbufferGLTex) {
|
|
|
|
gfx::IntSize size(aData.mSize.width, aData.mSize.height);
|
2015-06-05 03:15:38 +03:00
|
|
|
mGLFrontbuffer = SharedSurface_Basic::Wrap(aData.mGLContext, size, aData.mHasAlpha,
|
|
|
|
aData.mFrontbufferGLTex);
|
2015-10-20 11:35:00 +03:00
|
|
|
mBufferProvider = aData.mBufferProvider;
|
2014-10-08 08:15:39 +04:00
|
|
|
}
|
2015-06-19 02:07:21 +03:00
|
|
|
} else if (aData.mBufferProvider) {
|
|
|
|
mBufferProvider = aData.mBufferProvider;
|
2015-10-12 06:21:03 +03:00
|
|
|
} else if (aData.mRenderer) {
|
|
|
|
mAsyncRenderer = aData.mRenderer;
|
|
|
|
mOriginPos = gl::OriginPos::BottomLeft;
|
2013-05-01 09:03:25 +04:00
|
|
|
} else {
|
2016-07-29 21:19:28 +03:00
|
|
|
MOZ_CRASH("GFX: CanvasLayer created without BufferProvider, DrawTarget or GLContext?");
|
2013-05-01 09:03:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
mBounds.SetRect(0, 0, aData.mSize.width, aData.mSize.height);
|
|
|
|
}
|
|
|
|
|
2013-12-05 02:46:20 +04:00
|
|
|
bool
|
|
|
|
CopyableCanvasLayer::IsDataValid(const Data& aData)
|
|
|
|
{
|
2014-10-08 08:15:39 +04:00
|
|
|
return mGLContext == aData.mGLContext;
|
2013-12-05 02:46:20 +04:00
|
|
|
}
|
|
|
|
|
2014-02-12 19:07:46 +04:00
|
|
|
DataSourceSurface*
|
|
|
|
CopyableCanvasLayer::GetTempSurface(const IntSize& aSize,
|
|
|
|
const SurfaceFormat aFormat)
|
2013-09-25 00:45:14 +04:00
|
|
|
{
|
|
|
|
if (!mCachedTempSurface ||
|
2014-05-01 03:12:41 +04:00
|
|
|
aSize != mCachedTempSurface->GetSize() ||
|
|
|
|
aFormat != mCachedTempSurface->GetFormat())
|
2013-09-25 00:45:14 +04:00
|
|
|
{
|
2014-05-13 06:20:27 +04:00
|
|
|
// Create a surface aligned to 8 bytes since that's the highest alignment WebGL can handle.
|
2016-08-25 20:57:39 +03:00
|
|
|
uint32_t stride = GetAlignedStride<8>(aSize.width, BytesPerPixel(aFormat));
|
2014-05-13 06:20:27 +04:00
|
|
|
mCachedTempSurface = Factory::CreateDataSourceSurfaceWithStride(aSize, aFormat, stride);
|
2013-09-25 00:45:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return mCachedTempSurface;
|
|
|
|
}
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace layers
|
|
|
|
} // namespace mozilla
|