michael@0: /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef GRALLOCIMAGES_H michael@0: #define GRALLOCIMAGES_H michael@0: michael@0: #ifdef MOZ_WIDGET_GONK michael@0: michael@0: #include "ImageLayers.h" michael@0: #include "ImageContainer.h" michael@0: #include "mozilla/gfx/Point.h" michael@0: #include "mozilla/layers/AtomicRefCountedWithFinalize.h" michael@0: #include "mozilla/layers/FenceUtils.h" michael@0: #include "mozilla/layers/LayersSurfaces.h" michael@0: michael@0: #include michael@0: michael@0: namespace mozilla { michael@0: namespace layers { michael@0: michael@0: class GrallocTextureClientOGL; michael@0: michael@0: /** michael@0: * The YUV format supported by Android HAL michael@0: * michael@0: * 4:2:0 - CbCr width and height is half that of Y. michael@0: * michael@0: * This format assumes michael@0: * - an even width michael@0: * - an even height michael@0: * - a horizontal stride multiple of 16 pixels michael@0: * - a vertical stride equal to the height michael@0: * michael@0: * y_size = stride * height michael@0: * c_size = ALIGN(stride/2, 16) * height/2 michael@0: * size = y_size + c_size * 2 michael@0: * cr_offset = y_size michael@0: * cb_offset = y_size + c_size michael@0: * michael@0: * The Image that is rendered is the picture region defined by michael@0: * mPicX, mPicY and mPicSize. The size of the rendered image is michael@0: * mPicSize, not mYSize or mCbCrSize. michael@0: */ michael@0: class GrallocImage : public PlanarYCbCrImage michael@0: , public ISharedImage michael@0: { michael@0: typedef PlanarYCbCrData Data; michael@0: static uint32_t sColorIdMap[]; michael@0: public: michael@0: struct GrallocData { michael@0: nsRefPtr mGraphicBuffer; michael@0: gfx::IntSize mPicSize; michael@0: }; michael@0: michael@0: GrallocImage(); michael@0: michael@0: virtual ~GrallocImage(); michael@0: michael@0: /** michael@0: * This makes a copy of the data buffers, in order to support functioning michael@0: * in all different layer managers. michael@0: */ michael@0: virtual void SetData(const Data& aData); michael@0: michael@0: /** michael@0: * Share the SurfaceDescriptor without making the copy, in order michael@0: * to support functioning in all different layer managers. michael@0: */ michael@0: virtual void SetData(const GrallocData& aData); michael@0: michael@0: // From [android 4.0.4]/hardware/msm7k/libgralloc-qsd8k/gralloc_priv.h michael@0: enum { michael@0: /* OEM specific HAL formats */ michael@0: HAL_PIXEL_FORMAT_YCbCr_422_P = 0x102, michael@0: HAL_PIXEL_FORMAT_YCbCr_420_P = 0x103, michael@0: HAL_PIXEL_FORMAT_YCbCr_420_SP = 0x109, michael@0: HAL_PIXEL_FORMAT_YCrCb_420_SP_ADRENO = 0x10A, michael@0: HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED = 0x7FA30C03, michael@0: HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS = 0x7FA30C04, michael@0: }; michael@0: michael@0: virtual TemporaryRef GetAsSourceSurface() MOZ_OVERRIDE; michael@0: michael@0: android::sp GetGraphicBuffer() const; michael@0: michael@0: void* GetNativeBuffer(); michael@0: michael@0: virtual bool IsValid() { return !!mTextureClient; } michael@0: michael@0: virtual ISharedImage* AsSharedImage() MOZ_OVERRIDE { return this; } michael@0: michael@0: virtual TextureClient* GetTextureClient(CompositableClient* aClient) MOZ_OVERRIDE; michael@0: michael@0: virtual uint8_t* GetBuffer() michael@0: { michael@0: return static_cast(GetNativeBuffer()); michael@0: } michael@0: michael@0: private: michael@0: RefPtr mTextureClient; michael@0: }; michael@0: michael@0: } // namespace layers michael@0: } // namespace mozilla michael@0: #endif michael@0: michael@0: #endif /* GRALLOCIMAGES_H */