Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/gfx/layers/basic/BasicCanvasLayer.cpp
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
3
/* This Source Code Form is subject to the terms of the Mozilla Public
4
 * License, v. 2.0. If a copy of the MPL was not distributed with this
5
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
#include "BasicCanvasLayer.h"
8
#include "AsyncCanvasRenderer.h"
9
#include "basic/BasicLayers.h"          // for BasicLayerManager
10
#include "basic/BasicLayersImpl.h"      // for GetEffectiveOperator
11
#include "CopyableCanvasRenderer.h"
12
#include "mozilla/mozalloc.h"           // for operator new
13
#include "nsCOMPtr.h"                   // for already_AddRefed
14
#include "nsISupportsImpl.h"            // for Layer::AddRef, etc
15
#include "gfx2DGlue.h"
16
#include "GLScreenBuffer.h"
17
#include "GLContext.h"
18
#include "gfxUtils.h"
19
#include "mozilla/layers/PersistentBufferProvider.h"
20
#include "client/TextureClientSharedSurface.h"
21
22
class gfxContext;
23
24
using namespace mozilla::gfx;
25
using namespace mozilla::gl;
26
27
namespace mozilla {
28
namespace layers {
29
30
void
31
BasicCanvasLayer::Paint(DrawTarget* aDT,
32
                        const Point& aDeviceOffset,
33
                        Layer* aMaskLayer)
34
0
{
35
0
  if (IsHidden())
36
0
    return;
37
0
38
0
  RefPtr<SourceSurface> surface;
39
0
  CopyableCanvasRenderer* canvasRenderer = mCanvasRenderer->AsCopyableCanvasRenderer();
40
0
  MOZ_ASSERT(canvasRenderer);
41
0
  if (IsDirty()) {
42
0
    Painted();
43
0
44
0
    surface = canvasRenderer->ReadbackSurface();
45
0
  }
46
0
47
0
  bool bufferPoviderSnapshot = false;
48
0
  PersistentBufferProvider* bufferProvider = canvasRenderer->GetBufferProvider();
49
0
  if (!surface && bufferProvider) {
50
0
    surface = bufferProvider->BorrowSnapshot();
51
0
    bufferPoviderSnapshot = !!surface;
52
0
  }
53
0
54
0
  if (!surface) {
55
0
    return;
56
0
  }
57
0
58
0
  Matrix oldTM;
59
0
  if (canvasRenderer->NeedsYFlip()) {
60
0
    oldTM = aDT->GetTransform();
61
0
    aDT->SetTransform(Matrix(oldTM).
62
0
                      PreTranslate(0.0f, mBounds.Height()).
63
0
                        PreScale(1.0f, -1.0f));
64
0
  }
65
0
66
0
  FillRectWithMask(aDT, aDeviceOffset,
67
0
                   Rect(0, 0, mBounds.Width(), mBounds.Height()),
68
0
                   surface, mSamplingFilter,
69
0
                   DrawOptions(GetEffectiveOpacity(), GetEffectiveOperator(this)),
70
0
                   aMaskLayer);
71
0
72
0
  if (canvasRenderer->NeedsYFlip()) {
73
0
    aDT->SetTransform(oldTM);
74
0
  }
75
0
76
0
  if (bufferPoviderSnapshot) {
77
0
    bufferProvider->ReturnSnapshot(surface.forget());
78
0
  }
79
0
}
80
81
CanvasRenderer*
82
BasicCanvasLayer::CreateCanvasRendererInternal()
83
0
{
84
0
  return new CopyableCanvasRenderer();
85
0
}
86
87
already_AddRefed<CanvasLayer>
88
BasicLayerManager::CreateCanvasLayer()
89
0
{
90
0
  NS_ASSERTION(InConstruction(), "Only allowed in construction phase");
91
0
  RefPtr<CanvasLayer> layer = new BasicCanvasLayer(this);
92
0
  return layer.forget();
93
0
}
94
95
} // namespace layers
96
} // namespace mozilla