Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 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 | |
Romain Guy | 85bf02f | 2010-06-22 13:11:24 -0700 | [diff] [blame] | 17 | #ifndef ANDROID_OPENGL_RENDERER_H |
| 18 | #define ANDROID_OPENGL_RENDERER_H |
| 19 | |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame^] | 20 | #include <SkMatrix.h> |
Romain Guy | 85bf02f | 2010-06-22 13:11:24 -0700 | [diff] [blame] | 21 | #include <SkXfermode.h> |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 22 | |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 23 | #include <utils/RefBase.h> |
| 24 | |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame^] | 25 | #include "Matrix.h" |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 26 | #include "Rect.h" |
| 27 | |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 28 | namespace android { |
| 29 | |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame^] | 30 | /////////////////////////////////////////////////////////////////////////////// |
| 31 | // Support |
| 32 | /////////////////////////////////////////////////////////////////////////////// |
| 33 | |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 34 | class Snapshot: public LightRefBase<Snapshot> { |
| 35 | public: |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame^] | 36 | Snapshot() { |
| 37 | } |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 38 | |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame^] | 39 | Snapshot(const sp<Snapshot> s): transform(s->transform), clipRect(s->clipRect), |
| 40 | flags(0), previous(s) { |
| 41 | } |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 42 | |
| 43 | enum Flags { |
| 44 | kFlagClipSet = 0x1, |
| 45 | }; |
| 46 | |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame^] | 47 | // Local transformations |
| 48 | mat4 transform; |
| 49 | |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 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 | |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame^] | 60 | /////////////////////////////////////////////////////////////////////////////// |
| 61 | // Renderer |
| 62 | /////////////////////////////////////////////////////////////////////////////// |
| 63 | |
Romain Guy | 85bf02f | 2010-06-22 13:11:24 -0700 | [diff] [blame] | 64 | class OpenGLRenderer { |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 65 | public: |
Romain Guy | 85bf02f | 2010-06-22 13:11:24 -0700 | [diff] [blame] | 66 | OpenGLRenderer(); |
| 67 | ~OpenGLRenderer(); |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 68 | |
| 69 | void setViewport(int width, int height); |
| 70 | void prepare(); |
Romain Guy | 08ae317 | 2010-06-21 19:35:50 -0700 | [diff] [blame] | 71 | |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 72 | int getSaveCount() const; |
| 73 | int save(int flags); |
| 74 | void restore(); |
| 75 | void restoreToCount(int saveCount); |
| 76 | |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame^] | 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 | |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 85 | bool clipRect(float left, float top, float right, float bottom); |
| 86 | |
Romain Guy | 85bf02f | 2010-06-22 13:11:24 -0700 | [diff] [blame] | 87 | void drawColor(int color, SkXfermode::Mode mode); |
Romain Guy | 08ae317 | 2010-06-21 19:35:50 -0700 | [diff] [blame] | 88 | |
Romain Guy | 85bf02f | 2010-06-22 13:11:24 -0700 | [diff] [blame] | 89 | private: |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 90 | int saveSnapshot(); |
| 91 | bool restoreSnapshot(); |
| 92 | |
| 93 | void setScissorFromClip(); |
| 94 | |
| 95 | // Dimensions of the drawing surface |
| 96 | int mWidth, mHeight; |
| 97 | |
Romain Guy | 85bf02f | 2010-06-22 13:11:24 -0700 | [diff] [blame] | 98 | // Matrix used for ortho projection in shaders |
| 99 | float mOrthoMatrix[16]; |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 100 | |
| 101 | // Number of saved states |
| 102 | int mSaveCount; |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame^] | 103 | // Base state |
| 104 | Snapshot mFirstSnapshot; |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 105 | // Current state |
| 106 | sp<Snapshot> mSnapshot; |
| 107 | }; // class OpenGLRenderer |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 108 | |
| 109 | }; // namespace android |
| 110 | |
Romain Guy | 85bf02f | 2010-06-22 13:11:24 -0700 | [diff] [blame] | 111 | #endif // ANDROID_OPENGL_RENDERER_H |