Esempio n. 1
0
int scan_device()
{
  ocl_device_init();

  static char vendor_name[STRING_RETURN_SIZE];
  status = clGetDeviceInfo (device, CL_DEVICE_VENDOR, STRING_RETURN_SIZE, vendor_name, NULL);
  if(status != CL_SUCCESS) dump_error("Failed clGetDeviceInfo(CL_DEVICE_VENDOR)", status);
  printf ("Board vendor name: %s\n", vendor_name);

  // get all supported board names from MMD
  static char board_name[STRING_RETURN_SIZE];
  status = clGetDeviceInfo (device, CL_DEVICE_NAME, STRING_RETURN_SIZE, board_name, NULL);
  if(status != CL_SUCCESS) dump_error("Failed clGetDeviceInfo(CL_DEVICE_NAME)", status);
  printf ("Board name: %s\n\n", board_name);
  

  char *shared_buf1 = (char*)malloc(SHARED_BUFFER_SIZE * sizeof(char));
  char *shared_buf2 = (char*)malloc(SHARED_BUFFER_SIZE * sizeof(char));
  if (shared_buf1 == NULL || shared_buf2 == NULL) {
    dump_error("Failed to allocate two buffers with malloc", 0);
  }
  
  int i;
  for (i = 0; i < SHARED_BUFFER_SIZE; i++) {
    shared_buf1[i] = i;
    shared_buf2[i] = -1;
  }
  
  cl_mem in1 = clCreateBuffer (context, CL_MEM_READ_WRITE, SHARED_BUFFER_SIZE, NULL, &status);
  if(status != CL_SUCCESS) dump_error("Failed clCreateBuffer for in1", status);
  
  status = clEnqueueWriteBuffer (queue, in1, CL_TRUE, 0, SHARED_BUFFER_SIZE, shared_buf1, 0, NULL, NULL);
  if (status != CL_SUCCESS) dump_error("Could not launch clEnqueueWriteBuffer!", status);
  
  status = clEnqueueReadBuffer (queue, in1, CL_TRUE, 0, SHARED_BUFFER_SIZE, shared_buf2, 0, NULL, NULL);
  if (status != CL_SUCCESS) dump_error("Could not launch clEnqueueWriteBuffer!", status);
  
  for (i = 0; i < SHARED_BUFFER_SIZE; i++) {
    if (shared_buf1[i] != shared_buf2[i] ) {
      printf("\nBuffer comparison failed!\n");
      printf ("#%d: %d vs %d\n", i, shared_buf1[i], shared_buf2[i]);
      freeResources();
      return -1;
    }
  }
  printf ("Buffer read/write test passed.\n");

  free (shared_buf1);
  free (shared_buf2);
  clReleaseMemObject (in1);
  freeResources();
  return 0;
}
Esempio n. 2
0
void TrainTask::returnUnit(Unit unit)
{
	if(mProductionBuilding == unit)
	{
		freeResources();
		mProductionBuilding = StaticUnits::nullunit;
	}
	else if(mProducedUnit == unit)
	{
		freeResources();
		mProducedUnit = StaticUnits::nullunit;
	}
	else
		assert(false);
}
/*
 *  ======== freeAlgResources ========
 */
