Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dist/include/mozilla/layers/UpdateImageHelper.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 GFX_UPDATEIMAGEHELPER_H
8
#define GFX_UPDATEIMAGEHELPER_H
9
10
#include "Layers.h"
11
#include "mozilla/layers/ImageClient.h"
12
#include "mozilla/layers/TextureClient.h"
13
#include "mozilla/layers/TextureClientRecycleAllocator.h"
14
#include "mozilla/layers/TextureWrapperImage.h"
15
#include "mozilla/gfx/Types.h"
16
17
namespace mozilla {
18
namespace layers {
19
20
class UpdateImageHelper
21
{
22
public:
23
  UpdateImageHelper(ImageContainer* aImageContainer,
24
                    ImageClient* aImageClient,
25
                    gfx::IntSize aImageSize,
26
                    gfx::SurfaceFormat aFormat) :
27
    mImageContainer(aImageContainer),
28
    mImageClient(aImageClient),
29
    mImageSize(aImageSize),
30
    mIsLocked(false)
31
0
  {
32
0
    mTexture = mImageClient->GetTextureClientRecycler()->CreateOrRecycle(aFormat,
33
0
                                                                         mImageSize,
34
0
                                                                         BackendSelector::Content,
35
0
                                                                         TextureFlags::DEFAULT);
36
0
    if (!mTexture) {
37
0
      return;
38
0
    }
39
0
40
0
    mIsLocked = mTexture->Lock(OpenMode::OPEN_WRITE_ONLY);
41
0
    if (!mIsLocked) {
42
0
      return;
43
0
    }
44
0
  }
45
46
  ~UpdateImageHelper()
47
0
  {
48
0
    if (mIsLocked) {
49
0
      mTexture->Unlock();
50
0
      mIsLocked = false;
51
0
    }
52
0
  }
53
54
  already_AddRefed<gfx::DrawTarget> GetDrawTarget()
55
0
  {
56
0
    RefPtr<gfx::DrawTarget> target;
57
0
    if (mTexture) {
58
0
      target = mTexture->BorrowDrawTarget();
59
0
    }
60
0
    return target.forget();
61
0
  }
62
63
  bool UpdateImage()
64
0
  {
65
0
    if (!mTexture) {
66
0
      return false;
67
0
    }
68
0
69
0
    if (mIsLocked) {
70
0
      mTexture->Unlock();
71
0
      mIsLocked = false;
72
0
    }
73
0
74
0
    RefPtr<TextureWrapperImage> image = new TextureWrapperImage(mTexture,
75
0
                                                                gfx::IntRect(gfx::IntPoint(0, 0), mImageSize));
76
0
    mImageContainer->SetCurrentImageInTransaction(image);
77
0
    return mImageClient->UpdateImage(mImageContainer, /* unused */0);
78
0
  }
79
80
private:
81
  RefPtr<ImageContainer> mImageContainer;
82
  RefPtr<ImageClient> mImageClient;
83
  gfx::IntSize mImageSize;
84
  RefPtr<TextureClient> mTexture;
85
  bool mIsLocked;
86
};
87
88
} // namespace layers
89
} // namespace mozilla
90
91
#endif  // GFX_UPDATEIMAGEHELPER_H