1 #ifndef _TCUSURFACEACCESS_HPP
2 #define _TCUSURFACEACCESS_HPP
3 /*-------------------------------------------------------------------------
4 * drawElements Quality Program Tester Core
5 * ----------------------------------------
7 * Copyright 2014 The Android Open Source Project
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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.
23 * \brief Surface access class.
24 *//*--------------------------------------------------------------------*/
26 #include "tcuDefs.hpp"
27 #include "tcuTextureUtil.hpp"
28 #include "tcuPixelFormat.hpp"
29 #include "tcuSurface.hpp"
34 inline deUint8 getColorMask (const tcu::PixelFormat& format)
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));
42 inline tcu::RGBA toRGBAMasked (const tcu::Vec4& v, deUint8 mask)
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
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);
57 int getWidth (void) const { return m_width; }
58 int getHeight (void) const { return m_height; }
60 void setPixel (const tcu::Vec4& color, int x, int y) const;
63 mutable tcu::Surface* m_surface;
71 inline void SurfaceAccess::setPixel (const tcu::Vec4& color, int x, int y) const
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));
79 #endif // _TCUSURFACEACCESS_HPP