1 /*---------------------------------------------------------------------------*
2   Project:  NintendoWare
3   File:     lyt_ResourceAccessor.cpp
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: 19854 $
14  *---------------------------------------------------------------------------*/
15 
16 #include "precompiled.h"
17 
18 #include <nw/lyt/lyt_Layout.h>
19 #include <nw/lyt/lyt_ResourceAccessor.h>
20 #include <nw/lyt/lyt_Resources.h>
21 #include <nw/lyt/lyt_Util.h>
22 
23 namespace nw
24 {
25 namespace lyt
26 {
27 
~ResourceAccessor()28 ResourceAccessor::~ResourceAccessor()
29 {
30 }
31 
ResourceAccessor()32 ResourceAccessor::ResourceAccessor()
33 {
34 }
35 
36 const TextureInfo
LoadTexture(const char * name)37 ResourceAccessor::LoadTexture(const char *name)
38 {
39     u32 size = 0;
40     void* pTexRes = this->GetResource(res::RESOURCETYPE_TEXTURE, name, &size);
41     if (!pTexRes || size == 0)
42     {
43         NW_WARNING(false, "texture resource not found. - %s", name);
44         return TextureInfo();
45     }
46 
47     TextureInfo texInfo = lyt::LoadTexture(pTexRes, size);
48     if (!texInfo.IsValid())
49     {
50         NW_WARNING(false, "texture object unavailable. - %s", name);
51         return TextureInfo();
52     }
53 
54     return texInfo;
55 }
56 
57 font::Font*
LoadFont(const char * name)58 ResourceAccessor::LoadFont(const char *name)
59 {
60     u32 size = 0;
61     void* pFontRes = this->GetResource(res::RESOURCETYPE_FONT, name, &size);
62     if (!pFontRes || size == 0)
63     {
64         NW_WARNING(false, "font resource not found. - %s", name);
65         return NULL;
66     }
67 
68     font::ResFont* pResFont = Layout::NewObj<font::ResFont>();
69     if (pResFont == NULL)
70     {
71         NW_WARNING(false, "font object creation failed.");
72         return NULL;
73     }
74 
75     bool bSuccess = pResFont->SetResource(pFontRes);
76     if (!bSuccess)
77     {
78         NW_WARNING(false, "Fail to load ResFont.");
79         Layout::DeleteObj(pResFont);
80         return NULL;
81     }
82 
83 #if !defined(NW_FONT_TEXTURENAMES_BINARY_ALLOCATED)
84     {
85         const u32 drawBufferSize = font::ResFont::GetDrawBufferSize(pFontRes);
86         void* drawBuffer = Layout::AllocMemory(drawBufferSize, 4);
87         pResFont->SetDrawBuffer(drawBuffer);
88     }
89 #endif
90 
91     return pResFont;
92 }
93 
94 } // namespace nw::lyt
95 } // namespace nw
96