Use max texture size when loading images 52/136852/3
authorHeeyong Song <heeyong.song@samsung.com>
Mon, 3 Jul 2017 07:41:26 +0000 (16:41 +0900)
committerHeeyong Song <heeyong.song@samsung.com>
Tue, 4 Jul 2017 01:51:23 +0000 (01:51 +0000)
Change-Id: I610c9d6c0a5ccd85b0dd0677b660c784a54d22a3

adaptors/base/environment-options.cpp
adaptors/base/environment-options.h
adaptors/base/environment-variables.h
adaptors/common/adaptor-impl.cpp
adaptors/devel-api/adaptor-framework/image-loading.cpp
adaptors/devel-api/adaptor-framework/image-loading.h
platform-abstractions/portable/image-operations.cpp

index 0dbf614..806c428 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2017 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.
@@ -108,6 +108,7 @@ EnvironmentOptions::EnvironmentOptions()
   mRenderRefreshRate( 1 ),
   mGlesCallAccumulate( false ),
   mMultiSamplingLevel( 0 ),
+  mMaxTextureSize( 0 ),
   mLogFunction( NULL )
 {
   ParseEnvironmentOptions();
@@ -259,6 +260,11 @@ unsigned int EnvironmentOptions::GetMultiSamplingLevel() const
   return mMultiSamplingLevel;
 }
 
+unsigned int EnvironmentOptions::GetMaxTextureSize() const
+{
+  return mMaxTextureSize;
+}
+
 bool EnvironmentOptions::PerformanceServerRequired() const
 {
   return ( ( GetPerformanceStatsLoggingOptions() > 0) ||
@@ -411,6 +417,15 @@ void EnvironmentOptions::ParseEnvironmentOptions()
       mMultiSamplingLevel = multiSamplingLevel;
     }
   }
+
+  int maxTextureSize( 0 );
+  if( GetIntegerEnvironmentVariable( DALI_ENV_MAX_TEXTURE_SIZE, maxTextureSize ) )
+  {
+    if( maxTextureSize > 0 )
+    {
+      mMaxTextureSize = maxTextureSize;
+    }
+  }
 }
 
 } // Adaptor
index dacaa11..2ab19a9 100644 (file)
@@ -2,7 +2,7 @@
 #define __DALI_INTERNAL_ADAPTOR_ENVIRONMENT_OPTIONS_H__
 
 /*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2017 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.
@@ -208,6 +208,11 @@ public:
    */
   unsigned int GetMultiSamplingLevel() const;
 
