Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dist/include/mozilla/layers/ImageHost.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_IMAGEHOST_H
8
#define MOZILLA_GFX_IMAGEHOST_H
9
10
#include <stdio.h>                      // for FILE
11
#include "CompositableHost.h"           // for CompositableHost
12
#include "mozilla/Attributes.h"         // for override
13
#include "mozilla/RefPtr.h"             // for RefPtr
14
#include "mozilla/gfx/MatrixFwd.h"      // for Matrix4x4
15
#include "mozilla/gfx/Point.h"          // for Point
16
#include "mozilla/gfx/Polygon.h"        // for Polygon
17
#include "mozilla/gfx/Rect.h"           // for Rect
18
#include "mozilla/gfx/Types.h"          // for SamplingFilter
19
#include "mozilla/layers/CompositorTypes.h"  // for TextureInfo, etc
20
#include "mozilla/layers/ImageComposite.h"  // for ImageComposite
21
#include "mozilla/layers/LayersSurfaces.h"  // for SurfaceDescriptor
22
#include "mozilla/layers/LayersTypes.h"  // for LayerRenderState, etc
23
#include "mozilla/layers/TextureHost.h"  // for TextureHost, etc
24
#include "mozilla/mozalloc.h"           // for operator delete
25
#include "nsCOMPtr.h"                   // for already_AddRefed
26
#include "nsRect.h"                     // for mozilla::gfx::IntRect
27
#include "nsRegionFwd.h"                // for nsIntRegion
28
#include "nscore.h"                     // for nsACString
29
30
namespace mozilla {
31
namespace layers {
32
33
class Compositor;
34
struct EffectChain;
35
class HostLayerManager;
36
37
/**
38
 * ImageHost. Works with ImageClientSingle and ImageClientBuffered
39
 */
40
class ImageHost : public CompositableHost,
41
                  public ImageComposite
42
{
43
public:
44
  explicit ImageHost(const TextureInfo& aTextureInfo);
45
  ~ImageHost();
46
47
0
  virtual CompositableType GetType() override { return mTextureInfo.mCompositableType; }
48
0
  virtual ImageHost* AsImageHost() override { return this; }
49
50
  virtual void Composite(Compositor* aCompositor,
51
                         LayerComposite* aLayer,
52
                         EffectChain& aEffectChain,
53
                         float aOpacity,
54
                         const gfx::Matrix4x4& aTransform,
55
                         const gfx::SamplingFilter aSamplingFilter,
56
                         const gfx::IntRect& aClipRect,
57
                         const nsIntRegion* aVisibleRegion = nullptr,
58
                         const Maybe<gfx::Polygon>& aGeometry = Nothing()) override;
59
60
  virtual void UseTextureHost(const nsTArray<TimedTexture>& aTextures) override;
61
62
  virtual void RemoveTextureHost(TextureHost* aTexture) override;
63
64
  virtual TextureHost* GetAsTextureHost(gfx::IntRect* aPictureRect = nullptr) override;
65
66
  virtual void Attach(Layer* aLayer,
67
                      TextureSourceProvider* aProvider,
68
                      AttachFlags aFlags = NO_FLAGS) override;
69
70
  virtual void SetTextureSourceProvider(TextureSourceProvider* aProvider) override;
71
72
  gfx::IntSize GetImageSize() override;
73
74
  virtual void PrintInfo(std::stringstream& aStream, const char* aPrefix) override;
75
76
  virtual void Dump(std::stringstream& aStream,
77
                    const char* aPrefix = "",
78
                    bool aDumpHtml = false) override;
79
80
  virtual already_AddRefed<gfx::DataSourceSurface> GetAsSurface() override;
81
82
  virtual bool Lock() override;
83
84
  virtual void Unlock() override;
85
86
  virtual already_AddRefed<TexturedEffect> GenEffect(const gfx::SamplingFilter aSamplingFilter) override;
87
88
  void SetCurrentTextureHost(TextureHost* aTexture);
89
90
  virtual void CleanupResources() override;
91
92
  bool IsOpaque();
93
94
  uint32_t GetDroppedFrames() override
95
0
  {
96
0
    return GetDroppedFramesAndReset();
97
0
  }
98
99
  struct RenderInfo {
100
    int imageIndex;
101
    const TimedImage* img;
102
    RefPtr<TextureHost> host;
103
104
    RenderInfo() : imageIndex(-1), img(nullptr)
105
0
    {}
106
  };
107
108
  // Acquire rendering information for the current frame.
109
  bool PrepareToRender(TextureSourceProvider* aProvider, RenderInfo* aOutInfo);
110
111
  // Acquire the TextureSource for the currently prepared frame.
112
  RefPtr<TextureSource> AcquireTextureSource(const RenderInfo& aInfo);
113
114
  // Send ImageComposite notifications and update the ChooseImage bias.
115
  void FinishRendering(const RenderInfo& aInfo);
116
117
  // This should only be called inside a lock, or during rendering. It is
118
  // infallible to enforce this.
119
0
  TextureHost* CurrentTextureHost() const {
120
0
    MOZ_ASSERT(mCurrentTextureHost);
121
0
    return mCurrentTextureHost;
122
0
  }
123
124
protected:
125
  // ImageComposite
126
  virtual TimeStamp GetCompositionTime() const override;
127
128
  // Use a simple RefPtr because the same texture is already held by a
129
  // a CompositableTextureHostRef in the array of TimedImage.
130
  // See the comment in CompositableTextureRef for more details.
131
  RefPtr<TextureHost> mCurrentTextureHost;
132
  CompositableTextureSourceRef mCurrentTextureSource;
133
  // When doing texture uploads it's best to alternate between two (or three)
134
  // texture sources so that the texture we upload to isn't being used by
135
  // the GPU to composite the previous frame.
136
  RefPtr<TextureSource> mExtraTextureSource;
137
138
  bool mLocked;
139
};
140
141
} // namespace layers
142
} // namespace mozilla
143
144
#endif