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 | /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
michael@0 | 2 | // * This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #ifndef MOZILLA_GFX_GRALLOCTEXTURECLIENT_H |
michael@0 | 7 | #define MOZILLA_GFX_GRALLOCTEXTURECLIENT_H |
michael@0 | 8 | #ifdef MOZ_WIDGET_GONK |
michael@0 | 9 | |
michael@0 | 10 | #include "mozilla/layers/TextureClient.h" |
michael@0 | 11 | #include "ISurfaceAllocator.h" // For IsSurfaceDescriptorValid |
michael@0 | 12 | #include "mozilla/layers/FenceUtils.h" // for FenceHandle |
michael@0 | 13 | #include "mozilla/layers/ShadowLayerUtilsGralloc.h" |
michael@0 | 14 | #include <ui/GraphicBuffer.h> |
michael@0 | 15 | |
michael@0 | 16 | |
michael@0 | 17 | namespace android { |
michael@0 | 18 | class MediaBuffer; |
michael@0 | 19 | }; |
michael@0 | 20 | |
michael@0 | 21 | namespace mozilla { |
michael@0 | 22 | namespace layers { |
michael@0 | 23 | |
michael@0 | 24 | /** |
michael@0 | 25 | * A TextureClient implementation based on android::GraphicBuffer (also referred to |
michael@0 | 26 | * as "gralloc"). |
michael@0 | 27 | * |
michael@0 | 28 | * Gralloc lets us map texture data in memory (accessible through pointers) |
michael@0 | 29 | * and also use it directly as an OpenGL texture without the cost of texture |
michael@0 | 30 | * uploads. |
michael@0 | 31 | * Gralloc buffers can also be shared accros processes. |
michael@0 | 32 | * |
michael@0 | 33 | * More info about Gralloc here: https://wiki.mozilla.org/Platform/GFX/Gralloc |
michael@0 | 34 | * |
michael@0 | 35 | * This is only used in Firefox OS |
michael@0 | 36 | */ |
michael@0 | 37 | class GrallocTextureClientOGL : public BufferTextureClient |
michael@0 | 38 | { |
michael@0 | 39 | public: |
michael@0 | 40 | GrallocTextureClientOGL(GrallocBufferActor* aActor, |
michael@0 | 41 | gfx::IntSize aSize, |
michael@0 | 42 | gfx::BackendType aMoz2dBackend, |
michael@0 | 43 | TextureFlags aFlags = TEXTURE_FLAGS_DEFAULT); |
michael@0 | 44 | GrallocTextureClientOGL(ISurfaceAllocator* aAllocator, |
michael@0 | 45 | gfx::SurfaceFormat aFormat, |
michael@0 | 46 | gfx::BackendType aMoz2dBackend, |
michael@0 | 47 | TextureFlags aFlags = TEXTURE_FLAGS_DEFAULT); |
michael@0 | 48 | |
michael@0 | 49 | ~GrallocTextureClientOGL(); |
michael@0 | 50 | |
michael@0 | 51 | virtual bool Lock(OpenMode aMode) MOZ_OVERRIDE; |
michael@0 | 52 | |
michael@0 | 53 | virtual void Unlock() MOZ_OVERRIDE; |
michael@0 | 54 | |
michael@0 | 55 | virtual bool ImplementsLocking() const MOZ_OVERRIDE { return true; } |
michael@0 | 56 | |
michael@0 | 57 | virtual bool HasInternalBuffer() const MOZ_OVERRIDE { return false; } |
michael@0 | 58 | |
michael@0 | 59 | virtual bool IsAllocated() const MOZ_OVERRIDE; |
michael@0 | 60 | |
michael@0 | 61 | virtual bool ToSurfaceDescriptor(SurfaceDescriptor& aOutDescriptor) MOZ_OVERRIDE; |
michael@0 | 62 | |
michael@0 | 63 | virtual TextureClientData* DropTextureData() MOZ_OVERRIDE; |
michael@0 | 64 | |
michael@0 | 65 | virtual void SetReleaseFenceHandle(FenceHandle aReleaseFenceHandle) MOZ_OVERRIDE; |
michael@0 | 66 | |
michael@0 | 67 | virtual void WaitReleaseFence() MOZ_OVERRIDE; |
michael@0 | 68 | |
michael@0 | 69 | void InitWith(GrallocBufferActor* aActor, gfx::IntSize aSize); |
michael@0 | 70 | |
michael@0 | 71 | void SetTextureFlags(TextureFlags aFlags) { AddFlags(aFlags); } |
michael@0 | 72 | |
michael@0 | 73 | gfx::IntSize GetSize() const MOZ_OVERRIDE { return mSize; } |
michael@0 | 74 | |
michael@0 | 75 | android::sp<android::GraphicBuffer> GetGraphicBuffer() |
michael@0 | 76 | { |
michael@0 | 77 | return mGraphicBuffer; |
michael@0 | 78 | } |
michael@0 | 79 | |
michael@0 | 80 | android::PixelFormat GetPixelFormat() |
michael@0 | 81 | { |
michael@0 | 82 | return mGraphicBuffer->getPixelFormat(); |
michael@0 | 83 | } |
michael@0 | 84 | |
michael@0 | 85 | virtual uint8_t* GetBuffer() const MOZ_OVERRIDE; |
michael@0 | 86 | |
michael@0 | 87 | virtual TemporaryRef<gfx::DrawTarget> GetAsDrawTarget() MOZ_OVERRIDE; |
michael@0 | 88 | |
michael@0 | 89 | virtual bool AllocateForSurface(gfx::IntSize aSize, |
michael@0 | 90 | TextureAllocationFlags aFlags = ALLOC_DEFAULT) MOZ_OVERRIDE; |
michael@0 | 91 | |
michael@0 | 92 | virtual bool AllocateForYCbCr(gfx::IntSize aYSize, |
michael@0 | 93 | gfx::IntSize aCbCrSize, |
michael@0 | 94 | StereoMode aStereoMode) MOZ_OVERRIDE; |
michael@0 | 95 | |
michael@0 | 96 | bool AllocateForGLRendering(gfx::IntSize aSize); |
michael@0 | 97 | |
michael@0 | 98 | bool AllocateGralloc(gfx::IntSize aYSize, uint32_t aAndroidFormat, uint32_t aUsage); |
michael@0 | 99 | |
michael@0 | 100 | virtual bool Allocate(uint32_t aSize) MOZ_OVERRIDE; |
michael@0 | 101 | |
michael@0 | 102 | virtual size_t GetBufferSize() const MOZ_OVERRIDE; |
michael@0 | 103 | |
michael@0 | 104 | /** |
michael@0 | 105 | * Hold android::MediaBuffer. |
michael@0 | 106 | * MediaBuffer needs to be add refed to keep MediaBuffer alive |
michael@0 | 107 | * during TextureClient is in use. |
michael@0 | 108 | */ |
michael@0 | 109 | void SetMediaBuffer(android::MediaBuffer* aMediaBuffer) |
michael@0 | 110 | { |
michael@0 | 111 | mMediaBuffer = aMediaBuffer; |
michael@0 | 112 | } |
michael@0 | 113 | |
michael@0 | 114 | android::MediaBuffer* GetMediaBuffer() |
michael@0 | 115 | { |
michael@0 | 116 | return mMediaBuffer; |
michael@0 | 117 | } |
michael@0 | 118 | |
michael@0 | 119 | protected: |
michael@0 | 120 | /** |
michael@0 | 121 | * Unfortunately, until bug 879681 is fixed we need to use a GrallocBufferActor. |
michael@0 | 122 | */ |
michael@0 | 123 | GrallocBufferActor* mGrallocActor; |
michael@0 | 124 | |
michael@0 | 125 | android::sp<android::GraphicBuffer> mGraphicBuffer; |
michael@0 | 126 | |
michael@0 | 127 | /** |
michael@0 | 128 | * Points to a mapped gralloc buffer between calls to lock and unlock. |
michael@0 | 129 | * Should be null outside of the lock-unlock pair. |
michael@0 | 130 | */ |
michael@0 | 131 | uint8_t* mMappedBuffer; |
michael@0 | 132 | |
michael@0 | 133 | RefPtr<gfx::DrawTarget> mDrawTarget; |
michael@0 | 134 | |
michael@0 | 135 | /** |
michael@0 | 136 | * android::GraphicBuffer has a size information. But there are cases |
michael@0 | 137 | * that GraphicBuffer's size and actual video's size are different. |
michael@0 | 138 | * Extra size member is necessary. See Bug 850566. |
michael@0 | 139 | */ |
michael@0 | 140 | gfx::IntSize mSize; |
michael@0 | 141 | |
michael@0 | 142 | android::MediaBuffer* mMediaBuffer; |
michael@0 | 143 | }; |
michael@0 | 144 | |
michael@0 | 145 | } // namespace layers |
michael@0 | 146 | } // namespace mozilla |
michael@0 | 147 | |
michael@0 | 148 | #endif // MOZ_WIDGET_GONK |
michael@0 | 149 | #endif |