+  /**
+   * @return The maximum texture size
+   */
+  unsigned int GetMaxTextureSize() const;
+
 private: // Internal
 
   /**
@@ -244,6 +249,7 @@ private: // Data
   unsigned int mRenderRefreshRate;                ///< render refresh rate
   bool mGlesCallAccumulate;                       ///< Whether or not to accumulate gles call statistics
   unsigned int mMultiSamplingLevel;               ///< The number of samples required in multisample buffers
+  unsigned int mMaxTextureSize;                   ///< The maximum texture size that GL can handle
 
   Dali::Integration::Log::LogFunction mLogFunction;
 
index fa010f9..53fe21b 100644 (file)
@@ -2,7 +2,7 @@
 #define __DALI_INTERNAL_ADAPTOR_ENVIRONMENT_VARIABLES_H__
 
 /*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2017 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.
@@ -95,6 +95,8 @@ namespace Adaptor
 
 #define DALI_ENV_MULTI_SAMPLING_LEVEL "DALI_MULTI_SAMPLING_LEVEL"
 
+#define DALI_ENV_MAX_TEXTURE_SIZE "DALI_MAX_TEXTURE_SIZE"
+
 } // namespace Adaptor
 
 } // namespace Internal
index a97a6af..70f65ad 100644 (file)
@@ -29,7 +29,7 @@
 
 // INTERNAL INCLUDES
 #include <base/thread-controller.h>
-#  include <base/performance-logging/performance-interface-factory.h>
+#include <base/performance-logging/performance-interface-factory.h>
 #include <base/lifecycle-observer.h>
 
 #include <dali/devel-api/text-abstraction/font-client.h>
@@ -53,6 +53,7 @@
 #include <window-impl.h>
 
 #include <tizen-logging.h>
+#include <image-loading.h>
 
 using Dali::TextAbstraction::FontClient;
 
@@ -183,6 +184,12 @@ void Adaptor::Initialize( Dali::Configuration::ContextLoss configuration )
   {
     Integration::SetPanGestureSmoothingAmount(mEnvironmentOptions->GetPanGestureSmoothingAmount());
   }
+
+  // Set max texture size
+  if( mEnvironmentOptions->GetMaxTextureSize() > 0 )
+  {
+    Dali::SetMaxTextureSize( mEnvironmentOptions->GetMaxTextureSize() );
+  }
 }
 
 Adaptor::~Adaptor()
index d8f8adf..e2f896b 100644 (file)
@@ -28,8 +28,12 @@ namespace Dali
 
 namespace
 {
+
 // limit maximum image down load size to 50 MB
 const size_t MAXIMUM_DOWNLOAD_IMAGE_SIZE  = 50 * 1024 * 1024 ;
+
+static unsigned int gMaxTextureSize = 4096;
+
 }
 
 Devel::PixelBuffer LoadImageFromFile( const std::string& url, ImageDimensions size, FittingMode::Type fittingMode, SamplingMode::Type samplingMode, bool orientationCorrection )
@@ -68,7 +72,12 @@ ImageDimensions GetClosestImageSize( const std::string& filename,
                                      SamplingMode::Type samplingMode,
                                      bool orientationCorrection )
 {
-  return TizenPlatform::ImageLoader::GetClosestImageSize( filename, size, fittingMode, samplingMode, orientationCorrection );
+  ImageDimensions dimension = TizenPlatform::ImageLoader::GetClosestImageSize( filename, size, fittingMode, samplingMode, orientationCorrection );
+
+  dimension.SetWidth( std::min( dimension.GetWidth(), static_cast< uint16_t >( GetMaxTextureSize() ) ) );
+  dimension.SetHeight( std::min( dimension.GetHeight(), static_cast< uint16_t >( GetMaxTextureSize() ) ) );
+
+  return dimension;
 }
 
 
@@ -126,5 +135,14 @@ Devel::PixelBuffer DownloadImageSynchronously( const std::string& url, ImageDime
   return Dali::Devel::PixelBuffer();
 }
 
+void SetMaxTextureSize( unsigned int size )
+{
+  gMaxTextureSize = size;
+}
+
+unsigned int GetMaxTextureSize()
+{
+  return gMaxTextureSize;
+}
 
 } // namespace Dali
index 00a6a45..a9476e3 100644 (file)
@@ -92,6 +92,19 @@ DALI_IMPORT_API Devel::PixelBuffer DownloadImageSynchronously(
   SamplingMode::Type samplingMode = SamplingMode::BOX_THEN_LINEAR,
   bool orientationCorrection = true );
 
+/**
+ * @brief Set the maximum texture size. Then size can be kwown by GL_MAX_TEXTURE_SIZE.
+ *
+ * @param [in] size The maximum texture size to set
+ */
+void SetMaxTextureSize( unsigned int size );
+
+/**
+ * @brief get the maximum texture size.
+ *
+ * @return The maximum texture size
+ */
+unsigned int GetMaxTextureSize();
 
 } // Dali
 
index f9856cf..81936fa 100644 (file)
@@ -26,6 +26,7 @@
 #include <dali/public-api/common/dali-vector.h>
 #include <dali/public-api/math/vector2.h>
 #include <resampler.h>
+#include <image-loading.h>
 
 // INTERNAL INCLUDES
 
@@ -449,24 +450,29 @@ BitmapPtr MakeBitmap( const uint8_t * const pixels, Pixel::Format pixelFormat, u
  */
 ImageDimensions CalculateDesiredDimensions( unsigned int bitmapWidth, unsigned int bitmapHeight, unsigned int requestedWidth, unsigned int requestedHeight )
 {
+  unsigned int maxSize = Dali::GetMaxTextureSize();
+
   // If no dimensions have been requested, default to the source ones:
   if( requestedWidth == 0 && requestedHeight == 0 )
   {
-    return ImageDimensions( bitmapWidth, bitmapHeight );
+    return ImageDimensions( std::min( bitmapWidth, maxSize ), std::min( bitmapHeight, maxSize ) );
   }
 
   // If both dimensions have values requested, use them both:
   if( requestedWidth != 0 && requestedHeight != 0 )
   {
-    return ImageDimensions( requestedWidth, requestedHeight );
+    return ImageDimensions( std::min( requestedWidth, maxSize ), std::min( requestedHeight, maxSize ) );
   }
 
   // Only one of the dimensions has been requested. Calculate the other from
   // the requested one and the source image aspect ratio:
   if( requestedWidth != 0 )
   {
+    requestedWidth = std::min( requestedWidth, maxSize );
     return ImageDimensions( requestedWidth, bitmapHeight / float(bitmapWidth) * requestedWidth + 0.5f );
   }
+
+  requestedHeight = std::min( requestedHeight, maxSize );
   return ImageDimensions( bitmapWidth / float(bitmapHeight) * requestedHeight + 0.5f, requestedHeight );
 }