gfx/layers/basic/BasicThebesLayer.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 "BasicThebesLayer.h"
     7 #include <stdint.h>                     // for uint32_t
     8 #include "GeckoProfiler.h"              // for PROFILER_LABEL
     9 #include "ReadbackLayer.h"              // for ReadbackLayer, ReadbackSink
    10 #include "ReadbackProcessor.h"          // for ReadbackProcessor::Update, etc
    11 #include "RenderTrace.h"                // for RenderTraceInvalidateEnd, etc
    12 #include "BasicLayersImpl.h"            // for AutoMaskData, etc
    13 #include "gfxContext.h"                 // for gfxContext, etc
    14 #include "gfxRect.h"                    // for gfxRect
    15 #include "gfxUtils.h"                   // for gfxUtils
    16 #include "mozilla/gfx/2D.h"             // for DrawTarget
    17 #include "mozilla/gfx/BaseRect.h"       // for BaseRect
    18 #include "mozilla/gfx/Matrix.h"         // for Matrix
    19 #include "mozilla/gfx/Rect.h"           // for Rect, IntRect
    20 #include "mozilla/gfx/Types.h"          // for Float, etc
    21 #include "mozilla/layers/LayersTypes.h"
    22 #include "nsAutoPtr.h"                  // for nsRefPtr
    23 #include "nsCOMPtr.h"                   // for already_AddRefed
    24 #include "nsISupportsImpl.h"            // for gfxContext::Release, etc
    25 #include "nsPoint.h"                    // for nsIntPoint
    26 #include "nsRect.h"                     // for nsIntRect
    27 #include "nsTArray.h"                   // for nsTArray, nsTArray_Impl
    28 #include "AutoMaskData.h"
    29 #include "gfx2DGlue.h"
    31 using namespace mozilla::gfx;
    33 namespace mozilla {
    34 namespace layers {
    36 static nsIntRegion
    37 IntersectWithClip(const nsIntRegion& aRegion, gfxContext* aContext)
    38 {
    39   gfxRect clip = aContext->GetClipExtents();
    40   clip.RoundOut();
    41   nsIntRect r(clip.X(), clip.Y(), clip.Width(), clip.Height());
    42   nsIntRegion result;
    43   result.And(aRegion, r);
    44   return result;
    45 }
    47 void
    48 BasicThebesLayer::PaintThebes(gfxContext* aContext,
    49                               Layer* aMaskLayer,
    50                               LayerManager::DrawThebesLayerCallback aCallback,
    51                               void* aCallbackData,
    52                               ReadbackProcessor* aReadback)
    53 {
    54   PROFILER_LABEL("BasicThebesLayer", "PaintThebes");
    55   NS_ASSERTION(BasicManager()->InDrawing(),
    56                "Can only draw in drawing phase");
    58   nsTArray<ReadbackProcessor::Update> readbackUpdates;
    59   if (aReadback && UsedForReadback()) {
    60     aReadback->GetThebesLayerUpdates(this, &readbackUpdates);
    61   }
    63   float opacity = GetEffectiveOpacity();
    64   CompositionOp effectiveOperator = GetEffectiveOperator(this);
    66   if (!BasicManager()->IsRetained()) {
    67     NS_ASSERTION(readbackUpdates.IsEmpty(), "Can't do readback for non-retained layer");
    69     mValidRegion.SetEmpty();
    70     mContentClient->Clear();
    72     nsIntRegion toDraw = IntersectWithClip(GetEffectiveVisibleRegion(), aContext);
    74     RenderTraceInvalidateStart(this, "FFFF00", toDraw.GetBounds());
    76     if (!toDraw.IsEmpty() && !IsHidden()) {
    77       if (!aCallback) {
    78         BasicManager()->SetTransactionIncomplete();
    79         return;
    80       }
    82       aContext->Save();
    84       bool needsClipToVisibleRegion = GetClipToVisibleRegion();
    85       bool needsGroup = opacity != 1.0 ||
    86                         effectiveOperator != CompositionOp::OP_OVER ||
    87                         aMaskLayer;
    88       nsRefPtr<gfxContext> groupContext;
    89       if (needsGroup) {
    90         groupContext =
    91           BasicManager()->PushGroupForLayer(aContext, this, toDraw,
    92                                             &needsClipToVisibleRegion);
    93         if (effectiveOperator != CompositionOp::OP_OVER) {
    94           needsClipToVisibleRegion = true;
    95         }
    96       } else {
    97         groupContext = aContext;
    98       }
    99       SetAntialiasingFlags(this, groupContext);
   100       aCallback(this, groupContext, toDraw, DrawRegionClip::CLIP_NONE, nsIntRegion(), aCallbackData);
   101       if (needsGroup) {
   102         BasicManager()->PopGroupToSourceWithCachedSurface(aContext, groupContext);
   103         if (needsClipToVisibleRegion) {
   104           gfxUtils::ClipToRegion(aContext, toDraw);
   105         }
   106         AutoSetOperator setOptimizedOperator(aContext, ThebesOp(effectiveOperator));
   107         PaintWithMask(aContext, opacity, aMaskLayer);
   108       }
   110       aContext->Restore();
   111     }
   113     RenderTraceInvalidateEnd(this, "FFFF00");
   114     return;
   115   }
   117   if (BasicManager()->IsTransactionIncomplete())
   118     return;
   120   gfxRect clipExtents;
   121   clipExtents = aContext->GetClipExtents();
   123   // Pull out the mask surface and transform here, because the mask
   124   // is internal to basic layers
   125   AutoMoz2DMaskData mask;
   126   SourceSurface* maskSurface = nullptr;
   127   Matrix maskTransform;
   128   if (GetMaskData(aMaskLayer, Point(), &mask)) {
   129     maskSurface = mask.GetSurface();
   130     maskTransform = mask.GetTransform();
   131   }
   133   if (!IsHidden() && !clipExtents.IsEmpty()) {
   134     mContentClient->DrawTo(this, aContext->GetDrawTarget(), opacity,
   135                            GetOperator(),
   136                            maskSurface, &maskTransform);
   137   }
   139   for (uint32_t i = 0; i < readbackUpdates.Length(); ++i) {
   140     ReadbackProcessor::Update& update = readbackUpdates[i];
   141     nsIntPoint offset = update.mLayer->GetBackgroundLayerOffset();
   142     nsRefPtr<gfxContext> ctx =
   143       update.mLayer->GetSink()->BeginUpdate(update.mUpdateRect + offset,
   144                                             update.mSequenceCounter);
   145     if (ctx) {
   146       NS_ASSERTION(opacity == 1.0, "Should only read back opaque layers");
   147       ctx->Translate(gfxPoint(offset.x, offset.y));
   148       mContentClient->DrawTo(this, ctx->GetDrawTarget(), 1.0,
   149                              CompositionOpForOp(ctx->CurrentOperator()),
   150                              maskSurface, &maskTransform);
   151       update.mLayer->GetSink()->EndUpdate(ctx, update.mUpdateRect + offset);
   152     }
   153   }
   154 }
   156 void
   157 BasicThebesLayer::Validate(LayerManager::DrawThebesLayerCallback aCallback,
   158                            void* aCallbackData)
   159 {
   160   if (!mContentClient) {
   161     // This client will have a null Forwarder, which means it will not have
   162     // a ContentHost on the other side.
   163     mContentClient = new ContentClientBasic();
   164   }
   166   if (!BasicManager()->IsRetained()) {
   167     return;
   168   }
   170   uint32_t flags = 0;
   171 #ifndef MOZ_WIDGET_ANDROID
   172   if (BasicManager()->CompositorMightResample()) {
   173     flags |= RotatedContentBuffer::PAINT_WILL_RESAMPLE;
   174   }
   175   if (!(flags & RotatedContentBuffer::PAINT_WILL_RESAMPLE)) {
   176     if (MayResample()) {
   177       flags |= RotatedContentBuffer::PAINT_WILL_RESAMPLE;
   178     }
   179   }
   180 #endif
   181   if (mDrawAtomically) {
   182     flags |= RotatedContentBuffer::PAINT_NO_ROTATION;
   183   }
   184   PaintState state =
   185     mContentClient->BeginPaintBuffer(this, flags);
   186   mValidRegion.Sub(mValidRegion, state.mRegionToInvalidate);
   188   if (DrawTarget* target = mContentClient->BorrowDrawTargetForPainting(state)) {
   189     // The area that became invalid and is visible needs to be repainted
   190     // (this could be the whole visible area if our buffer switched
   191     // from RGB to RGBA, because we might need to repaint with
   192     // subpixel AA)
   193     state.mRegionToInvalidate.And(state.mRegionToInvalidate,
   194                                   GetEffectiveVisibleRegion());
   195     SetAntialiasingFlags(this, target);
   197     RenderTraceInvalidateStart(this, "FFFF00", state.mRegionToDraw.GetBounds());
   199     nsRefPtr<gfxContext> ctx = gfxContext::ContextForDrawTarget(target);
   200     PaintBuffer(ctx,
   201                 state.mRegionToDraw, state.mRegionToDraw, state.mRegionToInvalidate,
   202                 state.mDidSelfCopy,
   203                 state.mClip,
   204                 aCallback, aCallbackData);
   205     MOZ_LAYERS_LOG_IF_SHADOWABLE(this, ("Layer::Mutated(%p) PaintThebes", this));
   206     Mutated();
   207     ctx = nullptr;
   208     mContentClient->ReturnDrawTargetToBuffer(target);
   210     RenderTraceInvalidateEnd(this, "FFFF00");
   211   } else {
   212     // It's possible that state.mRegionToInvalidate is nonempty here,
   213     // if we are shrinking the valid region to nothing. So use mRegionToDraw
   214     // instead.
   215     NS_WARN_IF_FALSE(state.mRegionToDraw.IsEmpty(),
   216                      "No context when we have something to draw, resource exhaustion?");
   217   }
   218 }
   220 already_AddRefed<ThebesLayer>
   221 BasicLayerManager::CreateThebesLayer()
   222 {
   223   NS_ASSERTION(InConstruction(), "Only allowed in construction phase");
   224   nsRefPtr<ThebesLayer> layer = new BasicThebesLayer(this);
   225   return layer.forget();
   226 }
   228 }
   229 }

mercurial