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