Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dist/include/mozilla/layers/ImageClient.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_IMAGECLIENT_H
8
#define MOZILLA_GFX_IMAGECLIENT_H
9
10
#include <stdint.h>                     // for uint32_t, uint64_t
11
#include <sys/types.h>                  // for int32_t
12
#include "mozilla/Attributes.h"         // for override
13
#include "mozilla/RefPtr.h"             // for RefPtr, already_AddRefed
14
#include "mozilla/gfx/Types.h"          // for SurfaceFormat
15
#include "mozilla/layers/CompositableClient.h"  // for CompositableClient
16
#include "mozilla/layers/CompositorTypes.h"  // for CompositableType, etc
17
#include "mozilla/layers/LayersSurfaces.h"  // for SurfaceDescriptor
18
#include "mozilla/layers/TextureClient.h"  // for TextureClient, etc
19
#include "mozilla/mozalloc.h"           // for operator delete
20
#include "nsCOMPtr.h"                   // for already_AddRefed
21
#include "nsRect.h"                     // for mozilla::gfx::IntRect
22
23
namespace mozilla {
24
namespace layers {
25
26
class ClientLayer;
27
class CompositableForwarder;
28
class Image;
29
class ImageContainer;
30
class ShadowableLayer;
31
class ImageClientSingle;
32
33
/**
34
 * Image clients are used by basic image layers on the content thread, they
35
 * always match with an ImageHost on the compositor thread. See
36
 * CompositableClient.h for information on connecting clients to hosts.
37
 */
38
class ImageClient : public CompositableClient
39
{
40
public:
41
  /**
42
   * Creates, configures, and returns a new image client. If necessary, a
43
   * message will be sent to the compositor to create a corresponding image
44
   * host.
45
   */
46
  static already_AddRefed<ImageClient> CreateImageClient(CompositableType aImageHostType,
47
                                                     CompositableForwarder* aFwd,
48
                                                     TextureFlags aFlags);
49
50
0
  virtual ~ImageClient() {}
51
52
  /**
53
   * Update this ImageClient from aContainer in aLayer
54
   * returns false if this is the wrong kind of ImageClient for aContainer.
55
   * Note that returning true does not necessarily imply success
56
   */
57
  virtual bool UpdateImage(ImageContainer* aContainer, uint32_t aContentFlags) = 0;
58
59
  void SetLayer(ClientLayer* aLayer) { mLayer = aLayer; }
60
0
  ClientLayer* GetLayer() const { return mLayer; }
61
62
  /**
63
   * asynchronously remove all the textures used by the image client.
64
   *
65
   */
66
  virtual void FlushAllImages() {}
67
68
  virtual void RemoveTexture(TextureClient* aTexture) override;
69
70
  virtual ImageClientSingle* AsImageClientSingle() { return nullptr; }
71
72
  static already_AddRefed<TextureClient> CreateTextureClientForImage(Image* aImage, KnowsCompositor* aForwarder);
73
74
0
  uint32_t GetLastUpdateGenerationCounter() { return mLastUpdateGenerationCounter; }
75
76
  virtual RefPtr<TextureClient> GetForwardedTexture() { return nullptr; }
77
78
protected:
79
  ImageClient(CompositableForwarder* aFwd, TextureFlags aFlags,
80
              CompositableType aType);
81
82
  ClientLayer* mLayer;
83
  CompositableType mType;
84
  uint32_t mLastUpdateGenerationCounter;
85
};
86
87
/**
88
 * An image client which uses a single texture client.
89
 */
90
class ImageClientSingle : public ImageClient
91
{
92
public:
93
  ImageClientSingle(CompositableForwarder* aFwd,
94
                    TextureFlags aFlags,
95
                    CompositableType aType);
96
97
  virtual bool UpdateImage(ImageContainer* aContainer, uint32_t aContentFlags) override;
98
99
  virtual void OnDetach() override;
100
101
  virtual bool AddTextureClient(TextureClient* aTexture) override;
102
103
  virtual TextureInfo GetTextureInfo() const override;
104
105
  virtual void FlushAllImages() override;
106
107
  ImageClientSingle* AsImageClientSingle() override { return this; }
108
109
  virtual RefPtr<TextureClient> GetForwardedTexture() override;
110
111
0
  bool IsEmpty() { return mBuffers.IsEmpty(); }
112
113
protected:
114
  struct Buffer {
115
    RefPtr<TextureClient> mTextureClient;
116
    int32_t mImageSerial;
117
  };
118
  nsTArray<Buffer> mBuffers;
119
};
120
121
/**
122
 * Image class to be used for async image uploads using the image bridge
123
 * protocol.
124
 * We store the ImageBridge id in the TextureClientIdentifier.
125
 */
126
class ImageClientBridge : public ImageClient
127
{
128
public:
129
  ImageClientBridge(CompositableForwarder* aFwd,
130
                    TextureFlags aFlags);
131
132
  virtual bool UpdateImage(ImageContainer* aContainer, uint32_t aContentFlags) override;
133
  virtual bool Connect(ImageContainer* aImageContainer) override { return false; }
134
135
  virtual TextureInfo GetTextureInfo() const override
136
  {
137
    return TextureInfo(mType);
138
  }
139
140
protected:
141
  CompositableHandle mAsyncContainerHandle;
142
};
143
144
} // namespace layers
145
} // namespace mozilla
146
147
#endif