1 /*---------------------------------------------------------------------------* 2 Project: NintendoWare 3 File: dev_Screenshot.h 4 5 Copyright (C)2009-2010 Nintendo Co., Ltd./HAL Laboratory, Inc. All rights reserved. 6 7 These coded instructions, statements, and computer programs contain 8 proprietary information of Nintendo of America Inc. and/or Nintendo 9 Company Ltd., and are protected by Federal copyright law. They may 10 not be disclosed to third parties or copied or duplicated in any form, 11 in whole or in part, without the prior written consent of Nintendo. 12 13 $Revision: 21180 $ 14 *---------------------------------------------------------------------------*/ 15 16 #ifndef NW_DEV_SCREENSHOT_H_ 17 #define NW_DEV_SCREENSHOT_H_ 18 19 #include <nw/types.h> 20 #include <nw/ut/ut_MoveArray.h> 21 #include <nw/dev/dev_Utility.h> 22 23 #include <GLES2/gl2.h> 24 #include <GLES2/gl2ext.h> 25 26 #if defined(NW_DEV_ENABLED) && defined(NW_PLATFORM_CTR) 27 #include <nn/crypto/crypto_Sha1.h> 28 #endif 29 30 namespace nw 31 { 32 33 namespace os 34 { 35 class IAllocator; 36 } 37 38 namespace dev 39 { 40 41 #if defined(NW_DEV_ENABLED) && defined(NW_PLATFORM_CTR) 42 43 44 //! @brief ディスプレイバッファの内容を表す構造体です。 45 struct DisplayDescription 46 { 47 //! @brief コンストラクタです。 DisplayDescriptionDisplayDescription48 DisplayDescription() 49 : format(0), 50 width(0), 51 height(0), 52 offsetX(0), 53 offsetY(0), 54 display(0) 55 {} 56 57 GLint format; //!< カラーフォーマットです。 58 GLint width; //!< バッファの横幅です。 59 GLint height; //!< バッファの縦幅です。 60 int offsetX; //!< ディスプレイに表示するオフセットです。 61 int offsetY; //!< ディスプレイに表示するオフセットです。 62 GLenum display; //!< ディスプレイを表す定義です。 63 }; 64 65 //! @brief スクリーンショットを表すクラスです。 66 class Screenshot 67 { 68 public: 69 //! @brief ハッシュコードを取得します。 GetHash()70 u32* GetHash() 71 { 72 return this->m_Hash; 73 } 74 75 //! @brief ハッシュコードを取得します。 GetHash()76 const u32* GetHash() const 77 { 78 return this->m_Hash; 79 } 80 81 //! @brief スクリーンショットとハッシュコードの比較を行います。 Equal(const Screenshot * source)82 bool Equal(const Screenshot* source) const 83 { 84 return (this->m_Hash[0] == source->GetHash()[0] && 85 this->m_Hash[1] == source->GetHash()[1] && 86 this->m_Hash[2] == source->GetHash()[2] && 87 this->m_Hash[3] == source->GetHash()[3]); 88 } 89 90 //! @brief ハッシュコードの比較を行います。 Equal(const u32 * hash)91 bool Equal(const u32* hash) const 92 { 93 return (this->m_Hash[0] == hash[0] && 94 this->m_Hash[1] == hash[1] && 95 this->m_Hash[2] == hash[2] && 96 this->m_Hash[3] == hash[3]); 97 } 98 99 //! @brief スクリーンショットが書き込まれたかどうかを調べます。 IsWrited()100 bool IsWrited() const 101 { 102 return m_Writed; 103 } 104 105 //! @brief ハッシュを文字列で出力します。 106 void DumpHash() const; 107 108 //! @brief スクリーンショットを生成します。 109 //! 110 //! @param[in] allocator アロケータです。 111 //! @param[in] maxLength バッファ領域の大きさです。 112 //! 113 //! @return 生成したスクリーンショットです。 114 //! 115 static Screenshot* Create( 116 nw::os::IAllocator* allocator, 117 size_t maxLength); 118 119 //! @brief ディスプレイバッファからスクリーンショットを設定します。 120 //! 121 //! @param[in] displayDescription ディスプレイバッファの内容です。 122 //! @param[in] srcScreen コピー元のディスプレイバッファの領域です。 123 //! @param[in] length バッファ領域の大きさです。 124 //! @param[in] width スクリーンショットの横幅です。 125 //! @param[in] height スクリーンショットの縦幅です。 126 //! 127 void Set(const DisplayDescription& displayDescription, void* srcScreen, int length, int width, int height); 128 129 //! @brief バッファのサイズを取得します。 GetBufferLength()130 int GetBufferLength() const { return m_Length; } 131 132 //! @brief バッファを取得します。 GetBuffer()133 const void* GetBuffer() const { return m_CopyScreen; } 134 135 //! @brief スクリーンショットの横幅を取得します。 GetWidth()136 int GetWidth() const { return m_Width; } 137 138 //! @brief スクリーンショットの縦幅を取得します。 GetHeight()139 int GetHeight() const { return m_Height; } 140 141 //! @brief デストラクタです。 142 ~Screenshot(); 143 144 private: 145 146 //! @brief コンストラクタです。 Screenshot(nw::os::IAllocator * allocator,void * copyScreen,size_t maxLength,u32 * hash)147 Screenshot( 148 nw::os::IAllocator* allocator, 149 void* copyScreen, 150 size_t maxLength, 151 u32* hash) 152 : m_Allocator(allocator), 153 m_CopyScreen(copyScreen), 154 m_SrcScreen(NULL), 155 m_Length(0), 156 m_MaxLength(maxLength), 157 m_Hash(hash), 158 m_Writed(false), 159 m_Width(0), 160 m_Height(0) 161 {} 162 163 DisplayDescription m_DisplayDescription; 164 nw::os::IAllocator* m_Allocator; 165 void* m_CopyScreen; 166 void* m_SrcScreen; 167 size_t m_Length; 168 size_t m_MaxLength; 169 u32* m_Hash; 170 bool m_Writed; 171 int m_Width; 172 int m_Height; 173 }; 174 175 //! @brief テスト用にスクリーンショットを作成する機能を提供します。 176 class ScreenshotManager 177 { 178 public: 179 //! @brief スクリーンショットの管理クラスを生成します。 180 static ScreenshotManager* Create( 181 nw::os::IAllocator* allocator, 182 int maxScreenshot, 183 int memorySize 184 ); 185 186 //! @brief スクリーンショットを撮影してメモリを確保して保存します。 187 //! 188 //! @return 撮影したスクリーンショットのインデックス番号を返します。 189 int Take( 190 GLenum display, 191 int offsetX = 0, 192 int offsetY = 0); 193 194 //---------------------------------------- 195 //! @name 取得/設定 196 //@{ 197 198 //! @brief 保存したスクリーンショットを削除します。 199 void ClearScreenshots(); 200 201 //! @brief スクリーンショットのリストを表します。 202 typedef ut::MoveArray<Screenshot*> ScreenshotArray; 203 204 //! @brief スクリーンショットのリストの範囲を表す型の定義です。 205 typedef std::pair< 206 ScreenshotArray::iterator, 207 ScreenshotArray::iterator> ScreenshotRange; 208 209 //! @brief スクリーンショットのリストの先頭と末尾を取得します。 GetScreenshots()210 ScreenshotRange GetScreenshots() 211 { 212 return std::make_pair( 213 m_Screenshots.begin(), 214 m_Screenshots.end()); 215 } 216 217 //! @brief スクリーンショットの数を取得します。 GetScreenshotCount()218 int GetScreenshotCount() const { return m_Screenshots.size(); } 219 220 //! @brief 指定したインデックス番号のスクリーンショットを取得します。 GetScreenshot(int index)221 Screenshot* GetScreenshot(int index) 222 { 223 return m_Screenshots[index]; 224 } 225 226 //! @brief 指定したインデックス番号のスクリーンショットを取得します。 GetScreenshot(int index)227 const Screenshot* GetScreenshot(int index) const 228 { 229 return m_Screenshots[index]; 230 } 231 232 //@} 233 234 void Destroy(os::IAllocator* allocator); 235 236 private: 237 //! @brief コンストラクタです。 238 ScreenshotManager( 239 nw::os::IAllocator* allocator, 240 ScreenshotArray screenshots 241 ); 242 243 //! @brief デストラクタです。 244 ~ScreenshotManager(); 245 246 nw::os::IAllocator* m_Allocator; 247 ScreenshotArray m_Screenshots; 248 int m_NextWrited; 249 }; 250 251 #else 252 253 struct DisplayDescription 254 { 255 DisplayDescription() 256 : format(0), 257 width(0), 258 height(0), 259 offsetX(0), 260 offsetY(0), 261 display(0) 262 {} 263 264 GLint format; 265 GLint width; 266 GLint height; 267 int offsetX; 268 int offsetY; 269 GLenum display; 270 }; 271 272 class Screenshot 273 { 274 public: 275 u32* GetHash() { return NULL; } 276 277 const u32* GetHash() const { return NULL; } 278 279 void DumpHash() const {} 280 281 static Screenshot* Create(DisplayDescription, nw::os::IAllocator*, void*, void*, size_t) { return NULL; } 282 283 bool Equal(const Screenshot*) const { return false; } 284 285 bool Equal(const u32*) const { return false; } 286 287 bool IsWrited() const { return false; } 288 289 void Set(const DisplayDescription&, void*, int) {}; 290 private: 291 }; 292 293 class ScreenshotManager 294 { 295 public: 296 static ScreenshotManager* Create(nw::os::IAllocator*, int, int) { return NULL; } 297 298 bool Take(GLenum, int = 0, int = 0) { return false; } 299 300 void ClearScreenshots() {} 301 302 typedef ut::MoveArray<Screenshot*> ScreenshotArray; 303 304 typedef std::pair< 305 ScreenshotArray::iterator, 306 ScreenshotArray::iterator> ScreenshotRange; 307 308 ScreenshotRange GetScreenshots() { return ScreenshotRange(); } 309 310 int GetScreenshotCount() const { return 0; } 311 312 Screenshot* GetScreenshot(int) { return NULL; } 313 314 const Screenshot* GetScreenshot(int) const { return NULL; } 315 316 void Destroy(os::IAllocator*) {} 317 private: 318 }; 319 320 321 #endif // NW_DEV_ENABLED 322 323 } // namespace nw::dev 324 } // namespace nw 325 326 #endif // NW_DEV_SCREENSHOT_H_ 327