ShaderPtr CShaderManager::_LoadShader(SHADER_TYPE eType, xst_castring& strFileName, xst_castring& strShaderName, xst_castring& strEntryPoint, SHADER_PROFILE eProfile, xst_castring& strGroupName)
	{
		this->m_eShaderType = eType;
		this->m_strEntryPoint = strEntryPoint;
		this->m_eShaderProfile = eProfile;

		ResourcePtr pRes = this->LoadResource( strShaderName, strGroupName, strFileName, strGroupName );
		if( pRes.IsNull() )
		{
			return ShaderPtr();
		}

		//ShaderPtr pShader( pRes );
		//pShader->m_eShaderType = eType;
		
		/*if( XST_FAILED( this->AddResource( strShaderName, pShader, strGroupName ) ) )
		{
			this->DestroyResource( pShader );
			return ShaderPtr();
		}*/

		this->m_eShaderType = ( SHADER_TYPE )0;
		this->m_strEntryPoint.clear();
		this->m_eShaderProfile = ( SHADER_PROFILE )0;
		return pRes;
	}
void ResourceManager::load(const ResourceGroup& group)
{
    List<ResourcePtr> resources = group.resources();
    List<ResourcePtr>::iterator it = resources.begin();
    List<ResourcePtr>::const_iterator end = resources.end();

    for (; it != end; ++it)
    {
        ResourcePtr resource;
        Url url = resource->url();
        String filename = url.filename();

        if (!m_cache.exists(filename))
        {
            // TODO load in a thread
            m_cache.add(filename, resource);
        }

        else {
            resource = m_cache.get(filename);
        }

    }

    // TODO input->injectEvent...
}
TEST_F(MemoryCacheTest, LiveResourceEvictionAtEndOfTask_MultipleResourceMaps)
{
    {
        Resource* cachedDeadResource =
            new Resource(ResourceRequest("hhtp://foo"), Resource::Raw);
        cachedDeadResource->setCacheIdentifier("foo");
        ResourcePtr<Resource> cachedLiveResource =
            new FakeDecodedResource(ResourceRequest("http://test/resource"), Resource::Raw);
        TestLiveResourceEvictionAtEndOfTask(cachedDeadResource, cachedLiveResource);
        memoryCache()->evictResources();
    }
    {
        Resource* cachedDeadResource =
            new Resource(ResourceRequest("hhtp://foo"), Resource::Raw);
        ResourcePtr<Resource> cachedLiveResource =
            new FakeDecodedResource(ResourceRequest("http://test/resource"), Resource::Raw);
        cachedLiveResource->setCacheIdentifier("foo");
        TestLiveResourceEvictionAtEndOfTask(cachedDeadResource, cachedLiveResource);
        memoryCache()->evictResources();
    }
    {
        Resource* cachedDeadResource =
            new Resource(ResourceRequest("hhtp://test/resource"), Resource::Raw);
        cachedDeadResource->setCacheIdentifier("foo");
        ResourcePtr<Resource> cachedLiveResource =
            new FakeDecodedResource(ResourceRequest("http://test/resource"), Resource::Raw);
        cachedLiveResource->setCacheIdentifier("bar");
        TestLiveResourceEvictionAtEndOfTask(cachedDeadResource, cachedLiveResource);
        memoryCache()->evictResources();
    }
}
void surf_presolve(void)
{
  double next_event_date = -1.0;
  tmgr_trace_event_t event = NULL;
  double value = -1.0;
  ResourcePtr resource = NULL;
  ModelPtr model = NULL;
  unsigned int iter;

  XBT_DEBUG
      ("First Run! Let's \"purge\" events and put models in the right state");
  while ((next_event_date = tmgr_history_next_date(history)) != -1.0) {
    if (next_event_date > NOW)
      break;
    while ((event =
            tmgr_history_get_next_event_leq(history, next_event_date,
                                            &value,
                                            (void **) &resource))) {
      if (value >= 0){
        resource->updateState(event, value, NOW);
      }
    }
  }
  xbt_dynar_foreach(model_list, iter, model)
      model->updateActionsState(NOW, 0.0);
}
Exemple #5
0
ResourcePtr<Resource> ResourceFetcher::createResourceForRevalidation(const FetchRequest& request, Resource* resource)
{
    ASSERT(resource);
    ASSERT(memoryCache()->contains(resource));
    ASSERT(resource->isLoaded());
    ASSERT(resource->canUseCacheValidator());
    ASSERT(!resource->resourceToRevalidate());

    ResourceRequest revalidatingRequest(resource->resourceRequest());
    revalidatingRequest.clearHTTPReferrer();
    addAdditionalRequestHeaders(revalidatingRequest, resource->type());

    const AtomicString& lastModified = resource->response().httpHeaderField("Last-Modified");
    const AtomicString& eTag = resource->response().httpHeaderField("ETag");
    if (!lastModified.isEmpty() || !eTag.isEmpty()) {
        ASSERT(context().cachePolicy(document()) != CachePolicyReload);
        if (context().cachePolicy(document()) == CachePolicyRevalidate)
            revalidatingRequest.setHTTPHeaderField("Cache-Control", "max-age=0");
    }
    if (!lastModified.isEmpty())
        revalidatingRequest.setHTTPHeaderField("If-Modified-Since", lastModified);
    if (!eTag.isEmpty())
        revalidatingRequest.setHTTPHeaderField("If-None-Match", eTag);

    ResourcePtr<Resource> newResource = createResource(resource->type(), revalidatingRequest, resource->encoding());
    WTF_LOG(ResourceLoading, "Resource %p created to revalidate %p", newResource.get(), resource);

    newResource->setResourceToRevalidate(resource);

    memoryCache()->remove(resource);
    memoryCache()->add(newResource.get());
    return newResource;
}
// Verifies that dead resources that exceed dead resource capacity are evicted
// from cache when pruning.
TEST_F(MemoryCacheTest, DeadResourceEviction)
{
    const unsigned totalCapacity = 1000000;
    const unsigned minDeadCapacity = 0;
    const unsigned maxDeadCapacity = 0;
    memoryCache()->setCapacities(minDeadCapacity, maxDeadCapacity, totalCapacity);

    ResourcePtr<Resource> cachedResource =
        new Resource(ResourceRequest(""), Resource::Raw);
    const char data[5] = "abcd";
    cachedResource->appendData(data, 3);
    // The resource size has to be nonzero for this test to be meaningful, but
    // we do not rely on it having any particular value.
    ASSERT_GT(cachedResource->size(), 0u);

    ASSERT_EQ(0u, memoryCache()->deadSize());
    ASSERT_EQ(0u, memoryCache()->liveSize());

    memoryCache()->add(cachedResource.get());
    ASSERT_EQ(cachedResource->size(), memoryCache()->deadSize());
    ASSERT_EQ(0u, memoryCache()->liveSize());

    memoryCache()->prune();
    ASSERT_EQ(0u, memoryCache()->deadSize());
    ASSERT_EQ(0u, memoryCache()->liveSize());
}
TEST_F(CachingCorrectnessTest, FreshWithStaleRedirect)
{
    KURL redirectUrl(ParsedURLString, kResourceURL);
    const char redirectTargetUrlString[] = "http://redirect-target.com";
    KURL redirectTargetUrl(ParsedURLString, redirectTargetUrlString);

    ResourcePtr<Resource> firstResource = new Resource(ResourceRequest(redirectUrl), Resource::Raw);

    ResourceResponse stale301Response;
    stale301Response.setURL(redirectUrl);
    stale301Response.setHTTPStatusCode(301);
    stale301Response.setHTTPHeaderField("Date", kOriginalRequestDateAsString);
    stale301Response.setHTTPHeaderField("Location", redirectTargetUrlString);

    // Add the redirect to our request.
    ResourceRequest redirectRequest = ResourceRequest(redirectTargetUrl);
    firstResource->willFollowRedirect(redirectRequest, stale301Response);

    // Add the final response to our request.
    ResourceResponse fresh200Response;
    fresh200Response.setURL(redirectTargetUrl);
    fresh200Response.setHTTPStatusCode(200);
    fresh200Response.setHTTPHeaderField("Date", kOriginalRequestDateAsString);
    fresh200Response.setHTTPHeaderField("Expires", kOneDayAfterOriginalRequest);

    firstResource->setResponse(fresh200Response);
    memoryCache()->add(firstResource.get());

    advanceClock(500.);

    ResourcePtr<Resource> fetched = fetch();
    EXPECT_NE(firstResource, fetched);
}
Exemple #8
0
Statement::Statement(ResourcePtr subject, PropertyPtr predicate,
                        NodePtr object) : d(new StatementPrivate)
{
    d->model = subject->model().d;
    d->subjectID = subject->id();
    d->predicateID = predicate->id();
    d->objectID = object->id();
}
    //-----------------------------------------------------------------------
    ResourcePtr ResourceManager::load(const String& name, 
        const String& group, bool isManual, ManualResourceLoader* loader, 
        const NameValuePairList* loadParams, bool backgroundThread)
    {
        ResourcePtr r = createOrRetrieve(name,group,isManual,loader,loadParams).first;
		// ensure loaded
        r->load(backgroundThread);
        return r;
    }
	//-----------------------------------------------------------------------
	void ResourceManager::remove(ResourceHandle handle)
	{
		ResourcePtr res = getByHandle(handle);

		if (!res.isNull())
		{
			removeImpl(res);
		}
	}
	//-----------------------------------------------------------------------
	void ResourceManager::remove(const String& name)
	{
		ResourcePtr res = getResourceByName(name);

		if (!res.isNull())
		{
			removeImpl(res);
		}
	}
