blob: 595768c6373205df729680b00fad302c6191a3d9 [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
Romain Guyf6a11b82010-06-23 17:47:49 -070020#include <SkMatrix.h>
Romain Guy85bf02f2010-06-22 13:11:24 -070021#include <SkXfermode.h>
Romain Guye4d01122010-06-16 18:44:05 -070022
Romain Guybb9524b2010-06-22 18:56:38 -070023#include <utils/RefBase.h>
24
Romain Guyf6a11b82010-06-23 17:47:49 -070025#include "Matrix.h"
Romain Guybb9524b2010-06-22 18:56:38 -070026#include "Rect.h"
27
Romain Guye4d01122010-06-16 18:44:05 -070028namespace android {
29
Romain Guyf6a11b82010-06-23 17:47:49 -070030///////////////////////////////////////////////////////////////////////////////
31// Support
32///////////////////////////////////////////////////////////////////////////////
33
Romain Guybb9524b2010-06-22 18:56:38 -070034class Snapshot: public LightRefBase<Snapshot> {
35public:
Romain Guyf6a11b82010-06-23 17:47:49 -070036 Snapshot() {
37 }
Romain Guybb9524b2010-06-22 18:56:38 -070038
Romain Guyf6a11b82010-06-23 17:47:49 -070039 Snapshot(const sp<Snapshot> s): transform(s->transform), clipRect(s->clipRect),
40 flags(0), previous(s) {
41 }
Romain Guybb9524b2010-06-22 18:56:38 -070042
43 enum Flags {
44 kFlagClipSet = 0x1,
45 };
46
Romain Guyf6a11b82010-06-23 17:47:49 -070047 // Local transformations
48 mat4 transform;
49
Romain Guybb9524b2010-06-22 18:56:38 -070050 // 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 Guyf6a11b82010-06-23 17:47:49 -070060///////////////////////////////////////////////////////////////////////////////
61// Renderer
62///////////////////////////////////////////////////////////////////////////////
63
Romain Guy85bf02f2010-06-22 13:11:24 -070064class OpenGLRenderer {
Romain Guye4d01122010-06-16 18:44:05 -070065public:
Romain Guy85bf02f2010-06-22 13:11:24 -070066 OpenGLRenderer();
67 ~OpenGLRenderer();
Romain Guye4d01122010-06-16 18:44:05 -070068
69 void setViewport(int width, int height);
70 void prepare();
Romain Guy08ae3172010-06-21 19:35:50 -070071
Romain Guybb9524b2010-06-22 18:56:38 -070072 int getSaveCount() const;
73 int save(int flags);
74 void restore();
75 void restoreToCount(int saveCount);
76
Romain Guyf6a11b82010-06-23 17:47:49 -070077 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 Guybb9524b2010-06-22 18:56:38 -070085 bool clipRect(float left, float top, float right, float bottom);
86
Romain Guy85bf02f2010-06-22 13:11:24 -070087 void drawColor(int color, SkXfermode::Mode mode);
Romain Guy08ae3172010-06-21 19:35:50 -070088
Romain Guy85bf02f2010-06-22 13:11:24 -070089private:
Romain Guybb9524b2010-06-22 18:56:38 -070090 int saveSnapshot();
91 bool restoreSnapshot();
92
93 void setScissorFromClip();
94
95 // Dimensions of the drawing surface
96 int mWidth, mHeight;
97
Romain Guy85bf02f2010-06-22 13:11:24 -070098 // Matrix used for ortho projection in shaders
99 float mOrthoMatrix[16];
Romain Guybb9524b2010-06-22 18:56:38 -0700100
101 // Number of saved states
102 int mSaveCount;
Romain Guyf6a11b82010-06-23 17:47:49 -0700103 // Base state
104 Snapshot mFirstSnapshot;
Romain Guybb9524b2010-06-22 18:56:38 -0700105 // Current state
106 sp<Snapshot> mSnapshot;
107}; // class OpenGLRenderer
Romain Guye4d01122010-06-16 18:44:05 -0700108
109}; // namespace android
110
Romain Guy85bf02f2010-06-22 13:11:24 -0700111#endif // ANDROID_OPENGL_RENDERER_H