static Bool freeAlgResources(BUFALG_TI_Handle alg, IRES_Fxns *fxns,
        Int scratchId)
{
    IRES_ResourceDescriptor desc[MAXDESCS];
    IALG_Handle             h = (IALG_Handle)alg;
    Int                     numRes;
    Int                     status;

    numRes = (fxns->numResourceDescriptors)(h);
    if (numRes > MAXDESCS) {
        System_printf("Too many resources: %d\n", numRes);
        return (FALSE);
    }

    System_printf("Number of resources: %d\n", numRes);

    status = (fxns->getResourceDescriptors)(h, desc);

    if (status != IRES_OK) {
        System_printf("Failed to get resource descriptors\n");
        return (FALSE);
    }

    freeResources(h, desc, numRes, scratchId);

    return (TRUE);
}
Esempio n. 4
0
DesktopWindowLinux::DesktopWindowLinux(DesktopWindowClient* client, int width, int height)
    : DesktopWindow(client, width, height)
    , m_eventSource(0)
    , m_display(0)
    , m_window(0)
    , m_im(0)
    , m_ic(0)
    , m_cursor(0)
    , m_currentX11Cursor(XC_left_ptr)
    , m_lastClickTime(0)
    , m_lastClickX(0)
    , m_lastClickY(0)
    , m_lastClickButton(kWKEventMouseButtonNoButton)
    , m_clickCount(0)
{
    try {
        setup();
    } catch(const FatalError&) {
        freeResources();
        throw;
    }

    m_eventSource = new XlibEventSource(m_display, this);

    makeCurrent();
    glEnable(GL_DEPTH_TEST);
}
Esempio n. 5
0
MediaImpl::~MediaImpl()
{
  freeResources();
  /* _data points to gstreamer-allocated data, we don't manage it ourselves */
  //if (_data)
  //  free(_data);
}
Esempio n. 6
0
Xsltproc::ReturnValue Xsltproc::execute()
{
    Xsltproc::ReturnValue retval = Xsltproc::Success;
    try
    {
        if( freopen(mErrorFilename.toUtf8().data(),"w",stderr) == NULL ) throw Xsltproc::GenericFailure;

        mStylesheet = xsltParseStylesheetFile( (const xmlChar*)mStyleSheetFilename.toUtf8().data() );
        if(mStylesheet == 0) throw Xsltproc::InvalidStylesheet;

        mXml = xmlParseFile( (const char*)mXmlFilename.toUtf8().data() );
        if(mXml == 0) throw Xsltproc::InvalidXmlFile;

        mOutput = xsltApplyStylesheet(mStylesheet, mXml, (const char**)mParams);
        if(mOutput == 0) throw Xsltproc::GenericFailure;

        FILE *foutput = 0;
        foutput = fopen(mOutputFilename.toUtf8().data(),"w");
        if( foutput == 0 ) throw Xsltproc::CouldNotOpenOutput;
        xsltSaveResultToFile(foutput, mOutput, mStylesheet);
        fclose(foutput);
    }
    catch(Xsltproc::ReturnValue e)
    {
        retval = e;
    }

    fclose(stderr);

    freeResources();

    return retval;
}
Esempio n. 7
0
 void TreeBuilder::initialiseParse(const StringRef& input, const StringRef& baseUri, ParseErrorList* errors, Allocator* allocator) {
     freeResources();
     
     CSOUP_ASSERT(input.size() > 0 && input.data() != NULL);
     CSOUP_ASSERT(baseUri.size() > 0 && baseUri.data() != NULL);
     
     // Don't destroy this
     errors_ = errors;
     
     if (allocator == NULL) {
         // if invoked didn't give an allocator, you should pass NULL to Document's construtor
         // and update allocator.
         // User can destroy the document using delete expression. And this should be the usual case.
         doc_ = new Document(baseUri, allocator);
         allocator = doc_->allocator();
     } else {
         // when user specify the allocator, you should initialize memory for Document from it.
         // User must invoke free of allocator in order to destroy Document.
         // User shouldn't use this style except the some extreme cases.
         doc_ = new (allocator->malloc_t<Document>()) Document(baseUri, allocator);
     }
     
     reader_ = new (allocator->malloc_t<CharacterReader>()) CharacterReader(input);
     tokeniser_ = new (allocator->malloc_t<Tokeniser>()) Tokeniser(reader_, errors, allocator);
     stack_ = new (allocator->malloc_t< internal::Vector<Element*> >()) internal::Vector<Element*>(4, allocator);
     baseUri_ = new (allocator->malloc_t< String>()) String(baseUri, allocator);
     allocator_ = allocator;
     currentToken_ = NULL;
 }
Esempio n. 8
0
ExVPJoinTcb::~ExVPJoinTcb()
{
  delete qParent_.up;
  delete qParent_.down;

  freeResources();
}
Esempio n. 9
0
ExIarTcb::~ExIarTcb()
{
   delete qparent_.up;
   delete qparent_.down;

   freeResources();
};
ExFastExtractTcb::~ExFastExtractTcb()
{
  // Release resources acquired
  //
  freeResources();

  delete qParent_.up;
  delete qParent_.down;
 
  if (workAtp_)
  {
    workAtp_->release();
    deallocateAtp(workAtp_, getSpace());
  }

  if (inSqlBuffer_ && getHeap())
  {
    getHeap()->deallocateMemory(inSqlBuffer_);
    inSqlBuffer_ = NULL;
    childOutputTD_ = NULL;
  }
  if (sourceFieldsConvIndex_)
    getHeap()->deallocateMemory(sourceFieldsConvIndex_);

} // ExFastExtractTcb::~ExFastExtractTcb()
ExExeUtilTcb::~ExExeUtilTcb()
{
  delete qparent_.up;
  delete qparent_.down;
  if (workAtp_)
    {
      workAtp_->release();
      deallocateAtp(workAtp_, getGlobals()->getSpace());
      workAtp_ = NULL;
    }
  freeResources();

  if (extractedPartsObj_)
    {
      delete extractedPartsObj_;
      extractedPartsObj_ = NULL;
    }
  if (explQuery_)
    NADELETEBASIC(explQuery_, getHeap());
  if (childQueryId_ != NULL)
  {
    NADELETEBASIC(childQueryId_, getHeap());
    childQueryId_ = NULL;
    childQueryIdLen_ = 0;
  }
  if (outputBuf_ != NULL)
  {
    NADELETEBASIC(outputBuf_, getHeap());
    outputBuf_ = NULL;
    outputBuf_ = 0;
  }

};
Esempio n. 12
0
void ConstructionTask::giveUnit(Unit unit)
{
	if(unit->getType() == mType.whatBuilds().first)
	{
		LOGMESSAGE(String_Builder() << "ConstructionTask : " << mType.getName() << " : Given Builder");
		assert(!mBuilder);
		mBuilder = unit;
		reserveResources();
	}
	else if(unit == mReservedLocation->getUnitPrediction() || unit->getTilePosition() == mReservedLocation->getTilePosition())
	{
		LOGMESSAGE(String_Builder() << "ConstructionTask : " << mType.getName() << " : Given Produced Unit");

		assert(!mProducedUnit || !mProducedUnit->exists());

		mProducedUnit = unit;
		if(mProducedUnit->exists())
		{
			freeResources();
			freeLocation();
		}
	}
	else
		assert(false);
}
Esempio n. 13
0
void ConstructionTask::returnUnit(Unit unit)
{
	if(unit == mBuilder)
	{
		LOGMESSAGE(String_Builder() << "ConstructionTask : " << mType.getName() << " : Returning Builder");
		freeResources();
		mBuilder = StaticUnits::nullunit;
	}
	else if(unit == mProducedUnit)
	{
		LOGMESSAGE(String_Builder() << "ConstructionTask : " << mType.getName() << " : Returning Produced Unit");
		freeResources();
		mProducedUnit = StaticUnits::nullunit;
	}
	else
		assert(!unit->exists());//If it doesn't exist it was a prediction that has been replaced
}
Esempio n. 14
0
X11Grabber::~X11Grabber()
{
	if (_x11Display != nullptr)
	{
		freeResources();
		XCloseDisplay(_x11Display);
	}
}
Esempio n. 15
0
MediaImpl::~MediaImpl()
{
    // Free all resources.
    freeResources();

    // Free mutex locker object.
    delete _mutexLocker;
}
Esempio n. 16
0
int main( int argc, char** argv )
{
	srand (time(NULL));
	init_platform();
	run();
	freeResources();
	return 0;
}
SharedMemoryBlock::~SharedMemoryBlock() {
	// Destructor sin lanzamiento de excepciones
	try {
		freeResources();
	}
	catch(const SharedMemoryException &e) {
	}
}
Esempio n. 18
0
void GL3LightingManager::resizeFramebuffer(uint32_t width, uint32_t height) {
    // First check if the new size is actually bigger than the old
    if (width <= _framebufferSize.x && height <= _framebufferSize.y) {
        return; // Framebuffer is big enough, no need to change the size
    }

    freeResources();

    createFrameBuffer(width, height);
}
Esempio n. 19
0
void ParticleSystem::slotSetParticleRadius(float radius)
{
    qDebug() << "ParticleSystem::slotSetParticleRadius(): setting particle radius from" << mParametersSimulation->particleRadius << "to" << radius;
    mParametersSimulation->particleRadius = radius;

    // Need to rebuild data-structures when particle radius or -count changes.
    if(mIsInitialized) freeResources();

    //slotInitialize(); will happen lazily on update
}
Esempio n. 20
0
Shader::Shader(const std::string& vertShader, const std::string& fragShader)
{
    auto vertSrc = getShaderSource(vertShader);
    auto fragSrc = getShaderSource(fragShader);

    createVertexShader(vertSrc);
    createFragmentShader(fragSrc);
    createProgram();
    freeResources();
}
Esempio n. 21
0
int X11Grabber::updateScreenDimensions()
{
	const Status status = XGetWindowAttributes(_x11Display, _window, &_windowAttr);
	if (status == 0)
	{
		Error(_log, "Failed to obtain window attributes");
		return -1;
	}

	if (_screenWidth == unsigned(_windowAttr.width) && _screenHeight == unsigned(_windowAttr.height))
	{
		// No update required
		return 0;
	}

	if (_screenWidth || _screenHeight)
	{
		freeResources();
	}

	Info(_log, "Update of screen resolution: [%dx%d]  to [%dx%d]", _screenWidth, _screenHeight, _windowAttr.width, _windowAttr.height);
	_screenWidth  = _windowAttr.width;
	_screenHeight = _windowAttr.height;
	
	// Image scaling is performed by XRender when available, otherwise by ImageResampler
	if (_XRenderAvailable && !_useXGetImage)
	{
		_croppedWidth  =  (_screenWidth > unsigned(_cropLeft + _cropRight))
			? ((_screenWidth - _cropLeft - _cropRight) / _horizontalDecimation)
			: _screenWidth / _horizontalDecimation;
		
		_croppedHeight =  (_screenHeight > unsigned(_cropTop + _cropBottom))
			? ((_screenHeight - _cropTop - _cropBottom) / _verticalDecimation)
			: _screenHeight / _verticalDecimation;
			
		Info(_log, "Using XRender for grabbing");
	}
	else
	{
		_croppedWidth  =  (_screenWidth > unsigned(_cropLeft + _cropRight))
			? (_screenWidth - _cropLeft - _cropRight)
			: _screenWidth;
		
		_croppedHeight =  (_screenHeight > unsigned(_cropTop + _cropBottom))
			? (_screenHeight - _cropTop - _cropBottom)
			: _screenHeight;
			
		Info(_log, "Using XGetImage for grabbing");
	}

	_image.resize(_croppedWidth, _croppedHeight);
	setupResources();

	return 1;
}
void UVAnimParticleQuadSystem::setTextureWithRectForAnimation(Texture2D *texture, const Rect& rect, 
	int tileWidth, int tileHeight, int number_Frames_per_Second, bool NeedsToRemoveParticleAfterAniamtion) {
    m_nItemWidth = tileWidth;
    m_nItemHeight = tileHeight;
    m_bNeedsToRemoveParticleAfterAniamtion = NeedsToRemoveParticleAfterAniamtion;

	if (texture && tileWidth > 0 && tileHeight > 0 && number_Frames_per_Second > 0) {
	    const Size& s = texture->getContentSizeInPixels();
		m_nItemsPerColumn = (int)(s.height / m_nItemHeight);
		m_nItemsPerRow = (int)(s.width / m_nItemWidth);
		m_nFrameCount = m_nItemsPerRow * m_nItemsPerColumn;
        m_fFrameRate = 1.f / number_Frames_per_Second;
		
	    const float inv_wide = 1.f/texture->getPixelsWide();
        const float inv_high = 1.f/texture->getPixelsHigh();

		freeResources();

		const int UVCount = (m_nItemsPerColumn+1) * (m_nItemsPerRow+1);
		m_pTexCoords = new Tex2F[UVCount];
		Tex2F *texPtr = m_pTexCoords;
		// Important. Texture in cocos2d are inverted, so the Y component should be inverted
		for (int j = 0; j <= m_nItemsPerColumn; ++j) {
			const float y = (rect.origin.y + m_nItemHeight*j)*inv_high;
			for (int i = 0; i <= m_nItemsPerRow; ++i) {
				texPtr->u = (rect.origin.x + m_nItemWidth*i)*inv_wide;
				texPtr->v = y;
				++texPtr;
			}
		}

		m_pUVRects = new UVRect[m_nFrameCount];
		UVRect *rectPtr = m_pUVRects;
		for (int j = 0; j < m_nItemsPerColumn; ++j) {
			Tex2F *texPtr = m_pTexCoords + j * (m_nItemsPerRow+1);
			for (int i = 0; i < m_nItemsPerRow; ++i) {
				Tex2F *ptr = texPtr + i;
				rectPtr->tl = ptr;
				rectPtr->tr = ptr + 1;
				rectPtr->bl = ptr + m_nItemsPerRow + 1;
				rectPtr->br = ptr + m_nItemsPerRow + 2;
				//CCLOG("%f,%f;%f,%f;%f,%f;%f,%f;",  \
					rectPtr->tl->u,rectPtr->tl->v, \
					rectPtr->tr->u,rectPtr->tr->v, \
					rectPtr->bl->u,rectPtr->bl->v, \
					rectPtr->br->u,rectPtr->br->v);
				++rectPtr;
			}
		}

		ParticleSystemQuad::setTextureWithRect(texture, Rect(rect.origin.x, rect.origin.y, tileWidth, tileHeight));
	} else {
Esempio n. 23
0
void Text::regenerate()
{
    if (!doc)
    {
        doc = DocumentCache::getInstance().pop();
        dirty = true;
    }

    if (dirty)
    {
        doc->setDefaultFont(defFont);

        if (elide)
        {
            QFontMetrics metrics = QFontMetrics(defFont);
            QString elidedText = metrics.elidedText(text, Qt::ElideRight, qRound(width));

            doc->setPlainText(elidedText);
        }
        else
        {
            doc->setDefaultStyleSheet(defStyleSheet);
            doc->setHtml(text);
        }

        // wrap mode
        QTextOption opt;
        opt.setWrapMode(elide ? QTextOption::NoWrap : QTextOption::WrapAtWordBoundaryOrAnywhere);
        doc->setDefaultTextOption(opt);

        // width
        doc->setTextWidth(width);
        doc->documentLayout()->update();

        // update ascent
        if (doc->firstBlock().layout()->lineCount() > 0)
            ascent = doc->firstBlock().layout()->lineAt(0).ascent();

        // let the scene know about our change in size
        if (size != idealSize())
            prepareGeometryChange();

        // get the new width and height
        size = idealSize();

        dirty = false;
    }

    // if we are not visible -> free mem
    if (!keepInMemory)
        freeResources();
}
Esempio n. 24
0
StaticMapLayer::StaticMapLayer(const QVector<QVector<StaticMapObject*>> & staticObjects) :
    staticObjects(staticObjects)
{
    try
    {
        checkArguments(staticObjects);
    }
    catch(...)
    {
        freeResources();
        throw;
    }
}
Esempio n. 25
0
void MediaImpl::unloadMovie()
{
    // Reset variables.
    _terminate = false;
    _seekEnabled = false;

    // Un-ready.
    _setMovieReady(false);
    setPlayState(false);

    // Free allocated resources.
    freeResources();
}
// Destructor
//
//
ExSequenceTcb::~ExSequenceTcb()
{
  if(qparent_.up) delete qparent_.up;
  qparent_.up = NULL;

  if(qparent_.down) delete qparent_.down;
  qparent_.down = NULL;

  if(pool_) delete pool_;
  pool_ = NULL;

  freeResources();
}
Esempio n. 27
0
bool ConstructionTask::preUpdate()
{
	if(mProducedUnit)
	{
		if(mProducedUnit->exists())
		{
			freeResources();
			freeLocation();
		}

		if(!isStopped() && !isCanceled() && mProducedUnit->isCompleted())
		{
			complete();
			return true;
		}
	}

	if(mReservedLocation)
	{
		if(hasEnded())
			freeLocation();
		else if(isPaused() || isStopped())
		{
			freeResources();

			mRequiredSatisfyTime = Requirement::maxTime;
			mRequiredDelayTime = Requirement::maxTime;
			mReservedLocation->setStartTime(Requirement::maxTime);
		}
	}

	if(!shouldReturnUnit())
		updateRequirements();

	if(mBuilder && finishedWithBuilder() && (mType.getRace() == BWAPI::Races::Protoss || !mBuilder->isConstructing()))
		return true;

	return false;
}
Esempio n. 28
0
void TrainTask::giveUnit(Unit unit)
{
	if(unit->getType() == mType.whatBuilds().first)
	{
		reserveResources();
		mProductionBuilding = unit;
	}
	else
	{
		freeResources();
		mProducedUnit = unit;
	}
}
//------------------------------------------------------------------------------------------------
// Name:  stateConnect
// Desc:  
//------------------------------------------------------------------------------------------------
void VolucrisClient::stateLostD3DDevice()
{
    // Get rid of everything
    global_actor_manager_.onLostDevice();
    global_rendering_manager_.resetCurrentTexture();
    freeResources();
    mySceneryRenderer.destroy();
    global_map_manager_.clearCache();
    global_sound_manager_.destroy();

    // Wait for a connection reply from the server
    HRESULT hr;
    while(D3DERR_DEVICELOST == (hr = myD3DDevice->TestCooperativeLevel()))
    {
        if (!windowsMessagePump())
        {
            myStateMachine.jumpState(VCS_SHUTDOWN);
            return;
        }

        // Poll the connection to keep it alive.  Watch for disconnection.
        ENetEvent netEvent;
        while(enet_host_service(myENetClient, &netEvent, 0) > 0) {
            if (netEvent.type == ENET_EVENT_TYPE_DISCONNECT) {
                myStateMachine.jumpState(VCS_SHUTDOWN);
                return;
            }
            // Free packet memory
            if (netEvent.packet) enet_packet_destroy(netEvent.packet);
        }

        // Don't overload the program
        Sleep(200);
    }

    CONFIRM(hr == D3DERR_DEVICENOTRESET && SUCCEEDED(myD3DDevice->Reset(&myD3DParams))) else {
        myStateMachine.jumpState(VCS_SHUTDOWN);
        return;
    }

    // Reset everything
    if (APP_FATAL(!acquireResources())("The game couldn't load its resource file")) {
        myStateMachine.jumpState(VCS_DISCONNECT);
        myStateMachine.jumpState(VCS_SHUTDOWN);
        return;
    }

    mySceneryRenderer.create(myD3DDevice, myUsingSoftwareDeviceFlag);
    global_sound_manager_.create(myMainWindow);
}
Esempio n. 30
0
bool ConstructionTask::morph(Unit unit, BWAPI::UnitType previousType)
{
	if(unit == mBuilder && unit->getType() == mType)
	{
		freeLocation();
		freeResources();

		mProducedUnit = unit;
		mBuilder = StaticUnits::nullunit;

		return false;
	}

	return true;
}