ResourcePtr<ScriptResource> ScriptResource::fetch(FetchRequest& request, ResourceFetcher* fetcher)
{
    ASSERT(request.resourceRequest().frameType() == WebURLRequest::FrameTypeNone);
    request.mutableResourceRequest().setRequestContext(WebURLRequest::RequestContextScript);
    ResourcePtr<ScriptResource> resource = toScriptResource(fetcher->requestResource(request, ScriptResourceFactory()));
    if (resource && !request.integrityMetadata().isEmpty())
        resource->setIntegrityMetadata(request.integrityMetadata());
    return resource;
}
//-----------------------------------------------------------------------------
void ProgramManager::destroyGpuProgram(GpuProgramPtr& gpuProgram)
{		
	const String& programName = gpuProgram->getName();
	ResourcePtr res			  = HighLevelGpuProgramManager::getSingleton().getByName(programName);	

	if (res.isNull() == false)
	{		
		HighLevelGpuProgramManager::getSingleton().remove(programName);
	}
}
/**
 * @author Blakharaz
 * @date 03-14-2005
 */
SoundResourcePtr::SoundResourcePtr(const ResourcePtr& res) : SharedPtr<SoundResource>()
{
    // lock & copy other mutex pointer
    OGRE_LOCK_MUTEX(*res.OGRE_AUTO_MUTEX_NAME)
        OGRE_COPY_AUTO_SHARED_MUTEX(res.OGRE_AUTO_MUTEX_NAME)
        pRep = static_cast<SoundResource*>(res.getPointer());
    pUseCount = res.useCountPointer();
    if (pUseCount != 0)
        ++(*pUseCount);
}
// Verifies that ImageBitmaps constructed from HTMLImageElements hold a reference to the original Image if the HTMLImageElement src is changed.
TEST_F(ImageBitmapTest, ImageBitmapSourceChanged)
{
    RefPtrWillBeRawPtr<HTMLImageElement> image = HTMLImageElement::create(*Document::create().get());
    ResourcePtr<ImageResource> originalImageResource = new ImageResource(
        StaticBitmapImage::create(m_image).get());
    image->setImageResource(originalImageResource.get());

    RefPtrWillBeRawPtr<ImageBitmap> imageBitmap = ImageBitmap::create(image.get(),
        IntRect(0, 0, m_image->width(), m_image->height()));
    ASSERT_EQ(imageBitmap->bitmapImage().get(), originalImageResource->image());

    ResourcePtr<ImageResource> newImageResource = new ImageResource(
        StaticBitmapImage::create(m_image2).get());
    image->setImageResource(newImageResource.get());

    // The ImageBitmap should contain the same data as the original cached image but should no longer hold a reference.
    {
        ASSERT_NE(imageBitmap->bitmapImage().get(), originalImageResource->image());
        RefPtr<SkImage> image1 = imageBitmap->bitmapImage()->imageForCurrentFrame();
        ASSERT_NE(image1, nullptr);
        RefPtr<SkImage> image2 = originalImageResource->image()->imageForCurrentFrame();
        ASSERT_NE(image2, nullptr);
        ASSERT_EQ(image1, image2);
    }

    {
        ASSERT_NE(imageBitmap->bitmapImage().get(), newImageResource->image());
        RefPtr<SkImage> image1 = imageBitmap->bitmapImage()->imageForCurrentFrame();
        ASSERT_NE(image1, nullptr);
        RefPtr<SkImage> image2 = newImageResource->image()->imageForCurrentFrame();
        ASSERT_NE(image2, nullptr);
        ASSERT_NE(image1, image2);
    }
}
    //-----------------------------------------------------------------------
    ResourcePtr ResourceManager::getResourceByName(const String& name, const String& groupName /* = ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME */)
    {		
		ResourcePtr res;

		// if not in the global pool - get it from the grouped pool 
		if(!ResourceGroupManager::getSingleton().isResourceGroupInGlobalPool(groupName))
		{
                    OGRE_LOCK_AUTO_MUTEX;
			ResourceWithGroupMap::iterator itGroup = mResourcesWithGroup.find(groupName);

			if( itGroup != mResourcesWithGroup.end())
			{
				ResourceMap::iterator it = itGroup->second.find(name);

				if( it != itGroup->second.end())
				{
					res = it->second;
				}
			}
		}

		// if didn't find it the grouped pool - get it from the global pool 
		if (res.isNull())
		{
                    OGRE_LOCK_AUTO_MUTEX;

			ResourceMap::iterator it = mResources.find(name);

			if( it != mResources.end())
			{
				res = it->second;
			}
			else
			{
				// this is the case when we need to search also in the grouped hash
				if (groupName == ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME)
				{
					ResourceWithGroupMap::iterator iter = mResourcesWithGroup.begin();
					ResourceWithGroupMap::iterator iterE = mResourcesWithGroup.end();
					for ( ; iter != iterE ; ++iter )
					{
						ResourceMap::iterator resMapIt = iter->second.find(name);

						if( resMapIt != iter->second.end())
						{
							res = resMapIt->second;
							break;
						}
					}
				}
			}
		}
	
		return res;
    }
