gfx/layers/client/ClientThebesLayer.cpp

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     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 #include "ClientThebesLayer.h"
     7 #include "ClientTiledThebesLayer.h"     // for ClientTiledThebesLayer
     8 #include "SimpleTiledContentClient.h"
     9 #include <stdint.h>                     // for uint32_t
    10 #include "GeckoProfiler.h"              // for PROFILER_LABEL
    11 #include "client/ClientLayerManager.h"  // for ClientLayerManager, etc
    12 #include "gfxContext.h"                 // for gfxContext
    13 #include "gfxRect.h"                    // for gfxRect
    14 #include "gfxPrefs.h"                   // for gfxPrefs
    15 #include "mozilla/Assertions.h"         // for MOZ_ASSERT, etc
    16 #include "mozilla/gfx/2D.h"             // for DrawTarget
    17 #include "mozilla/gfx/Matrix.h"         // for Matrix
    18 #include "mozilla/gfx/Rect.h"           // for Rect, IntRect
    19 #include "mozilla/gfx/Types.h"          // for Float, etc
    20 #include "mozilla/layers/LayersTypes.h"
    21 #include "mozilla/Preferences.h"
    22 #include "nsAutoPtr.h"                  // for nsRefPtr
    23 #include "nsCOMPtr.h"                   // for already_AddRefed
    24 #include "nsISupportsImpl.h"            // for Layer::AddRef, etc
    25 #include "nsRect.h"                     // for nsIntRect
    26 #include "gfx2DGlue.h"
    28 using namespace mozilla::gfx;
    30 namespace mozilla {
    31 namespace layers {
    33 void
    34 ClientThebesLayer::PaintThebes()
    35 {
    36   PROFILER_LABEL("ClientThebesLayer", "PaintThebes");
    37   NS_ASSERTION(ClientManager()->InDrawing(),
    38                "Can only draw in drawing phase");
    40   uint32_t flags = RotatedContentBuffer::PAINT_CAN_DRAW_ROTATED;
    41 #ifndef MOZ_WIDGET_ANDROID
    42   if (ClientManager()->CompositorMightResample()) {
    43     flags |= RotatedContentBuffer::PAINT_WILL_RESAMPLE;
    44   }
    45   if (!(flags & RotatedContentBuffer::PAINT_WILL_RESAMPLE)) {
    46     if (MayResample()) {
    47       flags |= RotatedContentBuffer::PAINT_WILL_RESAMPLE;
    48     }
    49   }
    50 #endif
    51   PaintState state =
    52     mContentClient->BeginPaintBuffer(this, flags);
    53   mValidRegion.Sub(mValidRegion, state.mRegionToInvalidate);
    55   if (!state.mRegionToDraw.IsEmpty() && !ClientManager()->GetThebesLayerCallback()) {
    56     ClientManager()->SetTransactionIncomplete();
    57     return;
    58   }
    60   // The area that became invalid and is visible needs to be repainted
    61   // (this could be the whole visible area if our buffer switched
    62   // from RGB to RGBA, because we might need to repaint with
    63   // subpixel AA)
    64   state.mRegionToInvalidate.And(state.mRegionToInvalidate,
    65                                 GetEffectiveVisibleRegion());
    67   bool didUpdate = false;
    68   RotatedContentBuffer::DrawIterator iter;
    69   while (DrawTarget* target = mContentClient->BorrowDrawTargetForPainting(state, &iter)) {
    70     SetAntialiasingFlags(this, target);
    72     nsRefPtr<gfxContext> ctx = gfxContext::ContextForDrawTarget(target);
    74     ClientManager()->GetThebesLayerCallback()(this,
    75                                               ctx,
    76                                               iter.mDrawRegion,
    77                                               state.mClip,
    78                                               state.mRegionToInvalidate,
    79                                               ClientManager()->GetThebesLayerCallbackData());
    81     ctx = nullptr;
    82     mContentClient->ReturnDrawTargetToBuffer(target);
    83     didUpdate = true;
    84   }
    86   if (didUpdate) {
    87     Mutated();
    89     mValidRegion.Or(mValidRegion, state.mRegionToDraw);
    91     ContentClientRemote* contentClientRemote = static_cast<ContentClientRemote*>(mContentClient.get());
    92     MOZ_ASSERT(contentClientRemote->GetIPDLActor());
    94     // Hold(this) ensures this layer is kept alive through the current transaction
    95     // The ContentClient assumes this layer is kept alive (e.g., in CreateBuffer),
    96     // so deleting this Hold for whatever reason will break things.
    97     ClientManager()->Hold(this);
    98     contentClientRemote->Updated(state.mRegionToDraw,
    99                                  mVisibleRegion,
   100                                  state.mDidSelfCopy);
   101   }
   102 }
   104 void
   105 ClientThebesLayer::RenderLayer()
   106 {
   107   if (GetMaskLayer()) {
   108     ToClientLayer(GetMaskLayer())->RenderLayer();
   109   }
   111   if (!mContentClient) {
   112     mContentClient = ContentClient::CreateContentClient(ClientManager()->AsShadowForwarder());
   113     if (!mContentClient) {
   114       return;
   115     }
   116     mContentClient->Connect();
   117     ClientManager()->AsShadowForwarder()->Attach(mContentClient, this);
   118     MOZ_ASSERT(mContentClient->GetForwarder());
   119   }
   121   mContentClient->BeginPaint();
   122   PaintThebes();
   123   mContentClient->EndPaint();
   124 }
   126 already_AddRefed<ThebesLayer>
   127 ClientLayerManager::CreateThebesLayer()
   128 {
   129   return CreateThebesLayerWithHint(NONE);
   130 }
   132 already_AddRefed<ThebesLayer>
   133 ClientLayerManager::CreateThebesLayerWithHint(ThebesLayerCreationHint aHint)
   134 {
   135   NS_ASSERTION(InConstruction(), "Only allowed in construction phase");
   136   if (
   137 #ifdef MOZ_B2G
   138       aHint == SCROLLABLE &&
   139 #endif
   140       gfxPrefs::LayersTilesEnabled() &&
   141       (AsShadowForwarder()->GetCompositorBackendType() == LayersBackend::LAYERS_OPENGL ||
   142        AsShadowForwarder()->GetCompositorBackendType() == LayersBackend::LAYERS_D3D9 ||
   143        AsShadowForwarder()->GetCompositorBackendType() == LayersBackend::LAYERS_D3D11)) {
   144     if (gfxPrefs::LayersUseSimpleTiles()) {
   145       nsRefPtr<SimpleClientTiledThebesLayer> layer =
   146         new SimpleClientTiledThebesLayer(this);
   147       CREATE_SHADOW(Thebes);
   148       return layer.forget();
   149     } else {
   150       nsRefPtr<ClientTiledThebesLayer> layer =
   151         new ClientTiledThebesLayer(this);
   152       CREATE_SHADOW(Thebes);
   153       return layer.forget();
   154     }
   155   } else
   156   {
   157     nsRefPtr<ClientThebesLayer> layer =
   158       new ClientThebesLayer(this);
   159     CREATE_SHADOW(Thebes);
   160     return layer.forget();
   161   }
   162 }
   165 }
   166 }

mercurial