Exemplo n.º 1
0
static uavcan_linux::NodePtr initMainNode(const std::vector<std::string>& ifaces, uavcan::NodeID nid,
                                          const std::string& name)
{
    std::cout << "Initializing main node" << std::endl;

    auto node = uavcan_linux::makeNode(ifaces);

    node->setNodeID(nid);
    node->setName(name.c_str());

    node->getLogger().setLevel(uavcan::protocol::debug::LogLevel::DEBUG);

    const int start_res = node->start();
    ENFORCE(0 == start_res);

    uavcan::NetworkCompatibilityCheckResult init_result;
    ENFORCE(0 == node->checkNetworkCompatibility(init_result));
    if (!init_result.isOk())
    {
        throw std::runtime_error("Network conflict with node " + std::to_string(init_result.conflicting_node.get()));
    }

    node->setStatusOk();
    return node;
}
Exemplo n.º 2
0
int SqlQuery::prepare(const QByteArray &sql, bool allow_failure)
{
    _sql = sql.trimmed();
    if (_stmt) {
        finish();
    }
    if (!_sql.isEmpty()) {
        int n = 0;
        int rc;
        do {
            rc = sqlite3_prepare_v2(_db, _sql.constData(), -1, &_stmt, 0);
            if ((rc == SQLITE_BUSY) || (rc == SQLITE_LOCKED)) {
                n++;
                OCC::Utility::usleep(SQLITE_SLEEP_TIME_USEC);
            }
        } while ((n < SQLITE_REPEAT_COUNT) && ((rc == SQLITE_BUSY) || (rc == SQLITE_LOCKED)));
        _errId = rc;

        if (_errId != SQLITE_OK) {
            _error = QString::fromUtf8(sqlite3_errmsg(_db));
            qCWarning(lcSql) << "Sqlite prepare statement error:" << _error << "in" << _sql;
            ENFORCE(allow_failure, "SQLITE Prepare error");
        } else {
            ASSERT(_stmt);
            _sqldb->_queries.insert(this);
        }
    }
    return _errId;
}
Exemplo n.º 3
0
void SubtitleRenderer::initialize_vg() {
  // get an EGL display connection
  display_ = eglGetDisplay(EGL_DEFAULT_DISPLAY);
  ENFORCE(display_);

  // initialize the EGL display connection
  ENFORCE(eglInitialize(display_, NULL, NULL));

  // get an appropriate EGL frame buffer configuration
  static const EGLint attribute_list[] = {
    EGL_RED_SIZE, 8,
    EGL_GREEN_SIZE, 8,
    EGL_BLUE_SIZE, 8,
    EGL_ALPHA_SIZE, 8,
    EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
    EGL_NONE
  };
  EGLConfig config{};
  EGLint num_config{};

  ENFORCE(eglChooseConfig(display_, attribute_list, &config, 1, &num_config));
  ENFORCE(num_config);

  ENFORCE(eglBindAPI(EGL_OPENVG_API));

  static EGL_DISPMANX_WINDOW_T nativewindow;
  nativewindow.element = dispman_element_;
  nativewindow.width = buffer_width_;
  nativewindow.height = buffer_height_;
     
  surface_ = eglCreateWindowSurface(display_, config, &nativewindow, NULL);
  ENFORCE(surface_);

  // create an EGL rendering context
  context_ = eglCreateContext(display_, config, EGL_NO_CONTEXT, NULL);
  ENFORCE(context_);

  auto result = eglMakeCurrent(display_, surface_, surface_, context_);
  assert(result);

  vgSeti(VG_FILTER_FORMAT_LINEAR, VG_TRUE);
  assert(!vgGetError());

  vgSeti(VG_IMAGE_QUALITY, VG_IMAGE_QUALITY_NONANTIALIASED);
  assert(!vgGetError());

  auto create_vg_font = [](VGFont& font) {
    font = vgCreateFont(64);
    ENFORCE(font);
  };

  create_vg_font(vg_font_);
  create_vg_font(vg_font_border_);

  // VGfloat color[4] = { 1.0f, 0.0f, 0.0f, 1.0f };
  // vgSetfv(VG_CLEAR_COLOR, 4, color);
}
 void send(const Request<T> &req) {
     m_buff.clear();
     msgpack::pack(&m_buff, req);
     quint32 s = static_cast<quint32>(m_buff.size());
     quint8 type = static_cast<quint8>(T);
     s += sizeof(type) + sizeof(PROTOCOL_VERSION);
     ENFORCE(m_tcp.write(reinterpret_cast<const char*>(&s), sizeof(s)) == sizeof(s),
             "failed to write message size");
     ENFORCE(m_tcp.write(reinterpret_cast<const char*>(&PROTOCOL_VERSION), sizeof(PROTOCOL_VERSION)) == sizeof(PROTOCOL_VERSION),
             "failed to write protocol version");
     ENFORCE(m_tcp.write(reinterpret_cast<const char*>(&type), sizeof(type)) == sizeof(type),
             "failed to write message type");
     ENFORCE(m_tcp.write(m_buff.data(), m_buff.size()) == static_cast<qint64>(m_buff.size()),
             "failed to write message");
     ENFORCE(m_tcp.waitForBytesWritten(1000),
             "unfinished socket write");
 }
 void recv(Reply<T> &rep, int timeout = 1000) {
     ENFORCE(m_tcp.waitForDisconnected(timeout), "server operation timeout");
     QByteArray arr = m_tcp.readAll();
     quint32 s = *reinterpret_cast<const quint32*>(arr.data());
     ENFORCE(s == arr.size() - sizeof(s), "message length mismatched");
     ENFORCE(s > sizeof(quint8) + sizeof(quint8), "message is too small");
     quint8 v = *reinterpret_cast<const quint8*>(arr.data() + sizeof(s));
     ENFORCE(v == PROTOCOL_VERSION, "protocol version mismatched");
     quint8 type = *reinterpret_cast<const quint8*>(arr.data() + sizeof(s) + sizeof(v));
     ENFORCE(type == T, "message type mismatched");
     const char *pkg = arr.data() + sizeof(s) + sizeof(v) + sizeof(type);
     const size_t pkgLength = s - sizeof(v) - sizeof(type);
     msgpack::unpack(&m_unp, pkg, pkgLength);
     msgpack::object obj = m_unp.get();
     rep = obj.as<Reply<T> >();
     m_unp.zone()->clear();
 }
