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