Skip to content

Commit

Permalink
check for quartz device at startup
Browse files Browse the repository at this point in the history
  • Loading branch information
jjallaire committed Jan 5, 2012
1 parent 61ea10a commit 7f2b823
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/cpp/r/session/graphics/RGraphicsDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ SEXP createGD()
Error makeActive()
{
// don't make active if our graphics version is incompatible
if (!graphics::validateEngineVersion())
if (!graphics::validateRequirements())
return Error(graphics::errc::IncompatibleGraphicsEngine, ERROR_LOCATION);

// make sure we have been created
Expand Down Expand Up @@ -681,7 +681,7 @@ Error initialize(

// check for an incompatible graphics version before fully initializing.
std::string message;
if (graphics::validateEngineVersion(&message))
if (graphics::validateRequirements(&message))
{
// register device creation routine
R_CallMethodDef createGDMethodDef ;
Expand Down
75 changes: 72 additions & 3 deletions src/cpp/r/session/graphics/RGraphicsUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,17 @@
#include <core/Log.hpp>
#include <core/Error.hpp>

#include <r/RExec.hpp>

#include <Rinternals.h>
#define R_USE_PROTOTYPES 1
#include <R_ext/GraphicsEngine.h>
#include <R_ext/GraphicsDevice.h>

#ifdef __APPLE__
#include <R_ext/QuartzDevice.h>
#endif

#include <r/RErrorCategory.hpp>

using namespace core;
Expand All @@ -32,15 +38,77 @@ namespace session {
namespace graphics {

namespace {

int s_compatibleEngineVersion = 8;

#ifdef __APPLE__
class QuartzStatus : boost::noncopyable
{
public:
QuartzStatus() : checked_(false), installed_(false) {}

bool isInstalled()
{
if (!checked_)
{
checked_ = true;

QuartzFunctions_t* pQuartzFunctions = NULL;
Error error = r::exec::executeSafely<QuartzFunctions_t*>(
&getQuartzFunctions,
&pQuartzFunctions);
if (error)
LOG_ERROR(error);

installed_ = pQuartzFunctions != NULL;
}

return installed_;
}

private:
bool checked_;
bool installed_;
};

bool hasRequiredGraphicsDevices(std::string* pMessage)
{
static QuartzStatus s_quartzStatus;
if (!s_quartzStatus.isInstalled())
{
if (pMessage != NULL)
{
*pMessage = "\nWARNING: The version of R you are running against "
"does not support the quartz graphics device (which is "
"required by RStudio for graphics). The Plots tab will "
"be disabled until a version of R that supports quartz "
"is installed.";
}
return false;
}
else
{
return true;
}
}

#else

bool hasRequiredGraphicsDevices(std::string* pMessage)
{
return true;
}

#endif

} // anonymous namespace

void setCompatibleEngineVersion(int version)
{
s_compatibleEngineVersion = version;
}

bool validateEngineVersion(std::string* pMessage)
bool validateRequirements(std::string* pMessage)
{
// get engineVersion
int engineVersion = R_GE_getVersion();
Expand Down Expand Up @@ -75,10 +143,11 @@ bool validateEngineVersion(std::string* pMessage)
return false;
}

// compatible

// check for required devices
else
{
return true;
return hasRequiredGraphicsDevices(pMessage);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/cpp/r/session/graphics/RGraphicsUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace session {
namespace graphics {

void setCompatibleEngineVersion(int version);
bool validateEngineVersion(std::string* pMessage = NULL);
bool validateRequirements(std::string* pMessage = NULL);

class RestorePreviousGraphicsDeviceScope
{
Expand Down

0 comments on commit 7f2b823

Please sign in to comment.