Dali 3D User Interface Engine
native-bitmap-buffer-impl.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014 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
20 
21 // EXTERNAL HEADERS
24 
25 // INTERNAL HEADERS
27 
28 namespace Dali
29 {
30 
31 namespace Internal
32 {
33 
34 namespace Adaptor
35 {
36 
37 NativeBitmapBuffer::NativeBitmapBuffer( Adaptor* adaptor, unsigned int width, unsigned int height, Pixel::Format pFormat )
38 : mWidth(width),
39  mHeight(height),
40  mPixelFormat(pFormat),
41  mLastReadBuffer(NULL)
42 {
43  DALI_ASSERT_ALWAYS( adaptor );
44  mBuffer = new Integration::LocklessBuffer( width * height * Pixel::GetBytesPerPixel(pFormat) );
45  mGlAbstraction = &(adaptor->GetGlAbstraction());
46 }
47 
49 {
50  delete mBuffer;
51 }
52 
54 {
56  GLenum pixelFormat = GL_RGBA;
57  GLenum pixelDataType = GL_UNSIGNED_BYTE;
58 
59  Integration::ConvertToGlFormat( mPixelFormat, pixelDataType, pixelFormat );
60 
61  const unsigned char* buf = mBuffer->Read();
62 
63  if( buf && buf != mLastReadBuffer ) // Prevent same buffer being uploaded multiple times
64  {
65  mLastReadBuffer = buf;
66 
67  // The active texture has already been set to a sampler and bound.
68  mGlAbstraction->TexImage2D( GL_TEXTURE_2D, 0, pixelFormat, mWidth, mHeight, 0, pixelFormat, pixelDataType, buf );
69  }
70 }
71 
72 void NativeBitmapBuffer::Write( const unsigned char *src, size_t size )
73 {
74  mBuffer->Write( src, size ); // Write will cause LocklessBuffer to switch to the other buffer
75 }
76 
78 {
79  return true;
80 }
81 
83 {
84 }
85 
87 {
88  return 0;
89 }
90 
91 unsigned int NativeBitmapBuffer::GetWidth() const
92 {
93  return mWidth;
94 }
95 
96 unsigned int NativeBitmapBuffer::GetHeight() const
97 {
98  return mHeight;
99 }
100 
102 {
103  return Pixel::HasAlpha( mPixelFormat );
104 }
105 
106 } // namespace Adaptor
107 
108 } // namespace Internal
109 
110 } // namespace Dali
Dali Docs Home
Read more about Dali