1/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16#ifndef _HWC2_TEST_PIXEL_COMPARATOR_H
17#define _HWC2_TEST_PIXEL_COMPARATOR_H
18
19#include <ui/GraphicBuffer.h>
20#include <cstdint>
21#include <string>
22#include <utility>
23#include <vector>
24
25class ComparatorResult {
26public:
27    static ComparatorResult& get()
28    {
29        static ComparatorResult instance;
30        return instance;
31    }
32
33    void CompareBuffers(android::sp<android::GraphicBuffer>& resultBuffer,
34            android::sp<android::GraphicBuffer>& expectedBuffer);
35
36    std::string dumpComparison() const;
37
38    ComparatorResult(const ComparatorResult&) = delete;
39    ComparatorResult(ComparatorResult&&) = delete;
40    ComparatorResult& operator=(ComparatorResult const&) = delete;
41    ComparatorResult& operator=(ComparatorResult&&) = delete;
42
43    int32_t getDifferentPixelCount() const { return mDifferentPixelCount; }
44    int32_t getBlankPixelCount() const { return mBlankPixelCount; }
45
46private:
47    ComparatorResult() = default;
48    uint32_t getPixel(int32_t x, int32_t y, uint32_t stride, uint8_t* img) const;
49    std::string pixelDiff(uint32_t x, uint32_t y, uint32_t resultPixel,
50            uint32_t expectedPixel) const;
51
52    int32_t mDifferentPixelCount;
53    int32_t mBlankPixelCount;
54    /* std::tuple<X coordinate, Y coordinate, resultPixel, expectedPixel> */
55    std::vector<std::tuple<uint32_t, uint32_t, uint32_t, uint32_t>>
56            mComparisons;
57};
58
59#endif /* ifndef _HWC2_TEST_PIXEL_COMPARATOR_H */
60