gfx/layers/client/ClientThebesLayer.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial