2017-10-28 01:55:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* 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/. */
|
2014-10-21 17:53:02 +04:00
|
|
|
|
|
|
|
#include "GLImages.h"
|
|
|
|
#include "GLContext.h"
|
|
|
|
#include "GLContextProvider.h"
|
|
|
|
#include "ScopedGLHelpers.h"
|
|
|
|
#include "GLImages.h"
|
|
|
|
#include "GLBlitHelper.h"
|
|
|
|
#include "GLReadTexImageHelper.h"
|
2014-11-27 00:16:07 +03:00
|
|
|
#include "GLLibraryEGL.h"
|
2014-10-21 17:53:02 +04:00
|
|
|
|
2016-03-05 18:20:47 +03:00
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::gl;
|
|
|
|
|
2014-10-21 17:53:02 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace layers {
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
static RefPtr<GLContext> sSnapshotContext;
|
2014-10-21 17:53:02 +04:00
|
|
|
|
2015-06-17 17:00:52 +03:00
|
|
|
already_AddRefed<gfx::SourceSurface> GLImage::GetAsSourceSurface() {
|
2014-10-21 17:53:02 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread(), "Should be on the main thread");
|
|
|
|
|
|
|
|
if (!sSnapshotContext) {
|
2016-06-06 23:52:42 +03:00
|
|
|
nsCString discardFailureId;
|
|
|
|
sSnapshotContext = GLContextProvider::CreateHeadless(
|
|
|
|
CreateContextFlags::NONE, &discardFailureId);
|
2014-10-21 17:53:02 +04:00
|
|
|
if (!sSnapshotContext) {
|
2014-11-27 00:16:08 +03:00
|
|
|
NS_WARNING("Failed to create snapshot GLContext");
|
2014-10-21 17:53:02 +04:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sSnapshotContext->MakeCurrent();
|
|
|
|
ScopedTexture scopedTex(sSnapshotContext);
|
|
|
|
ScopedBindTexture boundTex(sSnapshotContext, scopedTex.Texture());
|
2014-11-27 00:16:08 +03:00
|
|
|
|
|
|
|
gfx::IntSize size = GetSize();
|
2014-10-21 17:53:02 +04:00
|
|
|
sSnapshotContext->fTexImage2D(LOCAL_GL_TEXTURE_2D, 0, LOCAL_GL_RGBA,
|
2014-11-27 00:16:08 +03:00
|
|
|
size.width, size.height, 0, LOCAL_GL_RGBA,
|
2014-10-21 17:53:02 +04:00
|
|
|
LOCAL_GL_UNSIGNED_BYTE, nullptr);
|
|
|
|
|
2015-04-21 03:49:25 +03:00
|
|
|
ScopedFramebufferForTexture autoFBForTex(sSnapshotContext,
|
|
|
|
scopedTex.Texture());
|
|
|
|
if (!autoFBForTex.IsComplete()) {
|
2016-10-11 22:01:08 +03:00
|
|
|
gfxCriticalError()
|
|
|
|
<< "GetAsSourceSurface: ScopedFramebufferForTexture failed.";
|
|
|
|
return nullptr;
|
2015-04-21 03:49:25 +03:00
|
|
|
}
|
2014-10-21 17:53:02 +04:00
|
|
|
|
2015-04-21 03:49:25 +03:00
|
|
|
const gl::OriginPos destOrigin = gl::OriginPos::TopLeft;
|
|
|
|
{
|
2017-07-18 05:17:41 +03:00
|
|
|
const ScopedBindFramebuffer bindFB(sSnapshotContext, autoFBForTex.FB());
|
|
|
|
if (!sSnapshotContext->BlitHelper()->BlitImageToFramebuffer(this, size,
|
|
|
|
destOrigin)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2015-02-03 00:25:22 +03:00
|
|
|
}
|
2014-10-21 17:53:02 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<gfx::DataSourceSurface> source =
|
2014-11-27 00:16:08 +03:00
|
|
|
gfx::Factory::CreateDataSourceSurface(size, gfx::SurfaceFormat::B8G8R8A8);
|
2014-10-21 17:53:02 +04:00
|
|
|
if (NS_WARN_IF(!source)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-04-21 03:49:25 +03:00
|
|
|
ScopedBindFramebuffer bind(sSnapshotContext, autoFBForTex.FB());
|
2014-10-21 17:53:02 +04:00
|
|
|
ReadPixelsIntoDataSurface(sSnapshotContext, source);
|
|
|
|
return source.forget();
|
|
|
|
}
|
|
|
|
|
2015-11-17 11:09:00 +03:00
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
2017-03-04 00:14:27 +03:00
|
|
|
SurfaceTextureImage::SurfaceTextureImage(AndroidSurfaceTextureHandle aHandle,
|
2015-11-17 11:09:00 +03:00
|
|
|
const gfx::IntSize& aSize,
|
2017-03-10 02:50:21 +03:00
|
|
|
bool aContinuous,
|
2019-04-10 11:08:22 +03:00
|
|
|
gl::OriginPos aOriginPos,
|
|
|
|
bool aHasAlpha /* = true */)
|
2015-11-17 11:09:00 +03:00
|
|
|
: GLImage(ImageFormat::SURFACE_TEXTURE),
|
2017-03-04 00:14:27 +03:00
|
|
|
mHandle(aHandle),
|
2015-11-17 11:09:00 +03:00
|
|
|
mSize(aSize),
|
2017-03-10 02:50:21 +03:00
|
|
|
mContinuous(aContinuous),
|
2019-04-10 11:08:22 +03:00
|
|
|
mOriginPos(aOriginPos),
|
|
|
|
mHasAlpha(aHasAlpha) {
|
2017-03-04 00:14:27 +03:00
|
|
|
MOZ_ASSERT(mHandle);
|
2015-11-17 11:09:00 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace layers
|
|
|
|
} // namespace mozilla
|