Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dist/include/mozilla/layers/ImageComposite.h
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
#ifndef MOZILLA_GFX_IMAGECOMPOSITE_H
8
#define MOZILLA_GFX_IMAGECOMPOSITE_H
9
10
#include "CompositableHost.h"           // for CompositableTextureHostRef
11
#include "mozilla/gfx/2D.h"
12
#include "mozilla/TimeStamp.h"          // for TimeStamp
13
#include "nsTArray.h"
14
15
namespace mozilla {
16
namespace layers {
17
18
/**
19
 * Implements Image selection logic.
20
 */
21
class ImageComposite
22
{
23
public:
24
  static const float BIAS_TIME_MS;
25
26
  explicit ImageComposite();
27
  ~ImageComposite();
28
29
  int32_t GetFrameID()
30
0
  {
31
0
    const TimedImage* img = ChooseImage();
32
0
    return img ? img->mFrameID : -1;
33
0
  }
34
35
  int32_t GetProducerID()
36
0
  {
37
0
    const TimedImage* img = ChooseImage();
38
0
    return img ? img->mProducerID : -1;
39
0
  }
40
41
0
  int32_t GetLastFrameID() const { return mLastFrameID; }
42
0
  int32_t GetLastProducerID() const { return mLastProducerID; }
43
  uint32_t GetDroppedFramesAndReset()
44
0
  {
45
0
    uint32_t dropped = mDroppedFrames;
46
0
    mDroppedFrames = 0;
47
0
    return dropped;
48
0
  }
49
50
  enum Bias {
51
    // Don't apply bias to frame times
52
    BIAS_NONE,
53
    // Apply a negative bias to frame times to keep them before the vsync time
54
    BIAS_NEGATIVE,
55
    // Apply a positive bias to frame times to keep them after the vsync time
56
    BIAS_POSITIVE,
57
  };
58
59
protected:
60
  void UpdateBias(size_t aImageIndex);
61
62
  virtual TimeStamp GetCompositionTime() const = 0;
63
64
  struct TimedImage {
65
    CompositableTextureHostRef mTextureHost;
66
    TimeStamp mTimeStamp;
67
    gfx::IntRect mPictureRect;
68
    int32_t mFrameID;
69
    int32_t mProducerID;
70
  };
71
72
  /**
73
   * ChooseImage is guaranteed to return the same TimedImage every time it's
74
   * called during the same composition, up to the end of Composite() ---
75
   * it depends only on mImages, mCompositor->GetCompositionTime(), and mBias.
76
   * mBias is updated at the end of Composite().
77
   */
78
  const TimedImage* ChooseImage();
79
  int ChooseImageIndex();
80
  const TimedImage* GetImage(size_t aIndex) const;
81
0
  size_t ImagesCount() const { return mImages.Length(); }
82
0
  const nsTArray<TimedImage>& Images() const { return mImages; }
83
84
  void RemoveImagesWithTextureHost(TextureHost* aTexture);
85
  void ClearImages();
86
  void SetImages(nsTArray<TimedImage>&& aNewImages);
87
88
  int32_t mLastFrameID;
89
  int32_t mLastProducerID;
90
91
private:
92
  nsTArray<TimedImage> mImages;
93
  TimeStamp GetBiasedTime(const TimeStamp& aInput) const;
94
  // Scan new images and look for common ones in the existing mImages array.
95
  // Will determine if an image has been dropped through gaps between images and
96
  // adjust mDroppedFrames accordingly.
97
  // Return the index of what the last returned image would have been.
98
  uint32_t ScanForLastFrameIndex(const nsTArray<TimedImage>& aNewImages);
99
100
  /**
101
   * Bias to apply to the next frame.
102
   */
103
  Bias mBias;
104
  uint32_t mDroppedFrames;
105
  uint32_t mLastChosenImageIndex;
106
};
107
108
} // namespace layers
109
} // namespace mozilla
110
111
#endif // MOZILLA_GFX_IMAGECOMPOSITE_H