1 /* 2 * Copyright (C) 2015 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 #ifndef _LIBRENDER_TEXTURERESIZE_H 17 #define _LIBRENDER_TEXTURERESIZE_H 18 19 #include <GLES2/gl2.h> 20 #include <memory> 21 22 namespace gfxstream { 23 namespace gl { 24 25 class TextureResize { 26 public: 27 TextureResize(GLuint width, GLuint height); 28 ~TextureResize(); 29 30 // Scales the given texture for the current viewport and returns the scaled 31 // texture. May return the input if no scaling is required. 32 GLuint update(GLuint texture); 33 GLuint update(GLuint texture, int width, int height, int skinRotation); 34 35 struct Framebuffer { 36 GLuint texture = 0; 37 GLuint framebuffer = 0; 38 GLuint program = 0; 39 GLuint aPosition = 0; 40 GLuint uTexture = 0; 41 }; 42 43 class GenericResizer { 44 public: 45 GenericResizer(); 46 ~GenericResizer(); 47 48 // Renders the contents of 2D |input_texture| on screen 49 // |width| and |height| are the dimensions of the texture. 50 GLuint draw(GLuint texture, int width, int height, int skinRotation); 51 52 private: 53 GLuint mProgram; 54 GLuint mVertexBuffer; 55 GLuint mIndexBuffer; 56 GLuint mInputUniformLocation; 57 GLuint mPositionAttribLocation; 58 GLuint mInCoordAttribLocation; 59 Framebuffer mFrameBuffer; 60 int mWidth; 61 int mHeight; 62 }; 63 64 private: 65 void setupFramebuffers(unsigned int factor); 66 void resize(GLuint texture); 67 68 private: 69 GLuint mWidth; 70 GLuint mHeight; 71 unsigned int mFactor; 72 Framebuffer mFBWidth; 73 Framebuffer mFBHeight; 74 GLuint mVertexBuffer; 75 GLenum mTextureDataType; 76 GLenum mTextureFilteringMode = GL_LINEAR; 77 std::unique_ptr<GenericResizer> mGenericResizer; 78 }; 79 80 } // namespace gl 81 } // namespace gfxstream 82 83 #endif 84