2 * Copyright (c) 2015 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/event/rendering/texture-impl.h> // Dali::Internal::Texture
22 #include <dali/internal/update/manager/update-manager.h>
23 #include <dali/internal/event/common/stage-impl.h>
30 NewTexturePtr NewTexture::New(TextureType::Type type, Pixel::Format format, unsigned int width, unsigned int height )
32 NewTexturePtr texture( new NewTexture( type, format, width, height ) );
33 texture->Initialize();
37 NewTexturePtr NewTexture::New( NativeImageInterface& nativeImageInterface )
39 NewTexturePtr texture( new NewTexture( &nativeImageInterface ) );
40 texture->Initialize();
44 Render::NewTexture* NewTexture::GetRenderObject() const
49 NewTexture::NewTexture(TextureType::Type type, Pixel::Format format, unsigned int width, unsigned int height )
50 : mEventThreadServices( *Stage::GetCurrent() ),
51 mRenderObject( NULL ),
60 NewTexture::NewTexture( NativeImageInterfacePtr nativeImageInterface )
61 : mEventThreadServices( *Stage::GetCurrent() ),
62 mRenderObject( NULL ),
63 mNativeImage( nativeImageInterface ),
64 mType( TextureType::TEXTURE_2D ),
65 mFormat( Pixel::RGB888 ),
66 mWidth( nativeImageInterface->GetWidth() ),
67 mHeight( nativeImageInterface->GetHeight() )
71 void NewTexture::Initialize()
75 mRenderObject = new Render::NewTexture( mNativeImage );
79 mRenderObject = new Render::NewTexture( mType, mFormat, mWidth, mHeight );
82 AddTexture( mEventThreadServices.GetUpdateManager(), *mRenderObject );
85 NewTexture::~NewTexture()
87 if( EventThreadServices::IsCoreRunning() && mRenderObject )
89 RemoveTexture( mEventThreadServices.GetUpdateManager(), *mRenderObject );
93 bool NewTexture::CheckUploadParametres( const Vector<unsigned char>& buffer, const UploadParams& parameters ) const
97 DALI_LOG_ERROR( "Error: Uploading data to a native texture");
100 else if( buffer.Size() < GetBytesPerPixel( mFormat ) * parameters.width * parameters.height )
102 DALI_LOG_ERROR( "Error: Buffer of an incorrect size when trying to update texture");
105 else if( ( parameters.xOffset + parameters.width > static_cast<unsigned int>( mWidth/(1<<parameters.mipmap ))) ||
106 ( parameters.yOffset + parameters.height > static_cast<unsigned int>( mHeight/(1<<parameters.mipmap ))))
108 DALI_LOG_ERROR( "Error: Out of bounds texture update");
117 void NewTexture::Upload( Vector<unsigned char>& buffer,
118 unsigned int layer, unsigned int mipmap,
119 unsigned int xOffset, unsigned int yOffset,
120 unsigned int width, unsigned int height )
122 UploadParams params = { layer, mipmap, xOffset, yOffset, width, height };
123 if( CheckUploadParametres( buffer, params ) )
125 UploadTextureMessage(mEventThreadServices.GetUpdateManager(), *mRenderObject, buffer, params );
129 void NewTexture::Upload( Vector<unsigned char>& buffer )
131 UploadParams params = {0u,0u,0u,0u,mWidth,mHeight};
132 if( CheckUploadParametres( buffer, params ) )
134 UploadTextureMessage(mEventThreadServices.GetUpdateManager(), *mRenderObject, buffer, params );
138 void NewTexture::GenerateMipmaps()
140 GenerateMipmapsMessage(mEventThreadServices.GetUpdateManager(), *mRenderObject );
143 unsigned int NewTexture::GetWidth() const
148 unsigned int NewTexture::GetHeight() const
153 } // namespace Internal