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.
9 #include "JNIXBMCMainView.h"
11 #include "CompileInfo.h"
12 #include "utils/StringUtils.h"
13 #include "utils/log.h"
19 #include <androidjni/Context.h>
20 #include <androidjni/jutils-details.hpp>
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());
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
)
51 void CJNIXBMCMainView::_attach(JNIEnv
* env
, jobject thiz
)
56 m_instance
->attach(thiz
);
59 void CJNIXBMCMainView::_surfaceChanged(JNIEnv
*env
, jobject thiz
, jobject holder
, jint format
, jint width
, jint height
)
64 m_instance
->surfaceChanged(CJNISurfaceHolder(jhobject(holder
)), format
, width
, height
);
67 void CJNIXBMCMainView::_surfaceCreated(JNIEnv
* env
, jobject thiz
, jobject holder
)
72 m_instance
->surfaceCreated(CJNISurfaceHolder(jhobject(holder
)));
75 void CJNIXBMCMainView::_surfaceDestroyed(JNIEnv
* env
, jobject thiz
, jobject holder
)
80 m_instance
->surfaceDestroyed(CJNISurfaceHolder(jhobject(holder
)));
83 void CJNIXBMCMainView::attach(const jobject
& thiz
)
87 m_object
= jhobject(thiz
);
92 void CJNIXBMCMainView::surfaceChanged(CJNISurfaceHolder holder
, int format
, int width
, int height
)
95 m_callback
->surfaceChanged(holder
, format
, width
, height
);
98 void CJNIXBMCMainView::surfaceCreated(CJNISurfaceHolder holder
)
101 m_callback
->surfaceCreated(holder
);
102 m_surfaceCreated
.Set();
105 void CJNIXBMCMainView::surfaceDestroyed(CJNISurfaceHolder holder
)
107 m_surfaceCreated
.Reset();
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
121 return get_field
<jboolean
>(m_object
, "mIsCreated");