From e4dd251c4cd61940c01b5d219af8c3c4c9c7738c Mon Sep 17 00:00:00 2001 From: "srinivasa.mr" Date: Mon, 3 Jun 2013 15:17:53 +0900 Subject: [PATCH] Coding idioms Change-Id: I1c9f6561c680e55d739a3074e1e3221f86d7c53b Signed-off-by: srinivasa.mr --- project/src/Audio/GlesCubePlayer.cpp | 132 +++++++++++++++-------------------- project/src/Audio/GlesCubePlayer.h | 7 +- 2 files changed, 64 insertions(+), 75 deletions(-) diff --git a/project/src/Audio/GlesCubePlayer.cpp b/project/src/Audio/GlesCubePlayer.cpp index 6a90b8b..bd1fc5e 100644 --- a/project/src/Audio/GlesCubePlayer.cpp +++ b/project/src/Audio/GlesCubePlayer.cpp @@ -1,6 +1,6 @@ // // Tizen Native SDK -// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// Copyright (c) 2013 Samsung Electronics Co., Ltd. // // Licensed under the Flora License, Version 1.1 (the License); // you may not use this file except in compliance with the License. @@ -152,9 +152,9 @@ result EventThreadTimer::Start(int interval) { __interval = interval; - Tizen::Base::Collection::ArrayList *pArg = new Tizen::Base::Collection::ArrayList(); + Tizen::Base::Collection::ArrayList *pArg = new (std::nothrow) Tizen::Base::Collection::ArrayList(); pArg->Construct(1); - pArg->Add(new Integer(interval)); + pArg->Add(new (std::nothrow) Integer(interval)); AppLog("Enter %d", interval); SendUserEvent(EventThreadTimer::REQ_START, pArg); return E_SUCCESS; @@ -165,9 +165,9 @@ EventThreadTimer::StartAsRepeatable(int interval) { result r = E_SUCCESS; __interval = interval; - Tizen::Base::Collection::ArrayList *pArg = new Tizen::Base::Collection::ArrayList(); + Tizen::Base::Collection::ArrayList *pArg = new (std::nothrow ) Tizen::Base::Collection::ArrayList(); pArg->Construct(1); - pArg->Add(new Integer(interval)); + pArg->Add(new (std::nothrow) Integer(interval)); r = SendUserEvent(EventThreadTimer::REQ_START_AS_REPEATABLE, pArg); AppLog("Enter %d %s", interval, GetErrorMessage(r)); return E_SUCCESS; @@ -187,8 +187,7 @@ EventThreadTimer::OnStart(void) result r; AppLog("Enter"); r = __timer.Construct(*__pListener); - AppLog("__timer.Construct:%s", GetErrorMessage(r)); - + TryReturn(r == E_SUCCESS, false," [%s]Timer.Construct() failed", GetErrorMessage(r)); return true; } @@ -274,7 +273,7 @@ OpenAlPlayer::Construct(const Tizen::Base::String &filePath) if (ext.Equals("wav", false)) { // load wav file into buffer - char filename[256]; + char filename[MAX_FILE_NAME]; snprintf(filename, sizeof(filename), "%ls", filePath.GetPointer()); __alBuffers[0] = alutCreateBufferFromFile(filename); __alBufCount = 1; @@ -432,7 +431,7 @@ OpenAlPlayer::FillAlBuffer(ALuint alBuffer) int ret = 0; if (__pDec.get() == null) { - __pDec.reset(new AudioDecoder()); + __pDec.reset(new (std::nothrow) AudioDecoder()); r = __pDec->Construct(__codecType, null); TryReturn(r == E_SUCCESS, -1, "dec.Construct:%s", GetErrorMessage(r)); r = __pDec->Probe(__srcBuf, __sampleType, __channelType, __sampleRate); @@ -471,7 +470,7 @@ OpenAlPlayer::FillAlBuffer(ALuint alBuffer) static File *pFile = null; if (pFile == null) { - pFile = new File(); + pFile = new (std::nothrow) File(); r = pFile->Construct(Tizen::App::App::GetInstance()->GetAppRootPath() + L"data/dump.pcm", L"wb"); if (IsFailed(r)) { @@ -543,12 +542,8 @@ OpenAlPlayer::OnUserEventReceivedN (RequestId requestId, Tizen::Base::Collection case REQ_UPDATE_QUEUE: { bool ret; - AppLog("UpdateQueue"); ret = UpdateQueue(); - if (ret == false) - { - // __timer.Cancel(); - } + TryReturn (ret == true, ,"UpdateQueue failed"); break; } default: @@ -740,26 +735,9 @@ GlesCubePlayerForm::OnTimerExpired(Timer& timer) draw=Draw(); #endif - TryLog(draw, "[GlesCubePlayerForm] GlesCubePlayerForm::Draw() failed."); + TryLog(draw, "GlesCubePlayerForm::Draw() failed."); //Update OpenAL Player player.Update(); -#ifdef TEST - static int playCalled = 0; - static int counter = 0; - if((counter % 100) == 0) - { - // counter = 0; - - //PERF_CALL_LOG(player.Play()); - playCalled = true; - } - else - { - playCalled = false; - } - - counter++; -#endif } result GlesCubePlayerForm::OnInitializing() @@ -927,22 +905,22 @@ CATCH: bool GlesCubePlayerForm::InitGL(void) { - GLint linked = GL_FALSE; - GLuint fragShader = glCreateShader(GL_FRAGMENT_SHADER); - GLuint vertShader = glCreateShader(GL_VERTEX_SHADER); + GLint linked = GL_FALSE; + GLuint fragShader = glCreateShader(GL_FRAGMENT_SHADER); + GLuint vertShader = glCreateShader(GL_VERTEX_SHADER); - glShaderSource(fragShader, 1, static_cast (&FRAGMENT_TEXT), null); - glCompileShader(fragShader); - GLint bShaderCompiled = GL_FALSE; - glGetShaderiv(fragShader, GL_COMPILE_STATUS, &bShaderCompiled); + glShaderSource(fragShader, 1, static_cast (&FRAGMENT_TEXT), null); + glCompileShader(fragShader); + GLint bShaderCompiled = GL_FALSE; + glGetShaderiv(fragShader, GL_COMPILE_STATUS, &bShaderCompiled); - TryCatch(bShaderCompiled != GL_FALSE, , "[GlesCubePlayerForm] bShaderCompiled = GL_FALSE"); + TryCatch(bShaderCompiled != GL_FALSE, , "[GlesCubePlayerForm] bShaderCompiled = GL_FALSE"); - glShaderSource(vertShader, 1, static_cast (&VERTEX_TEXT), null); - glCompileShader(vertShader); - glGetShaderiv(vertShader, GL_COMPILE_STATUS, &bShaderCompiled); + glShaderSource(vertShader, 1, static_cast (&VERTEX_TEXT), null); + glCompileShader(vertShader); + glGetShaderiv(vertShader, GL_COMPILE_STATUS, &bShaderCompiled); - TryCatch(bShaderCompiled != GL_FALSE, , "[GlesCubePlayerForm] bShaderCompiled == GL_FALSE"); + TryCatch(bShaderCompiled != GL_FALSE, , "[GlesCubePlayerForm] bShaderCompiled == GL_FALSE"); __programObject = glCreateProgram(); glAttachShader(__programObject, fragShader); @@ -963,7 +941,7 @@ GlesCubePlayerForm::InitGL(void) delete [] infoLog; } - TryCatch(false, , "[GlesCubePlayerForm] linked == GL_FALSE"); + TryCatch(false, , "linked == GL_FALSE"); } __idxPosition = glGetAttribLocation(__programObject, "a_position"); @@ -985,7 +963,7 @@ GlesCubePlayerForm::InitGL(void) return true; -CATCH: + CATCH: glDeleteShader(vertShader); glDeleteShader(fragShader); @@ -1038,18 +1016,21 @@ GlesCubePlayerForm::Update(void) __angle -= 360.0f; } - int x, y, width, height; + int x = 0; + int y = 0; + int width = 0; + int height = 0; this->GetBounds(x, y, width, height); Tizen::System::SystemInfo::GetValue(String(L"http://tizen.org/feature/screen.width"), width); - if (width == 480) + if (width == WVGA_WIDTH) { - height = 800; + height = WVGA_HEIGHT; } else { - height = 1280; + height = HD_HEIGHT; } float aspect = float(width) / float(height); @@ -1074,17 +1055,20 @@ GlesCubePlayerForm::Draw(void) return false; } - int x, y, width, height; + int x = 0; + int y = 0; + int width = 0; + int height = 0; Form::GetBounds(x, y, width, height); Tizen::System::SystemInfo::GetValue(String(L"http://tizen.org/feature/screen.width"), width); - if (width == 480) + if (width == WVGA_WIDTH) { - height = 800; + height = WVGA_HEIGHT; } else { - height = 1280; + height = HD_HEIGHT; } glViewport(0, 0, width, height); @@ -1146,27 +1130,27 @@ GlesCubePlayerForm::Draw(void) void GlesCubePlayerForm::Frustum(FloatMatrix4* pResult, float left, float right, float bottom, float top, float near, float far) { - float diffX = right - left; - float diffY = top - bottom; - float diffZ = far - near; + float diffX = right - left; + float diffY = top - bottom; + float diffZ = far - near; - if ((near <= 0.0f) || (far <= 0.0f) || - (diffX <= 0.0f) || (diffY <= 0.0f) || (diffZ <= 0.0f)) + if ((near <= 0.0f) || (far <= 0.0f) || + (diffX <= 0.0f) || (diffY <= 0.0f) || (diffZ <= 0.0f)) { - return; + return; } - pResult->matrix[0][0] = 2.0f * near / diffX; - pResult->matrix[1][1] = 2.0f * near / diffY; - pResult->matrix[2][0] = (right + left) / diffX; - pResult->matrix[2][1] = (top + bottom) / diffY; - pResult->matrix[2][2] = -(near + far) / diffZ; - pResult->matrix[2][3] = -1.0f; - pResult->matrix[3][2] = -2.0f * near * far / diffZ; - - pResult->matrix[0][1] = pResult->matrix[0][2] = pResult->matrix[0][3] = 0.0f; - pResult->matrix[1][0] = pResult->matrix[1][2] = pResult->matrix[1][3] = 0.0f; - pResult->matrix[3][0] = pResult->matrix[3][1] = pResult->matrix[3][3] = 0.0f; + pResult->matrix[0][0] = 2.0f * near / diffX; + pResult->matrix[1][1] = 2.0f * near / diffY; + pResult->matrix[2][0] = (right + left) / diffX; + pResult->matrix[2][1] = (top + bottom) / diffY; + pResult->matrix[2][2] = -(near + far) / diffZ; + pResult->matrix[2][3] = -1.0f; + pResult->matrix[3][2] = -2.0f * near * far / diffZ; + + pResult->matrix[0][1] = pResult->matrix[0][2] = pResult->matrix[0][3] = 0.0f; + pResult->matrix[1][0] = pResult->matrix[1][2] = pResult->matrix[1][3] = 0.0f; + pResult->matrix[3][0] = pResult->matrix[3][1] = pResult->matrix[3][3] = 0.0f; } void @@ -1184,8 +1168,8 @@ GlesCubePlayerForm::Translate(FloatMatrix4* pResult, float tx, float ty, float t { pResult->matrix[3][0] += (pResult->matrix[0][0] * tx + pResult->matrix[1][0] * ty + pResult->matrix[2][0] * tz); pResult->matrix[3][1] += (pResult->matrix[0][1] * tx + pResult->matrix[1][1] * ty + pResult->matrix[2][1] * tz); - pResult->matrix[3][2] += (pResult->matrix[0][2] * tx + pResult->matrix[1][2] * ty + pResult->matrix[2][2] * tz); - pResult->matrix[3][3] += (pResult->matrix[0][3] * tx + pResult->matrix[1][3] * ty + pResult->matrix[2][3] * tz); + pResult->matrix[3][2] += (pResult->matrix[0][2] * tx + pResult->matrix[1][2] * ty + pResult->matrix[2][2] * tz); + pResult->matrix[3][3] += (pResult->matrix[0][3] * tx + pResult->matrix[1][3] * ty + pResult->matrix[2][3] * tz); } void diff --git a/project/src/Audio/GlesCubePlayer.h b/project/src/Audio/GlesCubePlayer.h index 067e98b..0f69a5f 100644 --- a/project/src/Audio/GlesCubePlayer.h +++ b/project/src/Audio/GlesCubePlayer.h @@ -1,6 +1,6 @@ // // Tizen Native SDK -// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// Copyright (c) 2013 Samsung Electronics Co., Ltd. // // Licensed under the Flora License, Version 1.1 (the License); // you may not use this file except in compliance with the License. @@ -78,6 +78,7 @@ public: result Pause(); protected: static const int REQ_UPDATE_QUEUE = 101; + static const int MAX_FILE_NAME = 256; virtual bool OnStart(void){return true;} virtual void OnUserEventReceivedN (RequestId requestId, Tizen::Base::Collection::IList *pArgs); virtual void OnStop(void) {} @@ -162,6 +163,10 @@ private: const static int STOP_INDEX = 1; const static int ID_PLAY = FOOTER_BUTTON_BASE + PLAY_INDEX; const static int ID_STOP = FOOTER_BUTTON_BASE + STOP_INDEX; + static const int WVGA_WIDTH = 480; + static const int WVGA_HEIGHT = 800; + static const int HD_WIDTH = 720; + static const int HD_HEIGHT = 1280; Tizen::Graphics::Opengl::EGLDisplay __eglDisplay; Tizen::Graphics::Opengl::EGLSurface __eglSurface; -- 2.7.4