Add new robustness extension tests am: 83c250d247 am: 9df12c2edc am: 630f00b166
[platform/upstream/VK-GL-CTS.git] / framework / common / tcuSurfaceAccess.hpp
1 #ifndef _TCUSURFACEACCESS_HPP
2 #define _TCUSURFACEACCESS_HPP
3 /*-------------------------------------------------------------------------
4  * drawElements Quality Program Tester Core
5  * ----------------------------------------
6  *
7  * Copyright 2014 The Android Open Source Project
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  *//*!
22  * \file
23  * \brief Surface access class.
24  *//*--------------------------------------------------------------------*/
25
26 #include "tcuDefs.hpp"
27 #include "tcuTextureUtil.hpp"
28 #include "tcuPixelFormat.hpp"
29 #include "tcuSurface.hpp"
30
31 namespace tcu
32 {
33
34 inline deUint8 getColorMask (const tcu::PixelFormat& format)
35 {
36         return (deUint8)((format.redBits        ? tcu::RGBA::RED_MASK   : 0) |
37                                          (format.greenBits      ? tcu::RGBA::GREEN_MASK : 0) |
38                                          (format.blueBits       ? tcu::RGBA::BLUE_MASK  : 0) |
39                                          (format.alphaBits      ? tcu::RGBA::ALPHA_MASK : 0));
40 }
41
42 inline tcu::RGBA toRGBAMasked (const tcu::Vec4& v, deUint8 mask)
43 {
44         return tcu::RGBA((mask&tcu::RGBA::RED_MASK)             ? tcu::floatToU8(v.x()) : 0,
45                                          (mask&tcu::RGBA::GREEN_MASK)   ? tcu::floatToU8(v.y()) : 0,
46                                          (mask&tcu::RGBA::BLUE_MASK)    ? tcu::floatToU8(v.z()) : 0,
47                                          (mask&tcu::RGBA::ALPHA_MASK)   ? tcu::floatToU8(v.w()) : 0xFF); //!< \note Alpha defaults to full saturation when reading masked format
48 }
49
50 class SurfaceAccess
51 {
52 public:
53                                                         SurfaceAccess           (tcu::Surface& surface, const tcu::PixelFormat& colorFmt);
54                                                         SurfaceAccess           (tcu::Surface& surface, const tcu::PixelFormat& colorFmt, int x, int y, int width, int height);
55                                                         SurfaceAccess           (const SurfaceAccess& parent, int x, int y, int width, int height);
56
57         int                                             getWidth                        (void) const    { return m_width;       }
58         int                                             getHeight                       (void) const    { return m_height;      }
59
60         void                                    setPixel                        (const tcu::Vec4& color, int x, int y) const;
61
62 private:
63         mutable tcu::Surface*   m_surface;
64         deUint8                                 m_colorMask;
65         int                                             m_x;
66         int                                             m_y;
67         int                                             m_width;
68         int                                             m_height;
69 };
70
71 inline void SurfaceAccess::setPixel (const tcu::Vec4& color, int x, int y) const
72 {
73         DE_ASSERT(de::inBounds(x, 0, m_width) && de::inBounds(y, 0, m_height));
74         m_surface->setPixel(m_x+x, m_y+y, toRGBAMasked(color, m_colorMask));
75 }
76
77 } // tcu
78
79 #endif // _TCUSURFACEACCESS_HPP