Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/image/SurfacePipe.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 "SurfacePipe.h"
8
9
#include <algorithm>    // for min
10
11
#include "Decoder.h"
12
13
namespace mozilla {
14
namespace image {
15
16
using namespace gfx;
17
18
using std::min;
19
20
Maybe<SurfaceInvalidRect>
21
AbstractSurfaceSink::TakeInvalidRect()
22
0
{
23
0
  if (mInvalidRect.IsEmpty()) {
24
0
    return Nothing();
25
0
  }
26
0
27
0
  SurfaceInvalidRect invalidRect;
28
0
  invalidRect.mInputSpaceRect = invalidRect.mOutputSpaceRect = mInvalidRect;
29
0
30
0
  // Forget about the invalid rect we're returning.
31
0
  mInvalidRect = IntRect();
32
0
33
0
  return Some(invalidRect);
34
0
}
35
36
uint8_t*
37
AbstractSurfaceSink::DoResetToFirstRow()
38
0
{
39
0
  mRow = 0;
40
0
  return GetRowPointer();
41
0
}
42
43
uint8_t*
44
AbstractSurfaceSink::DoAdvanceRow()
45
0
{
46
0
  if (mRow >= uint32_t(InputSize().height)) {
47
0
    return nullptr;
48
0
  }
49
0
50
0
  // If we're vertically flipping the output, we need to flip the invalid rect. Since we're
51
0
  // dealing with an axis-aligned rect, only the y coordinate needs to change.
52
0
  int32_t invalidY = mFlipVertically
53
0
                   ? InputSize().height - (mRow + 1)
54
0
                   : mRow;
55
0
  mInvalidRect.UnionRect(mInvalidRect,
56
0
                         IntRect(0, invalidY, InputSize().width, 1));
57
0
58
0
  mRow = min(uint32_t(InputSize().height), mRow + 1);
59
0
60
0
  return mRow < uint32_t(InputSize().height) ? GetRowPointer()
61
0
                                             : nullptr;
62
0
}
63
64
nsresult
65
SurfaceSink::Configure(const SurfaceConfig& aConfig)
66
0
{
67
0
  // For non-paletted surfaces, the surface size is just the output size.
68
0
  IntSize surfaceSize = aConfig.mOutputSize;
69
0
70
0
  // Non-paletted surfaces should not have frame rects, so we just pass
71
0
  // AllocateFrame() a frame rect which covers the entire surface.
72
0
  IntRect frameRect(0, 0, surfaceSize.width, surfaceSize.height);
73
0
74
0
  // Allocate the frame.
75
0
  // XXX(seth): Once every Decoder subclass uses SurfacePipe, we probably want
76
0
  // to allocate the frame directly here and get rid of Decoder::AllocateFrame
77
0
  // altogether.
78
0
  nsresult rv = aConfig.mDecoder->AllocateFrame(surfaceSize,
79
0
                                                frameRect,
80
0
                                                aConfig.mFormat,
81
0
                                                /* aPaletteDepth */ 0,
82
0
                                                aConfig.mAnimParams);
83
0
  if (NS_FAILED(rv)) {
84
0
    return rv;
85
0
  }
86
0
87
0
  mImageData = aConfig.mDecoder->mImageData;
88
0
  mImageDataLength = aConfig.mDecoder->mImageDataLength;
89
0
  mFlipVertically = aConfig.mFlipVertically;
90
0
91
0
  MOZ_ASSERT(mImageData);
92
0
  MOZ_ASSERT(mImageDataLength ==
93
0
               uint32_t(surfaceSize.width * surfaceSize.height * sizeof(uint32_t)));
94
0
95
0
  ConfigureFilter(surfaceSize, sizeof(uint32_t));
96
0
  return NS_OK;
97
0
}
98
99
uint8_t*
100
SurfaceSink::GetRowPointer() const
101
0
{
102
0
  // If we're flipping vertically, reverse the order in which we traverse the
103
0
  // rows.
104
0
  uint32_t row = mFlipVertically
105
0
               ? InputSize().height - (mRow + 1)
106
0
               : mRow;
107
0
108
0
  uint8_t* rowPtr = mImageData + row * InputSize().width * sizeof(uint32_t);
109
0
110
0
  MOZ_ASSERT(rowPtr >= mImageData);
111
0
  MOZ_ASSERT(rowPtr < mImageData + mImageDataLength);
112
0
  MOZ_ASSERT(rowPtr + InputSize().width * sizeof(uint32_t) <=
113
0
               mImageData + mImageDataLength);
114
0
115
0
  return rowPtr;
116
0
}
117
118
119
nsresult
120
PalettedSurfaceSink::Configure(const PalettedSurfaceConfig& aConfig)
121
0
{
122
0
  MOZ_ASSERT(aConfig.mFormat == SurfaceFormat::B8G8R8A8);
123
0
124
0
  // For paletted surfaces, the surface size is the size of the frame rect.
125
0
  IntSize surfaceSize = aConfig.mFrameRect.Size();
126
0
127
0
  // Allocate the frame.
128
0
  // XXX(seth): Once every Decoder subclass uses SurfacePipe, we probably want
129
0
  // to allocate the frame directly here and get rid of Decoder::AllocateFrame
130
0
  // altogether.
131
0
  nsresult rv = aConfig.mDecoder->AllocateFrame(aConfig.mOutputSize,
132
0
                                                aConfig.mFrameRect,
133
0
                                                aConfig.mFormat,
134
0
                                                aConfig.mPaletteDepth,
135
0
                                                aConfig.mAnimParams);
136
0
  if (NS_FAILED(rv)) {
137
0
    return rv;
138
0
  }
139
0
140
0
  mImageData = aConfig.mDecoder->mImageData;
141
0
  mImageDataLength = aConfig.mDecoder->mImageDataLength;
142
0
  mFlipVertically = aConfig.mFlipVertically;
143
0
  mFrameRect = aConfig.mFrameRect;
144
0
145
0
  MOZ_ASSERT(mImageData);
146
0
  MOZ_ASSERT(mImageDataLength ==
147
0
             uint32_t(mFrameRect.Width() * mFrameRect.Height() * sizeof(uint8_t)));
148
0
149
0
  ConfigureFilter(surfaceSize, sizeof(uint8_t));
150
0
  return NS_OK;
151
0
}
152
153
uint8_t*
154
PalettedSurfaceSink::GetRowPointer() const
155
0
{
156
0
  // If we're flipping vertically, reverse the order in which we traverse the
157
0
  // rows.
158
0
  uint32_t row = mFlipVertically
159
0
               ? InputSize().height - (mRow + 1)
160
0
               : mRow;
161
0
162
0
  uint8_t* rowPtr = mImageData + row * InputSize().width * sizeof(uint8_t);
163
0
164
0
  MOZ_ASSERT(rowPtr >= mImageData);
165
0
  MOZ_ASSERT(rowPtr < mImageData + mImageDataLength);
166
0
  MOZ_ASSERT(rowPtr + InputSize().width * sizeof(uint8_t) <=
167
0
               mImageData + mImageDataLength);
168
0
169
0
  return rowPtr;
170
0
}
171
172
} // namespace image
173
} // namespace mozilla