1 /*
2  * Copyright 2013 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 
17 #ifndef ANDROID_SURFACE_TEXTURE_FBO_H
18 #define ANDROID_SURFACE_TEXTURE_FBO_H
19 
20 #include "SurfaceTextureGL.h"
21 
22 #include <GLES2/gl2.h>
23 
24 namespace android {
25 
26 class SurfaceTextureFBOTest : public SurfaceTextureGLTest {
27 protected:
SetUp()28     virtual void SetUp() {
29         SurfaceTextureGLTest::SetUp();
30 
31         glGenFramebuffers(1, &mFbo);
32         ASSERT_EQ(GLenum(GL_NO_ERROR), glGetError());
33 
34         glGenTextures(1, &mFboTex);
35         glBindTexture(GL_TEXTURE_2D, mFboTex);
36         glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, getSurfaceWidth(),
37                 getSurfaceHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
38         glBindTexture(GL_TEXTURE_2D, 0);
39         ASSERT_EQ(GLenum(GL_NO_ERROR), glGetError());
40 
41         glBindFramebuffer(GL_FRAMEBUFFER, mFbo);
42         glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
43                 GL_TEXTURE_2D, mFboTex, 0);
44         glBindFramebuffer(GL_FRAMEBUFFER, 0);
45         ASSERT_EQ(GLenum(GL_NO_ERROR), glGetError());
46     }
47 
TearDown()48     virtual void TearDown() {
49         SurfaceTextureGLTest::TearDown();
50 
51         glDeleteTextures(1, &mFboTex);
52         glDeleteFramebuffers(1, &mFbo);
53     }
54 
55     GLuint mFbo;
56     GLuint mFboTex;
57 };
58 
fillRGBA8BufferSolid(uint8_t * buf,int w,int h,int stride,uint8_t r,uint8_t g,uint8_t b,uint8_t a)59 void fillRGBA8BufferSolid(uint8_t* buf, int w, int h, int stride,
60         uint8_t r, uint8_t g, uint8_t b, uint8_t a) {
61     const size_t PIXEL_SIZE = 4;
62     for (int y = 0; y < h; y++) {
63         for (int x = 0; x < w; x++) {
64             off_t offset = (y * stride + x) * PIXEL_SIZE;
65             buf[offset + 0] = r;
66             buf[offset + 1] = g;
67             buf[offset + 2] = b;
68             buf[offset + 3] = a;
69         }
70     }
71 }
72 
73 } // namespace android
74 
75 #endif
76