void ResourceTicket::LoadingSucceeded() { DALI_ASSERT_DEBUG(mLoadingState == ResourceLoading); mLoadingState = ResourceLoadingSucceeded; // Using array operator as the call back out to application code might call back in // and corrupt the mObservers list. Presumption is the operator gets the current address // and adds an offset so a push_back() triggered reallocation should still work. size_t count = mObservers.size(); for(size_t i = 0; i < count; i++) { if( mObservers[i] != NULL) { mObservers[i]->ResourceLoadingSucceeded(*this); } } // Move NULL pointers to the end... ObserverIter endIter = remove_if( mObservers.begin(), mObservers.end(), isNULL ); // ...and remove them mObservers.erase( endIter, mObservers.end() ); }
bool Property::Value::HasKey(const std::string& key) const { bool has = false; if( Property::MAP == GetType() ) { Property::Map *container = AnyCast<Property::Map>(&(mImpl->mValue)); DALI_ASSERT_DEBUG(container && "Property::Map has no container?"); if(container) { for(Property::Map::iterator iter = container->begin(); iter != container->end(); ++iter) { if(iter->first == key) { has = true; } } } } return has; }
RenderableAttachment& ImageActor::GetRenderableAttachment() const { DALI_ASSERT_DEBUG( mImageAttachment && "ImageAttachment missing from ImageActor" ); return *mImageAttachment; }
const SceneGraph::RenderableAttachment& TextAttachment::GetSceneObject() const { DALI_ASSERT_DEBUG( mSceneObject != NULL ); return *mSceneObject; }
void BitmapTexture::Update( Integration::Bitmap* bitmap ) { DALI_LOG_INFO( Debug::Filter::gGLResource, Debug::General, "BitmapTexture::Update(bitmap:%p )\n", bitmap ); DALI_ASSERT_DEBUG( bitmap != 0 ); if( !bitmap ) { DALI_LOG_ERROR( "Passed a null bitmap to update this bitmap texture." ); return; } // Only Packed-pixel bitmaps are ever associated with BitmapTextures, so we should never be passed any other kind: const Integration::Bitmap::PackedPixelsProfile * const bitmapPackedPixels = bitmap->GetPackedPixelsProfile(); DALI_ASSERT_DEBUG(bitmapPackedPixels); if( !bitmapPackedPixels ) { ///! This should never happen. DALI_LOG_ERROR("Passed an incompatible bitmap type to update this bitmap texture."); return; } mBitmap = bitmap; const unsigned char* pixels = mBitmap->GetBuffer(); DALI_ASSERT_DEBUG( pixels != NULL ); if ( NULL == pixels ) { DALI_LOG_ERROR("bitmap has no data\n"); GlCleanup(); // Note, We suicide here in the case of bad input. } else { if( mImageWidth == mBitmap->GetImageWidth() && mImageHeight == mBitmap->GetImageHeight() && mWidth == bitmapPackedPixels->GetBufferWidth() && mHeight == bitmapPackedPixels->GetBufferHeight() && mPixelFormat == mBitmap->GetPixelFormat() ) // and size hasn't changed { if ( mId ) // If the texture is already bound { RectArea area(0, 0, mImageWidth, mImageHeight); // just update whole texture AreaUpdated( area, pixels ); mBitmap->DiscardBuffer(); } } else { // Otherwise, reload the pixel data mImageWidth = mBitmap->GetImageWidth(); mImageHeight = mBitmap->GetImageHeight(); mWidth = bitmapPackedPixels->GetBufferWidth(); mHeight = bitmapPackedPixels->GetBufferHeight(); mPixelFormat = mBitmap->GetPixelFormat(); if ( mId ) // If the texture is already bound { AssignBitmap( false, pixels ); mBitmap->DiscardBuffer(); } } } }
void Property::Value::Get(std::string &out) const { DALI_ASSERT_DEBUG(Property::STRING == GetType() && "Property type invalid"); out = AnyCast<std::string>(mImpl->mValue); }
void Property::Value::Get(Matrix& matrixValue) const { DALI_ASSERT_DEBUG( Property::MATRIX == GetType() && "Property type invalid" ); matrixValue = AnyCast<Matrix>(mImpl->mValue); }
void Property::Value::Get(unsigned int& unsignedIntegerValue) const { DALI_ASSERT_DEBUG( Property::UNSIGNED_INTEGER == GetType() && "Property type invalid" ); unsignedIntegerValue = AnyCast<unsigned int>(mImpl->mValue); }
RenderInstruction& RenderInstructionContainer::At( BufferIndex bufferIndex, size_t index ) { DALI_ASSERT_DEBUG( index < mInstructions[ bufferIndex ].Count() ); return *mInstructions[ bufferIndex ][ index ]; }
float ModelData::GetAnimationDuration(size_t animationIndex) const { DALI_ASSERT_DEBUG (animationIndex < mAnimationMaps.size ()); const ModelAnimationMap& animData( mAnimationMaps[animationIndex] ); return animData.duration; }
Dali::Material ModelData::GetMaterial(unsigned int index) const { DALI_ASSERT_DEBUG(index < mMaterials.size()); return mMaterials[index]; }
void NodeAttachment::SetParent( Node& parent ) { DALI_ASSERT_DEBUG(mParent == NULL); mParent = &parent; }
Integration::PlatformAbstraction& Adaptor::GetPlatformAbstraction() const { DALI_ASSERT_DEBUG( mPlatformAbstraction && "PlatformAbstraction not created" ); return *mPlatformAbstraction; }
Integration::GlAbstraction& Adaptor::GetGlAbstraction() const { DALI_ASSERT_DEBUG( mGLES && "GLImplementation not created" ); return *mGLES; }
EglFactory& Adaptor::GetEGLFactory() const { DALI_ASSERT_DEBUG( mEglFactory && "EGL Factory not created" ); return *mEglFactory; }
void Property::Value::Get(float& floatValue) const { DALI_ASSERT_DEBUG( Property::FLOAT == GetType() && "Property type invalid" ); floatValue = AnyCast<float>(mImpl->mValue); }
void Property::Value::Get(int& integerValue) const { DALI_ASSERT_DEBUG( Property::INTEGER == GetType() && "Property type invalid" ); integerValue = AnyCast<int>(mImpl->mValue); }
bool LoadBitmapFromPng( const ResourceLoadingClient& client, const ImageLoader::Input& input, Integration::Bitmap& bitmap ) { png_structp png = NULL; png_infop info = NULL; auto_png autoPng(png, info); /// @todo: consider parameters unsigned int y; unsigned int width, height; unsigned char *pixels; png_bytep *rows; unsigned int bpp = 0; // bytes per pixel bool valid = false; // Load info from the header if( !LoadPngHeader( input.file, width, height, png, info ) ) { return false; } Pixel::Format pixelFormat = Pixel::RGBA8888; // decide pixel format unsigned int colordepth = png_get_bit_depth(png, info); // Ask PNGLib to convert high precision images into something we can use: if (colordepth == 16) { png_set_strip_16(png); colordepth = 8; } png_byte colortype = png_get_color_type(png, info); if(colortype == PNG_COLOR_TYPE_GRAY) { switch( colordepth ) { case 8: { pixelFormat = Pixel::L8; valid = true; break; } default: { break; } } } else if(colortype == PNG_COLOR_TYPE_GRAY_ALPHA) { switch(colordepth) { case 8: { pixelFormat = Pixel::LA88; valid = true; break; } default: { break; } } } else if(colortype == PNG_COLOR_TYPE_RGB ) { switch(colordepth) { case 8: { pixelFormat = Pixel::RGB888; valid = true; break; } case 5: /// @todo is this correct for RGB16 5-6-5 ? { pixelFormat = Pixel::RGB565; valid = true; break; } default: { break; } } } else if(colortype == PNG_COLOR_TYPE_RGBA) { switch(colordepth) { case 8: { pixelFormat = Pixel::RGBA8888; valid = true; break; } default: { break; } } } else if(colortype == PNG_COLOR_TYPE_PALETTE) { switch(colordepth) { case 2: case 4: case 8: { /* Expand paletted or RGB images with transparency to full alpha channels * so the data will be available as RGBA quartets. PNG_INFO_tRNS = 0x10 */ if(png_get_valid(png, info, PNG_INFO_tRNS) == 0x10) { pixelFormat = Pixel::RGBA8888; valid = true; } else { pixelFormat = Pixel::RGB888; png_set_packing(png); png_set_packswap(png); png_set_palette_to_rgb(png); valid = true; } break; } default: { break; } } } if( !valid ) { DALI_LOG_WARNING( "Unsupported png format\n" ); return false; } // bytes per pixel bpp = Pixel::GetBytesPerPixel(pixelFormat); png_read_update_info(png, info); if(setjmp(png_jmpbuf(png))) { DALI_LOG_WARNING("error during png_read_image\n"); return false; } unsigned int rowBytes = png_get_rowbytes(png, info); unsigned int bufferWidth = GetTextureDimension(width); unsigned int bufferHeight = GetTextureDimension(height); unsigned int stride = bufferWidth*bpp; // not sure if this ever happens if( rowBytes > stride ) { stride = GetTextureDimension(rowBytes); bufferWidth = stride / bpp; } // decode the whole image into bitmap buffer pixels = bitmap.GetPackedPixelsProfile()->ReserveBuffer(pixelFormat, width, height, bufferWidth, bufferHeight); DALI_ASSERT_DEBUG(pixels); rows = (png_bytep*) malloc(sizeof(png_bytep) * height); for(y=0; y<height; y++) { rows[y] = (png_byte*) (pixels + y * stride); } // decode image png_read_image(png, rows); free(rows); return true; }
void Property::Value::Get(Vector4& vectorValue) const { DALI_ASSERT_DEBUG( Property::VECTOR4 == GetType() && "Property type invalid" ); vectorValue = AnyCast<Vector4>(mImpl->mValue); }
AutoPngWrite(png_structp& _png, png_infop& _info) : png(_png), info(_info) { DALI_ASSERT_DEBUG(&_png != 0 && &_info != 0); }
void Property::Value::Get(Rect<int>& rect) const { DALI_ASSERT_DEBUG( Property::RECTANGLE == GetType() && "Property type invalid" ); rect = AnyCast<Rect<int> >(mImpl->mValue); }
void EcoreCallbackManager::Start() { DALI_ASSERT_DEBUG( mRunning == false ); mRunning = true; }
void Property::Value::Get(Property::Map &out) const { DALI_ASSERT_DEBUG(Property::MAP == GetType() && "Property type invalid"); out = AnyCast<Property::Map>(mImpl->mValue); }
/** * This is called recursively for all children of the root Node */ inline int UpdateNodesAndAttachments( Node& node, int parentFlags, BufferIndex updateBufferIndex, ResourceManager& resourceManager, RenderQueue& renderQueue, Layer& currentLayer, Shader* defaultShader, int inheritedDrawMode ) { Layer* layer = ¤tLayer; // Short-circuit for invisible nodes if ( !node.IsVisible( updateBufferIndex ) ) { return 0; } // If the node was not previously visible BufferIndex previousBuffer = updateBufferIndex ? 0u : 1u; if ( !node.IsVisible( previousBuffer ) ) { // The node was skipped in the previous update; it must recalculate everything node.SetAllDirtyFlags(); } // Some dirty flags are inherited from parent int nodeDirtyFlags( node.GetDirtyFlags() | ( parentFlags & InheritedDirtyFlags ) ); if ( node.GetInheritedShader() == NULL ) { nodeDirtyFlags |= ShaderFlag; } int cumulativeDirtyFlags = nodeDirtyFlags; if ( node.IsLayer() ) { // all childs go to this layer layer = node.GetLayer(); // assume layer is clean to begin with layer->SetReuseRenderers( updateBufferIndex, true ); // Layers do not inherit the DrawMode from their parents inheritedDrawMode = DrawMode::NORMAL; } DALI_ASSERT_DEBUG( NULL != layer ); UpdateNodeShader( node, nodeDirtyFlags, defaultShader ); UpdateNodeOpacity( node, nodeDirtyFlags, updateBufferIndex ); UpdateNodeGeometry( node, nodeDirtyFlags, updateBufferIndex ); UpdateNodeTransformValues( node, nodeDirtyFlags, updateBufferIndex ); // Setting STENCIL will override OVERLAY, if that would otherwise have been inherited. inheritedDrawMode |= node.GetDrawMode(); if ( node.HasAttachment() ) { /* * Add renderables for the children into the current Layer */ RenderableAttachment* renderable = UpdateAttachment( node.GetAttachment(), node, updateBufferIndex, resourceManager, nodeDirtyFlags ); if( NULL != renderable ) { // Update the world matrix after renderable update; the ScaleForSize property should now be calculated UpdateNodeWorldMatrix( node, *renderable, nodeDirtyFlags, updateBufferIndex ); // The attachment is ready to render, so it is added to a set of renderables. AddRenderableToLayer( *layer, *renderable, updateBufferIndex, inheritedDrawMode ); } } else if( node.IsObserved() ) { // This node is being used as a property input for an animation, constraint, // camera or bone. Ensure it's matrix is updated UpdateNodeWorldMatrix( node, nodeDirtyFlags, updateBufferIndex ); } // if any child node has moved or had its sort modifier changed, layer is not clean and old frame cannot be reused // also if node has been deleted, dont reuse old render items if( nodeDirtyFlags & RenderableUpdateFlags ) { layer->SetReuseRenderers( updateBufferIndex, false ); } // recurse children NodeContainer& children = node.GetChildren(); const NodeIter endIter = children.End(); for ( NodeIter iter = children.Begin(); iter != endIter; ++iter ) { Node& child = **iter; cumulativeDirtyFlags |=UpdateNodesAndAttachments( child, nodeDirtyFlags, updateBufferIndex, resourceManager, renderQueue, *layer, defaultShader, inheritedDrawMode ); } return cumulativeDirtyFlags; }
Property::Value& Property::Value::GetItem(const int index) const { switch( GetType() ) { case Property::MAP: { int i = 0; Property::Map *container = AnyCast<Property::Map>(&(mImpl->mValue)); DALI_ASSERT_DEBUG(container && "Property::Map has no container?"); if(container) { DALI_ASSERT_ALWAYS(index < static_cast<int>(container->size()) && "Property array index invalid"); DALI_ASSERT_ALWAYS(index >= 0 && "Property array index invalid"); for(Property::Map::iterator iter = container->begin(); iter != container->end(); ++iter) { if(i++ == index) { return iter->second; } } } } break; case Property::ARRAY: { int i = 0; Property::Array *container = AnyCast<Property::Array>(&(mImpl->mValue)); DALI_ASSERT_DEBUG(container && "Property::Map has no container?"); if(container) { DALI_ASSERT_ALWAYS(index < static_cast<int>(container->size()) && "Property array index invalid"); DALI_ASSERT_ALWAYS(index >= 0 && "Property array index invalid"); for(Property::Array::iterator iter = container->begin(); iter != container->end(); ++iter) { if(i++ == index) { return *iter; } } } } break; case Property::NONE: case Property::BOOLEAN: case Property::FLOAT: case Property::INTEGER: case Property::UNSIGNED_INTEGER: case Property::VECTOR2: case Property::VECTOR3: case Property::VECTOR4: case Property::MATRIX3: case Property::MATRIX: case Property::RECTANGLE: case Property::ROTATION: case Property::STRING: case Property::TYPE_COUNT: { DALI_ASSERT_ALWAYS(!"Cannot GetItem on property Type; not a container"); break; } } // switch GetType() DALI_ASSERT_ALWAYS(!"Property value index not valid"); // should never return this static Property::Value null; return null; }
void Renderer::SetCullFace( CullFaceMode mode ) { DALI_ASSERT_DEBUG(mode >= CullNone && mode <= CullFrontAndBack); mCullFaceMode = mode; }
void ImageAttachment::DoPrepareRender( BufferIndex updateBufferIndex ) { DALI_ASSERT_DEBUG( mSceneController && mImageRenderer ); ATTACHMENT_LOG_FMT(Debug::General, "ObjName:%s textureId:%d\n", DALI_LOG_GET_OBJECT_C_STR(mParent), mTextureId); // Check whether we need to refresh the vertex buffer. if ( mRefreshMeshData ) { const Vector3& actorSize = GetParent().GetSize( updateBufferIndex ); mGeometrySize.x = actorSize.x; mGeometrySize.y = actorSize.y; Render::ImageRenderer::MeshType meshType = Render::ImageRenderer::GRID_QUAD; if ( !PreviousHintEnabled( Dali::ShaderEffect::HINT_GRID ) ) { if ( mStyle == Dali::ImageActor::STYLE_NINE_PATCH ) { meshType = Render::ImageRenderer::NINE_PATCH; } else if ( mStyle == Dali::ImageActor::STYLE_NINE_PATCH_NO_CENTER ) { meshType = Render::ImageRenderer::NINE_PATCH_NO_CENTER; } else { meshType = Render::ImageRenderer::QUAD; } } else { if ( mStyle == Dali::ImageActor::STYLE_NINE_PATCH ) { meshType = Render::ImageRenderer::GRID_NINE_PATCH; } else if ( mStyle == Dali::ImageActor::STYLE_NINE_PATCH_NO_CENTER ) { meshType = Render::ImageRenderer::GRID_NINE_PATCH_NO_CENTER; } else { meshType = Render::ImageRenderer::GRID_QUAD; } } // Recalculate the mesh data in the next render { typedef MessageValue3< Render::ImageRenderer, Render::ImageRenderer::MeshType, Vector2, bool > DerivedType; // Reserve some memory inside the render queue unsigned int* slot = mSceneController->GetRenderQueue().ReserveMessageSlot( updateBufferIndex, sizeof( DerivedType ) ); // Construct message in the render queue memory; note that delete should not be called on the return value new (slot) DerivedType( mImageRenderer, &Render::ImageRenderer::CalculateMeshData, meshType, mGeometrySize, mIsPixelAreaSet ); } mRefreshMeshData = false; } }
void Renderer::Render( Context& context, SceneGraph::TextureCache& textureCache, BufferIndex bufferIndex, const SceneGraph::NodeDataProvider& node, SceneGraph::Shader& defaultShader, const Matrix& modelViewMatrix, const Matrix& viewMatrix, const Matrix& projectionMatrix, bool cull, bool blend ) { NewRenderer* renderer = GetNewRenderer(); // avoid a dynamic cast per item per frame if( renderer ) { // Get the shader from the material: mShader = &renderer->mRenderDataProvider->GetShader(); } // if mShader is NULL it means we're set to default if( !mShader ) { mShader = &defaultShader; } if( !CheckResources() ) { // CheckResources() is overriden in derived classes. // Prevents modify the GL state if resources are not ready and nothing is to be rendered. return; } // Get the program to use: Program* program = mShader->GetProgram(); if( !program ) { // if program is NULL it means this is a custom shader with non matching geometry type so we need to use default shaders program program = defaultShader.GetProgram(); DALI_ASSERT_DEBUG( program && "Default shader should always have a program available." ); if( !program ) { DALI_LOG_ERROR( "Failed to get program for shader at address %p.", (void*) &*mShader ); return; } } // Take the program into use so we can send uniforms to it program->Use(); DoSetCullFaceMode( context, bufferIndex ); DoSetBlending( context, bufferIndex, blend ); // Ignore missing uniforms - custom shaders and flat color shaders don't have SAMPLER // set projection and view matrix if program has not yet received them yet this frame const Matrix& modelMatrix = node.GetModelMatrix( bufferIndex ); SetMatrices( *program, modelMatrix, viewMatrix, projectionMatrix, modelViewMatrix ); // set color uniform GLint loc = program->GetUniformLocation( Program::UNIFORM_COLOR ); if( Program::UNIFORM_UNKNOWN != loc ) { const Vector4& color = node.GetRenderColor( bufferIndex ); program->SetUniform4f( loc, color.r, color.g, color.b, color.a ); } //@todo MESH_REWORK Remove after removing ImageRenderer DoSetUniforms(context, bufferIndex, mShader, program ); // subclass rendering and actual draw call DoRender( context, textureCache, node, bufferIndex, *program, modelViewMatrix, viewMatrix ); }
void ConstraintBase::ResetDefaultProperties( BufferIndex updateBufferIndex ) { DALI_ASSERT_DEBUG( false ); }
void Property::Value::Get(bool& boolValue) const { DALI_ASSERT_DEBUG( Property::BOOLEAN == GetType() && "Property type invalid" ); // AnyCast does asserted type checking boolValue = AnyCast<bool>(mImpl->mValue); }