Removing rendering backend
[platform/core/uifw/dali-core.git] / dali / internal / update / rendering / scene-graph-property-buffer.cpp
1 /*
2  * Copyright (c) 2018 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali/internal/update/rendering/scene-graph-property-buffer.h>
20
21 // INTERNAL HEADERS
22 #include <dali/internal/event/common/property-buffer-impl.h>  // Dali::Internal::PropertyBuffer
23 #include <dali/graphics-api/graphics-api-controller.h>
24 #include <dali/graphics-api/graphics-api-buffer.h>
25
26
27 namespace Dali
28 {
29 namespace Internal
30 {
31 namespace SceneGraph
32 {
33
34 PropertyBuffer::PropertyBuffer()
35 : mGraphics( nullptr ),
36   mFormat( nullptr ),
37   mData( nullptr ),
38   mSize(0),
39   mDataChanged(true),
40   mGraphicsBuffer{ nullptr },
41   mGraphicsBufferUsage{ Graphics::API::Buffer::UsageHint::ATTRIBUTES }
42 {
43 }
44
45 PropertyBuffer::~PropertyBuffer()
46 {
47 }
48
49 void PropertyBuffer::Initialize( Integration::Graphics::Graphics& graphics )
50 {
51   mGraphics = &graphics;
52 }
53
54 void PropertyBuffer::SetUsage( Graphics::API::Buffer::UsageHint usage )
55 {
56   mGraphicsBufferUsage = usage;
57 }
58
59 void PropertyBuffer::SetFormat( OwnerPointer< PropertyBuffer::Format >& format )
60 {
61   mFormat.Swap( format );
62   mDataChanged = true;
63 }
64
65 void PropertyBuffer::SetData( OwnerPointer< Dali::Vector<char> >& data, size_t size )
66 {
67   mData.Swap( data );
68   mSize = size;
69   mDataChanged = true;
70
71   if( mGraphics )
72   {
73     auto& controller = mGraphics->GetController();
74     mGraphicsBuffer = controller.CreateBuffer( controller.GetBufferFactory()
75                                            .SetSize( uint32_t( mFormat->size * size) )
76                                            .SetUsage(Graphics::API::Buffer::UsageHint::ATTRIBUTES ));
77
78   }
79 }
80
81 bool PropertyBuffer::Update( Dali::Graphics::API::Controller& controller )
82 {
83   if( !mData || !mFormat || !mSize )
84   {
85     return false;
86   }
87
88   if( mDataChanged || !mGraphicsBuffer )
89   {
90     if( !mGraphicsBuffer )
91     {
92       mGraphicsBuffer = controller.CreateBuffer( controller.GetBufferFactory()
93                                                       .SetUsage( mGraphicsBufferUsage )
94                                                       .SetSize( mSize ) );
95     }
96
97     // schedule deferred write
98     mGraphicsBuffer.Get().Write( mData.Get()->begin(), GetDataSize(), 0u );
99
100     mDataChanged = false;
101   }
102
103   return true;
104 }
105
106 } //Render
107 } //Internal
108 } //Dali