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
getColorMask(const tcu::PixelFormat & format)34 inline uint8_t getColorMask(const tcu::PixelFormat &format)
35 {
36 return (uint8_t)((format.redBits ? tcu::RGBA::RED_MASK : 0) | (format.greenBits ? tcu::RGBA::GREEN_MASK : 0) |
37 (format.blueBits ? tcu::RGBA::BLUE_MASK : 0) | (format.alphaBits ? tcu::RGBA::ALPHA_MASK : 0));
38 }
39
toRGBAMasked(const tcu::Vec4 & v,uint8_t mask)40 inline tcu::RGBA toRGBAMasked(const tcu::Vec4 &v, uint8_t mask)
41 {
42 return tcu::RGBA((mask & tcu::RGBA::RED_MASK) ? tcu::floatToU8(v.x()) : 0,
43 (mask & tcu::RGBA::GREEN_MASK) ? tcu::floatToU8(v.y()) : 0,
44 (mask & tcu::RGBA::BLUE_MASK) ? tcu::floatToU8(v.z()) : 0,
45 (mask & tcu::RGBA::ALPHA_MASK) ?
46 tcu::floatToU8(v.w()) :
47 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
getWidth(void) const57 int getWidth(void) const
58 {
59 return m_width;
60 }
getHeight(void) const61 int getHeight(void) const
62 {
63 return m_height;
64 }
65
66 void setPixel(const tcu::Vec4 &color, int x, int y) const;
67
68 private:
69 mutable tcu::Surface *m_surface;
70 uint8_t m_colorMask;
71 int m_x;
72 int m_y;
73 int m_width;
74 int m_height;
75 };
76
setPixel(const tcu::Vec4 & color,int x,int y) const77 inline void SurfaceAccess::setPixel(const tcu::Vec4 &color, int x, int y) const
78 {
79 DE_ASSERT(de::inBounds(x, 0, m_width) && de::inBounds(y, 0, m_height));
80 m_surface->setPixel(m_x + x, m_y + y, toRGBAMasked(color, m_colorMask));
81 }
82
83 } // namespace tcu
84
85 #endif // _TCUSURFACEACCESS_HPP
86