[Windows] Remove redundant DirectSound error codes
[xbmc.git] / xbmc / platform / android / activity / JNIXBMCMainView.cpp
blob2187bdad2d407afabbb82795a99016941399a573
1 /*
2 * Copyright (C) 2017 Christian Browet
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
9 #include "JNIXBMCMainView.h"
11 #include "CompileInfo.h"
12 #include "utils/StringUtils.h"
13 #include "utils/log.h"
15 #include <algorithm>
16 #include <cassert>
17 #include <list>
19 #include <androidjni/Context.h>
20 #include <androidjni/jutils-details.hpp>
22 using namespace jni;
24 static std::string s_className = std::string(CCompileInfo::GetClass()) + "/XBMCMainView";
25 CEvent CJNIXBMCMainView::m_surfaceCreated;
26 CJNIXBMCMainView* CJNIXBMCMainView::m_instance = nullptr;
28 void CJNIXBMCMainView::RegisterNatives(JNIEnv* env)
30 jclass cClass = env->FindClass(s_className.c_str());
31 if(cClass)
33 JNINativeMethod methods[] =
35 {"_attach", "()V", (void*)&CJNIXBMCMainView::_attach},
36 {"_surfaceChanged", "(Landroid/view/SurfaceHolder;III)V", (void*)&CJNIXBMCMainView::_surfaceChanged},
37 {"_surfaceCreated", "(Landroid/view/SurfaceHolder;)V", (void*)&CJNIXBMCMainView::_surfaceCreated},
38 {"_surfaceDestroyed", "(Landroid/view/SurfaceHolder;)V", (void*)&CJNIXBMCMainView::_surfaceDestroyed}
41 env->RegisterNatives(cClass, methods, sizeof(methods)/sizeof(methods[0]));
45 CJNIXBMCMainView::CJNIXBMCMainView(CJNISurfaceHolderCallback* callback)
46 : m_callback(callback)
48 m_instance = this;
51 void CJNIXBMCMainView::_attach(JNIEnv* env, jobject thiz)
53 (void)env;
55 if (m_instance)
56 m_instance->attach(thiz);
59 void CJNIXBMCMainView::_surfaceChanged(JNIEnv *env, jobject thiz, jobject holder, jint format, jint width, jint height )
61 (void)env;
63 if (m_instance)
64 m_instance->surfaceChanged(CJNISurfaceHolder(jhobject(holder)), format, width, height);
67 void CJNIXBMCMainView::_surfaceCreated(JNIEnv* env, jobject thiz, jobject holder)
69 (void)env;
71 if (m_instance)
72 m_instance->surfaceCreated(CJNISurfaceHolder(jhobject(holder)));
75 void CJNIXBMCMainView::_surfaceDestroyed(JNIEnv* env, jobject thiz, jobject holder)
77 (void)env;
79 if (m_instance)
80 m_instance->surfaceDestroyed(CJNISurfaceHolder(jhobject(holder)));
83 void CJNIXBMCMainView::attach(const jobject& thiz)
85 if (!m_object)
87 m_object = jhobject(thiz);
88 m_object.setGlobal();
92 void CJNIXBMCMainView::surfaceChanged(CJNISurfaceHolder holder, int format, int width, int height)
94 if (m_callback)
95 m_callback->surfaceChanged(holder, format, width, height);
98 void CJNIXBMCMainView::surfaceCreated(CJNISurfaceHolder holder)
100 if (m_callback)
101 m_callback->surfaceCreated(holder);
102 m_surfaceCreated.Set();
105 void CJNIXBMCMainView::surfaceDestroyed(CJNISurfaceHolder holder)
107 m_surfaceCreated.Reset();
108 if (m_callback)
109 m_callback->surfaceDestroyed(holder);
112 bool CJNIXBMCMainView::waitForSurface(unsigned int millis)
114 return m_surfaceCreated.Wait(std::chrono::milliseconds(millis));
117 bool CJNIXBMCMainView::isCreated() const
119 if (!m_object)
120 return false;
121 return get_field<jboolean>(m_object, "mIsCreated");