TEST_F(ResourceFetcherTest, StartLoadAfterFrameDetach)
{
    KURL secureURL(ParsedURLString, "https://secureorigin.test/image.png");
    // Try to request a url. The request should fail, no resource should be returned,
    // and no resource should be present in the cache.
    RefPtrWillBeRawPtr<ResourceFetcher> fetcher = ResourceFetcher::create(FetchContext::create());
    FetchRequest fetchRequest = FetchRequest(ResourceRequest(secureURL), FetchInitiatorInfo());
    ResourcePtr<ImageResource> image = fetcher->fetchImage(fetchRequest);
    EXPECT_EQ(image.get(), static_cast<ImageResource*>(0));
    EXPECT_EQ(memoryCache()->resourceForURL(secureURL), static_cast<Resource*>(0));
}
	//-----------------------------------------------------------------------
	void ResourceManager::unload(ResourceHandle handle)
	{
		ResourcePtr res = getByHandle(handle);

		if (!res.isNull())
		{
			// Unload resource
			res->unload();

		}
	}
	//-----------------------------------------------------------------------
	void ResourceManager::unload(const String& name)
	{
		ResourcePtr res = getResourceByName(name);

		if (!res.isNull())
		{
			// Unload resource
			res->unload();

		}
	}
Exemple #20
0
void UnloadAll() {
for (auto iter = _resources.begin(); iter != _resources.end(); iter++) {
    ResourcePtr res = *iter;
    res->Unload();
}
_resources.clear();
for (auto iter2 = _sources.begin(); iter2 != _sources.end(); iter2++) {
    iter2->second->Unload();
}
_sources.clear();
}
 //---------------------------------------------------------------------------
 ResourcePtr GpuProgramManager::getByName(const String& name, bool preferHighLevelPrograms)
 {
     ResourcePtr ret;
     if (preferHighLevelPrograms)
     {
         ret = HighLevelGpuProgramManager::getSingleton().getByName(name);
         if (!ret.isNull())
             return ret;
     }
     return ResourceManager::getByName(name);
 }
