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_GL_H
18 #define ANDROID_SURFACE_TEXTURE_GL_H
19 
20 #include "Constants.h"
21 #include "GLTest.h"
22 
23 #include "FrameWaiter.h"
24 #include "TextureRenderer.h"
25 
26 #include <gui/GLConsumer.h>
27 #include <gui/Surface.h>
28 
29 namespace android {
30 
31 class FrameWaiter;
32 class GLConsumer;
33 class TextureRenderer;
34 
35 class SurfaceTextureGLTest : public GLTest {
36 protected:
37     enum { TEX_ID = 123 };
38 
SetUp()39     void SetUp() {
40         GLTest::SetUp();
41         sp<IGraphicBufferProducer> producer;
42         BufferQueue::createBufferQueue(&producer, &mConsumer);
43         mST = new GLConsumer(mConsumer, TEX_ID, GLConsumer::TEXTURE_EXTERNAL,
44                 true, false);
45         mSTC = new Surface(producer);
46         mANW = mSTC;
47         ASSERT_EQ(NO_ERROR, native_window_set_usage(mANW.get(), TEST_PRODUCER_USAGE_BITS));
48         mTextureRenderer = new TextureRenderer(TEX_ID, mST);
49         ASSERT_NO_FATAL_FAILURE(mTextureRenderer->SetUp());
50         mFW = new FrameWaiter;
51         mST->setFrameAvailableListener(mFW);
52     }
53 
TearDown()54     void TearDown() {
55         mTextureRenderer.clear();
56         mANW.clear();
57         mSTC.clear();
58         mST.clear();
59         GLTest::TearDown();
60     }
61 
drawTexture()62     void drawTexture() {
63         mTextureRenderer->drawTexture();
64     }
65 
66     sp<IGraphicBufferConsumer> mConsumer;
67     sp<GLConsumer> mST;
68     sp<Surface> mSTC;
69     sp<ANativeWindow> mANW;
70     sp<TextureRenderer> mTextureRenderer;
71     sp<FrameWaiter> mFW;
72 };
73 
74 } // namespace android
75 
76 #endif
77