1*09537850SAkhilesh Sanikop // Copyright 2021 The libgav1 Authors
2*09537850SAkhilesh Sanikop //
3*09537850SAkhilesh Sanikop // Licensed under the Apache License, Version 2.0 (the "License");
4*09537850SAkhilesh Sanikop // you may not use this file except in compliance with the License.
5*09537850SAkhilesh Sanikop // You may obtain a copy of the License at
6*09537850SAkhilesh Sanikop //
7*09537850SAkhilesh Sanikop // http://www.apache.org/licenses/LICENSE-2.0
8*09537850SAkhilesh Sanikop //
9*09537850SAkhilesh Sanikop // Unless required by applicable law or agreed to in writing, software
10*09537850SAkhilesh Sanikop // distributed under the License is distributed on an "AS IS" BASIS,
11*09537850SAkhilesh Sanikop // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12*09537850SAkhilesh Sanikop // See the License for the specific language governing permissions and
13*09537850SAkhilesh Sanikop // limitations under the License.
14*09537850SAkhilesh Sanikop
15*09537850SAkhilesh Sanikop #include "src/buffer_pool.h"
16*09537850SAkhilesh Sanikop
17*09537850SAkhilesh Sanikop #include <climits>
18*09537850SAkhilesh Sanikop #include <cstdint>
19*09537850SAkhilesh Sanikop #include <memory>
20*09537850SAkhilesh Sanikop #include <ostream>
21*09537850SAkhilesh Sanikop #include <tuple>
22*09537850SAkhilesh Sanikop #include <utility>
23*09537850SAkhilesh Sanikop
24*09537850SAkhilesh Sanikop #include "gtest/gtest.h"
25*09537850SAkhilesh Sanikop #include "src/frame_buffer_utils.h"
26*09537850SAkhilesh Sanikop #include "src/gav1/decoder_buffer.h"
27*09537850SAkhilesh Sanikop #include "src/gav1/frame_buffer.h"
28*09537850SAkhilesh Sanikop #include "src/internal_frame_buffer_list.h"
29*09537850SAkhilesh Sanikop #include "src/utils/constants.h"
30*09537850SAkhilesh Sanikop #include "src/utils/types.h"
31*09537850SAkhilesh Sanikop #include "src/yuv_buffer.h"
32*09537850SAkhilesh Sanikop
33*09537850SAkhilesh Sanikop namespace libgav1 {
34*09537850SAkhilesh Sanikop namespace {
35*09537850SAkhilesh Sanikop
TEST(BufferPoolTest,RefCountedBufferPtr)36*09537850SAkhilesh Sanikop TEST(BufferPoolTest, RefCountedBufferPtr) {
37*09537850SAkhilesh Sanikop InternalFrameBufferList buffer_list;
38*09537850SAkhilesh Sanikop BufferPool buffer_pool(OnInternalFrameBufferSizeChanged,
39*09537850SAkhilesh Sanikop GetInternalFrameBuffer, ReleaseInternalFrameBuffer,
40*09537850SAkhilesh Sanikop &buffer_list);
41*09537850SAkhilesh Sanikop RefCountedBufferPtr buffer_ptr = buffer_pool.GetFreeBuffer();
42*09537850SAkhilesh Sanikop EXPECT_NE(buffer_ptr, nullptr);
43*09537850SAkhilesh Sanikop EXPECT_EQ(buffer_ptr.use_count(), 1);
44*09537850SAkhilesh Sanikop
45*09537850SAkhilesh Sanikop RefCountedBufferPtr buffer_ptr2 = buffer_ptr;
46*09537850SAkhilesh Sanikop RefCountedBufferPtr buffer_ptr3 = buffer_ptr;
47*09537850SAkhilesh Sanikop EXPECT_EQ(buffer_ptr.use_count(), 3);
48*09537850SAkhilesh Sanikop EXPECT_EQ(buffer_ptr2.use_count(), 3);
49*09537850SAkhilesh Sanikop EXPECT_EQ(buffer_ptr3.use_count(), 3);
50*09537850SAkhilesh Sanikop
51*09537850SAkhilesh Sanikop buffer_ptr2 = nullptr;
52*09537850SAkhilesh Sanikop EXPECT_EQ(buffer_ptr.use_count(), 2);
53*09537850SAkhilesh Sanikop EXPECT_EQ(buffer_ptr2.use_count(), 0);
54*09537850SAkhilesh Sanikop EXPECT_EQ(buffer_ptr3.use_count(), 2);
55*09537850SAkhilesh Sanikop
56*09537850SAkhilesh Sanikop RefCountedBufferPtr buffer_ptr4 = std::move(buffer_ptr);
57*09537850SAkhilesh Sanikop EXPECT_EQ(buffer_ptr.use_count(), 0);
58*09537850SAkhilesh Sanikop EXPECT_EQ(buffer_ptr2.use_count(), 0);
59*09537850SAkhilesh Sanikop EXPECT_EQ(buffer_ptr3.use_count(), 2);
60*09537850SAkhilesh Sanikop EXPECT_EQ(buffer_ptr4.use_count(), 2);
61*09537850SAkhilesh Sanikop }
62*09537850SAkhilesh Sanikop
TEST(RefCountedBufferTest,SetFrameDimensions)63*09537850SAkhilesh Sanikop TEST(RefCountedBufferTest, SetFrameDimensions) {
64*09537850SAkhilesh Sanikop InternalFrameBufferList buffer_list;
65*09537850SAkhilesh Sanikop BufferPool buffer_pool(OnInternalFrameBufferSizeChanged,
66*09537850SAkhilesh Sanikop GetInternalFrameBuffer, ReleaseInternalFrameBuffer,
67*09537850SAkhilesh Sanikop &buffer_list);
68*09537850SAkhilesh Sanikop RefCountedBufferPtr buffer_ptr = buffer_pool.GetFreeBuffer();
69*09537850SAkhilesh Sanikop EXPECT_NE(buffer_ptr, nullptr);
70*09537850SAkhilesh Sanikop
71*09537850SAkhilesh Sanikop // Test the undocumented default values of rows4x4() and columns4x4(). (Not
72*09537850SAkhilesh Sanikop // sure if this is a good idea.)
73*09537850SAkhilesh Sanikop EXPECT_EQ(buffer_ptr->rows4x4(), 0);
74*09537850SAkhilesh Sanikop EXPECT_EQ(buffer_ptr->columns4x4(), 0);
75*09537850SAkhilesh Sanikop
76*09537850SAkhilesh Sanikop // Test the side effects of SetFrameDimensions().
77*09537850SAkhilesh Sanikop ObuFrameHeader frame_header = {};
78*09537850SAkhilesh Sanikop frame_header.rows4x4 = 20;
79*09537850SAkhilesh Sanikop frame_header.columns4x4 = 30;
80*09537850SAkhilesh Sanikop EXPECT_TRUE(buffer_ptr->SetFrameDimensions(frame_header));
81*09537850SAkhilesh Sanikop EXPECT_EQ(buffer_ptr->rows4x4(), 20);
82*09537850SAkhilesh Sanikop EXPECT_EQ(buffer_ptr->columns4x4(), 30);
83*09537850SAkhilesh Sanikop }
84*09537850SAkhilesh Sanikop
TEST(RefCountedBuffertTest,WaitUntil)85*09537850SAkhilesh Sanikop TEST(RefCountedBuffertTest, WaitUntil) {
86*09537850SAkhilesh Sanikop InternalFrameBufferList buffer_list;
87*09537850SAkhilesh Sanikop BufferPool buffer_pool(OnInternalFrameBufferSizeChanged,
88*09537850SAkhilesh Sanikop GetInternalFrameBuffer, ReleaseInternalFrameBuffer,
89*09537850SAkhilesh Sanikop &buffer_list);
90*09537850SAkhilesh Sanikop RefCountedBufferPtr buffer_ptr = buffer_pool.GetFreeBuffer();
91*09537850SAkhilesh Sanikop EXPECT_NE(buffer_ptr, nullptr);
92*09537850SAkhilesh Sanikop
93*09537850SAkhilesh Sanikop int progress_row_cache;
94*09537850SAkhilesh Sanikop buffer_ptr->SetProgress(10);
95*09537850SAkhilesh Sanikop EXPECT_TRUE(buffer_ptr->WaitUntil(5, &progress_row_cache));
96*09537850SAkhilesh Sanikop EXPECT_EQ(progress_row_cache, 10);
97*09537850SAkhilesh Sanikop
98*09537850SAkhilesh Sanikop buffer_ptr->SetFrameState(kFrameStateDecoded);
99*09537850SAkhilesh Sanikop EXPECT_TRUE(buffer_ptr->WaitUntil(500, &progress_row_cache));
100*09537850SAkhilesh Sanikop EXPECT_EQ(progress_row_cache, INT_MAX);
101*09537850SAkhilesh Sanikop
102*09537850SAkhilesh Sanikop buffer_ptr->Abort();
103*09537850SAkhilesh Sanikop EXPECT_FALSE(buffer_ptr->WaitUntil(50, &progress_row_cache));
104*09537850SAkhilesh Sanikop }
105*09537850SAkhilesh Sanikop
106*09537850SAkhilesh Sanikop constexpr struct Params {
107*09537850SAkhilesh Sanikop int width;
108*09537850SAkhilesh Sanikop int height;
109*09537850SAkhilesh Sanikop int8_t subsampling_x;
110*09537850SAkhilesh Sanikop int8_t subsampling_y;
111*09537850SAkhilesh Sanikop int border;
112*09537850SAkhilesh Sanikop } kParams[] = {
113*09537850SAkhilesh Sanikop {1920, 1080, 1, 1, 96}, //
114*09537850SAkhilesh Sanikop {1920, 1080, 1, 1, 64}, //
115*09537850SAkhilesh Sanikop {1920, 1080, 1, 1, 32}, //
116*09537850SAkhilesh Sanikop {1920, 1080, 1, 1, 160}, //
117*09537850SAkhilesh Sanikop {1920, 1080, 1, 0, 160}, //
118*09537850SAkhilesh Sanikop {1920, 1080, 0, 0, 160}, //
119*09537850SAkhilesh Sanikop };
120*09537850SAkhilesh Sanikop
operator <<(std::ostream & os,const Params & param)121*09537850SAkhilesh Sanikop std::ostream& operator<<(std::ostream& os, const Params& param) {
122*09537850SAkhilesh Sanikop return os << param.width << "x" << param.height
123*09537850SAkhilesh Sanikop << ", subsampling(x/y): " << static_cast<int>(param.subsampling_x)
124*09537850SAkhilesh Sanikop << "/" << static_cast<int>(param.subsampling_y)
125*09537850SAkhilesh Sanikop << ", border: " << param.border;
126*09537850SAkhilesh Sanikop }
127*09537850SAkhilesh Sanikop
128*09537850SAkhilesh Sanikop class RefCountedBufferReallocTest
129*09537850SAkhilesh Sanikop : public testing::TestWithParam<std::tuple<bool, Params>> {
130*09537850SAkhilesh Sanikop protected:
131*09537850SAkhilesh Sanikop const bool use_external_callbacks_ = std::get<0>(GetParam());
132*09537850SAkhilesh Sanikop const Params& param_ = std::get<1>(GetParam());
133*09537850SAkhilesh Sanikop };
134*09537850SAkhilesh Sanikop
135*09537850SAkhilesh Sanikop TEST_P(RefCountedBufferReallocTest, 8Bit) {
136*09537850SAkhilesh Sanikop InternalFrameBufferList buffer_list;
137*09537850SAkhilesh Sanikop FrameBufferSizeChangedCallback on_frame_buffer_size_changed = nullptr;
138*09537850SAkhilesh Sanikop GetFrameBufferCallback get_frame_buffer = nullptr;
139*09537850SAkhilesh Sanikop ReleaseFrameBufferCallback release_frame_buffer = nullptr;
140*09537850SAkhilesh Sanikop void* callback_private_data = nullptr;
141*09537850SAkhilesh Sanikop if (use_external_callbacks_) {
142*09537850SAkhilesh Sanikop on_frame_buffer_size_changed = OnInternalFrameBufferSizeChanged;
143*09537850SAkhilesh Sanikop get_frame_buffer = GetInternalFrameBuffer;
144*09537850SAkhilesh Sanikop release_frame_buffer = ReleaseInternalFrameBuffer;
145*09537850SAkhilesh Sanikop callback_private_data = &buffer_list;
146*09537850SAkhilesh Sanikop }
147*09537850SAkhilesh Sanikop
148*09537850SAkhilesh Sanikop BufferPool buffer_pool(on_frame_buffer_size_changed, get_frame_buffer,
149*09537850SAkhilesh Sanikop release_frame_buffer, callback_private_data);
150*09537850SAkhilesh Sanikop
151*09537850SAkhilesh Sanikop RefCountedBufferPtr buffer_ptr = buffer_pool.GetFreeBuffer();
152*09537850SAkhilesh Sanikop EXPECT_NE(buffer_ptr, nullptr);
153*09537850SAkhilesh Sanikop
154*09537850SAkhilesh Sanikop const Libgav1ImageFormat image_format = ComposeImageFormat(
155*09537850SAkhilesh Sanikop /*is_monochrome=*/false, param_.subsampling_x, param_.subsampling_y);
156*09537850SAkhilesh Sanikop EXPECT_TRUE(buffer_pool.OnFrameBufferSizeChanged(
157*09537850SAkhilesh Sanikop /*bitdepth=*/8, image_format, param_.width, param_.height, param_.border,
158*09537850SAkhilesh Sanikop param_.border, param_.border, param_.border));
159*09537850SAkhilesh Sanikop
160*09537850SAkhilesh Sanikop EXPECT_TRUE(buffer_ptr->Realloc(
161*09537850SAkhilesh Sanikop /*bitdepth=*/8, /*is_monochrome=*/false, param_.width, param_.height,
162*09537850SAkhilesh Sanikop param_.subsampling_x, param_.subsampling_y, param_.border, param_.border,
163*09537850SAkhilesh Sanikop param_.border, param_.border));
164*09537850SAkhilesh Sanikop
165*09537850SAkhilesh Sanikop // The first row of each plane is aligned at 16-byte boundaries.
166*09537850SAkhilesh Sanikop EXPECT_EQ(
167*09537850SAkhilesh Sanikop reinterpret_cast<uintptr_t>(buffer_ptr->buffer()->data(kPlaneY)) % 16, 0);
168*09537850SAkhilesh Sanikop EXPECT_EQ(
169*09537850SAkhilesh Sanikop reinterpret_cast<uintptr_t>(buffer_ptr->buffer()->data(kPlaneU)) % 16, 0);
170*09537850SAkhilesh Sanikop EXPECT_EQ(
171*09537850SAkhilesh Sanikop reinterpret_cast<uintptr_t>(buffer_ptr->buffer()->data(kPlaneV)) % 16, 0);
172*09537850SAkhilesh Sanikop
173*09537850SAkhilesh Sanikop // Subsequent rows are aligned at 16-byte boundaries.
174*09537850SAkhilesh Sanikop EXPECT_EQ(buffer_ptr->buffer()->stride(kPlaneY) % 16, 0);
175*09537850SAkhilesh Sanikop EXPECT_EQ(buffer_ptr->buffer()->stride(kPlaneU) % 16, 0);
176*09537850SAkhilesh Sanikop EXPECT_EQ(buffer_ptr->buffer()->stride(kPlaneV) % 16, 0);
177*09537850SAkhilesh Sanikop
178*09537850SAkhilesh Sanikop // Check the borders.
179*09537850SAkhilesh Sanikop EXPECT_EQ(buffer_ptr->buffer()->left_border(kPlaneY), param_.border);
180*09537850SAkhilesh Sanikop EXPECT_EQ(buffer_ptr->buffer()->right_border(kPlaneY), param_.border);
181*09537850SAkhilesh Sanikop EXPECT_EQ(buffer_ptr->buffer()->top_border(kPlaneY), param_.border);
182*09537850SAkhilesh Sanikop EXPECT_EQ(buffer_ptr->buffer()->bottom_border(kPlaneY), param_.border);
183*09537850SAkhilesh Sanikop EXPECT_EQ(buffer_ptr->buffer()->left_border(kPlaneU),
184*09537850SAkhilesh Sanikop param_.border >> param_.subsampling_x);
185*09537850SAkhilesh Sanikop EXPECT_EQ(buffer_ptr->buffer()->right_border(kPlaneU),
186*09537850SAkhilesh Sanikop param_.border >> param_.subsampling_x);
187*09537850SAkhilesh Sanikop EXPECT_EQ(buffer_ptr->buffer()->top_border(kPlaneU),
188*09537850SAkhilesh Sanikop param_.border >> param_.subsampling_y);
189*09537850SAkhilesh Sanikop EXPECT_EQ(buffer_ptr->buffer()->bottom_border(kPlaneU),
190*09537850SAkhilesh Sanikop param_.border >> param_.subsampling_y);
191*09537850SAkhilesh Sanikop EXPECT_EQ(buffer_ptr->buffer()->left_border(kPlaneV),
192*09537850SAkhilesh Sanikop param_.border >> param_.subsampling_x);
193*09537850SAkhilesh Sanikop EXPECT_EQ(buffer_ptr->buffer()->right_border(kPlaneV),
194*09537850SAkhilesh Sanikop param_.border >> param_.subsampling_x);
195*09537850SAkhilesh Sanikop EXPECT_EQ(buffer_ptr->buffer()->top_border(kPlaneV),
196*09537850SAkhilesh Sanikop param_.border >> param_.subsampling_y);
197*09537850SAkhilesh Sanikop EXPECT_EQ(buffer_ptr->buffer()->bottom_border(kPlaneV),
198*09537850SAkhilesh Sanikop param_.border >> param_.subsampling_y);
199*09537850SAkhilesh Sanikop
200*09537850SAkhilesh Sanikop // Write to the upper-left corner of the border.
201*09537850SAkhilesh Sanikop uint8_t* y_buffer = buffer_ptr->buffer()->data(kPlaneY);
202*09537850SAkhilesh Sanikop int y_stride = buffer_ptr->buffer()->stride(kPlaneY);
203*09537850SAkhilesh Sanikop y_buffer[-buffer_ptr->buffer()->left_border(kPlaneY) -
204*09537850SAkhilesh Sanikop buffer_ptr->buffer()->top_border(kPlaneY) * y_stride] = 0;
205*09537850SAkhilesh Sanikop // Write to the lower-right corner of the border.
206*09537850SAkhilesh Sanikop uint8_t* v_buffer = buffer_ptr->buffer()->data(kPlaneV);
207*09537850SAkhilesh Sanikop int v_stride = buffer_ptr->buffer()->stride(kPlaneV);
208*09537850SAkhilesh Sanikop v_buffer[(buffer_ptr->buffer()->height(kPlaneV) +
209*09537850SAkhilesh Sanikop buffer_ptr->buffer()->bottom_border(kPlaneV) - 1) *
210*09537850SAkhilesh Sanikop v_stride +
211*09537850SAkhilesh Sanikop buffer_ptr->buffer()->width(kPlaneV) +
212*09537850SAkhilesh Sanikop buffer_ptr->buffer()->right_border(kPlaneV) - 1] = 0;
213*09537850SAkhilesh Sanikop }
214*09537850SAkhilesh Sanikop
215*09537850SAkhilesh Sanikop #if LIBGAV1_MAX_BITDEPTH >= 10
216*09537850SAkhilesh Sanikop TEST_P(RefCountedBufferReallocTest, 10Bit) {
217*09537850SAkhilesh Sanikop InternalFrameBufferList buffer_list;
218*09537850SAkhilesh Sanikop FrameBufferSizeChangedCallback on_frame_buffer_size_changed = nullptr;
219*09537850SAkhilesh Sanikop GetFrameBufferCallback get_frame_buffer = nullptr;
220*09537850SAkhilesh Sanikop ReleaseFrameBufferCallback release_frame_buffer = nullptr;
221*09537850SAkhilesh Sanikop void* callback_private_data = nullptr;
222*09537850SAkhilesh Sanikop if (use_external_callbacks_) {
223*09537850SAkhilesh Sanikop on_frame_buffer_size_changed = OnInternalFrameBufferSizeChanged;
224*09537850SAkhilesh Sanikop get_frame_buffer = GetInternalFrameBuffer;
225*09537850SAkhilesh Sanikop release_frame_buffer = ReleaseInternalFrameBuffer;
226*09537850SAkhilesh Sanikop callback_private_data = &buffer_list;
227*09537850SAkhilesh Sanikop }
228*09537850SAkhilesh Sanikop
229*09537850SAkhilesh Sanikop BufferPool buffer_pool(on_frame_buffer_size_changed, get_frame_buffer,
230*09537850SAkhilesh Sanikop release_frame_buffer, callback_private_data);
231*09537850SAkhilesh Sanikop
232*09537850SAkhilesh Sanikop RefCountedBufferPtr buffer_ptr = buffer_pool.GetFreeBuffer();
233*09537850SAkhilesh Sanikop EXPECT_NE(buffer_ptr, nullptr);
234*09537850SAkhilesh Sanikop
235*09537850SAkhilesh Sanikop const Libgav1ImageFormat image_format = ComposeImageFormat(
236*09537850SAkhilesh Sanikop /*is_monochrome=*/false, param_.subsampling_x, param_.subsampling_y);
237*09537850SAkhilesh Sanikop EXPECT_TRUE(buffer_pool.OnFrameBufferSizeChanged(
238*09537850SAkhilesh Sanikop /*bitdepth=*/8, image_format, param_.width, param_.height, param_.border,
239*09537850SAkhilesh Sanikop param_.border, param_.border, param_.border));
240*09537850SAkhilesh Sanikop
241*09537850SAkhilesh Sanikop EXPECT_TRUE(buffer_ptr->Realloc(
242*09537850SAkhilesh Sanikop /*bitdepth=*/10, /*is_monochrome=*/false, param_.width, param_.height,
243*09537850SAkhilesh Sanikop param_.subsampling_x, param_.subsampling_y, param_.border, param_.border,
244*09537850SAkhilesh Sanikop param_.border, param_.border));
245*09537850SAkhilesh Sanikop
246*09537850SAkhilesh Sanikop // The first row of each plane is aligned at 16-byte boundaries.
247*09537850SAkhilesh Sanikop EXPECT_EQ(
248*09537850SAkhilesh Sanikop reinterpret_cast<uintptr_t>(buffer_ptr->buffer()->data(kPlaneY)) % 16, 0);
249*09537850SAkhilesh Sanikop EXPECT_EQ(
250*09537850SAkhilesh Sanikop reinterpret_cast<uintptr_t>(buffer_ptr->buffer()->data(kPlaneU)) % 16, 0);
251*09537850SAkhilesh Sanikop EXPECT_EQ(
252*09537850SAkhilesh Sanikop reinterpret_cast<uintptr_t>(buffer_ptr->buffer()->data(kPlaneV)) % 16, 0);
253*09537850SAkhilesh Sanikop
254*09537850SAkhilesh Sanikop // Subsequent rows are aligned at 16-byte boundaries.
255*09537850SAkhilesh Sanikop EXPECT_EQ(buffer_ptr->buffer()->stride(kPlaneY) % 16, 0);
256*09537850SAkhilesh Sanikop EXPECT_EQ(buffer_ptr->buffer()->stride(kPlaneU) % 16, 0);
257*09537850SAkhilesh Sanikop EXPECT_EQ(buffer_ptr->buffer()->stride(kPlaneV) % 16, 0);
258*09537850SAkhilesh Sanikop
259*09537850SAkhilesh Sanikop // Check the borders.
260*09537850SAkhilesh Sanikop EXPECT_EQ(buffer_ptr->buffer()->left_border(kPlaneY), param_.border);
261*09537850SAkhilesh Sanikop EXPECT_EQ(buffer_ptr->buffer()->right_border(kPlaneY), param_.border);
262*09537850SAkhilesh Sanikop EXPECT_EQ(buffer_ptr->buffer()->top_border(kPlaneY), param_.border);
263*09537850SAkhilesh Sanikop EXPECT_EQ(buffer_ptr->buffer()->bottom_border(kPlaneY), param_.border);
264*09537850SAkhilesh Sanikop EXPECT_EQ(buffer_ptr->buffer()->left_border(kPlaneU),
265*09537850SAkhilesh Sanikop param_.border >> param_.subsampling_x);
266*09537850SAkhilesh Sanikop EXPECT_EQ(buffer_ptr->buffer()->right_border(kPlaneU),
267*09537850SAkhilesh Sanikop param_.border >> param_.subsampling_x);
268*09537850SAkhilesh Sanikop EXPECT_EQ(buffer_ptr->buffer()->top_border(kPlaneU),
269*09537850SAkhilesh Sanikop param_.border >> param_.subsampling_y);
270*09537850SAkhilesh Sanikop EXPECT_EQ(buffer_ptr->buffer()->bottom_border(kPlaneU),
271*09537850SAkhilesh Sanikop param_.border >> param_.subsampling_y);
272*09537850SAkhilesh Sanikop EXPECT_EQ(buffer_ptr->buffer()->left_border(kPlaneV),
273*09537850SAkhilesh Sanikop param_.border >> param_.subsampling_x);
274*09537850SAkhilesh Sanikop EXPECT_EQ(buffer_ptr->buffer()->right_border(kPlaneV),
275*09537850SAkhilesh Sanikop param_.border >> param_.subsampling_x);
276*09537850SAkhilesh Sanikop EXPECT_EQ(buffer_ptr->buffer()->top_border(kPlaneV),
277*09537850SAkhilesh Sanikop param_.border >> param_.subsampling_y);
278*09537850SAkhilesh Sanikop EXPECT_EQ(buffer_ptr->buffer()->bottom_border(kPlaneV),
279*09537850SAkhilesh Sanikop param_.border >> param_.subsampling_y);
280*09537850SAkhilesh Sanikop
281*09537850SAkhilesh Sanikop // Write to the upper-left corner of the border.
282*09537850SAkhilesh Sanikop auto* y_buffer =
283*09537850SAkhilesh Sanikop reinterpret_cast<uint16_t*>(buffer_ptr->buffer()->data(kPlaneY));
284*09537850SAkhilesh Sanikop int y_stride = buffer_ptr->buffer()->stride(kPlaneY) / sizeof(uint16_t);
285*09537850SAkhilesh Sanikop y_buffer[-buffer_ptr->buffer()->left_border(kPlaneY) -
286*09537850SAkhilesh Sanikop buffer_ptr->buffer()->top_border(kPlaneY) * y_stride] = 0;
287*09537850SAkhilesh Sanikop // Write to the lower-right corner of the border.
288*09537850SAkhilesh Sanikop auto* v_buffer =
289*09537850SAkhilesh Sanikop reinterpret_cast<uint16_t*>(buffer_ptr->buffer()->data(kPlaneV));
290*09537850SAkhilesh Sanikop int v_stride = buffer_ptr->buffer()->stride(kPlaneV) / sizeof(uint16_t);
291*09537850SAkhilesh Sanikop v_buffer[(buffer_ptr->buffer()->height(kPlaneV) +
292*09537850SAkhilesh Sanikop buffer_ptr->buffer()->bottom_border(kPlaneV) - 1) *
293*09537850SAkhilesh Sanikop v_stride +
294*09537850SAkhilesh Sanikop buffer_ptr->buffer()->width(kPlaneV) +
295*09537850SAkhilesh Sanikop buffer_ptr->buffer()->right_border(kPlaneV) - 1] = 0;
296*09537850SAkhilesh Sanikop }
297*09537850SAkhilesh Sanikop #endif // LIBGAV1_MAX_BITDEPTH >= 10
298*09537850SAkhilesh Sanikop
299*09537850SAkhilesh Sanikop INSTANTIATE_TEST_SUITE_P(
300*09537850SAkhilesh Sanikop Default, RefCountedBufferReallocTest,
301*09537850SAkhilesh Sanikop testing::Combine(testing::Bool(), // use_external_callbacks
302*09537850SAkhilesh Sanikop testing::ValuesIn(kParams)));
303*09537850SAkhilesh Sanikop
304*09537850SAkhilesh Sanikop } // namespace
305*09537850SAkhilesh Sanikop } // namespace libgav1
306