Exemple #22
0
ResourcePtr<Resource> ResourceFetcher::createResourceForLoading(Resource::Type type, FetchRequest& request, const String& charset)
{
    ASSERT(!memoryCache()->resourceForURL(request.resourceRequest().url()));

    WTF_LOG(ResourceLoading, "Loading Resource for '%s'.", request.resourceRequest().url().elidedString().latin1().data());

    addAdditionalRequestHeaders(request.mutableResourceRequest(), type);
    ResourcePtr<Resource> resource = createResource(type, request.resourceRequest(), charset);

    memoryCache()->add(resource.get());
    return resource;
}
 ResourcePtr<Resource> createTestResource(const KURL& url, const KURL& allowOriginUrl, CorsStatus corsStatus)
 {
     OwnPtr<ResourceResponse> response = adoptPtr(new ResourceResponse);
     response->setURL(url);
     response->setHTTPStatusCode(200);
     if (corsStatus == WithCors) {
         response->setHTTPHeaderField("access-control-allow-origin", SecurityOrigin::create(allowOriginUrl)->toAtomicString());
         response->setHTTPHeaderField("access-control-allow-credentials", "true");
     }
     ResourcePtr<Resource> resource = new Resource(ResourceRequest(response->url()), Resource::Raw);
     resource->setResponse(*response);
     return resource;
 }
    //-----------------------------------------------------------------------
    ResourcePtr ResourceManager::load(const String& name, 
        const String& group, bool isManual, ManualResourceLoader* loader, 
        const NameValuePairList* loadParams)
    {
        ResourcePtr ret = getByName(name);
        if (ret.isNull())
        {
            ret = create(name, group, isManual, loader, loadParams);
        }
		// ensure loaded
        ret->load();
        return ret;
    }
    i32 IResourceManager::MoveResource(ResourcePtr pRes, GroupWeakPtr pSrc, GroupWeakPtr pDst)
    {
        xst_assert( pRes != xst_null, "(IResourceManager::MoveResource) Should not be null" );
        xst_assert( pSrc != xst_null, "(IResourceManager::MoveResource) Should not be null" );
        xst_assert( pDst != xst_null, "(IResourceManager::MoveResource) Should not be null" );

        ResourcePtr pResource = pSrc->RemoveResource( pRes );
        if( !pResource )
            return XST_FAIL;
        if( XST_FAILED( pDst->AddResource( pResource->GetResourceHandle(), pResource ) ) )
            return XST_FAIL;
        return XST_OK;
    }
    //-----------------------------------------------------------------------
    void ResourceManager::unload(ResourceHandle handle)
    {
        ResourcePtr res = getByHandle(handle);

#if OGRE_RESOURCEMANAGER_STRICT
        OgreAssert(res, "attempting to unload unknown resource");
#endif

        if (res)
        {
            res->unload();
        }
    }
    //-----------------------------------------------------------------------
    void ResourceManager::unload(const String& name, const String& group)
    {
        ResourcePtr res = getResourceByName(name, group);

#if OGRE_RESOURCEMANAGER_STRICT
        OgreAssert(res, ("attempting to unload unknown resource: "+name+" in group "+group).c_str());
#endif

        if (res)
        {
            res->unload();
        }
    }
