some minor fixes
This commit is contained in:
parent
3311799efe
commit
74d2ff3b54
|
|
@ -122,7 +122,7 @@ set_property(const string &property, P3D_object *value) {
|
|||
char *endptr;
|
||||
int index = strtoul(property.c_str(), &endptr, 10);
|
||||
if (*endptr != '\0') {
|
||||
return NULL;
|
||||
return false;
|
||||
}
|
||||
|
||||
return set_element(index, value);
|
||||
|
|
|
|||
|
|
@ -60,11 +60,10 @@ P3DOsxSplashWindow::
|
|||
void P3DOsxSplashWindow::
|
||||
set_image_filename(const string &image_filename,
|
||||
bool image_filename_temp) {
|
||||
int num_channels, row_stride;
|
||||
int num_channels;
|
||||
string data;
|
||||
if (!read_image(image_filename, image_filename_temp,
|
||||
_image_height, _image_width, num_channels, row_stride,
|
||||
data)) {
|
||||
_image_height, _image_width, num_channels, data)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -82,6 +81,7 @@ set_image_filename(const string &image_filename,
|
|||
}
|
||||
|
||||
// Now we need to copy from the RGB source image into the BGRA target image.
|
||||
int row_stride = _image_width * num_channels;
|
||||
int new_row_stride = _image_width * 4;
|
||||
_image_data = new char[new_row_stride * _image_height];
|
||||
for (int yi = 0; yi < _image_height; ++yi) {
|
||||
|
|
|
|||
|
|
@ -402,9 +402,9 @@ uncompress_archive() {
|
|||
return;
|
||||
}
|
||||
|
||||
static const int decompress_buffer_size = 1024;
|
||||
static const int decompress_buffer_size = 81920;
|
||||
char decompress_buffer[decompress_buffer_size];
|
||||
static const int write_buffer_size = 1024;
|
||||
static const int write_buffer_size = 81920;
|
||||
char write_buffer[write_buffer_size];
|
||||
|
||||
z_stream z;
|
||||
|
|
|
|||
|
|
@ -127,19 +127,17 @@ handle_event(P3D_event_data event) {
|
|||
// Function: P3DSplashWindow::read_image
|
||||
// Access: Protected
|
||||
// Description: Reads the image filename and sets image parameters
|
||||
// height, width, num_channels, row_stride, and data.
|
||||
// Returns true on success, false on failure. If
|
||||
// image_filename_temp is true, the file will be deleted
|
||||
// after reading.
|
||||
// height, width, num_channels, and data. Returns true
|
||||
// on success, false on failure. If image_filename_temp
|
||||
// is true, the file will be deleted after reading.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool P3DSplashWindow::
|
||||
read_image(const string &image_filename, bool image_filename_temp,
|
||||
int &height, int &width, int &num_channels, int &row_stride,
|
||||
int &height, int &width, int &num_channels,
|
||||
string &data) {
|
||||
height = 0;
|
||||
width = 0;
|
||||
num_channels = 0;
|
||||
row_stride = 0;
|
||||
data.clear();
|
||||
|
||||
// We currently only support JPEG images. Maybe that's all we'll
|
||||
|
|
@ -198,11 +196,7 @@ read_image(const string &image_filename, bool image_filename_temp,
|
|||
height = cinfo.output_height;
|
||||
num_channels = cinfo.output_components;
|
||||
|
||||
row_stride = width * num_channels;
|
||||
|
||||
// We'll pad row_stride out to word alignment, in case someone
|
||||
// requires this.
|
||||
row_stride = 4 * ((row_stride + 3) / 4);
|
||||
int row_stride = width * num_channels;
|
||||
|
||||
size_t buffer_size = height * row_stride;
|
||||
buffer = new JSAMPLE[buffer_size];
|
||||
|
|
|
|||
|
|
@ -53,8 +53,7 @@ public:
|
|||
|
||||
protected:
|
||||
bool read_image(const string &image_filename, bool image_filename_temp,
|
||||
int &height, int &width, int &num_channels, int &row_stride,
|
||||
string &data);
|
||||
int &height, int &width, int &num_channels, string &data);
|
||||
|
||||
protected:
|
||||
P3DInstance *_inst;
|
||||
|
|
|
|||
|
|
@ -467,14 +467,14 @@ update_image_filename(const string &image_filename, bool image_filename_temp) {
|
|||
|
||||
// Go read the image.
|
||||
string data;
|
||||
int num_channels, row_stride;
|
||||
int num_channels;
|
||||
if (!read_image(image_filename, image_filename_temp,
|
||||
_bitmap_height, _bitmap_width, num_channels, row_stride,
|
||||
data)) {
|
||||
_bitmap_height, _bitmap_width, num_channels, data)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Massage the data into Windows' conventions.
|
||||
int row_stride = _bitmap_width * num_channels;
|
||||
int new_row_stride = (_bitmap_width * 3);
|
||||
// DWORD-pad the row.
|
||||
new_row_stride = 4 * ((new_row_stride + 3) / 4);
|
||||
|
|
|
|||
|
|
@ -220,11 +220,11 @@ thread_run() {
|
|||
redraw(install_label);
|
||||
override = false;
|
||||
XFillRectangle(_display, _window, _graphics_context, 12, _height - 18,
|
||||
install_progress * (_width - 24), 7);
|
||||
(unsigned int)(install_progress * (_width - 24)), 7);
|
||||
XFlush(_display);
|
||||
} else if (install_progress != prev_progress) {
|
||||
XFillRectangle(_display, _window, _graphics_context, 12, _height - 18,
|
||||
install_progress * (_width - 24), 7);
|
||||
(unsigned int)(install_progress * (_width - 24)), 7);
|
||||
}
|
||||
prev_label = install_label;
|
||||
prev_progress = install_progress;
|
||||
|
|
@ -250,10 +250,14 @@ redraw(string label) {
|
|||
// We have an image. Let's see how we can output it.
|
||||
if (_image_width <= _width && _image_height <= _height) {
|
||||
// It fits within the window - just draw it.
|
||||
XPutImage(_display, _window, _graphics_context, _image, 0, 0, (_width - _image_width) * 0.5, (_height - _image_height) * 0.5, _image_width, _image_height);
|
||||
XPutImage(_display, _window, _graphics_context, _image, 0, 0,
|
||||
(_width - _image_width) / 2, (_height - _image_height) / 2,
|
||||
_image_width, _image_height);
|
||||
} else if (_resized_image != NULL) {
|
||||
// We have a resized image already, draw that one.
|
||||
XPutImage(_display, _window, _graphics_context, _resized_image, 0, 0, (_width - _resized_width) * 0.5, (_height - _resized_height) * 0.5, _resized_width, _resized_height);
|
||||
XPutImage(_display, _window, _graphics_context, _resized_image, 0, 0,
|
||||
(_width - _resized_width) / 2, (_height - _resized_height) / 2,
|
||||
_resized_width, _resized_height);
|
||||
} else {
|
||||
// Yuck, the bad case - we need to scale it down.
|
||||
double scale = min((double) _width / (double) _image_width,
|
||||
|
|
@ -262,17 +266,20 @@ redraw(string label) {
|
|||
_resized_height = (int)(_image_height * scale);
|
||||
char *new_data = (char*) malloc(4 * _width * _height);
|
||||
_resized_image = XCreateImage(_display, CopyFromParent, DefaultDepth(_display, _screen),
|
||||
ZPixmap, 0, (char *) new_data, _width, _height, 32, 0);
|
||||
ZPixmap, 0, (char *) new_data, _width, _height, 32, 0);
|
||||
double x_ratio = ((double) _image_width) / ((double) _resized_width);
|
||||
double y_ratio = ((double) _image_height) / ((double) _resized_height);
|
||||
for (int x = 0; x < _width; ++x) {
|
||||
for (int y = 0; y < _height; ++y) {
|
||||
XPutPixel(_resized_image, x, y, XGetPixel(_image,
|
||||
clamp(x * x_ratio, 0, _image_width),
|
||||
clamp(y * y_ratio, 0, _image_height)));
|
||||
XPutPixel(_resized_image, x, y,
|
||||
XGetPixel(_image,
|
||||
(int)clamp(x * x_ratio, 0, _image_width),
|
||||
(int)clamp(y * y_ratio, 0, _image_height)));
|
||||
}
|
||||
}
|
||||
XPutImage(_display, _window, _graphics_context, _resized_image, 0, 0, (_width - _resized_width) * 0.5, (_height - _resized_height) * 0.5, _resized_width, _resized_height);
|
||||
XPutImage(_display, _window, _graphics_context, _resized_image, 0, 0,
|
||||
(_width - _resized_width) / 2, (_height - _resized_height) / 2,
|
||||
_resized_width, _resized_height);
|
||||
}
|
||||
XClearArea(_display, _window, 10, _height - 20, _width - 20, 10, false);
|
||||
}
|
||||
|
|
@ -409,10 +416,9 @@ update_image_filename(const string &image_filename, bool image_filename_temp) {
|
|||
|
||||
// Go read the image.
|
||||
string data;
|
||||
int num_channels, row_stride;
|
||||
int num_channels;
|
||||
if (!read_image(image_filename, image_filename_temp,
|
||||
_image_height, _image_width, num_channels, row_stride,
|
||||
data)) {
|
||||
_image_height, _image_width, num_channels, data)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -62,14 +62,12 @@ extern ofstream logfile;
|
|||
|
||||
#include "load_plugin.h"
|
||||
|
||||
// Uncomment the following to enable use of the PluginThreadAsyncCall
|
||||
// function. (It's commented out for now to assist development of the
|
||||
// case in which this is not available.)
|
||||
/*
|
||||
// If we are building with a version of Gecko that supports the
|
||||
// asynchronous callback function, we should use it--it's just so
|
||||
// handy.
|
||||
#if defined(NPVERS_HAS_PLUGIN_THREAD_ASYNC_CALL) && NP_VERSION_MINOR >= NPVERS_HAS_PLUGIN_THREAD_ASYNC_CALL
|
||||
#define HAS_PLUGIN_THREAD_ASYNC_CALL 1
|
||||
#endif
|
||||
*/
|
||||
|
||||
// Appears in startup.cxx.
|
||||
extern NPNetscapeFuncs *browser;
|
||||
|
|
|
|||
|
|
@ -458,6 +458,25 @@ handle_request(P3D_request *request) {
|
|||
P3D_request_finish(request, handled);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PPInstance::generic_browser_call
|
||||
// Access: Public, Static
|
||||
// Description: This method is called from strategically-chosen
|
||||
// browser callback functions. Its purpose is to
|
||||
// provide another hook into the main thread callback,
|
||||
// particularly if the PluginAsyncCall function isn't
|
||||
// available.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void PPInstance::
|
||||
generic_browser_call() {
|
||||
#ifndef HAS_PLUGIN_THREAD_ASYNC_CALL
|
||||
// If we can't ask Mozilla to call us back using
|
||||
// NPN_PluginThreadAsyncCall(), then we'll do it explicitly now,
|
||||
// since we know we're in the main thread here.
|
||||
handle_request_loop();
|
||||
#endif
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PPInstance::handle_event
|
||||
// Access: Public
|
||||
|
|
@ -469,13 +488,6 @@ bool PPInstance::
|
|||
handle_event(void *event) {
|
||||
bool retval = false;
|
||||
|
||||
#ifndef HAS_PLUGIN_THREAD_ASYNC_CALL
|
||||
// If we can't ask Mozilla to call us back using
|
||||
// NPN_PluginThreadAsyncCall(), then we'll take advantage of the
|
||||
// event loop to do it now.
|
||||
handle_request_loop();
|
||||
#endif
|
||||
|
||||
if (_p3d_inst == NULL) {
|
||||
// Ignore events that come in before we've launched the instance.
|
||||
return retval;
|
||||
|
|
@ -653,16 +665,9 @@ request_ready(P3D_instance *instance) {
|
|||
}
|
||||
|
||||
#else
|
||||
// On Mac, we ignore this asynchronous event, and rely on detecting
|
||||
// it within HandleEvent(). TODO: enable a timer to ensure we get
|
||||
// HandleEvent callbacks in a timely manner? Or maybe we should
|
||||
// enable a one-shot timer in response to this asynchronous event?
|
||||
|
||||
#ifndef __APPLE__
|
||||
// On Unix, HandleEvent isn't called, so we will do what it does
|
||||
// right here. Not sure if this is right.
|
||||
handle_request_loop();
|
||||
#endif // __APPLE__
|
||||
// On Mac and Linux, we ignore this asynchronous event, and rely on
|
||||
// detecting it within HandleEvent() and similar callbacks.
|
||||
|
||||
#endif // _WIN32
|
||||
|
||||
#endif // HAS_PLUGIN_THREAD_ASYNC_CALL
|
||||
|
|
@ -709,8 +714,8 @@ read_contents_file(const string &filename) {
|
|||
xpackage = xpackage->NextSiblingElement("package");
|
||||
}
|
||||
|
||||
// Couldn't find the core package description.
|
||||
logfile << "No core package defined in contents file.\n" << flush;
|
||||
// Couldn't find the coreapi package description.
|
||||
logfile << "No coreapi package defined in contents file.\n" << flush;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -51,6 +51,7 @@ public:
|
|||
void stream_as_file(NPStream *stream, const char *fname);
|
||||
|
||||
void handle_request(P3D_request *request);
|
||||
static void generic_browser_call();
|
||||
|
||||
bool handle_event(void *event);
|
||||
|
||||
|
|
|
|||
|
|
@ -176,9 +176,7 @@ NPP_New(NPMIMEType pluginType, NPP instance, uint16 mode,
|
|||
|
||||
// To experiment with a "windowless" plugin, which really means we
|
||||
// create our own window without an intervening window, try this.
|
||||
// At the moment, there's a deadlock condition when we try it, but
|
||||
// surely it can be solved.
|
||||
// browser->setvalue(instance, NPPVpluginWindowBool, (void *)false);
|
||||
//browser->setvalue(instance, NPPVpluginWindowBool, (void *)false);
|
||||
|
||||
// Now that we have stored the pointer, we can call begin(), which
|
||||
// starts to initiate downloads.
|
||||
|
|
@ -239,6 +237,7 @@ NPP_NewStream(NPP instance, NPMIMEType type, NPStream *stream,
|
|||
<< ", " << stream->end
|
||||
<< ", notifyData = " << stream->notifyData
|
||||
<< "\n" << flush;
|
||||
PPInstance::generic_browser_call();
|
||||
PPInstance *inst = (PPInstance *)(instance->pdata);
|
||||
assert(inst != NULL);
|
||||
|
||||
|
|
@ -258,6 +257,7 @@ NPP_DestroyStream(NPP instance, NPStream *stream, NPReason reason) {
|
|||
<< ", reason = " << reason
|
||||
<< "\n" << flush;
|
||||
|
||||
PPInstance::generic_browser_call();
|
||||
PPInstance *inst = (PPInstance *)(instance->pdata);
|
||||
assert(inst != NULL);
|
||||
|
||||
|
|
@ -286,6 +286,7 @@ NPP_WriteReady(NPP instance, NPStream *stream) {
|
|||
int32
|
||||
NPP_Write(NPP instance, NPStream *stream, int32 offset,
|
||||
int32 len, void *buffer) {
|
||||
PPInstance::generic_browser_call();
|
||||
PPInstance *inst = (PPInstance *)(instance->pdata);
|
||||
assert(inst != NULL);
|
||||
|
||||
|
|
@ -306,6 +307,7 @@ NPP_StreamAsFile(NPP instance, NPStream *stream, const char *fname) {
|
|||
<< ", notifyData = " << stream->notifyData
|
||||
<< "\n" << flush;
|
||||
|
||||
PPInstance::generic_browser_call();
|
||||
PPInstance *inst = (PPInstance *)(instance->pdata);
|
||||
assert(inst != NULL);
|
||||
|
||||
|
|
@ -330,6 +332,7 @@ NPP_Print(NPP instance, NPPrint *platformPrint) {
|
|||
int16
|
||||
NPP_HandleEvent(NPP instance, void *event) {
|
||||
// logfile << "HandleEvent\n" << flush;
|
||||
PPInstance::generic_browser_call();
|
||||
|
||||
PPInstance *inst = (PPInstance *)(instance->pdata);
|
||||
assert(inst != NULL);
|
||||
|
|
@ -350,6 +353,7 @@ NPP_URLNotify(NPP instance, const char *url,
|
|||
<< ", reason = " << reason
|
||||
<< "\n" << flush;
|
||||
|
||||
PPInstance::generic_browser_call();
|
||||
PPInstance *inst = (PPInstance *)(instance->pdata);
|
||||
assert(inst != NULL);
|
||||
|
||||
|
|
@ -364,6 +368,7 @@ NPP_URLNotify(NPP instance, const char *url,
|
|||
NPError
|
||||
NPP_GetValue(NPP instance, NPPVariable variable, void *value) {
|
||||
logfile << "GetValue " << variable << "\n";
|
||||
PPInstance::generic_browser_call();
|
||||
PPInstance *inst = (PPInstance *)(instance->pdata);
|
||||
assert(inst != NULL);
|
||||
|
||||
|
|
@ -387,6 +392,7 @@ NPP_GetValue(NPP instance, NPPVariable variable, void *value) {
|
|||
NPError
|
||||
NPP_SetValue(NPP instance, NPNVariable variable, void *value) {
|
||||
logfile << "SetValue " << variable << "\n";
|
||||
PPInstance::generic_browser_call();
|
||||
return NPERR_GENERIC_ERROR;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue