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 | |
| 20 | #include <SkXfermode.h> |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 21 | |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame^] | 22 | #include <utils/RefBase.h> |
| 23 | |
| 24 | #include "Rect.h" |
| 25 | |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 26 | namespace android { |
| 27 | |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame^] | 28 | class Snapshot: public LightRefBase<Snapshot> { |
| 29 | public: |
| 30 | Snapshot() { } |
| 31 | |
| 32 | Snapshot(const sp<Snapshot> s): clipRect(s->clipRect), flags(0), previous(s) { } |
| 33 | |
| 34 | enum Flags { |
| 35 | kFlagClipSet = 0x1, |
| 36 | }; |
| 37 | |
| 38 | // Clipping rectangle at the time of this snapshot |
| 39 | Rect clipRect; |
| 40 | |
| 41 | // Dirty flags |
| 42 | int flags; |
| 43 | |
| 44 | // Previous snapshot in the frames stack |
| 45 | sp<Snapshot> previous; |
| 46 | }; // struct Snapshot |
| 47 | |
Romain Guy | 85bf02f | 2010-06-22 13:11:24 -0700 | [diff] [blame] | 48 | class OpenGLRenderer { |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 49 | public: |
Romain Guy | 85bf02f | 2010-06-22 13:11:24 -0700 | [diff] [blame] | 50 | OpenGLRenderer(); |
| 51 | ~OpenGLRenderer(); |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 52 | |
| 53 | void setViewport(int width, int height); |
| 54 | void prepare(); |
Romain Guy | 08ae317 | 2010-06-21 19:35:50 -0700 | [diff] [blame] | 55 | |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame^] | 56 | int getSaveCount() const; |
| 57 | int save(int flags); |
| 58 | void restore(); |
| 59 | void restoreToCount(int saveCount); |
| 60 | |
| 61 | bool clipRect(float left, float top, float right, float bottom); |
| 62 | |
Romain Guy | 85bf02f | 2010-06-22 13:11:24 -0700 | [diff] [blame] | 63 | void drawColor(int color, SkXfermode::Mode mode); |
Romain Guy | 08ae317 | 2010-06-21 19:35:50 -0700 | [diff] [blame] | 64 | |
Romain Guy | 85bf02f | 2010-06-22 13:11:24 -0700 | [diff] [blame] | 65 | private: |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame^] | 66 | int saveSnapshot(); |
| 67 | bool restoreSnapshot(); |
| 68 | |
| 69 | void setScissorFromClip(); |
| 70 | |
| 71 | // Dimensions of the drawing surface |
| 72 | int mWidth, mHeight; |
| 73 | |
Romain Guy | 85bf02f | 2010-06-22 13:11:24 -0700 | [diff] [blame] | 74 | // Matrix used for ortho projection in shaders |
| 75 | float mOrthoMatrix[16]; |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame^] | 76 | |
| 77 | // Number of saved states |
| 78 | int mSaveCount; |
| 79 | // Current state |
| 80 | sp<Snapshot> mSnapshot; |
| 81 | }; // class OpenGLRenderer |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 82 | |
| 83 | }; // namespace android |
| 84 | |
Romain Guy | 85bf02f | 2010-06-22 13:11:24 -0700 | [diff] [blame] | 85 | #endif // ANDROID_OPENGL_RENDERER_H |