Пример #1
0
/* FIST-LITE special version of mmap */
static int unionfs_mmap(struct file *file, struct vm_area_struct *vma)
{
	int err = 0;
	struct file *hidden_file = NULL;
	int willwrite;

	print_entry_location();

	/* This might could be deferred to mmap's writepage. */
	willwrite = ((vma->vm_flags | VM_SHARED | VM_WRITE) == vma->vm_flags);
	if ((err = unionfs_file_revalidate(file, willwrite)))
		goto out;

	PASSERT(ftopd(file));
	hidden_file = ftohf(file);

	err = -ENODEV;
	if (!hidden_file->f_op || !hidden_file->f_op->mmap)
		goto out;

	PASSERT(hidden_file);
	PASSERT(hidden_file->f_op);
	PASSERT(hidden_file->f_op->mmap);

	vma->vm_file = hidden_file;
	err = hidden_file->f_op->mmap(hidden_file, vma);
	get_file(hidden_file);	/* make sure it doesn't get freed on us */
	fput(file);		/* no need to keep extra ref on ours */

      out:
	print_exit_status(err);
	return err;
}
Пример #2
0
ssize_t unionfs_read(struct file * file, char *buf, size_t count, loff_t * ppos)
{
	int err = -EINVAL;
	struct file *hidden_file = NULL;
	loff_t pos = *ppos;

	print_entry_location();

	if ((err = unionfs_file_revalidate(file, 0)))
		goto out;

	fist_print_file("entering read()", file);

	PASSERT(ftopd(file));
	hidden_file = ftohf(file);
	PASSERT(hidden_file);

	if (!hidden_file->f_op || !hidden_file->f_op->read)
		goto out;

	err = hidden_file->f_op->read(hidden_file, buf, count, &pos);
	*ppos = pos;
	if (err >= 0) {
		/* atime should also be updated for reads of size zero or more */
		fist_copy_attr_atime(file->f_dentry->d_inode,
				     hidden_file->f_dentry->d_inode);
	}
	memcpy(&(file->f_ra), &(hidden_file->f_ra),
	       sizeof(struct file_ra_state));

      out:
	fist_print_file("leaving read()", file);
	print_exit_status(err);
	return err;
}
PRenderTransform::PRenderTransform(PDrawable *drawable, PCamera *camera)
{
    PASSERT(drawable != P_NULL);
    PASSERT(camera != P_NULL);

    m_drawable = drawable;
    m_camera   = camera;
}
Пример #4
0
void PPropertyInt::setRange(const pint32 *range)
{
    PASSERT(range != P_NULL);
    PASSERT(range[0] < range[1]);

    m_range[0] = range[0];
    m_range[1] = range[1];

    operator=(m_value);
}
Пример #5
0
void PBackground::setSize(pfloat32 width, pfloat32 height)
{
    PASSERT(width > 0 && width <= 1.0f);
    PASSERT(height > 0 && height <= 1.0f);

    m_sizeInfo[0] = width;
    m_sizeInfo[1] = height;

    m_dirty = true;
}
Пример #6
0
void PPropertyInt::interpolate(pfloat32 t, PAbstractProperty *v1, PAbstractProperty *v2)
{
    PASSERT(t >= 0 && t <= 1);

    PASSERT(v1->type() == P_PROPERTY_INT);
    PASSERT(v2->type() == P_PROPERTY_INT);
    const PPropertyInt *v11 = (const PPropertyInt*)v1;
    const PPropertyInt *v22 = (const PPropertyInt*)v2;

    operator=((pint32)((pint32)v11->toInt() * (1.0f - t) + (pint32)v22->toInt() * t));
}
Пример #7
0
/* this unionfs_write() does not modify data pages! */
ssize_t unionfs_write(struct file * file, const char *buf, size_t count,
		      loff_t * ppos)
{
	int err = -EINVAL;
	struct file *hidden_file = NULL;
	struct inode *inode;
	struct inode *hidden_inode;
	loff_t pos = *ppos;
	int bstart, bend;

	print_entry_location();

	if ((err = unionfs_file_revalidate(file, 1)))
		goto out;

	inode = file->f_dentry->d_inode;

	bstart = fbstart(file);
	bend = fbend(file);

	ASSERT(bstart != -1);
	PASSERT(ftopd(file));
	PASSERT(ftohf(file));

	hidden_file = ftohf(file);
	hidden_inode = hidden_file->f_dentry->d_inode;

	if (!hidden_file->f_op || !hidden_file->f_op->write)
		goto out;

	/* adjust for append -- seek to the end of the file */
	if (file->f_flags & O_APPEND)
		pos = inode->i_size;

	err = hidden_file->f_op->write(hidden_file, buf, count, &pos);

	/*
	 * copy ctime and mtime from lower layer attributes
	 * atime is unchanged for both layers
	 */
	if (err >= 0)
		fist_copy_attr_times(inode, hidden_inode);

	*ppos = pos;

	/* update this inode's size */
	if (pos > inode->i_size)
		inode->i_size = pos;

      out:
	print_exit_status(err);
	return err;
}
void PGlTexture::copyTexture(PGlTextureFormatEnum format, 
        puint32 x, puint32 y, puint32 width, puint32 height, puint32 border)
{
    PASSERT(m_target == GL_TEXTURE_2D);
    PASSERT(m_enabled);

    puint32 internalFormat;
    puint32 dataFormat;
    interpretFormat(format, internalFormat, dataFormat);
    glCopyTexImage2D(GL_TEXTURE_2D, 0, internalFormat, x, y, width, height, border);

    pGlErrorCheckError();
}
Пример #9
0
pint32 P_APIENTRY pAssetRead(PAsset *asset, void *buffer, puint32 count)
{
    PASSERT(asset != P_NULL);
    if (asset != P_NULL)
    {
        PFile *fp = (PFile *)asset->pHandle;
        
        puint32 readLen = pfread(buffer, sizeof(puint8), count, fp);
        PASSERT(readLen == count);
        
        return readLen;
    }

    return 0;
}
Пример #10
0
void PPropertyColor::interpolate(pfloat32 t, PAbstractProperty *a, PAbstractProperty *b)
{
    PASSERT(t >= 0 && t <= 1);

    PASSERT(a->type() != P_PROPERTY_COLOR);
    PASSERT(b->type() != P_PROPERTY_COLOR);

    PPropertyColor *v1 = (PPropertyColor*)a;
    PPropertyColor *v2 = (PPropertyColor*)b;

    m_r.interpolate(t, &(v1->m_r), &(v2->m_r));
    m_g.interpolate(t, &(v1->m_g), &(v2->m_g));
    m_b.interpolate(t, &(v1->m_b), &(v2->m_b));
    m_a.interpolate(t, &(v1->m_a), &(v2->m_a));
}
Пример #11
0
void PGlState::setBlend(PGlStateEnum mode)
{
    if (m_blend == mode)
    {
        return ;
    }

    m_blend = mode;

    switch (mode)
    {
        case P_GLBLEND_OPAQUE:
            glDisable(GL_BLEND);
            break;
        case P_GLBLEND_ALPHA: 
            glEnable(GL_BLEND);
            glBlendEquationSeparate(GL_FUNC_ADD, GL_FUNC_ADD);
            glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
            break;
        case P_GLBLEND_DSTALPHA: 
            glEnable(GL_BLEND);
            glBlendEquationSeparate(GL_FUNC_ADD, GL_FUNC_ADD);
            glBlendFunc(GL_ONE_MINUS_DST_ALPHA, GL_DST_ALPHA);
            break;
        case P_GLBLEND_ADDITIVE:
            glEnable(GL_BLEND);
            glBlendEquationSeparate(GL_FUNC_ADD, GL_FUNC_ADD);
            glBlendFunc(GL_SRC_ALPHA, GL_ONE);
            break;
        default:
            PLOG_WARNINGX(P_LOG_CHANNEL_OPENGLEGL, "unknown blend mode");
            PASSERT(0);
            break;
    }
}
Пример #12
0
void PGlState::setViewport(puint32 x, puint32 y, puint32 width, puint32 height)
{
    // FIXME: We are still at 4K age.
    PASSERT(x < 4096 &&
            y < 4096 &&
            x + width <= 4096 &&
            y + height <= 4096);
    if (x >= 4096 || y >= 4096 || x + width > 4096 || y + height > 4096)
    {
        PLOG_ERRORX(P_LOG_CHANNEL_OPENGLEGL, "invalid viewport values: (%d, %d, %d, %d)", x, y, width, height);

        // FIXME: it is good to let application crash at OpenGL so we don't return here.
    }

    // Cache the viewport value.
    if (m_viewport[0] == x && m_viewport[1] == y && 
        m_viewport[2] == width && m_viewport[3] == height)  
    {
        return ;
    }

    m_viewport[0] = x;
    m_viewport[1] = y;
    m_viewport[2] = width;
    m_viewport[3] = height;

    glViewport(x, y, width, height);
}
Пример #13
0
MyScene::MyScene(PContext *context)
    : PScene("my-scene", context)
{
    if (!load("scene.psc"))
    {
        PASSERT(!"Failed to load scene.psc");
        return ;
    }
    
    // Create the skybox in a manual way.
    /*
    PResourceManager *resMgr = context->module<PResourceManager>("resource-manager");

    // -------------------------------------------------------------- 
    // Add camera
    // -------------------------------------------------------------- 
    const puint32 *rect = context->rect();

    PCamera *camera = PNEW(PCamera("camera", this));
    camera->setFixed(true);
    camera->transform().setLookAt(0.0f, 0.0f, 10.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);
    camera->projection().perspective(60.0f, 2.0f * (pfloat32)rect[2] / (pfloat32)rect[3], 0.1f, 100.0f);
    setMainCamera(camera);
    
    // -------------------------------------------------------------- 
    // Scene objects
    // -------------------------------------------------------------- 
    PSkyBox *skybox = PNEW(PSkyBox("skybox", this));
    skybox->setTexture(resMgr->getTexture("sky/*.tga"));
    */
}
Пример #14
0
static void DumpProfElems( void )
{
	track_p trk, trkN;
	EPINX_T ep, ep2;
	BOOL_T go;

	trk = pathStartTrk;
	ep = pathStartEp;

	if (pathStartTrk==NULL) lprintf( "s--:- e--:-" );
	else if (pathEndTrk == NULL) lprintf( "sT%d:%d e--:-", GetTrkIndex(pathStartTrk), pathStartEp );
	else lprintf( "sT%d:%d eT%d:%d", GetTrkIndex(pathStartTrk), pathStartEp, GetTrkIndex(pathEndTrk), pathEndEp );
	lprintf( " { " );
	go = TRUE;
	if (!PathListSingle())
	  while ( trk ) {
		if (trk==pathEndTrk) {
			ep2 = pathEndEp;
			go = FALSE;
		} else {
			ep2 = GetNextTrkOnPath( trk, ep );
			PASSERT( "computeProfElem", ep2 >= 0, NOP );
		}
		lprintf( "T%d:%d:%d ", GetTrkIndex(trk), ep, ep2 );
		if (!go)
			break;
		trkN = GetTrkEndTrk(trk,ep2);
		ep = GetEndPtConnectedToMe(trkN,trk);
		trk = trkN;
	}
	lprintf( "}" );
}
Пример #15
0
void pMain(int argc, char* argv[])
{
    PASSERT(PActivity::s_activity != P_NULL);

    if (PActivity::s_activity != P_NULL)
    {
        PContextProperties contextProperties;
        contextProperties.m_contextName = PString("background");
        contextProperties.m_archiveName = PString("background.par");
        contextProperties.m_windowWidth = 640;
        contextProperties.m_windowHeight = 480;
#if defined P_WIN32
        contextProperties.m_multisamples = 2;
#endif

        PContext* context = PNEW(MyContext(contextProperties));
		context->addModule(PNEW(PResourceManager(context)));
		context->addModule(PNEW(PSceneManager(context)));
		// More modules
        PActivity::s_activity->addContext(context);
    }
    else
    {
        PLOG_ERROR("No running activity");
    }
}
Пример #16
0
void mm_memory_init_file(mm_memory_t* mem)
{
  memset(mem->buf, 255, mem->size);
  PASSERT((mem->file = fopen(mem->fname, "wb+")),
          "Error while opening(wb) file %s", mem->fname);
  fwrite(mem->buf, sizeof(*mem->buf), mem->size, mem->file);
}
Пример #17
0
void PRenderer::render(PRenderState *renderState)
{
    PASSERT(m_scene->mainCamera() != P_NULL);

    // Create a default render pass if none exists
    if (m_renderPassArray.isEmpty())
    {
        PRenderPass *renderPass = PNEW(PRenderPass("default", m_scene));
        renderPass->setCamera(m_scene->mainCamera());
        renderPass->queue()->addNodes(m_scene->root());
        renderPass->target()->setColorClearValue(m_backgroundColor);

        PShadowPass *shadowPass = PNEW(PShadowPass("shadow", m_scene));
        
        addRenderPass(shadowPass);
        addRenderPass(renderPass);
    }

    if (m_renderPassArray.isEmpty())
    {
        PLOG_WARNING("There is no valid render pass existing.");
        return ;
    }

    for (puint32 i = 0; i < m_renderPassArray.size(); ++i)
    {
        m_renderPassArray[i]->render(renderState);
    }
}
Пример #18
0
static int unionfs_fsync(struct file *file, struct dentry *dentry, int datasync)
{
	int err;
	struct file *hidden_file = NULL;

	print_entry_location();

	if ((err = unionfs_file_revalidate(file, 1)))
		goto out;

	PASSERT(ftopd(file));
	hidden_file = ftohf(file);

	err = -EINVAL;
	if (!hidden_file->f_op || !hidden_file->f_op->fsync)
		goto out;

	down(&hidden_file->f_dentry->d_inode->i_sem);
	err = hidden_file->f_op->fsync(hidden_file, hidden_file->f_dentry,
				       datasync);
	up(&hidden_file->f_dentry->d_inode->i_sem);

      out:
	print_exit_status(err);
	return err;
}
Пример #19
0
void PTimer::update(pfloat32 deltaTime)
{
    PASSERT(m_manager != P_NULL);

    m_elapsedMillis += deltaTime;

    if (m_fireMillis < m_elapsedMillis)
    {
        m_repeatedTimes++;

        PEvent* event = createEvent(P_EVENT__TIMER_EXPIRED);
        event->setParameter(P_EVENTPARAMETER__TIMER_ID, m_id);
        event->setParameter(P_EVENTPARAMETER__TIMER_REPEAT_TIMES, m_repeatedTimes - 1);
        event->setParameter(P_EVENTPARAMETER__TIMER_ELAPSED_MILLIS, m_elapsedMillis);
        event->queue(reinterpret_cast<PObject *>(P_NULL));
        if (m_callback != P_NULL)
        {
            m_callback->onTimerOut(m_id, m_repeatedTimes, m_elapsedMillis);
        }

        if (m_repeatedTimes - 1 >= m_repeatCount)
        {
            kill();
        }
        else
        {
            m_fireMillis += m_repeatMillis;
        }
    }
}
Пример #20
0
pfloat32 * P_APIENTRY pMatrix4x4Multiply(const pfloat32 *a, const pfloat32 *b, pfloat32 *out)
{
    PASSERT(a != out && b != out);

#if defined P_USE_SSE
#elif defined P_USE_NEON
#else
    out[0] = a[0] * b[0] + a[4] * b[1] + a[8] * b[2] + a[12] * b[3]; 
    out[1] = a[1] * b[0] + a[5] * b[1] + a[9] * b[2] + a[13] * b[3]; 
    out[2] = a[2] * b[0] + a[6] * b[1] + a[10] * b[2] + a[14] * b[3]; 
    out[3] = a[3] * b[0] + a[7] * b[1] + a[11] * b[2] + a[15] * b[3]; 
    
    out[4] = a[0] * b[4] + a[4] * b[5] + a[8] * b[6] + a[12] * b[7]; 
    out[5] = a[1] * b[4] + a[5] * b[5] + a[9] * b[6] + a[13] * b[7]; 
    out[6] = a[2] * b[4] + a[6] * b[5] + a[10] * b[6] + a[14] * b[7]; 
    out[7] = a[3] * b[4] + a[7] * b[5] + a[11] * b[6] + a[15] * b[7]; 
    
    out[8]  = a[0] * b[8] + a[4] * b[9] + a[8] * b[10] + a[12] * b[11]; 
    out[9]  = a[1] * b[8] + a[5] * b[9] + a[9] * b[10] + a[13] * b[11]; 
    out[10] = a[2] * b[8] + a[6] * b[9] + a[10] * b[10] + a[14] * b[11]; 
    out[11] = a[3] * b[8] + a[7] * b[9] + a[11] * b[10] + a[15] * b[11]; 
    
    out[12] = a[0] * b[12] + a[4] * b[13] + a[8] * b[14] + a[12] * b[15]; 
    out[13] = a[1] * b[12] + a[5] * b[13] + a[9] * b[14] + a[13] * b[15]; 
    out[14] = a[2] * b[12] + a[6] * b[13] + a[10] * b[14] + a[14] * b[15]; 
    out[15] = a[3] * b[12] + a[7] * b[13] + a[11] * b[14] + a[15] * b[15]; 

#endif

    return out;
}
Пример #21
0
ns_epoll_t* ns_epoll_create(unsigned events_count)
{
  ns_epoll_t* epoll = malloc(sizeof(*epoll));
  PASSERT(epoll, NS_ERR_MALLOC);

  epoll->n = 0;
  epoll->events_count = events_count;
  epoll->events = calloc(epoll->events_count, sizeof(*epoll->events));
  PASSERT(epoll->events, NS_ERR_MALLOC);

  epoll->evs = calloc(epoll->events_count, sizeof(*epoll->evs));
  PASSERT(epoll->evs, NS_ERR_MALLOC);
  PASSERT(~(epoll->fd = epoll_create1(0)), "epoll_create1: ");

  return epoll;
}
Пример #22
0
PAbstractKeyframe::PAbstractKeyframe(pfloat32 time, PAnimationResource *animation)
{
    m_time = time;

    PASSERT(animation != P_NULL);
    m_animation = animation;
}
Пример #23
0
static void ComputeProfElem( void )
{
	track_p trk = pathStartTrk, trkN;
	EPINX_T ep = pathStartEp, ep2;
	BOOL_T go;
	DIST_T dist;
	BOOL_T defined;

	profElem_da.cnt = 0;
	station_da.cnt = 0;
	dist = 0;
	defined = TRUE;
	if (PathListEmpty())
		return;
	ChkElev( trk, ep, ep, dist, &defined );
	if (PathListSingle())
		return;
	go = TRUE;
	while ( go ) {
		if (trk == pathEndTrk) {
			go = FALSE;
			ep2 = pathEndEp;
		} else {
			ep2 = GetNextTrkOnPath( trk, ep );
			PASSERT( "computeProfElem", ep2 >= 0, NOP );
		}
		dist += GetTrkLength( trk, ep, ep2 );
		ChkElev( trk, ep2, ep, dist, &defined );
		if (!go)
			break;
		trkN = GetTrkEndTrk(trk,ep2);
		ep = GetEndPtConnectedToMe(trkN,trk);
		trk = trkN;
	}
}
Пример #24
0
mm_seglist_t* mm_seglist_create(unsigned size, mm_algorithms_e algorithm)
{
  mm_segment_t* hole_seg = mm_segment_create(0, size);
  mm_seglist_t* list = malloc(sizeof(*list));
  PASSERT(list, MM_ERR_MALLOC);

  list->size = size;
  list->processes = mm_dllist_create(NULL);
  list->holes = mm_dllist_create(NULL);

  mm_dllist_insert_after(list->holes, hole_seg);

  list->algorithm_type = algorithm;
  switch (algorithm) {
    case MM_ALG_FREE_FF:
      list->algorithm = &mm_freemem_ff;
      break;
    case MM_ALG_FREE_NF:
    case MM_ALG_FREE_QF:
      LOGERR("Unsupported algorithm");
      exit(EXIT_FAILURE);
      break;
  }

  return list;
}
Пример #25
0
fs_fat_t* fs_fat_create(size_t length)
{
  fs_fat_t* fat = malloc(sizeof(*fat));
  PASSERT(fat, FS_ERR_MALLOC);

  fat->length = length;
  fat->blocks = calloc(fat->length, sizeof(*fat->blocks));
  PASSERT(fat->blocks, FS_ERR_MALLOC);

  while (length-- > 0)
    fat->blocks[length] = length;

  fat->bmp = fs_bmp_create(fat->length);

  return fat;
}
Пример #26
0
void PGlTexture::disable()
{
    PASSERT(m_enabled);
    PASSERT(m_textureUnit != 0xffffffff);
    
    if (!m_enabled)
    {
        return ;
    }
    m_enabled = false;
    
    glActiveTexture(GL_TEXTURE0 + m_textureUnit);
    glBindTexture(m_target, 0);

    m_textureUnit = 0xffffffff;
}
void PMaterialParameter::operator=(PTexture *value)
{
    PASSERT(m_uniformType == P_GLSHADERUNIFORM_SAMPLERCUBE ||
            m_uniformType == P_GLSHADERUNIFORM_SAMPLER2D ||
            m_uniformType == P_GLSHADERUNIFORM_UNKNOWN);
    if (m_uniformType != P_GLSHADERUNIFORM_SAMPLERCUBE &&
        m_uniformType != P_GLSHADERUNIFORM_SAMPLER2D)
    {
        PLOG_WARNING("%s is not a texture parameter", m_name.c_str());
        return ;
    }
    if (m_value.t != value)
    {
        if (m_value.t != P_NULL)
        {
            m_value.t->release();
        }
        m_value.t = value;
        // Increase the reference count of texture object.
        if (m_value.t != P_NULL)
        {
            m_value.t->retain();
        }
    }
}
Пример #28
0
void PGlTexture::interpretFormat(PGlTextureFormatEnum format, 
    puint32 &internalFormat,
    puint32 &dataFormat)
{
    switch (format)
    {
        case P_GLTEXTURE_FORMAT_RGBA8888: 
            internalFormat = GL_RGBA;
            dataFormat = GL_RGBA;
            break;
        case P_GLTEXTURE_FORMAT_RGB888: 
            internalFormat = GL_RGB;
            dataFormat = GL_RGB;
            break;
        case P_GLTEXTURE_FORMAT_R8:
            internalFormat = GL_LUMINANCE;
            dataFormat = GL_LUMINANCE;
            break;
        case P_GLTEXTURE_FORMAT_RA88:
            internalFormat = GL_LUMINANCE_ALPHA;
            dataFormat = GL_LUMINANCE_ALPHA;
            break;
        default:
            PASSERT(!"Unsupported texture format");
            PLOG_ERRORX(P_LOG_CHANNEL_OPENGLEGL, "Unsupported texture format");
            break;
    }
}
Пример #29
0
void pMain(int argc, char* argv[])
{
    PASSERT(PActivity::s_activity != P_NULL);

    if (PActivity::s_activity != P_NULL)
    {
        PContextProperties contextProperties;
        contextProperties.m_contextName = PString("loadscene");
        contextProperties.m_archiveName = PString("loadscene.par");
#if defined P_WIN32
        contextProperties.m_windowWidth = 480;
        contextProperties.m_windowHeight = 800;
        contextProperties.m_multisamples = 2;
#elif defined P_ANDROID
		 contextProperties.m_windowWidth = 0xffffffff;
        contextProperties.m_windowHeight = 0xffffffff;
#endif

        PContext* context = PNEW(MyContext(contextProperties));
		context->addModule(PNEW(PResourceManager(context)));
		context->addModule(PNEW(PSceneManager(context)));
		// TODO: initialize more modules here.

        PActivity::s_activity->addContext(context);
    }
    else
    {
        PLOG_ERROR("No running activity");
    }
}
Пример #30
0
PMaterial::PMaterial(const pchar *id, const pchar *text, pbool autoRelease, PResourceManager *resourceManager)
    : PEntity()
{
    PASSERT(resourceManager != P_NULL);
    m_resource = resourceManager->createMaterial(text, id, autoRelease);
    m_resource->retain();

    // Clone the parameters
    puint32 numParameters = m_resource->numberOfMaterialParameters();
    for (puint32 i = 0; i < numParameters; ++i)
    {
        PMaterialParameter *parameter = PNEW(PMaterialParameter(*m_resource->materialParameter(i)));
        // The uniform location of parameter in material instance is the index of the parameter in 
        // the material resource.
        parameter->setUniformLocation((pint32)i);
        m_materialParameters.append(parameter);
    }

    m_isTransparent = false;
  
    if (s_phonyMaterialParameter == P_NULL)
    {
        s_phonyMaterialParameter = PNEW(PMaterialParameter("phony", "Phony", P_GLSHADERUNIFORM_UNKNOWN, 1));
    }
}