2017-10-28 02:10:06 +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
|
2016-09-21 12:24:44 +03:00
|
|
|
* 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/. */
|
|
|
|
|
|
|
|
#ifndef GFX_GPU_VIDEO_IMAGE_H
|
|
|
|
#define GFX_GPU_VIDEO_IMAGE_H
|
|
|
|
|
|
|
|
#include "mozilla/RefPtr.h"
|
|
|
|
#include "ImageContainer.h"
|
|
|
|
#include "mozilla/layers/GPUVideoTextureClient.h"
|
|
|
|
#include "mozilla/layers/CompositableClient.h"
|
|
|
|
#include "mozilla/layers/ImageBridgeChild.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
2016-11-02 23:55:07 +03:00
|
|
|
namespace dom {
|
2019-06-11 05:01:34 +03:00
|
|
|
class RemoteDecoderManagerChild;
|
2016-11-02 23:55:07 +03:00
|
|
|
}
|
2017-07-18 05:17:41 +03:00
|
|
|
namespace gl {
|
|
|
|
class GLBlitHelper;
|
|
|
|
}
|
2016-09-21 12:24:44 +03:00
|
|
|
namespace layers {
|
|
|
|
|
|
|
|
// Image class that refers to a decoded video frame within
|
|
|
|
// the GPU process.
|
2017-11-30 21:03:02 +03:00
|
|
|
class GPUVideoImage final : public Image {
|
2017-07-18 05:17:41 +03:00
|
|
|
friend class gl::GLBlitHelper;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-09-21 12:24:44 +03:00
|
|
|
public:
|
2019-06-11 05:01:34 +03:00
|
|
|
GPUVideoImage(RemoteDecoderManagerChild* aManager,
|
2016-11-02 23:55:07 +03:00
|
|
|
const SurfaceDescriptorGPUVideo& aSD, const gfx::IntSize& aSize)
|
2016-09-21 12:24:44 +03:00
|
|
|
: Image(nullptr, ImageFormat::GPU_VIDEO), mSize(aSize) {
|
|
|
|
// Create the TextureClient immediately since the GPUVideoTextureData
|
|
|
|
// is responsible for deallocating the SurfaceDescriptor.
|
2016-11-02 23:57:18 +03:00
|
|
|
//
|
|
|
|
// Use the RECYCLE texture flag, since it's likely that our 'real'
|
|
|
|
// TextureData (in the decoder thread of the GPU process) is using
|
|
|
|
// it too, and we want to make sure we don't send the delete message
|
|
|
|
// until we've stopped being used on the compositor.
|
2016-11-02 23:55:07 +03:00
|
|
|
mTextureClient = TextureClient::CreateWithData(
|
|
|
|
new GPUVideoTextureData(aManager, aSD, aSize), TextureFlags::RECYCLE,
|
2016-09-21 12:24:44 +03:00
|
|
|
ImageBridgeChild::GetSingleton().get());
|
|
|
|
}
|
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
virtual ~GPUVideoImage() = default;
|
2016-09-21 12:24:44 +03:00
|
|
|
|
2017-11-30 21:03:02 +03:00
|
|
|
gfx::IntSize GetSize() const override { return mSize; }
|
2016-09-21 12:24:44 +03:00
|
|
|
|
2017-07-18 05:17:41 +03:00
|
|
|
private:
|
2017-11-30 21:03:02 +03:00
|
|
|
GPUVideoTextureData* GetData() const {
|
2017-07-18 05:17:41 +03:00
|
|
|
if (!mTextureClient) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2018-09-25 00:11:00 +03:00
|
|
|
TextureData* data = mTextureClient->GetInternalData();
|
|
|
|
if (!data) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return data->AsGPUVideoTextureData();
|
2017-07-18 05:17:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
2017-11-30 21:03:02 +03:00
|
|
|
already_AddRefed<gfx::SourceSurface> GetAsSourceSurface() override {
|
2017-07-18 05:17:41 +03:00
|
|
|
GPUVideoTextureData* data = GetData();
|
|
|
|
if (!data) {
|
2016-11-04 03:28:28 +03:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return data->GetAsSourceSurface();
|
|
|
|
}
|
2016-09-21 12:24:44 +03:00
|
|
|
|
2019-06-07 15:27:05 +03:00
|
|
|
TextureClient* GetTextureClient(KnowsCompositor* aKnowsCompositor) override {
|
|
|
|
MOZ_ASSERT(aKnowsCompositor == ImageBridgeChild::GetSingleton(),
|
2016-09-23 00:43:11 +03:00
|
|
|
"Must only use GPUVideo on ImageBridge");
|
2016-09-21 12:24:44 +03:00
|
|
|
return mTextureClient;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
gfx::IntSize mSize;
|
|
|
|
RefPtr<TextureClient> mTextureClient;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace layers
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // GFX_GPU_VIDEO_IMAGE_H
|