OpenGLRenderer.h revision f6a11b8a9e25ff9861bbba19251bea84d8a5daf2
1/* 2 * Copyright (C) 2010 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_OPENGL_RENDERER_H 18#define ANDROID_OPENGL_RENDERER_H 19 20#include <SkMatrix.h> 21#include <SkXfermode.h> 22 23#include <utils/RefBase.h> 24 25#include "Matrix.h" 26#include "Rect.h" 27 28namespace android { 29 30/////////////////////////////////////////////////////////////////////////////// 31// Support 32/////////////////////////////////////////////////////////////////////////////// 33 34class Snapshot: public LightRefBase<Snapshot> { 35public: 36 Snapshot() { 37 } 38 39 Snapshot(const sp<Snapshot> s): transform(s->transform), clipRect(s->clipRect), 40 flags(0), previous(s) { 41 } 42 43 enum Flags { 44 kFlagClipSet = 0x1, 45 }; 46 47 // Local transformations 48 mat4 transform; 49 50 // Clipping rectangle at the time of this snapshot 51 Rect clipRect; 52 53 // Dirty flags 54 int flags; 55 56 // Previous snapshot in the frames stack 57 sp<Snapshot> previous; 58}; // struct Snapshot 59 60/////////////////////////////////////////////////////////////////////////////// 61// Renderer 62/////////////////////////////////////////////////////////////////////////////// 63 64class OpenGLRenderer { 65public: 66 OpenGLRenderer(); 67 ~OpenGLRenderer(); 68 69 void setViewport(int width, int height); 70 void prepare(); 71 72 int getSaveCount() const; 73 int save(int flags); 74 void restore(); 75 void restoreToCount(int saveCount); 76 77 void translate(float dx, float dy); 78 void rotate(float degrees); 79 void scale(float sx, float sy); 80 81 void setMatrix(SkMatrix* matrix); 82 void getMatrix(SkMatrix* matrix); 83 void concatMatrix(SkMatrix* matrix); 84 85 bool clipRect(float left, float top, float right, float bottom); 86 87 void drawColor(int color, SkXfermode::Mode mode); 88 89private: 90 int saveSnapshot(); 91 bool restoreSnapshot(); 92 93 void setScissorFromClip(); 94 95 // Dimensions of the drawing surface 96 int mWidth, mHeight; 97 98 // Matrix used for ortho projection in shaders 99 float mOrthoMatrix[16]; 100 101 // Number of saved states 102 int mSaveCount; 103 // Base state 104 Snapshot mFirstSnapshot; 105 // Current state 106 sp<Snapshot> mSnapshot; 107}; // class OpenGLRenderer 108 109}; // namespace android 110 111#endif // ANDROID_OPENGL_RENDERER_H 112