Exemplo n.º 6
0
 void ICreature::SetInterruptionAction(IActionBase* interruptionActionPtr)
 {
   ResetInterruptionAction();
   ENFORCE(interruptionActionPtr != NULL);
   m_ContactHandler = EntityContactHandler();
   interruptionActionPtr->ResetState();
   m_InterruptionActionPtr = interruptionActionPtr;
 }
Exemplo n.º 7
0
 void ICreatureBase::DecSensorModeCounter()
 {
   ENFORCE(m_SensorModeCounter != 0);
   if(--m_SensorModeCounter == 0)
   {
     SetSensorMode(false);
   }
 }
Exemplo n.º 8
0
static uavcan_linux::NodePtr initNodeInPassiveMode(const std::vector<std::string>& ifaces, const std::string& node_name)
{
    auto node = uavcan_linux::makeNode(ifaces);
    node->setName(node_name.c_str());
    ENFORCE(0 == node->start());
    node->setStatusOk();
    return node;
}
Exemplo n.º 9
0
static uavcan_linux::NodePtr initNode(const std::vector<std::string>& ifaces, uavcan::NodeID nid,
                                      const std::string& name)
{
    auto node = uavcan_linux::makeNode(ifaces);
    node->setNodeID(nid);
    node->setName(name.c_str());

    ENFORCE(0 <= node->start());

    uavcan::NetworkCompatibilityCheckResult ncc_result;
    ENFORCE(0 <= node->checkNetworkCompatibility(ncc_result));
    if (!ncc_result.isOk())
    {
        throw std::runtime_error("Network conflict with node " + std::to_string(ncc_result.conflicting_node.get()));
    }

    node->setStatusOk();
    return node;
}
Exemplo n.º 10
0
static uavcan_linux::NodePtr initNode(const std::vector<std::string>& ifaces, uavcan::NodeID nid,
                                      const std::string& name)
{
    auto node = uavcan_linux::makeNode(ifaces);

    /*
     * Configuring the node.
     */
    node->setNodeID(nid);
    node->setName(name.c_str());

    node->getLogger().setLevel(uavcan::protocol::debug::LogLevel::DEBUG);

    /*
     * Starting the node.
     */
    std::cout << "Starting the node..." << std::endl;
    const int start_res = node->start();
    std::cout << "Start returned: " << start_res << std::endl;
    ENFORCE(0 == start_res);

    /*
     * Checking if our node conflicts with other nodes. This may take a few seconds.
     */
    uavcan::NetworkCompatibilityCheckResult init_result;
    ENFORCE(0 == node->checkNetworkCompatibility(init_result));
    if (!init_result.isOk())
    {
        throw std::runtime_error("Network conflict with node " + std::to_string(init_result.conflicting_node.get()));
    }

    std::cout << "Node started successfully" << std::endl;

    /*
     * Say Hi to the world.
     */
    node->setStatusOk();
    node->logInfo("init", "Hello world! I'm [%*], NID %*",
                  node->getNodeStatusProvider().getName().c_str(), int(node->getNodeID().get()));
    return node;
}
Exemplo n.º 11
0
void SubtitleRenderer::initialize_window(int display, int layer,
                                         unsigned int x,
                                         unsigned int y,
                                         unsigned int width,
                                         unsigned int height) {
  VC_RECT_T dst_rect;
  dst_rect.x = x;
  dst_rect.y = y;
  dst_rect.width = width;
  dst_rect.height = height;

  VC_RECT_T src_rect;
  src_rect.x = 0;
  src_rect.y = 0;
  src_rect.width = dst_rect.width << 16;
  src_rect.height = dst_rect.height << 16;        

  dispman_display_ = vc_dispmanx_display_open(display);
  ENFORCE(dispman_display_);

  {
    auto dispman_update = vc_dispmanx_update_start(0);
    ENFORCE(dispman_update);
    SCOPE_EXIT {
      ENFORCE(!vc_dispmanx_update_submit_sync(dispman_update));
    };

    dispman_element_ =
        vc_dispmanx_element_add(dispman_update,
                                dispman_display_,
                                layer,
                                &dst_rect,
                                0 /*src*/,
                                &src_rect,
                                DISPMANX_PROTECTION_NONE,
                                0 /*alpha*/,
                                0 /*clamp*/,
                                (DISPMANX_TRANSFORM_T) 0 /*transform*/);
    ENFORCE(dispman_element_);
  }
}
Exemplo n.º 12
0
bool SqlQuery::initOrReset(const QByteArray &sql, OCC::SqlDatabase &db)
{
    ENFORCE(!_sqldb || &db == _sqldb);
    _sqldb = &db;
    _db = db.sqliteDb();
    if (_stmt) {
        reset_and_clear_bindings();
        return true;
    } else {
        return prepare(sql) == 0;
    }
}
Exemplo n.º 13
0
void SubtitleRenderer::initialize_window(int layer) {
  ENFORCE(graphics_get_display_size(0 /* LCD */, &screen_width_, &screen_height_)
          >= 0);

  VC_RECT_T dst_rect;
  dst_rect.x = 0;
  dst_rect.y = 0;
  dst_rect.width = screen_width_;
  dst_rect.height = screen_height_;
     
  VC_RECT_T src_rect;
  src_rect.x = 0;
  src_rect.y = 0;
  src_rect.width = screen_width_ << 16;
  src_rect.height = screen_height_ << 16;        

  dispman_display_ = vc_dispmanx_display_open(0 /* LCD */);
  ENFORCE(dispman_display_);

  {
    auto dispman_update = vc_dispmanx_update_start(0);
    ENFORCE(dispman_update);
    SCOPE_EXIT {
      ENFORCE(!vc_dispmanx_update_submit_sync(dispman_update));
    };

    dispman_element_ =
        vc_dispmanx_element_add(dispman_update,
                                dispman_display_,
                                layer,
                                &dst_rect,
                                0 /*src*/,
                                &src_rect,
                                DISPMANX_PROTECTION_NONE,
                                0 /*alpha*/,
                                0 /*clamp*/,
                                (DISPMANX_TRANSFORM_T) 0 /*transform*/);
    ENFORCE(dispman_element_);
  }
}
Exemplo n.º 14
0
void WindowsHeadlessHost::InitGL()
{
	glOkay = false;
	hWnd = CreateHiddenWindow();

	if (WINDOW_VISIBLE)
	{
		ShowWindow(hWnd, TRUE);
		SetFocus(hWnd);
	}

	int pixelFormat;

	static PIXELFORMATDESCRIPTOR pfd = {0};
	pfd.nSize = sizeof(pfd);
	pfd.nVersion = 1;
	pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
	pfd.iPixelType = PFD_TYPE_RGBA;
	pfd.cColorBits = 32;
	pfd.cDepthBits = 16;
	pfd.iLayerType = PFD_MAIN_PLANE;

#define ENFORCE(x, msg) { if (!(x)) { fprintf(stderr, msg); return; } }

	ENFORCE(hDC = GetDC(hWnd), "Unable to create DC.");
	ENFORCE(pixelFormat = ChoosePixelFormat(hDC, &pfd), "Unable to match pixel format.");
	ENFORCE(SetPixelFormat(hDC, pixelFormat, &pfd), "Unable to set pixel format.");
	ENFORCE(hRC = wglCreateContext(hDC), "Unable to create GL context.");
	ENFORCE(wglMakeCurrent(hDC, hRC), "Unable to activate GL context.");

	SetVSync(0);

	glewInit();
	glstate.Initialize();

	LoadNativeAssets();

	if (ResizeGL())
		glOkay = true;
}
Exemplo n.º 15
0
static void runForever(const uavcan_linux::NodePtr& node)
{
    /*
     * Subscribing to the UAVCAN logging topic
     */
    auto log_handler = [](const uavcan::ReceivedDataStructure<uavcan::protocol::debug::LogMessage>& msg)
    {
        std::cout << msg << std::endl;
    };
    auto log_sub = node->makeSubscriber<uavcan::protocol::debug::LogMessage>(log_handler);

    /*
     * Printing when other nodes enter the network or change status
     */
    struct NodeStatusMonitor : public uavcan::NodeStatusMonitor
    {
        explicit NodeStatusMonitor(uavcan::INode& node) : uavcan::NodeStatusMonitor(node) { }

        void handleNodeStatusChange(const NodeStatusChangeEvent& event) override
        {
            std::cout << "Remote node NID " << int(event.node_id.get()) << " changed status: "
                      << int(event.old_status.status_code) << " --> "
                      << int(event.status.status_code) << std::endl;
        }
    };

    NodeStatusMonitor nsm(*node);
    ENFORCE(0 == nsm.start());

    /*
     * Adding a stupid timer that does nothing once a minute
     */
    auto do_nothing_once_a_minute = [&node](const uavcan::TimerEvent&)
    {
        node->logInfo("timer", "Another minute passed...");
        // coverity[dont_call]
        node->setVendorSpecificStatusCode(static_cast<std::uint16_t>(std::rand())); // Setting to an arbitrary value
    };
    auto timer = node->makeTimer(uavcan::MonotonicDuration::fromMSec(60000), do_nothing_once_a_minute);

    /*
     * Spinning forever
     */
    while (true)
    {
        const int res = node->spin(uavcan::MonotonicDuration::getInfinite());
        if (res < 0)
        {
            node->logError("spin", "Error %*", res);
        }
    }
}
Exemplo n.º 16
0
static void runForever(const uavcan_linux::NodePtr& node)
{
    Monitor mon(node);
    ENFORCE(0 == mon.start());
    while (true)
    {
        const int res = node->spin(uavcan::MonotonicDuration::getInfinite());
        if (res < 0)
        {
            node->logError("spin", "Error %*", res);
        }
    }
}
Exemplo n.º 17
0
void SmtpClient::setAccount(const QMailAccountId &id)
{
    // Load the current configuration for this account
    config = QMailAccountConfiguration(id);
#ifdef USE_ACCOUNTS_QT
    if (!ssoSessionManager) {
        SmtpConfiguration smtpCfg(config);
        ssoSessionManager = new SSOSessionManager(this);
        if (ssoSessionManager->createSsoIdentity(id, "smtp", smtpCfg.smtpAuthentication())) {
            ENFORCE(connect(ssoSessionManager, SIGNAL(ssoSessionResponse(QList<QByteArray>))
                            ,this, SLOT(onSsoSessionResponse(QList<QByteArray>))));
            ENFORCE(connect(ssoSessionManager, SIGNAL(ssoSessionError(QString)),this, SLOT(onSsoSessionError(QString))));
            qMailLog(SMTP) << Q_FUNC_INFO << "SSO identity is found for account id: "<< id;
        } else {
            delete ssoSessionManager;
            ssoSessionManager = 0;
            qMailLog(SMTP) << Q_FUNC_INFO << "SSO identity is not found for account id: "<< id
                           << ", accounts configuration will be used";
        }
    }
#endif
}
Exemplo n.º 18
0
FaceDatabaseProvider::FaceDatabaseProvider(QSparqlConnection *connection, QObject *parent) :
    QStandardItemModel(0, GalleryPeopleListPage::CeilingColumn, parent),
    m_sparqlConnection(connection)
{
    QString databaseName = QString(getenv("XDG_DATA_HOME")) + "/gallerycore/data/faces.db";
    NullThumbnailer thumbnailer;
    m_faceDatabase = new XQFaceDatabase(thumbnailer, databaseName);
    update();
    ENFORCE(connect(m_faceDatabase, SIGNAL(faceUpdated(XQFaceRegion,QString)),
                    this, SLOT(update())));
    connect(m_faceDatabase, SIGNAL(groupMerged(QString,QString)),
            this, SLOT(update()));
}
Exemplo n.º 19
0
std::string IFStreamFile::readAll()
{
  ENFORCE(m_ifs.is_open(), "File must be opened before reading it!");
  LOG_DEBUG("Read all data from file: ", getName());

  std::string line;
  std::string data;
  while(getline(m_ifs, line))
  {
    LOG_FINE("line read: '", line, "'");
    data.append(line + "\n");
  }
  return data;
}
Exemplo n.º 20
0
void SimpleGLWindow::SetupGL() {
	int pixelFormat;

	static PIXELFORMATDESCRIPTOR pfd = {0};
	pfd.nSize = sizeof(pfd);
	pfd.nVersion = 1;
	pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
	pfd.iPixelType = PFD_TYPE_RGBA;
	pfd.cColorBits = 32;
	pfd.cDepthBits = 16;
	pfd.iLayerType = PFD_MAIN_PLANE;

#define ENFORCE(x, msg) { if (!(x)) { ERROR_LOG(COMMON, "SimpleGLWindow: %s (%08x)", msg, GetLastError()); return; } }

	ENFORCE(hDC_ = GetDC(hWnd_), "Unable to create DC.");
	ENFORCE(pixelFormat = ChoosePixelFormat(hDC_, &pfd), "Unable to match pixel format.");
	ENFORCE(SetPixelFormat(hDC_, pixelFormat, &pfd), "Unable to set pixel format.");
	ENFORCE(hGLRC_ = wglCreateContext(hDC_), "Unable to create GL context.");
	ENFORCE(wglMakeCurrent(hDC_, hGLRC_), "Unable to activate GL context.");

	glewInit();
	valid_ = true;
}
Exemplo n.º 21
0
void SubtitleRenderer::
initialize_fonts(const std::string& font_path, float font_size) {
  ENFORCE(!FT_Init_FreeType(&ft_library_));
  ENFORCE2(!FT_New_Face(ft_library_, font_path.c_str(), 0, &ft_face_),
           "Unable to open font");
  ENFORCE(!FT_Set_Pixel_Sizes(ft_face_, 0, font_size*screen_height_));

  auto get_bbox = [this](char32_t cp) {
    auto glyph_index = FT_Get_Char_Index(ft_face_, cp);
    ENFORCE(!FT_Load_Glyph(ft_face_, glyph_index, FT_LOAD_NO_HINTING));
    FT_Glyph glyph;
    ENFORCE(!FT_Get_Glyph(ft_face_->glyph, &glyph));
    SCOPE_EXIT {FT_Done_Glyph(glyph);};
    FT_BBox bbox;
    FT_Glyph_Get_CBox(glyph, FT_GLYPH_BBOX_PIXELS, &bbox);
    return bbox;
  };

  constexpr float padding_factor = 0.05f;
  int y_min = get_bbox('g').yMin;
  int y_max = get_bbox('M').yMax;
  y_max += -y_min*0.7f;
  line_height_ = y_max - y_min;
  const int v_padding = line_height_*padding_factor + 0.5f;
  line_height_ += v_padding*2;
  box_offset_ = y_min-v_padding;
  box_h_padding_ = line_height_/5.0f + 0.5f;


  constexpr float border_thickness = 0.045f;
  ENFORCE(!FT_Stroker_New(ft_library_, &ft_stroker_));
  FT_Stroker_Set(ft_stroker_,
                 line_height_*border_thickness*64.0f,
                 FT_STROKER_LINECAP_ROUND,
                 FT_STROKER_LINEJOIN_ROUND,
                 0);

  vgSeti(VG_FILTER_FORMAT_LINEAR, VG_TRUE);
  assert(!vgGetError());

  vgSeti(VG_IMAGE_QUALITY, VG_IMAGE_QUALITY_NONANTIALIASED);
  assert(!vgGetError());

  auto create_vg_font = [](VGFont& font) {
    font = vgCreateFont(128);
    ENFORCE(font);
  };

  create_vg_font(vg_font_);
  create_vg_font(vg_font_border_);
}
Exemplo n.º 22
0
 void ICreature::StartInterruptionAction(const InterruptionAction& interruptionAction)
 {
   ENFORCE(interruptionAction.CheckValid());
   if(m_InterruptionActionPtr != NULL)
   {
     OverstepInterruptionAction();
   }
   else
   {
     StopCurrentAction();
   }
   
   m_ContactHandler = EntityContactHandler();
   m_InterruptionAction = interruptionAction;
   const Ptr<IAction> action = m_InterruptionAction.GetBase();
   action->Initialize((IActionEnv*)this);
   action->Start();
   m_InterruptionActionPtr = action;
 }
