blob: 8a541fcf3a819c89454bcb39b93ed8537ef09fcc [file] [log] [blame]
Romain Guye4d01122010-06-16 18:44:05 -07001/*
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 Guy85bf02f2010-06-22 13:11:24 -070017#ifndef ANDROID_OPENGL_RENDERER_H
18#define ANDROID_OPENGL_RENDERER_H
19
20#include <SkXfermode.h>
Romain Guye4d01122010-06-16 18:44:05 -070021
Romain Guybb9524b2010-06-22 18:56:38 -070022#include <utils/RefBase.h>
23
24#include "Rect.h"
25
Romain Guye4d01122010-06-16 18:44:05 -070026namespace android {
27
Romain Guybb9524b2010-06-22 18:56:38 -070028class Snapshot: public LightRefBase<Snapshot> {
29public:
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 Guy85bf02f2010-06-22 13:11:24 -070048class OpenGLRenderer {
Romain Guye4d01122010-06-16 18:44:05 -070049public:
Romain Guy85bf02f2010-06-22 13:11:24 -070050 OpenGLRenderer();
51 ~OpenGLRenderer();
Romain Guye4d01122010-06-16 18:44:05 -070052
53 void setViewport(int width, int height);
54 void prepare();
Romain Guy08ae3172010-06-21 19:35:50 -070055
Romain Guybb9524b2010-06-22 18:56:38 -070056 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 Guy85bf02f2010-06-22 13:11:24 -070063 void drawColor(int color, SkXfermode::Mode mode);
Romain Guy08ae3172010-06-21 19:35:50 -070064
Romain Guy85bf02f2010-06-22 13:11:24 -070065private:
Romain Guybb9524b2010-06-22 18:56:38 -070066 int saveSnapshot();
67 bool restoreSnapshot();
68
69 void setScissorFromClip();
70
71 // Dimensions of the drawing surface
72 int mWidth, mHeight;
73
Romain Guy85bf02f2010-06-22 13:11:24 -070074 // Matrix used for ortho projection in shaders
75 float mOrthoMatrix[16];
Romain Guybb9524b2010-06-22 18:56:38 -070076
77 // Number of saved states
78 int mSaveCount;
79 // Current state
80 sp<Snapshot> mSnapshot;
81}; // class OpenGLRenderer
Romain Guye4d01122010-06-16 18:44:05 -070082
83}; // namespace android
84
Romain Guy85bf02f2010-06-22 13:11:24 -070085#endif // ANDROID_OPENGL_RENDERER_H