gfx/layers/LayersTypes.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: 2; 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 GFX_LAYERSTYPES_H
     7 #define GFX_LAYERSTYPES_H
     9 #include <stdint.h>                     // for uint32_t
    10 #include "nsPoint.h"                    // for nsIntPoint
    11 #include "nsRegion.h"
    13 #include "mozilla/TypedEnum.h"
    15 #ifdef MOZ_WIDGET_GONK
    16 #include <ui/GraphicBuffer.h>
    17 #endif
    18 #if defined(DEBUG) || defined(PR_LOGGING)
    19 #  include <stdio.h>            // FILE
    20 #  include "prlog.h"            // for PR_LOG
    21 #  ifndef MOZ_LAYERS_HAVE_LOG
    22 #    define MOZ_LAYERS_HAVE_LOG
    23 #  endif
    24 #  define MOZ_LAYERS_LOG(_args)                             \
    25   PR_LOG(LayerManager::GetLog(), PR_LOG_DEBUG, _args)
    26 #  define MOZ_LAYERS_LOG_IF_SHADOWABLE(layer, _args)         \
    27   do { if (layer->AsShadowableLayer()) { PR_LOG(LayerManager::GetLog(), PR_LOG_DEBUG, _args); } } while (0)
    28 #else
    29 struct PRLogModuleInfo;
    30 #  define MOZ_LAYERS_LOG(_args)
    31 #  define MOZ_LAYERS_LOG_IF_SHADOWABLE(layer, _args)
    32 #endif  // if defined(DEBUG) || defined(PR_LOGGING)
    34 namespace android {
    35 class GraphicBuffer;
    36 }
    38 namespace mozilla {
    39 namespace layers {
    41 class TextureHost;
    43 typedef uint32_t TextureFlags;
    45 #undef NONE
    46 #undef OPAQUE
    48 MOZ_BEGIN_ENUM_CLASS(LayersBackend, int8_t)
    49   LAYERS_NONE = 0,
    50   LAYERS_BASIC,
    51   LAYERS_OPENGL,
    52   LAYERS_D3D9,
    53   LAYERS_D3D10,
    54   LAYERS_D3D11,
    55   LAYERS_CLIENT,
    56   LAYERS_LAST
    57 MOZ_END_ENUM_CLASS(LayersBackend)
    59 MOZ_BEGIN_ENUM_CLASS(BufferMode, int8_t)
    60   BUFFER_NONE,
    61   BUFFERED
    62 MOZ_END_ENUM_CLASS(BufferMode)
    64 MOZ_BEGIN_ENUM_CLASS(DrawRegionClip, int8_t)
    65   DRAW,
    66   DRAW_SNAPPED,
    67   CLIP_NONE
    68 MOZ_END_ENUM_CLASS(DrawRegionClip)
    70 MOZ_BEGIN_ENUM_CLASS(SurfaceMode, int8_t)
    71   SURFACE_NONE = 0,
    72   SURFACE_OPAQUE,
    73   SURFACE_SINGLE_CHANNEL_ALPHA,
    74   SURFACE_COMPONENT_ALPHA
    75 MOZ_END_ENUM_CLASS(SurfaceMode)
    77 // LayerRenderState for Composer2D
    78 // We currently only support Composer2D using gralloc. If we want to be backed
    79 // by other surfaces we will need a more generic LayerRenderState.
    80 enum LayerRenderStateFlags {
    81   LAYER_RENDER_STATE_Y_FLIPPED = 1 << 0,
    82   LAYER_RENDER_STATE_BUFFER_ROTATION = 1 << 1,
    83   // Notify Composer2D to swap the RB pixels of gralloc buffer
    84   LAYER_RENDER_STATE_FORMAT_RB_SWAP = 1 << 2
    85 };
    87 // The 'ifdef MOZ_WIDGET_GONK' sadness here is because we don't want to include
    88 // android::sp unless we have to.
    89 struct LayerRenderState {
    90   LayerRenderState()
    91 #ifdef MOZ_WIDGET_GONK
    92     : mSurface(nullptr), mTexture(nullptr), mFlags(0), mHasOwnOffset(false)
    93 #endif
    94   {}
    96 #ifdef MOZ_WIDGET_GONK
    97   LayerRenderState(android::GraphicBuffer* aSurface,
    98                    const nsIntSize& aSize,
    99                    uint32_t aFlags,
   100                    TextureHost* aTexture)
   101     : mSurface(aSurface)
   102     , mSize(aSize)
   103     , mTexture(aTexture)
   104     , mFlags(aFlags)
   105     , mHasOwnOffset(false)
   106   {}
   108   bool YFlipped() const
   109   { return mFlags & LAYER_RENDER_STATE_Y_FLIPPED; }
   111   bool BufferRotated() const
   112   { return mFlags & LAYER_RENDER_STATE_BUFFER_ROTATION; }
   114   bool FormatRBSwapped() const
   115   { return mFlags & LAYER_RENDER_STATE_FORMAT_RB_SWAP; }
   116 #endif
   118   void SetOffset(const nsIntPoint& aOffset)
   119   {
   120     mOffset = aOffset;
   121     mHasOwnOffset = true;
   122   }
   124 #ifdef MOZ_WIDGET_GONK
   125   // surface to render
   126   android::sp<android::GraphicBuffer> mSurface;
   127   // size of mSurface 
   128   nsIntSize mSize;
   129   TextureHost* mTexture;
   130 #endif
   131   // see LayerRenderStateFlags
   132   uint32_t mFlags;
   133   // the location of the layer's origin on mSurface
   134   nsIntPoint mOffset;
   135   // true if mOffset is applicable
   136   bool mHasOwnOffset;
   137 };
   139 MOZ_BEGIN_ENUM_CLASS(ScaleMode, int8_t)
   140   SCALE_NONE,
   141   STRETCH,
   142   SENTINEL
   143 // Unimplemented - PRESERVE_ASPECT_RATIO_CONTAIN
   144 MOZ_END_ENUM_CLASS(ScaleMode)
   146 struct EventRegions {
   147   nsIntRegion mHitRegion;
   148   nsIntRegion mDispatchToContentHitRegion;
   150   bool operator==(const EventRegions& aRegions) const
   151   {
   152     return mHitRegion == aRegions.mHitRegion &&
   153            mDispatchToContentHitRegion == aRegions.mDispatchToContentHitRegion;
   154   }
   155   bool operator!=(const EventRegions& aRegions) const
   156   {
   157     return !(*this == aRegions);
   158   }
   160   nsCString ToString() const
   161   {
   162     nsCString result = mHitRegion.ToString();
   163     result.AppendLiteral(";dispatchToContent=");
   164     result.Append(mDispatchToContentHitRegion.ToString());
   165     return result;
   166   }
   167 };
   169 } // namespace
   170 } // namespace
   172 #endif /* GFX_LAYERSTYPES_H */

mercurial