Exemplo n.º 23
0
void hlsl_shader::init_domain_shader(ID3D11Device* p_device, const hlsl_shader_desc& desc)
{
	try {
		p_domain_shader_bytecode = compile_shader(desc.source_code, desc.source_filename,
			desc.compile_flags,
			hlsl_shader_desc::domain_shader_entry_point,
			hlsl_shader_desc::domain_shader_model);

		HRESULT hr = p_device->CreateDomainShader(
			p_domain_shader_bytecode->GetBufferPointer(),
			p_domain_shader_bytecode->GetBufferSize(),
			nullptr, &p_domain_shader.ptr);

		ENFORCE(hr == S_OK, std::to_string(hr));
	}
	catch (...) {
		const std::string exc_msg = EXCEPTION_MSG("Domain shader creation error.");
		std::throw_with_nested(std::runtime_error(exc_msg));
	}
}
Exemplo n.º 24
0
void Config::parseStream(std::istream & in)
{
  std::string line;
  std::getline(in, line);
  LOG_DEBUG("  line: '",line, "'");

  auto parts = helper::split(line, ' ');
  std::string nodeName = parts[0];
  LOG_INFO("node-name acquired: ", nodeName);

  Node * node = getNodePtr(nodeName);
  ENFORCE(node != nullptr, "Unknown node:"+nodeName);
  LOG_DEBUG("node-name valid: '", nodeName, "'");

  node->parseProperties(in);

  while(in.good())
  {
    std::getline(in, line);
    LOG_DEBUG("  line: '",line, "'");
  }
}
Exemplo n.º 25
0
void SubtitleRenderer::initialize_egl() {
  // get an EGL display connection
  display_ = eglGetDisplay(EGL_DEFAULT_DISPLAY);
  ENFORCE(display_);

  // initialize the EGL display connection
  ENFORCE(eglInitialize(display_, NULL, NULL));

  // get an appropriate EGL frame buffer configuration
  static const EGLint attribute_list[] = {
    EGL_RED_SIZE, 8,
    EGL_GREEN_SIZE, 8,
    EGL_BLUE_SIZE, 8,
    EGL_ALPHA_SIZE, 8,
    EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
    EGL_NONE
  };
  EGLConfig config{};
  EGLint num_config{};

  ENFORCE(eglChooseConfig(display_, attribute_list, &config, 1, &num_config));
  ENFORCE(num_config);

  ENFORCE(eglBindAPI(EGL_OPENVG_API));

  static EGL_DISPMANX_WINDOW_T nativewindow;
  nativewindow.element = dispman_element_;
  nativewindow.width = screen_width_;
  nativewindow.height = screen_height_;
     
  surface_ = eglCreateWindowSurface(display_, config, &nativewindow, NULL);
  ENFORCE(surface_);

  // create an EGL rendering context
  context_ = eglCreateContext(display_, config, EGL_NO_CONTEXT, NULL);
  ENFORCE(context_);

  auto result = eglMakeCurrent(display_, surface_, surface_, context_);
  assert(result);
}
Exemplo n.º 26
0
void SubtitleRenderer::
initialize_fonts(const std::string& font_path,
                 const std::string& italic_font_path,
                 unsigned int font_size) {
  ENFORCE(!FT_Init_FreeType(&ft_library_));
  ENFORCE2(!FT_New_Face(ft_library_, font_path.c_str(), 0, &ft_face_),
           "Unable to open font");
  ENFORCE2(!FT_New_Face(ft_library_, italic_font_path.c_str(), 0, &ft_face_italic_),
           "Unable to open italic font");
  ENFORCE(!FT_Set_Pixel_Sizes(ft_face_, 0, font_size));
  ENFORCE(!FT_Set_Pixel_Sizes(ft_face_italic_, 0, font_size));

  auto get_bbox = [this](char32_t cp) {
    auto glyph_index = FT_Get_Char_Index(ft_face_, cp);
    ENFORCE(!FT_Load_Glyph(ft_face_, glyph_index, FT_LOAD_NO_HINTING));
    FT_Glyph glyph;
    ENFORCE(!FT_Get_Glyph(ft_face_->glyph, &glyph));
    SCOPE_EXIT {FT_Done_Glyph(glyph);};
    FT_BBox bbox;
    FT_Glyph_Get_CBox(glyph, FT_GLYPH_BBOX_PIXELS, &bbox);
    return bbox;
  };

  constexpr float padding_factor = 0.05f;
  int y_min = get_bbox('g').yMin;
  int y_max = get_bbox('M').yMax;
  y_max += -y_min*0.7f;
  line_height_ = y_max - y_min;
  const int v_padding = line_height_*padding_factor + 0.5f;
  line_height_ += v_padding*2;
  box_offset_ = y_min-v_padding;
  box_h_padding_ = line_height_/5.0f + 0.5f;


  constexpr float border_thickness = 0.044f;
  ENFORCE(!FT_Stroker_New(ft_library_, &ft_stroker_));
  FT_Stroker_Set(ft_stroker_,
                 line_height_*border_thickness*64.0f,
                 FT_STROKER_LINECAP_ROUND,
                 FT_STROKER_LINEJOIN_ROUND,
                 0);
}
Exemplo n.º 27
0
 void CreatureMotionSys::SetSpatialMult(SpatialMultId spatialMultId,
   Float duration, const SpatialMult& spatialMult)
 {
   ENFORCE(spatialMult.linearSpeedMult >= 0.0f);
   ENFORCE(spatialMult.linearAccelMult >= 0.0f);
   ENFORCE(spatialMult.linearBrakingMult >= 0.0f);
   ENFORCE(spatialMult.angularSpeedMult >= 0.0f);
   ENFORCE(spatialMult.angularAccelMult >= 0.0f);
   ENFORCE(spatialMult.angularBrakingMult >= 0.0f);
   CancelSpatialMult(spatialMultId);
   SpatialMultState& state = m_SpatialMultStates[spatialMultId];
   state.remaining = duration;
   state.mult = spatialMult;
   m_Creature.SetMaxLinearSpeed(state.mult.linearSpeedMult * m_Creature.GetMaxLinearSpeed());
   m_Creature.SetMaxLinearAccel(state.mult.linearAccelMult * m_Creature.GetMaxLinearAccel());
   m_Creature.SetMaxLinearBraking(state.mult.linearBrakingMult * m_Creature.GetMaxLinearBraking());
   m_Creature.SetMaxAngularSpeed(state.mult.angularSpeedMult * m_Creature.GetMaxAngularSpeed());
   m_Creature.SetMaxAngularAccel(state.mult.angularAccelMult * m_Creature.GetMaxAngularAccel());
   m_Creature.SetMaxAngularBraking(state.mult.angularBrakingMult * m_Creature.GetMaxAngularBraking());
 }
