blob: 26e8c3eb10c4b55975abe0203ce8260660274855 [file] [log] [blame]
Mathias Agopian518ec112011-05-13 16:21:08 -07001/*
2 ** Copyright 2007, 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#include <ctype.h>
18#include <stdint.h>
19#include <stdlib.h>
20
21#include <EGL/egl.h>
22#include <EGL/eglext.h>
23#include <GLES/gl.h>
24#include <GLES/glext.h>
25
26#include <utils/threads.h>
27
28#include "egl_object.h"
29
30// ----------------------------------------------------------------------------
31namespace android {
32// ----------------------------------------------------------------------------
33
34egl_object_t::egl_object_t(egl_display_t* disp) :
Mathias Agopian5b287a62011-05-16 18:58:55 -070035 display(disp), count(1) {
36 // NOTE: this does an implicit incRef
Mathias Agopian518ec112011-05-13 16:21:08 -070037 display->addObject(this);
38}
39
Mathias Agopian5b287a62011-05-16 18:58:55 -070040egl_object_t::~egl_object_t() {
Mathias Agopian518ec112011-05-13 16:21:08 -070041}
42
Mathias Agopian5b287a62011-05-16 18:58:55 -070043void egl_object_t::terminate() {
44 // this marks the object as "terminated"
45 display->removeObject(this);
46 if (decRef() == 1) {
47 // shouldn't happen because this is called from LocalRef
Steve Blocke6f43dd2012-01-06 19:20:56 +000048 ALOGE("egl_object_t::terminate() removed the last reference!");
Mathias Agopian5b287a62011-05-16 18:58:55 -070049 }
50}
51
52void egl_object_t::destroy() {
53 if (decRef() == 1) {
54 delete this;
55 }
56}
57
Mathias Agopianf0480de2011-11-13 20:50:07 -080058bool egl_object_t::get(egl_display_t const* display, egl_object_t* object) {
Mathias Agopian5b287a62011-05-16 18:58:55 -070059 // used by LocalRef, this does an incRef() atomically with
60 // checking that the object is valid.
Mathias Agopianf0480de2011-11-13 20:50:07 -080061 return display->getObject(object);
Mathias Agopian518ec112011-05-13 16:21:08 -070062}
63
64// ----------------------------------------------------------------------------
65}; // namespace android
66// ----------------------------------------------------------------------------