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.

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

mercurial