Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | #include "SharedRGBImage.h" |
michael@0 | 6 | #include "ImageTypes.h" // for ImageFormat::SHARED_RGB, etc |
michael@0 | 7 | #include "Shmem.h" // for Shmem |
michael@0 | 8 | #include "gfx2DGlue.h" // for ImageFormatToSurfaceFormat, etc |
michael@0 | 9 | #include "gfxPlatform.h" // for gfxPlatform, gfxImageFormat |
michael@0 | 10 | #include "mozilla/layers/ISurfaceAllocator.h" // for ISurfaceAllocator, etc |
michael@0 | 11 | #include "mozilla/layers/ImageClient.h" // for ImageClient |
michael@0 | 12 | #include "mozilla/layers/ImageDataSerializer.h" // for ImageDataSerializer |
michael@0 | 13 | #include "mozilla/layers/LayersSurfaces.h" // for SurfaceDescriptor, etc |
michael@0 | 14 | #include "mozilla/layers/TextureClient.h" // for BufferTextureClient, etc |
michael@0 | 15 | #include "mozilla/layers/ImageBridgeChild.h" // for ImageBridgeChild |
michael@0 | 16 | #include "mozilla/mozalloc.h" // for operator delete, etc |
michael@0 | 17 | #include "nsAutoPtr.h" // for nsRefPtr |
michael@0 | 18 | #include "nsDebug.h" // for NS_WARNING, NS_ASSERTION |
michael@0 | 19 | #include "nsISupportsImpl.h" // for Image::AddRef, etc |
michael@0 | 20 | #include "nsRect.h" // for nsIntRect |
michael@0 | 21 | #include "nsSize.h" // for nsIntSize |
michael@0 | 22 | |
michael@0 | 23 | // Just big enough for a 1080p RGBA32 frame |
michael@0 | 24 | #define MAX_FRAME_SIZE (16 * 1024 * 1024) |
michael@0 | 25 | |
michael@0 | 26 | namespace mozilla { |
michael@0 | 27 | namespace layers { |
michael@0 | 28 | |
michael@0 | 29 | already_AddRefed<Image> |
michael@0 | 30 | CreateSharedRGBImage(ImageContainer *aImageContainer, |
michael@0 | 31 | nsIntSize aSize, |
michael@0 | 32 | gfxImageFormat aImageFormat) |
michael@0 | 33 | { |
michael@0 | 34 | NS_ASSERTION(aImageFormat == gfxImageFormat::ARGB32 || |
michael@0 | 35 | aImageFormat == gfxImageFormat::RGB24 || |
michael@0 | 36 | aImageFormat == gfxImageFormat::RGB16_565, |
michael@0 | 37 | "RGB formats supported only"); |
michael@0 | 38 | |
michael@0 | 39 | if (!aImageContainer) { |
michael@0 | 40 | NS_WARNING("No ImageContainer to allocate SharedRGBImage"); |
michael@0 | 41 | return nullptr; |
michael@0 | 42 | } |
michael@0 | 43 | |
michael@0 | 44 | nsRefPtr<Image> image = aImageContainer->CreateImage(ImageFormat::SHARED_RGB); |
michael@0 | 45 | |
michael@0 | 46 | if (!image) { |
michael@0 | 47 | NS_WARNING("Failed to create SharedRGBImage"); |
michael@0 | 48 | return nullptr; |
michael@0 | 49 | } |
michael@0 | 50 | |
michael@0 | 51 | nsRefPtr<SharedRGBImage> rgbImage = static_cast<SharedRGBImage*>(image.get()); |
michael@0 | 52 | if (!rgbImage->Allocate(gfx::ToIntSize(aSize), |
michael@0 | 53 | gfx::ImageFormatToSurfaceFormat(aImageFormat))) { |
michael@0 | 54 | NS_WARNING("Failed to allocate a shared image"); |
michael@0 | 55 | return nullptr; |
michael@0 | 56 | } |
michael@0 | 57 | return image.forget(); |
michael@0 | 58 | } |
michael@0 | 59 | |
michael@0 | 60 | SharedRGBImage::SharedRGBImage(ImageClient* aCompositable) |
michael@0 | 61 | : Image(nullptr, ImageFormat::SHARED_RGB) |
michael@0 | 62 | , mCompositable(aCompositable) |
michael@0 | 63 | { |
michael@0 | 64 | MOZ_COUNT_CTOR(SharedRGBImage); |
michael@0 | 65 | } |
michael@0 | 66 | |
michael@0 | 67 | SharedRGBImage::~SharedRGBImage() |
michael@0 | 68 | { |
michael@0 | 69 | MOZ_COUNT_DTOR(SharedRGBImage); |
michael@0 | 70 | |
michael@0 | 71 | if (mCompositable->GetAsyncID() != 0 && |
michael@0 | 72 | !InImageBridgeChildThread()) { |
michael@0 | 73 | ImageBridgeChild::DispatchReleaseTextureClient(mTextureClient.forget().drop()); |
michael@0 | 74 | ImageBridgeChild::DispatchReleaseImageClient(mCompositable.forget().drop()); |
michael@0 | 75 | } |
michael@0 | 76 | } |
michael@0 | 77 | |
michael@0 | 78 | bool |
michael@0 | 79 | SharedRGBImage::Allocate(gfx::IntSize aSize, gfx::SurfaceFormat aFormat) |
michael@0 | 80 | { |
michael@0 | 81 | mSize = aSize; |
michael@0 | 82 | mTextureClient = mCompositable->CreateBufferTextureClient(aFormat); |
michael@0 | 83 | return mTextureClient->AllocateForSurface(aSize); |
michael@0 | 84 | } |
michael@0 | 85 | |
michael@0 | 86 | uint8_t* |
michael@0 | 87 | SharedRGBImage::GetBuffer() |
michael@0 | 88 | { |
michael@0 | 89 | if (!mTextureClient) { |
michael@0 | 90 | return nullptr; |
michael@0 | 91 | } |
michael@0 | 92 | |
michael@0 | 93 | ImageDataSerializer serializer(mTextureClient->GetBuffer(), mTextureClient->GetBufferSize()); |
michael@0 | 94 | return serializer.GetData(); |
michael@0 | 95 | } |
michael@0 | 96 | |
michael@0 | 97 | gfx::IntSize |
michael@0 | 98 | SharedRGBImage::GetSize() |
michael@0 | 99 | { |
michael@0 | 100 | return mSize; |
michael@0 | 101 | } |
michael@0 | 102 | |
michael@0 | 103 | size_t |
michael@0 | 104 | SharedRGBImage::GetBufferSize() |
michael@0 | 105 | { |
michael@0 | 106 | return mTextureClient ? mTextureClient->GetBufferSize() |
michael@0 | 107 | : 0; |
michael@0 | 108 | } |
michael@0 | 109 | |
michael@0 | 110 | TextureClient* |
michael@0 | 111 | SharedRGBImage::GetTextureClient(CompositableClient* aClient) |
michael@0 | 112 | { |
michael@0 | 113 | return mTextureClient.get(); |
michael@0 | 114 | } |
michael@0 | 115 | |
michael@0 | 116 | TemporaryRef<gfx::SourceSurface> |
michael@0 | 117 | SharedRGBImage::GetAsSourceSurface() |
michael@0 | 118 | { |
michael@0 | 119 | return nullptr; |
michael@0 | 120 | } |
michael@0 | 121 | |
michael@0 | 122 | } // namespace layers |
michael@0 | 123 | } // namespace mozilla |