gfx/layers/GrallocImages.h

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

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 GRALLOCIMAGES_H
michael@0 7 #define GRALLOCIMAGES_H
michael@0 8
michael@0 9 #ifdef MOZ_WIDGET_GONK
michael@0 10
michael@0 11 #include "ImageLayers.h"
michael@0 12 #include "ImageContainer.h"
michael@0 13 #include "mozilla/gfx/Point.h"
michael@0 14 #include "mozilla/layers/AtomicRefCountedWithFinalize.h"
michael@0 15 #include "mozilla/layers/FenceUtils.h"
michael@0 16 #include "mozilla/layers/LayersSurfaces.h"
michael@0 17
michael@0 18 #include <ui/GraphicBuffer.h>
michael@0 19
michael@0 20 namespace mozilla {
michael@0 21 namespace layers {
michael@0 22
michael@0 23 class GrallocTextureClientOGL;
michael@0 24
michael@0 25 /**
michael@0 26 * The YUV format supported by Android HAL
michael@0 27 *
michael@0 28 * 4:2:0 - CbCr width and height is half that of Y.
michael@0 29 *
michael@0 30 * This format assumes
michael@0 31 * - an even width
michael@0 32 * - an even height
michael@0 33 * - a horizontal stride multiple of 16 pixels
michael@0 34 * - a vertical stride equal to the height
michael@0 35 *
michael@0 36 * y_size = stride * height
michael@0 37 * c_size = ALIGN(stride/2, 16) * height/2
michael@0 38 * size = y_size + c_size * 2
michael@0 39 * cr_offset = y_size
michael@0 40 * cb_offset = y_size + c_size
michael@0 41 *
michael@0 42 * The Image that is rendered is the picture region defined by
michael@0 43 * mPicX, mPicY and mPicSize. The size of the rendered image is
michael@0 44 * mPicSize, not mYSize or mCbCrSize.
michael@0 45 */
michael@0 46 class GrallocImage : public PlanarYCbCrImage
michael@0 47 , public ISharedImage
michael@0 48 {
michael@0 49 typedef PlanarYCbCrData Data;
michael@0 50 static uint32_t sColorIdMap[];
michael@0 51 public:
michael@0 52 struct GrallocData {
michael@0 53 nsRefPtr<TextureClient> mGraphicBuffer;
michael@0 54 gfx::IntSize mPicSize;
michael@0 55 };
michael@0 56
michael@0 57 GrallocImage();
michael@0 58
michael@0 59 virtual ~GrallocImage();
michael@0 60
michael@0 61 /**
michael@0 62 * This makes a copy of the data buffers, in order to support functioning
michael@0 63 * in all different layer managers.
michael@0 64 */
michael@0 65 virtual void SetData(const Data& aData);
michael@0 66
michael@0 67 /**
michael@0 68 * Share the SurfaceDescriptor without making the copy, in order
michael@0 69 * to support functioning in all different layer managers.
michael@0 70 */
michael@0 71 virtual void SetData(const GrallocData& aData);
michael@0 72
michael@0 73 // From [android 4.0.4]/hardware/msm7k/libgralloc-qsd8k/gralloc_priv.h
michael@0 74 enum {
michael@0 75 /* OEM specific HAL formats */
michael@0 76 HAL_PIXEL_FORMAT_YCbCr_422_P = 0x102,
michael@0 77 HAL_PIXEL_FORMAT_YCbCr_420_P = 0x103,
michael@0 78 HAL_PIXEL_FORMAT_YCbCr_420_SP = 0x109,
michael@0 79 HAL_PIXEL_FORMAT_YCrCb_420_SP_ADRENO = 0x10A,
michael@0 80 HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED = 0x7FA30C03,
michael@0 81 HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS = 0x7FA30C04,
michael@0 82 };
michael@0 83
michael@0 84 virtual TemporaryRef<gfx::SourceSurface> GetAsSourceSurface() MOZ_OVERRIDE;
michael@0 85
michael@0 86 android::sp<android::GraphicBuffer> GetGraphicBuffer() const;
michael@0 87
michael@0 88 void* GetNativeBuffer();
michael@0 89
michael@0 90 virtual bool IsValid() { return !!mTextureClient; }
michael@0 91
michael@0 92 virtual ISharedImage* AsSharedImage() MOZ_OVERRIDE { return this; }
michael@0 93
michael@0 94 virtual TextureClient* GetTextureClient(CompositableClient* aClient) MOZ_OVERRIDE;
michael@0 95
michael@0 96 virtual uint8_t* GetBuffer()
michael@0 97 {
michael@0 98 return static_cast<uint8_t*>(GetNativeBuffer());
michael@0 99 }
michael@0 100
michael@0 101 private:
michael@0 102 RefPtr<GrallocTextureClientOGL> mTextureClient;
michael@0 103 };
michael@0 104
michael@0 105 } // namespace layers
michael@0 106 } // namespace mozilla
michael@0 107 #endif
michael@0 108
michael@0 109 #endif /* GRALLOCIMAGES_H */

mercurial