Tizen 2.1 base
[framework/osp/uifw.git] / src / ui / effects / renderer / engine-model / FUiEffects_RendererEngineModelRenderTarget.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://floralicense.org/license/
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /**
19  * @file                FUiEffects_RendererEngineModelRenderTarget.cpp
20  * @brief               This file contains implementation of RenderTarget class
21  *
22  */
23
24 #include <renderer/engine-model/FUiEffects_RendererEngineModelRenderTarget.h>
25 #include <renderer/engine-model/FUiEffects_RendererEngineModelRenderTargetVisitor.h>
26
27 namespace Tizen { namespace Ui { namespace Effects { namespace _Renderer
28 {
29 namespace EngineModel
30 {
31
32 RenderTarget::RenderTarget():
33         _width(1),
34         _height(1)
35 {
36 }
37
38 RenderTarget::~RenderTarget(void)
39 {
40         const unsigned int len = RenderTarget::Attachment::ATTACHMENT_MAX;
41         for (unsigned int i = 0; len > i; ++i)
42         {
43                 if (_pTextures[i])
44                 {
45                         _pTextures[i]->RemovedFromRenderTarget(this);
46                 }
47         }
48
49         if (__pCache)
50         {
51                 __pCache->Die();
52         }
53         return;
54 }
55
56 void
57 RenderTarget::Visit(RenderTargetVisitor& v)
58 {
59         v.OnRenderTarget(*this);
60         return;
61 }
62
63 void
64 RenderTarget::AttachTexture2D(Attachment::Value attachment, Texture2DAttachmentPropertyPtr pTexture, size_t mipLevel)
65 {
66         _pTextures[attachment] = pTexture;
67         _attachments[attachment].Set(System::GetImpl(pTexture), mipLevel);
68         pTexture->AttachedToRenderTarget(this);
69         if (__pCache)
70         {
71                 __pCache->Invalidate();
72         }
73         return;
74 }
75
76 void
77 RenderTarget::AttachStub(Attachment::Value attachment, StubAttachmentPtr pStub)
78 {
79         _pTextures[attachment] = pStub;
80         _attachments[attachment].Set(System::GetImpl(pStub));
81         pStub->AttachedToRenderTarget(this);
82         if (__pCache)
83         {
84                 __pCache->Invalidate();
85         }
86         return;
87 }
88
89 void
90 RenderTarget::Detach(Attachment::Value attachment)
91 {
92         if (_pTextures[attachment])
93         {
94                 _pTextures[attachment]->RemovedFromRenderTarget(this);
95         }
96         System::Reset(_pTextures[attachment]);
97
98         if (__pCache)
99         {
100                 __pCache->Invalidate();
101         }
102         return;
103 }
104
105 RenderTarget::AttachInfo*
106 RenderTarget::GetAttachment(Attachment::Value attachment)
107 {
108         if (!_pTextures[attachment])
109         {
110                 return null;
111         }
112         return &_attachments[attachment];
113 }
114
115 CachePtr
116 RenderTarget::GetCache(void)
117 {
118         return __pCache;
119 }
120
121 void
122 RenderTarget::SetCache(CachePtr pCache)
123 {
124         if (__pCache)
125         {
126                 __pCache->Die();
127         }
128         __pCache = pCache;
129         return;
130 }
131
132 unsigned int
133 RenderTarget::GetWidth(void)
134 {
135         return _width;
136 }
137
138 unsigned int
139 RenderTarget::GetHeight(void)
140 {
141         return _height;
142 }
143
144 void
145 RenderTarget::SetSize(unsigned int width, unsigned int height)
146 {
147         _width = width;
148         _height = height;
149         if (__pCache)
150         {
151                 __pCache->Invalidate();
152         }
153         return;
154 }
155
156 }}}}} //Tizen::Ui::Effects::_Renderer::EngineModel