Use std::shared_ptr to store GLSharedGroup

GLSharedGroup used to be stored in SmartPtr, which may not be thread
safe. Migrate to std::shared_ptr.

Test: compile

Change-Id: Idb98c8a3a320811001a88a52f18920ec1e1d5434
diff --git a/shared/OpenglCodecCommon/GLSharedGroup.h b/shared/OpenglCodecCommon/GLSharedGroup.h
index 807a006..9832378 100755
--- a/shared/OpenglCodecCommon/GLSharedGroup.h
+++ b/shared/OpenglCodecCommon/GLSharedGroup.h
@@ -30,6 +30,7 @@
 #include <GLES2/gl2ext.h>
 
 #include <map>
+#include <memory>
 #include <string>
 #include <vector>
 
@@ -39,7 +40,6 @@
 #include <utils/threads.h>
 #include "auto_goldfish_dma_context.h"
 #include "IndexRangeCache.h"
-#include "SmartPtr.h"
 #include "StateTrackingSupport.h"
 
 struct BufferData {
@@ -258,6 +258,6 @@
     int getActiveAttributesCountForProgram(GLuint program);
 };
 
-typedef SmartPtr<GLSharedGroup> GLSharedGroupPtr; 
+typedef std::shared_ptr<GLSharedGroup> GLSharedGroupPtr;
 
 #endif //_GL_SHARED_GROUP_H_
diff --git a/shared/OpenglCodecCommon/SmartPtr.h b/shared/OpenglCodecCommon/SmartPtr.h
deleted file mode 100644
index 3d821c8..0000000
--- a/shared/OpenglCodecCommon/SmartPtr.h
+++ /dev/null
@@ -1,168 +0,0 @@
-/*
-* Copyright (C) 2011 The Android Open Source Project
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-#ifndef __SMART_PTR_H
-#define __SMART_PTR_H
-
-#include <PortableMutex.h>
-
-#include <cutils/atomic.h>
-
-template <class T, bool threadSafe = false>
-class SmartPtr
-{
-public:
-    explicit SmartPtr(T* ptr = (T*)NULL) {
-        if (threadSafe) {
-            m_lock = new mutex_t;
-            mutex_init(m_lock);
-        }
-        else m_lock = NULL;
-
-        m_ptr = ptr;
-        if (ptr)
-           m_pRefCount = new int32_t(1);
-        else
-           m_pRefCount = NULL;
-    }
-
-    SmartPtr<T,threadSafe>(const SmartPtr<T,false>& rhs) {
-        if (threadSafe) {
-            m_lock = new mutex_t;
-            mutex_init(m_lock);
-        }
-        else m_lock = NULL;
-
-        m_pRefCount = rhs.m_pRefCount;
-        m_ptr       = rhs.m_ptr;
-        use();
-    }
-
-    SmartPtr<T,threadSafe>(SmartPtr<T,true>& rhs) {
-        if (threadSafe) {
-            m_lock = new mutex_t;
-            mutex_init(m_lock);
-        }
-        else m_lock = NULL;
-
-        if (rhs.m_lock) mutex_lock(rhs.m_lock);
-        m_pRefCount = rhs.m_pRefCount;
-        m_ptr       = rhs.m_ptr;
-        use();
-        if (rhs.m_lock) mutex_unlock(rhs.m_lock);
-    }
-
-    ~SmartPtr() {
-        if (m_lock) mutex_lock(m_lock);
-        release();
-        if (m_lock)
-        {
-            mutex_unlock(m_lock);
-            mutex_destroy(m_lock);
-            delete m_lock;
-        }
-    }
-
-    T* Ptr() const {
-        return m_ptr;
-    }
-
-    const T* constPtr() const
-    {
-        return m_ptr;
-    }
-
-    T* operator->() const {
-        return m_ptr;
-    }
-
-    T& operator*() const {
-        return *m_ptr;
-    }
-
-    operator void*() const {
-        return (void *)m_ptr;
-    }
-
-    // This gives STL lists something to compare.
-    bool operator <(const SmartPtr<T>& t1) const {
-        return m_ptr < t1.m_ptr;
-    }
-
-    SmartPtr<T,threadSafe>& operator=(const SmartPtr<T,false>& rhs)
-    {
-        if (m_ptr == rhs.m_ptr)
-            return *this;
-
-        if (m_lock) mutex_lock(m_lock);
-        release();
-        m_pRefCount = rhs.m_pRefCount;
-        m_ptr       = rhs.m_ptr;
-        use();
-        if (m_lock) mutex_unlock(m_lock);
-
-        return *this;
-    }
-
-    SmartPtr<T,threadSafe>& operator=(SmartPtr<T,true>& rhs)
-    {
-        if (m_ptr == rhs.m_ptr)
-            return *this;
-
-        if (m_lock) mutex_lock(m_lock);
-        release();
-        if (rhs.m_lock) mutex_lock(rhs.m_lock);
-        m_pRefCount = rhs.m_pRefCount;
-        m_ptr       = rhs.m_ptr;
-        use();
-        if (rhs.m_lock) mutex_unlock(rhs.m_lock);
-        if (m_lock) mutex_unlock(m_lock);
-
-        return *this;
-    }
-
-private:
-    int32_t  *m_pRefCount;
-    mutex_t  *m_lock;
-    T* m_ptr;
-
-    // Increment the reference count on this pointer by 1.
-    int use() {
-        if (!m_pRefCount) return 0;
-        return android_atomic_inc(m_pRefCount) + 1;
-    }
-
-    // Decrement the reference count on the pointer by 1.
-    // If the reference count goes to (or below) 0, the pointer is deleted.
-    int release() {
-        if (!m_pRefCount) return 0;
-
-        int iVal = android_atomic_dec(m_pRefCount);
-        if (iVal > 1)
-            return iVal - 1;
-
-        delete m_pRefCount;
-        m_pRefCount = NULL;
-
-        if (m_ptr) {
-            delete m_ptr;
-            m_ptr = NULL;
-        }
-        return 0;
-    }
-
-};
-
-#endif // of  __SMART_PTR_H
diff --git a/system/GLESv1_enc/GLEncoder.h b/system/GLESv1_enc/GLEncoder.h
index a26636c..7837838 100644
--- a/system/GLESv1_enc/GLEncoder.h
+++ b/system/GLESv1_enc/GLEncoder.h
@@ -33,7 +33,7 @@
     }
     void setSharedGroup(GLSharedGroupPtr shared) {
         m_shared = shared;
-        if (m_state && m_shared.Ptr())
+        if (m_state && m_shared)
             m_state->setTextureData(m_shared->getTextureData());
     }
     void flush() { m_stream->flush(); }
diff --git a/system/GLESv2_enc/GL2Encoder.h b/system/GLESv2_enc/GL2Encoder.h
index 04b8be5..90978be 100644
--- a/system/GLESv2_enc/GL2Encoder.h
+++ b/system/GLESv2_enc/GL2Encoder.h
@@ -65,7 +65,7 @@
     }
     void setSharedGroup(GLSharedGroupPtr shared) {
         m_shared = shared;
-        if (m_state && m_shared.Ptr()) {
+        if (m_state && m_shared) {
             m_state->setTextureData(m_shared->getTextureData());
             m_state->setRenderbufferInfo(m_shared->getRenderbufferInfo());
             m_state->setSamplerInfo(m_shared->getSamplerInfo());