Back to index

unity  6.0.0
CairoTexture.h
Go to the documentation of this file.
00001 // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
00002 /*
00003  * Copyright 2011 Canonical Ltd.
00004  *
00005  * This program is free software: you can redistribute it and/or modify it
00006  * under the terms of the GNU Lesser General Public License version 3, as
00007  * published by the  Free Software Foundation.
00008  *
00009  * This program is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranties of
00011  * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
00012  * PURPOSE.  See the applicable version of the GNU Lesser General Public
00013  * License for more details.
00014  *
00015  * You should have received a copy of both the GNU Lesser General Public
00016  * License version 3 along with this program.  If not, see
00017  * <http://www.gnu.org/licenses/>
00018  *
00019  * Authored by: Tim Penhey <tim.penhey@canonical.com>
00020  *
00021  */
00022 
00023 #ifndef UNITY_CAIROTEXTURE_H
00024 #define UNITY_CAIROTEXTURE_H
00025 
00026 #include <Nux/Nux.h>
00027 #include <NuxGraphics/CairoGraphics.h>
00028 #include <NuxGraphics/NuxGraphics.h>
00029 #include <NuxGraphics/GLTextureResourceManager.h>
00030 
00031 namespace unity
00032 {
00033 
00034 typedef nux::ObjectPtr<nux::BaseTexture> BaseTexturePtr;
00035 
00036 // Create a texture from the CairoGraphics object.
00037 //
00038 // Returns a new BaseTexture that has a ref count of 1.
00039 inline nux::BaseTexture* texture_from_cairo_graphics(nux::CairoGraphics& cg)
00040 {
00041   nux::NBitmapData* bitmap = cg.GetBitmap();
00042   nux::BaseTexture* tex = nux::GetGraphicsDisplay()->GetGpuDevice()->CreateSystemCapableTexture();
00043   tex->Update(bitmap);
00044   delete bitmap;
00045   return tex;
00046 }
00047 
00048 // Create a texture from the CairoGraphics object.
00049 //
00050 // Returns a new smart pointer to a texture where that smart pointer is the
00051 // sole owner of the texture object.
00052 inline BaseTexturePtr texture_ptr_from_cairo_graphics(nux::CairoGraphics& cg)
00053 {
00054   BaseTexturePtr result(texture_from_cairo_graphics(cg));
00055   // Since the ObjectPtr takes a reference, and the texture is initially
00056   // owned, the reference count now is two.
00057   nuxAssert(result->GetReferenceCount() == 2);
00058   result->UnReference();
00059   return result;
00060 }
00061 
00062 }
00063 
00064 #endif