Shader & Program cleanup, Part 1: Remove cyclic dependency between programs and conte...
[platform/core/uifw/dali-core.git] / dali / internal / render / gl-resources / texture-cache.cpp
index c06fc0a..db4f027 100644 (file)
@@ -1,18 +1,19 @@
-//
-// Copyright (c) 2014 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Flora License, Version 1.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//     http://floralicense.org/license/
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an AS IS BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
 
 #include <dali/internal/render/gl-resources/texture-cache.h>
 
@@ -35,6 +36,14 @@ using Dali::Internal::Texture;
 using Dali::Internal::FrameBufferTexture;
 using Dali::Integration::Bitmap;
 
+namespace
+{
+#if defined(DEBUG_ENABLED)
+Debug::Filter* gTextureCacheFilter = Debug::Filter::New(Debug::Concise, false, "LOG_TEXTURE_CACHE");
+#endif
+}
+
+
 namespace Dali
 {
 namespace Internal
@@ -51,7 +60,8 @@ TextureCache::TextureCache( RenderQueue& renderQueue,
                             Context& context)
 : TextureCacheDispatcher(renderQueue),
   mPostProcessResourceDispatcher(postProcessResourceDispatcher),
-  mContext(context)
+  mContext(context),
+  mDiscardBitmapsPolicy(ResourcePolicy::DISCARD)
 {
 }
 
@@ -67,7 +77,7 @@ void TextureCache::CreateTexture( ResourceId        id,
 {
   DALI_LOG_INFO(Debug::Filter::gGLResource, Debug::General, "TextureCache::CreateTexture(id=%i width:%u height:%u)\n", id, width, height);
 
-  Texture* texture = TextureFactory::NewBitmapTexture(width, height, pixelFormat, clearPixels, mContext);
+  Texture* texture = TextureFactory::NewBitmapTexture(width, height, pixelFormat, clearPixels, mContext, GetDiscardBitmapsPolicy() );
   mTextures.insert(TexturePair(id, texture));
 }
 
@@ -75,7 +85,7 @@ void TextureCache::AddBitmap(ResourceId id, Integration::BitmapPtr bitmap)
 {
   DALI_LOG_INFO(Debug::Filter::gGLResource, Debug::General, "TextureCache::AddBitmap(id=%i Bitmap:%p)\n", id, bitmap.Get());
 
-  Texture* texture = TextureFactory::NewBitmapTexture(bitmap.Get(), mContext);
+  Texture* texture = TextureFactory::NewBitmapTexture(bitmap.Get(), mContext, GetDiscardBitmapsPolicy());
   mTextures.insert(TexturePair(id, texture));
 }
 
@@ -119,7 +129,7 @@ void TextureCache::UpdateTexture( ResourceId id, Integration::BitmapPtr bitmap )
     TexturePointer texturePtr = textureIter->second;
     if( texturePtr )
     {
-      texturePtr->Update(bitmap.Get());
+      texturePtr->Update( bitmap.Get() );
 
       ResourcePostProcessRequest ppRequest( id, ResourcePostProcessRequest::UPLOADED );
       mPostProcessResourceDispatcher.DispatchPostProcessRequest(ppRequest);
@@ -244,7 +254,7 @@ void TextureCache::DiscardTexture( ResourceId id )
   }
 }
 
-void TextureCache::BindTexture( Texture *texture, ResourceId id, GLenum target, GLenum textureunit )
+void TextureCache::BindTexture( Texture *texture, ResourceId id, GLenum target, TextureUnit textureunit )
 {
   bool created = texture->Bind(target, textureunit);
   if( created && texture->UpdateOnCreate() ) // i.e. the pixel data was sent to GL
@@ -362,8 +372,28 @@ void TextureCache::GlContextDestroyed()
   {
     (*iter->second).GlContextDestroyed(); // map holds intrusive pointers
   }
+
+  end = mFramebufferTextures.end();
+  iter = mFramebufferTextures.begin();
+  for( ; iter != end; ++iter )
+  {
+    (*iter->second).GlContextDestroyed(); // map holds intrusive pointers
+  }
+}
+
+void TextureCache::SetDiscardBitmapsPolicy( ResourcePolicy::Discardable policy )
+{
+  DALI_LOG_INFO( gTextureCacheFilter, Debug::General, "TextureCache::SetDiscardBitmapsPolicy(%s)\n",
+                 policy==ResourcePolicy::RETAIN?"RETAIN":"DISCARD" );
+  mDiscardBitmapsPolicy = policy;
 }
 
+ResourcePolicy::Discardable TextureCache::GetDiscardBitmapsPolicy()
+{
+  return mDiscardBitmapsPolicy;
+}
+
+
 /********************************************************************************
  **********************  Implements TextureCacheDispatcher  *********************
  ********************************************************************************/