Exemplo n.º 28
0
void SubtitleRenderer::load_glyph(char32_t codepoint) {
  VGfloat escapement[2]{};

  auto load_glyph_internal =
  [&](FT_Face ft_face, VGFont vg_font, bool border) {
    try {
      auto glyph_index = FT_Get_Char_Index(ft_face, codepoint);
      ENFORCE(!FT_Load_Glyph(ft_face, glyph_index, FT_LOAD_NO_HINTING));

      FT_Glyph glyph;
      ENFORCE(!FT_Get_Glyph(ft_face->glyph, &glyph));
      SCOPE_EXIT {FT_Done_Glyph(glyph);};

      if (border)
        ENFORCE(!FT_Glyph_StrokeBorder(&glyph, ft_stroker_, 0, 1));

      ENFORCE(!FT_Glyph_To_Bitmap(&glyph, FT_RENDER_MODE_NORMAL, NULL, 1));
      FT_BitmapGlyph bit_glyph = (FT_BitmapGlyph) glyph;
      FT_Bitmap& bitmap = bit_glyph->bitmap;

      VGImage image{};
      VGfloat glyph_origin[2]{};

      if (bitmap.width > 0 && bitmap.rows > 0) {
        constexpr VGfloat blur_stddev = 0.6;
        const int padding = static_cast<int>(3*blur_stddev + 0.5);
        const int image_width = bitmap.width + padding*2;
        const int image_height = bitmap.rows + padding*2;

        image = vgCreateImage(VG_A_8, image_width, image_height,
                              VG_IMAGE_QUALITY_NONANTIALIASED);
        assert(image);
        
        if (bitmap.pitch > 0) {
          vgImageSubData(image,
                         bitmap.buffer + bitmap.pitch*(bitmap.rows-1),
                         -bitmap.pitch,
                         VG_A_8,
                         padding,
                         padding,
                         bitmap.width,
                         bitmap.rows);
          assert(!vgGetError());
        } else {
          vgImageSubData(image,
                         bitmap.buffer,
                         bitmap.pitch,
                         VG_A_8,
                         padding,
                         padding,
                         bitmap.width,
                         bitmap.rows);
          assert(!vgGetError());
        }

        auto softened_image = vgCreateImage(VG_A_8,
                                            image_width,
                                            image_height,
                                            VG_IMAGE_QUALITY_NONANTIALIASED);
        assert(image);

        // Even out hard and soft edges
        vgGaussianBlur(softened_image, image, blur_stddev, blur_stddev, VG_TILE_FILL);
        assert(!vgGetError());

        vgDestroyImage(image);
        assert(!vgGetError());

        image = softened_image;

        glyph_origin[0] = static_cast<VGfloat>(padding - bit_glyph->left);
        glyph_origin[1] = static_cast<VGfloat>(padding + bitmap.rows - bit_glyph->top - 1);
      }

      escapement[0] = static_cast<VGfloat>((ft_face->glyph->advance.x + 32) / 64);
      escapement[1] = 0;

      vgSetGlyphToImage(vg_font, codepoint, image, glyph_origin, escapement);
      assert(!vgGetError());

      if (image) {
        vgDestroyImage(image);
        assert(!vgGetError());
      }
    } catch(...) {
      escapement[0] = 0;
      escapement[1] = 0;
      vgSetGlyphToImage(vg_font, codepoint, VG_INVALID_HANDLE, escapement, escapement);
      assert(!vgGetError());
    }
  };

  load_glyph_internal(ft_face_, vg_font_, false);
  glyphs_[codepoint].advance = escapement[0];
  load_glyph_internal(ft_face_, vg_font_border_, true);
}
Exemplo n.º 29
0
 std::ostream& getOutputStream()
 {
     ENFORCE(m_outputStream != nullptr, "Output stream not initialized!");
     return *m_outputStream;
 }
Exemplo n.º 30
0
 static Logger& instance()
 {
     ENFORCE(m_instance != nullptr, "Logger singleton instance is not valid!");
     return *m_instance;
 }