2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <dali/internal/imaging/common/native-bitmap-buffer-impl.h>
22 #include <dali/integration-api/bitmap.h>
23 #include <dali/integration-api/debug.h>
26 #include <dali/internal/graphics/gles/egl-graphics.h>
27 #include <dali/internal/graphics/gles/gl-implementation.h>
35 NativeBitmapBuffer::NativeBitmapBuffer(Adaptor* adaptor, unsigned int width, unsigned int height, Pixel::Format pFormat)
36 : mGlAbstraction(nullptr),
39 mPixelFormat(pFormat),
42 DALI_ASSERT_ALWAYS(adaptor);
43 mBuffer = new Integration::LocklessBuffer(width * height * Pixel::GetBytesPerPixel(pFormat));
45 GraphicsInterface* graphics = &(adaptor->GetGraphicsInterface());
46 auto eglGraphics = static_cast<EglGraphics*>(graphics);
47 mGlAbstraction = &(eglGraphics->GetGlAbstraction());
50 NativeBitmapBuffer::~NativeBitmapBuffer()
55 void NativeBitmapBuffer::PrepareTexture()
57 DALI_ASSERT_ALWAYS(mBuffer);
58 GLenum pixelFormat = GL_RGBA;
59 GLenum pixelDataType = GL_UNSIGNED_BYTE;
61 Integration::ConvertToGlFormat(mPixelFormat, pixelDataType, pixelFormat);
63 const unsigned char* buf = mBuffer->Read();
65 if(buf && buf != mLastReadBuffer) // Prevent same buffer being uploaded multiple times
67 mLastReadBuffer = buf;
69 // The active texture has already been set to a sampler and bound.
70 mGlAbstraction->TexImage2D(GL_TEXTURE_2D, 0, pixelFormat, mWidth, mHeight, 0, pixelFormat, pixelDataType, buf);
74 void NativeBitmapBuffer::Write(const unsigned char* src, size_t size)
76 mBuffer->Write(src, size); // Write will cause LocklessBuffer to switch to the other buffer
79 bool NativeBitmapBuffer::CreateResource()
84 void NativeBitmapBuffer::DestroyResource()
88 unsigned int NativeBitmapBuffer::TargetTexture()
93 unsigned int NativeBitmapBuffer::GetWidth() const
98 unsigned int NativeBitmapBuffer::GetHeight() const
103 bool NativeBitmapBuffer::RequiresBlending() const
105 return Pixel::HasAlpha(mPixelFormat);
108 int NativeBitmapBuffer::GetTextureTarget() const
113 bool NativeBitmapBuffer::ApplyNativeFragmentShader(std::string& shader)
118 const char* NativeBitmapBuffer::GetCustomSamplerTypename() const
123 Any NativeBitmapBuffer::GetNativeImageHandle() const
128 bool NativeBitmapBuffer::SourceChanged() const
133 } // namespace Adaptor
135 } // namespace Internal