Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion platform/linux/CMakeList.txt
Original file line number Diff line number Diff line change
Expand Up @@ -959,6 +959,7 @@ add_executable( Solar2DBuilder
${CORONA_ROOT}/tools/CoronaBuilder/main.cpp
${CORONA_ROOT}/tools/CoronaBuilder/Rtt_CoronaBuilder.cpp
${CORONA_ROOT}/tools/CoronaBuilder/Rtt_AppPackagerFactory.cpp
${CORONA_ROOT}/platform/shared/Rtt_AndroidSupportTools.c
${CORONA_ROOT}/tools/CoronaBuilder/Rtt_AppPackagerAndroidFactory.cpp
${CORONA_ROOT}/tools/CoronaBuilder/Rtt_AppPackagerHTML5Factory.cpp
${CORONA_ROOT}/tools/CoronaBuilder/Rtt_AppPackagerLinuxFactory.cpp
Expand Down Expand Up @@ -1028,7 +1029,7 @@ target_compile_definitions( Solar2DSimulator PUBLIC

target_compile_definitions( Solar2DBuilder PUBLIC
Rtt_BUILD_REVISION=${BUILD_NUMBER} Rtt_BUILD_YEAR=${YEAR}
LUA_USE_POPEN Rtt_LUA_COMPILER Rtt_SIMULATOR CORONABUILDER_LINUX LUA_DL_DLOPEN
LUA_USE_POPEN Rtt_LUA_COMPILER Rtt_SIMULATOR CORONABUILDER_LINUX CORONABUILDER_HTML5 CORONABUILDER_ANDROID LUA_DL_DLOPEN
Rtt_LINUX_ENV ALMIXER_COMPILE_WITHOUT_SDL SOUND_SUPPORTS_WAV SOUND_SUPPORTS_MPG123 SOUND_SUPPORTS_OGG
OPT_GENERIC HAVE_STRERROR NO_REAL ENABLE_ALMIXER_THREADS LINUX_LIB)

Expand Down
1 change: 1 addition & 0 deletions platform/linux/CMakeResources.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ file(COPY "${CORONA_ROOT}/platform/resources/json.lua" DESTINATION ${RESOURCES}
file(COPY "${CORONA_ROOT}/platform/resources/dkjson.lua" DESTINATION ${RESOURCES} FILE_PERMISSIONS OWNER_WRITE OWNER_READ GROUP_READ WORLD_READ)
file(COPY "${CORONA_ROOT}/platform/resources/CoronaPListSupport.lua" DESTINATION ${RESOURCES} FILE_PERMISSIONS OWNER_WRITE OWNER_READ GROUP_READ WORLD_READ)
file(COPY "${CORONA_ROOT}/platform/resources/AppSettings.lua" DESTINATION ${RESOURCES} FILE_PERMISSIONS OWNER_WRITE OWNER_READ GROUP_READ WORLD_READ)
file(COPY "${CORONA_ROOT}/platform/resources/AndroidValidation.lua" DESTINATION ${RESOURCES} FILE_PERMISSIONS OWNER_WRITE OWNER_READ GROUP_READ WORLD_READ)

file(COPY "${CORONA_ROOT}/platform/android/create_build_properties.lua" DESTINATION ${RESOURCES} FILE_PERMISSIONS OWNER_WRITE OWNER_READ GROUP_READ WORLD_READ)
file(COPY "${CORONA_ROOT}/platform/android/resources/build.xml" DESTINATION ${RESOURCES} FILE_PERMISSIONS OWNER_WRITE OWNER_READ GROUP_READ WORLD_READ)
Expand Down
28 changes: 27 additions & 1 deletion platform/linux/src/NetworkLibrary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "Rtt_PlatformNotifier.h"
#include "NetworkLibrary.h"
#include "NetworkSupport.h"
#include <climits>

int luaload_network(lua_State *L);

Expand Down Expand Up @@ -345,6 +346,7 @@ int NetworkLibrary::sendRequest(lua_State *L)
requestState->fResponseBody.bodyType = TYPE_NONE;
requestState->fResponseBody.bodyBytes = NULL;
requestState->setURL(requestParams->getRequestUrl());
requestState->setRequestID(requestParams->getID());
requestState->setStatus(status);
requestState->setPhase("ended");
requestState->setBytesEstimated(requestParams->fResponse.size());
Expand All @@ -370,8 +372,32 @@ int NetworkLibrary::sendRequest(lua_State *L)
int NetworkLibrary::cancel(lua_State *L)
{
Self* thiz = NetworkLibrary::ToLibrary(L);

// The id arrives as a plain number, and lua_tonumber() answers 0 for a missing
// argument, nil, false, a table or a non-numeric string, and truncates a
// fractional one. Converting before checking would let any of those name a
// request the caller never meant to cancel, and report success for it.
lua_Number requestIDValue = 0;
bool isValidRequestID = (lua_type(L, 1) == LUA_TNUMBER);
if (isValidRequestID)
{
requestIDValue = lua_tonumber(L, 1);

// Ordered so that a NaN fails the range test instead of reaching the cast.
isValidRequestID = (requestIDValue >= 0 && requestIDValue <= (lua_Number)UINT_MAX);
isValidRequestID = isValidRequestID && ((lua_Number)(unsigned int)requestIDValue == requestIDValue);
}

if (!isValidRequestID)
{
// The other backends log and return nothing rather than raising, so a bad
// argument stays a diagnosable no-op instead of a Lua error.
paramValidationFailure(L, "network.cancel() expects a requestId returned from a call to network.request()");
return 0;
}

bool rc = false;
unsigned int requestID = lua_tonumber(L, 1);
unsigned int requestID = (unsigned int)requestIDValue;
auto it = thiz->fRequests.find(requestID);
if (it != thiz->fRequests.end())
{
Expand Down
4 changes: 4 additions & 0 deletions platform/linux/src/NetworkSupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,10 @@ int NetworkRequestState::pushToLuaState( lua_State *luaState )
lua_setfield( luaState, luaTableStackIndex, "url" );
nPushed++;

lua_pushnumber( luaState, (lua_Number)fRequestID );
lua_setfield( luaState, luaTableStackIndex, "requestId" );
nPushed++;

lua_pushnumber( luaState, (lua_Number)fBytesTransferred );
lua_setfield( luaState, luaTableStackIndex, "bytesTransferred" );
nPushed++;
Expand Down
5 changes: 3 additions & 2 deletions platform/linux/src/NetworkSupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ typedef std::map<std::string, std::string> StringMap;
typedef std::vector<unsigned char> ByteVector;
typedef std::string UTF8String;

void paramValidationFailure(lua_State *luaState, char *message, ...);
void paramValidationFailure(lua_State *luaState, const char *message, ...);
bool isudatatype(lua_State *L, int idx, const char *name);
UTF8String pathForTemporaryFileWithPrefix(const char *prefix, UTF8String pathDir);

Expand Down Expand Up @@ -153,6 +153,7 @@ class NetworkRequestState: public ref_counted
void setDebugValue(char *debugValue, char *debugKey);
void setURL(const UTF8String& url) { fRequestURL = url; }
void setStatus(int status) { fStatus = status; }
void setRequestID(unsigned int requestID) { fRequestID = requestID; }

bool isError();
StringMap getResponseHeaders();
Expand All @@ -177,7 +178,7 @@ class NetworkRequestState: public ref_counted
long long fBytesTransferred;
StringMap fDebugValues;

int fRequestID;
unsigned int fRequestID;
};

// ----------------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions platform/linux/src/Rtt_LinuxBitmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ namespace Rtt
return fData != NULL;
}

bool LinuxBaseBitmap::SaveBitmap(Rtt_Allocator *context, PlatformBitmap *bitmap, const char *filePath)
bool LinuxBaseBitmap::SaveBitmap(Rtt_Allocator *context, PlatformBitmap *bitmap, const char *filePath, float jpegQuality)
{
// Validate.
if ((NULL == bitmap) || (NULL == filePath))
Expand All @@ -205,7 +205,7 @@ namespace Rtt
}
else if (path.rfind(".jpg") != std::string::npos)
{
rc = bitmapUtil::saveJPG(filePath, bits, w, h, fmt, 75); // jpegQuality);
rc = bitmapUtil::saveJPG(filePath, bits, w, h, fmt, jpegQuality);
}
return rc;
}
Expand Down
2 changes: 1 addition & 1 deletion platform/linux/src/Rtt_LinuxBitmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ namespace Rtt
virtual bool IsProperty(PropertyMask mask) const;
virtual void SetProperty(PropertyMask mask, bool newValue);
bool LoadFileBitmap(Rtt_Allocator &context, const char *path);
static bool SaveBitmap(Rtt_Allocator *context, PlatformBitmap *bitmap, const char *filePath);
static bool SaveBitmap(Rtt_Allocator *context, PlatformBitmap *bitmap, const char *filePath, float jpegQuality);

protected:
Rtt_INLINE bool IsPropertyInternal(PropertyMask mask) const { return (fProperties & mask) ? true : false; }
Expand Down
2 changes: 1 addition & 1 deletion platform/linux/src/Rtt_LinuxPlatform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ namespace Rtt

bool LinuxPlatform::SaveBitmap(PlatformBitmap* bitmap, const char* filePath, float jpegQuality) const
{
return LinuxBaseBitmap::SaveBitmap(fAllocator, bitmap, filePath);
return LinuxBaseBitmap::SaveBitmap(fAllocator, bitmap, filePath, jpegQuality);
}

bool LinuxPlatform::AddBitmapToPhotoLibrary(PlatformBitmap* bitmap) const
Expand Down
5 changes: 5 additions & 0 deletions platform/linux/src/Rtt_LinuxUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ const char* GetStartupPath(string* exeFileName)
{
static char buf[PATH_MAX + 1];
ssize_t count = readlink("/proc/self/exe", buf, PATH_MAX);
if (count < 0)
{
// readlink() failed
count = 0;
}
buf[count] = 0;

// remove file name
Expand Down
85 changes: 37 additions & 48 deletions platform/shared/Rtt_BitmapUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,58 +137,48 @@ namespace bitmapUtil
jpeg_stdio_dest(&cinfo, outfile);
cinfo.image_width = width;
cinfo.image_height = height;
jpeg_set_quality(&cinfo, Rtt::Clamp((int)(jpegQuality * 100), 1, 100), TRUE);

row_stride = width * 3; // JSAMPLEs per row in image_buffer
cinfo.input_components = 3; // # of color components per pixel
cinfo.in_color_space = JCS_RGB; // colorspace of input image

jpeg_set_defaults(&cinfo);
jpeg_set_quality(&cinfo, Rtt::Clamp((int)(jpegQuality * 100), 1, 100), TRUE);
jpeg_start_compress(&cinfo, TRUE);

std::unique_ptr<uint8_t> rgb;
std::unique_ptr<uint8_t[]> rgb;
switch (format)
{
case Rtt::PlatformBitmap::Format::kRGB:
break;

case Rtt::PlatformBitmap::Format::kRGBA:
{
// convert to RGB
rgb.reset((uint8_t*)malloc(width * height * 3));
uint8_t* src = data;
uint8_t* dst = rgb.get();
for (int i = 0; i < width * height; i++)
{
*dst++ = *src++;
*dst++ = *src++;
*dst++ = *src++;
src++;
}
data = rgb.get();
break;
}
case Rtt::PlatformBitmap::Format::kABGR:
case Rtt::PlatformBitmap::Format::kARGB:
Rtt_ASSERT(0); //todo
break;

case Rtt::PlatformBitmap::Format::kBGRA:
{
// a kBGRA capture is A,R,G,B, so RGB starts one byte in
const int rgbOffset = (format == Rtt::PlatformBitmap::Format::kBGRA) ? 1 : 0;

// convert to RGB
rgb.reset((uint8_t*)malloc(width * height * 3));
uint8_t* src = data;
rgb.reset(new uint8_t[(size_t)width * height * 3]);
const uint8_t* src = data;
uint8_t* dst = rgb.get();
for (int i = 0; i < width * height; i++)
{
*dst++ = src[2];
*dst++ = src[1];
*dst++ = src[0];
dst[0] = src[rgbOffset];
dst[1] = src[rgbOffset + 1];
dst[2] = src[rgbOffset + 2];
dst += 3;
src += 4;
}
data = rgb.get();
break;
}

default:
Rtt_LogException("jpeg writer: unsupported pixel format\n");
jpeg_destroy_compress(&cinfo);
fclose(outfile);
return false;
}

while (cinfo.next_scanline < cinfo.image_height)
Expand Down Expand Up @@ -347,16 +337,21 @@ namespace bitmapUtil
}

bool savePNG(const char* filename, uint8_t* data, int width, int height, Rtt::PlatformBitmap::Format format)
// Writes a 24 or 32-bit color image in .png format, to the
// given output stream. Data should be in [RGB or RGBA...] byte order.
{
int bpp = Rtt::PlatformBitmap::BytesPerPixel(format);
if (bpp != 3 && bpp != 4)
switch (format)
{
Rtt_LogException("png writer: bpp must be 3 or 4\n");
case Rtt::PlatformBitmap::Format::kRGB:
case Rtt::PlatformBitmap::Format::kRGBA:
case Rtt::PlatformBitmap::Format::kBGRA:
break;

default:
Rtt_LogException("png writer: unsupported pixel format\n");
return false;
}

int bpp = Rtt::PlatformBitmap::BytesPerPixel(format);

png_structp png_ptr;
png_infop info_ptr;

Expand All @@ -381,24 +376,23 @@ namespace bitmapUtil
png_set_IHDR(png_ptr, info_ptr, width, height, 8, bpp == 3 ? PNG_COLOR_TYPE_RGB : PNG_COLOR_TYPE_RGB_ALPHA, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
png_write_info(png_ptr, info_ptr);

bool free_data = false;
std::unique_ptr<U8[]> rgba;
if (format == Rtt::PlatformBitmap::Format::kBGRA)
{
// BGRA ==> RGBA
U8* rgba = (U8*)malloc(width * height * 4);
U8* src = data;
U8* dst = rgba;
// a capture is A,R,G,B
rgba.reset(new U8[(size_t)width * height * 4]);
const U8* src = data;
U8* dst = rgba.get();
for (int i = 0; i < width * height; i++)
{
dst[0] = src[2];
dst[1] = src[1];
dst[2] = src[0];
dst[3] = src[3];
dst[0] = src[1];
dst[1] = src[2];
dst[2] = src[3];
dst[3] = src[0];
dst += 4;
src += 4;
}
data = rgba;
free_data = true;
data = rgba.get();
}

for (int y = 0; y < height; y++)
Expand All @@ -409,11 +403,6 @@ namespace bitmapUtil
png_write_end(png_ptr, info_ptr);
png_destroy_write_struct(&png_ptr, &info_ptr);

if (free_data)
{
free(data);
}

size_t bytes = 0;
FILE* out = fopen(filename, "wb");
if (out)
Expand Down
2 changes: 2 additions & 0 deletions tools/CoronaBuilder/Rtt_AppPackagerAndroidFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ AppPackagerFactory::CreatePackagerParamsAndroid(
scriptPathStr.Set(GetResourceDirectory());
#if defined(Rtt_MAC_ENV)
scriptPathStr.Append("/AndroidValidation.lu");
#elif defined(Rtt_LINUX_ENV)
scriptPathStr.Append("/AndroidValidation.lua");
#elif defined(Rtt_WIN_ENV)
scriptPathStr.Append("/AndroidValidation.lua");
#endif
Expand Down
14 changes: 14 additions & 0 deletions tools/CoronaBuilder/Rtt_AppPackagerFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
#if defined(CORONABUILDER_LINUX)
#include "Rtt_LinuxAppPackager.h"
#endif
#if defined(Rtt_LINUX_ENV)
#include "Rtt_LinuxUtils.h"
#include <string>
#endif

#ifdef Rtt_WIN_ENV
#include "Rtt_JavaHost.h"
Expand Down Expand Up @@ -394,6 +398,16 @@ AppPackagerFactory::GetResourceDirectory() const
return GetResourceDirectoryOSX();
#elif defined(Rtt_WIN_ENV)
return GetResourceDirectoryWin();
#elif defined(Rtt_LINUX_ENV)
// Resources live beside the executable in the Linux layout.
static std::string resourceDir;
if (resourceDir.empty())
{
resourceDir = std::string(GetStartupPath(NULL)) + "/Resources";
}
return resourceDir.c_str();
#else
return NULL;
#endif
}

Expand Down
Loading