本文整理汇总了C++中Image::AsSharedImage方法的典型用法代码示例。如果您正苦于以下问题:C++ Image::AsSharedImage方法的具体用法?C++ Image::AsSharedImage怎么用?C++ Image::AsSharedImage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Image
的用法示例。
在下文中一共展示了Image::AsSharedImage方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: autoLock
bool
ImageClientSingle::UpdateImageInternal(ImageContainer* aContainer,
uint32_t aContentFlags, bool* aIsSwapped)
{
AutoLockImage autoLock(aContainer);
*aIsSwapped = false;
Image *image = autoLock.GetImage();
if (!image) {
return false;
}
if (mLastPaintedImageSerial == image->GetSerial()) {
return true;
}
if (image->AsSharedImage() && image->AsSharedImage()->GetTextureClient(this)) {
// fast path: no need to allocate and/or copy image data
RefPtr<TextureClient> texture = image->AsSharedImage()->GetTextureClient(this);
if (mFrontBuffer) {
GetForwarder()->RemoveTextureFromCompositable(this, mFrontBuffer);
}
mFrontBuffer = texture;
if (!AddTextureClient(texture)) {
mFrontBuffer = nullptr;
return false;
}
GetForwarder()->UpdatedTexture(this, texture, nullptr);
GetForwarder()->UseTexture(this, texture);
} else if (image->GetFormat() == ImageFormat::PLANAR_YCBCR) {
PlanarYCbCrImage* ycbcr = static_cast<PlanarYCbCrImage*>(image);
const PlanarYCbCrData* data = ycbcr->GetData();
if (!data) {
return false;
}
if (mFrontBuffer && mFrontBuffer->IsImmutable()) {
GetForwarder()->RemoveTextureFromCompositable(this, mFrontBuffer);
mFrontBuffer = nullptr;
}
bool bufferCreated = false;
if (!mFrontBuffer) {
mFrontBuffer = CreateBufferTextureClient(gfx::SurfaceFormat::YUV, TEXTURE_FLAGS_DEFAULT);
gfx::IntSize ySize(data->mYSize.width, data->mYSize.height);
gfx::IntSize cbCrSize(data->mCbCrSize.width, data->mCbCrSize.height);
if (!mFrontBuffer->AsTextureClientYCbCr()->AllocateForYCbCr(ySize, cbCrSize, data->mStereoMode)) {
mFrontBuffer = nullptr;
return false;
}
bufferCreated = true;
}
if (!mFrontBuffer->Lock(OPEN_WRITE_ONLY)) {
return false;
}
bool status = mFrontBuffer->AsTextureClientYCbCr()->UpdateYCbCr(*data);
mFrontBuffer->Unlock();
if (bufferCreated) {
if (!AddTextureClient(mFrontBuffer)) {
mFrontBuffer = nullptr;
return false;
}
}
if (status) {
GetForwarder()->UpdatedTexture(this, mFrontBuffer, nullptr);
GetForwarder()->UseTexture(this, mFrontBuffer);
} else {
MOZ_ASSERT(false);
return false;
}
} else if (image->GetFormat() == ImageFormat::SHARED_TEXTURE) {
SharedTextureImage* sharedImage = static_cast<SharedTextureImage*>(image);
const SharedTextureImage::Data *data = sharedImage->GetData();
gfx::IntSize size = gfx::IntSize(image->GetSize().width, image->GetSize().height);
if (mFrontBuffer) {
GetForwarder()->RemoveTextureFromCompositable(this, mFrontBuffer);
mFrontBuffer = nullptr;
}
RefPtr<SharedTextureClientOGL> buffer = new SharedTextureClientOGL(mTextureFlags);
buffer->InitWith(data->mHandle, size, data->mShareType, data->mInverted);
mFrontBuffer = buffer;
if (!AddTextureClient(mFrontBuffer)) {
mFrontBuffer = nullptr;
return false;
}
GetForwarder()->UseTexture(this, mFrontBuffer);
} else {
RefPtr<gfx::SourceSurface> surface = image->GetAsSourceSurface();
MOZ_ASSERT(surface);
gfx::IntSize size = image->GetSize();
//.........这里部分代码省略.........
示例2: autoLock
bool
ImageClientSingle::UpdateImage(ImageContainer* aContainer, uint32_t aContentFlags)
{
AutoLockImage autoLock(aContainer);
Image *image = autoLock.GetImage();
if (!image) {
return false;
}
if (mLastPaintedImageSerial == image->GetSerial()) {
return true;
}
RefPtr<TextureClient> texture = image->AsSharedImage()
? image->AsSharedImage()->GetTextureClient(this)
: nullptr;
AutoRemoveTexture autoRemoveTexture(this);
if (texture != mFrontBuffer) {
autoRemoveTexture.mTexture = mFrontBuffer;
mFrontBuffer = nullptr;
}
if (!texture) {
// Slow path, we should not be hitting it very often and if we do it means
// we are using an Image class that is not backed by textureClient and we
// should fix it.
if (image->GetFormat() == ImageFormat::PLANAR_YCBCR) {
PlanarYCbCrImage* ycbcr = static_cast<PlanarYCbCrImage*>(image);
const PlanarYCbCrData* data = ycbcr->GetData();
if (!data) {
return false;
}
texture = TextureClient::CreateForYCbCr(GetForwarder(),
data->mYSize, data->mCbCrSize, data->mStereoMode,
TextureFlags::DEFAULT | mTextureFlags
);
if (!texture || !texture->Lock(OpenMode::OPEN_WRITE_ONLY)) {
return false;
}
bool status = texture->AsTextureClientYCbCr()->UpdateYCbCr(*data);
MOZ_ASSERT(status);
texture->Unlock();
if (!status) {
return false;
}
} else if (image->GetFormat() == ImageFormat::SURFACE_TEXTURE ||
image->GetFormat() == ImageFormat::EGLIMAGE) {
gfx::IntSize size = image->GetSize();
if (image->GetFormat() == ImageFormat::EGLIMAGE) {
EGLImageImage* typedImage = static_cast<EGLImageImage*>(image);
texture = new EGLImageTextureClient(mTextureFlags,
typedImage,
size);
#ifdef MOZ_WIDGET_ANDROID
} else if (image->GetFormat() == ImageFormat::SURFACE_TEXTURE) {
SurfaceTextureImage* typedImage = static_cast<SurfaceTextureImage*>(image);
const SurfaceTextureImage::Data* data = typedImage->GetData();
texture = new SurfaceTextureClient(mTextureFlags, data->mSurfTex,
size, data->mInverted);
#endif
} else {
MOZ_ASSERT(false, "Bad ImageFormat.");
}
} else {
RefPtr<gfx::SourceSurface> surface = image->GetAsSourceSurface();
MOZ_ASSERT(surface);
texture = CreateTextureClientForDrawing(surface->GetFormat(), image->GetSize(),
gfx::BackendType::NONE, mTextureFlags);
if (!texture) {
return false;
}
MOZ_ASSERT(texture->CanExposeDrawTarget());
if (!texture->Lock(OpenMode::OPEN_WRITE_ONLY)) {
return false;
}
{
// We must not keep a reference to the DrawTarget after it has been unlocked.
DrawTarget* dt = texture->BorrowDrawTarget();
MOZ_ASSERT(surface.get());
dt->CopySurface(surface, IntRect(IntPoint(), surface->GetSize()), IntPoint());
}
texture->Unlock();
}
}
if (!texture || !AddTextureClient(texture)) {
return false;
}
mFrontBuffer = texture;
GetForwarder()->UpdatedTexture(this, texture, nullptr);
GetForwarder()->UseTexture(this, texture);
//.........这里部分代码省略.........
示例3: autoLock
bool
ImageClientSingle::UpdateImage(ImageContainer* aContainer,
uint32_t aContentFlags)
{
AutoLockImage autoLock(aContainer);
Image *image = autoLock.GetImage();
if (!image) {
return false;
}
if (mLastPaintedImageSerial == image->GetSerial()) {
return true;
}
if (image->AsSharedImage() && image->AsSharedImage()->GetTextureClient()) {
// fast path: no need to allocate and/or copy image data
RefPtr<TextureClient> texture = image->AsSharedImage()->GetTextureClient();
if (texture->IsSharedWithCompositor()) {
// XXX - temporary fix for bug 911941
// This will be changed with bug 912907
return false;
}
if (mFrontBuffer) {
RemoveTextureClient(mFrontBuffer);
}
mFrontBuffer = texture;
AddTextureClient(texture);
GetForwarder()->UpdatedTexture(this, texture, nullptr);
GetForwarder()->UseTexture(this, texture);
} else if (image->GetFormat() == PLANAR_YCBCR) {
PlanarYCbCrImage* ycbcr = static_cast<PlanarYCbCrImage*>(image);
const PlanarYCbCrData* data = ycbcr->GetData();
if (!data) {
return false;
}
if (mFrontBuffer && mFrontBuffer->IsImmutable()) {
RemoveTextureClient(mFrontBuffer);
mFrontBuffer = nullptr;
}
bool bufferCreated = false;
if (!mFrontBuffer) {
mFrontBuffer = CreateBufferTextureClient(gfx::FORMAT_YUV, TEXTURE_FLAGS_DEFAULT);
gfx::IntSize ySize(data->mYSize.width, data->mYSize.height);
gfx::IntSize cbCrSize(data->mCbCrSize.width, data->mCbCrSize.height);
if (!mFrontBuffer->AsTextureClientYCbCr()->AllocateForYCbCr(ySize, cbCrSize, data->mStereoMode)) {
mFrontBuffer = nullptr;
return false;
}
bufferCreated = true;
}
if (!mFrontBuffer->Lock(OPEN_READ_WRITE)) {
return false;
}
bool status = mFrontBuffer->AsTextureClientYCbCr()->UpdateYCbCr(*data);
mFrontBuffer->Unlock();
if (bufferCreated) {
AddTextureClient(mFrontBuffer);
}
if (status) {
GetForwarder()->UpdatedTexture(this, mFrontBuffer, nullptr);
GetForwarder()->UseTexture(this, mFrontBuffer);
} else {
MOZ_ASSERT(false);
return false;
}
} else if (image->GetFormat() == SHARED_TEXTURE) {
SharedTextureImage* sharedImage = static_cast<SharedTextureImage*>(image);
const SharedTextureImage::Data *data = sharedImage->GetData();
gfx::IntSize size = gfx::IntSize(image->GetSize().width, image->GetSize().height);
if (mFrontBuffer) {
RemoveTextureClient(mFrontBuffer);
mFrontBuffer = nullptr;
}
RefPtr<SharedTextureClientOGL> buffer = new SharedTextureClientOGL(mTextureFlags);
buffer->InitWith(data->mHandle, size, data->mShareType, data->mInverted);
mFrontBuffer = buffer;
AddTextureClient(mFrontBuffer);
GetForwarder()->UseTexture(this, mFrontBuffer);
} else {
nsRefPtr<gfxASurface> surface = image->GetAsSurface();
MOZ_ASSERT(surface);
gfx::IntSize size = gfx::IntSize(image->GetSize().width, image->GetSize().height);
if (mFrontBuffer &&
(mFrontBuffer->IsImmutable() || mFrontBuffer->GetSize() != size)) {
RemoveTextureClient(mFrontBuffer);
mFrontBuffer = nullptr;
//.........这里部分代码省略.........