Exemple #28
0
bool Font::deserialize(const ConfigParserPtr& config) {
    mGlyphs.clear();

    if(config && config->toNode(L"font")) {
        UknString font_name = config->getString(L"name");

        if(!font_name.empty()) {
            UknString fullFontPath = Path::CheckAndGetFontPath(font_name);

            if(fullFontPath.empty()) {
                log_error(L"ukn::Font::deserialize: error finding font name " + font_name);
                return false;
            }
            ResourcePtr fontResource = ResourceLoader::Instance().loadResource(fullFontPath);
            if(fontResource && fontResource->getResourceStream()) {
                bool result = mFace->load(fontResource);

                if(result) {
                    mGlyphs.resize(mFace->face->num_glyphs);

                    for(int i = 0; i < mFace->face->num_glyphs; ++i) {
                        mGlyphs[i].size = mFontSize;
                        mGlyphs[i].face = &mFace->face;
                    }
                }
            }
        }

        mEnableShadow = config->getBool(L"shadow", false);
        mEnableStroke = config->getBool(L"stroke", false);

        if(config->getBool(L"bold", false)) {
            this->setFTStyle(FT_STYLE_FLAG_BOLD);
        }
        if(config->getBool(L"italic", false)) {
            this->setFTStyle(FT_STYLE_FLAG_ITALIC);
        }
        mShadowXOffset = config->getInt(L"shadow_offset_x", 0);
        mShadowYOffset = config->getInt(L"shadow_offset_y", 0);

        mStrokeWidth = config->getInt(L"stroke_width", 0);

        mFontSize = config->getInt(L"size", 14);
        mFontName = font_name;

        config->toParent();

        return true;
    }
    return false;
}
TEST_F(MemoryCacheTest, DecodeCacheOrder_MultipleResourceMaps)
{
    {
        ResourcePtr<FakeDecodedResource> cachedImageLowPriority =
            new FakeDecodedResource(ResourceRequest("http://foo.com"), Resource::Raw);
        ResourcePtr<FakeDecodedResource> cachedImageHighPriority =
            new FakeDecodedResource(ResourceRequest("http://test/resource"), Resource::Raw);
        cachedImageLowPriority->setCacheIdentifier("foo");
        TestDecodeCacheOrder(cachedImageLowPriority, cachedImageHighPriority);
        memoryCache()->evictResources();
    }
    {
        ResourcePtr<FakeDecodedResource> cachedImageLowPriority =
            new FakeDecodedResource(ResourceRequest("http://foo.com"), Resource::Raw);
        ResourcePtr<FakeDecodedResource> cachedImageHighPriority =
            new FakeDecodedResource(ResourceRequest("http://test/resource"), Resource::Raw);
        cachedImageHighPriority->setCacheIdentifier("foo");
        TestDecodeCacheOrder(cachedImageLowPriority, cachedImageHighPriority);
        memoryCache()->evictResources();
    }
    {
        ResourcePtr<FakeDecodedResource> cachedImageLowPriority =
            new FakeDecodedResource(ResourceRequest("http://test/resource"), Resource::Raw);
        cachedImageLowPriority->setCacheIdentifier("foo");
        ResourcePtr<FakeDecodedResource> cachedImageHighPriority =
            new FakeDecodedResource(ResourceRequest("http://test/resource"), Resource::Raw);
        cachedImageHighPriority->setCacheIdentifier("bar");
        TestDecodeCacheOrder(cachedImageLowPriority, cachedImageHighPriority);
        memoryCache()->evictResources();
    }
}
	//-----------------------------------------------------------------------
	void CachedResourceOgreManager::frameRenderingQueued(const FrameEvent& _evt)
	{
		NumFramesNotUsedMap::iterator it = mNumFramesNotUsedMap.begin();
		while(it != mNumFramesNotUsedMap.end())
		{
			ResourceHandle handle = it->first;
			size_t& numFramesNotUsed = (it++)->second;
			if(numFramesNotUsed++ > mNumFramesBeforeUnload)
			{
				ResourcePtr resource = getByHandle(handle);
				resource->unload();
			}
		}
	}