⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 agg_platform_support.cpp

📁 gnash 在pc和嵌入式下开发需要的源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//----------------------------------------------------------------------------// Anti-Grain Geometry (AGG) - Version 2.5// A high quality rendering engine for C++// Copyright (C) 2002-2006 Maxim Shemanarev// Copyright (C) 2004 Steven Solie// Contact: mcseem@antigrain.com//          mcseemagg@yahoo.com//          http://antigrain.com// // AGG is free software; you can redistribute it and/or// modify it under the terms of the GNU General Public License// as published by the Free Software Foundation; either version 2// of the License, or (at your option) any later version.// // AGG is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the// GNU General Public License for more details.// // You should have received a copy of the GNU General Public License// along with AGG; if not, write to the Free Software// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, // MA 02110-1301, USA.//----------------------------------------------------------------------------#include "platform/agg_platform_support.h"#include "util/agg_color_conv_rgb8.h"#include <sys/time.h>#include <cstring>#include <classes/requester.h>#include <classes/window.h>#include <datatypes/pictureclass.h>#include <proto/exec.h>#include <proto/datatypes.h>#include <proto/dos.h>#include <proto/graphics.h>#include <proto/intuition.h>#include <proto/keymap.h>#include <proto/Picasso96API.h>#include <proto/utility.h>Library* DataTypesBase = 0;Library* GraphicsBase = 0;Library* IntuitionBase = 0;Library* KeymapBase = 0;Library* P96Base = 0;DataTypesIFace* IDataTypes = 0;GraphicsIFace* IGraphics = 0;IntuitionIFace* IIntuition = 0;KeymapIFace* IKeymap = 0;P96IFace* IP96 = 0;Class* RequesterClass = 0;Class* WindowClass = 0;namespace agg{	void handle_idcmp(Hook* hook, APTR win, IntuiMessage* msg);	//------------------------------------------------------------------------	class platform_specific	{	public:		platform_specific(platform_support& support, pix_format_e format,			bool flip_y);		~platform_specific();		bool handle_input();		bool load_img(const char* file, unsigned idx, rendering_buffer* rbuf);		bool create_img(unsigned idx, rendering_buffer* rbuf, unsigned width,			unsigned height);		bool make_bitmap();	public:		platform_support& m_support;		RGBFTYPE m_ftype;		pix_format_e m_format;		unsigned m_bpp;		BitMap* m_bitmap;		bool m_flip_y;		uint16 m_width;		uint16 m_height;		APTR m_window_obj;		Window* m_window;		Hook* m_idcmp_hook;		unsigned m_input_flags;		bool m_dragging;		double m_start_time;		uint16 m_last_key;		BitMap* m_img_bitmaps[platform_support::max_images];	};	//------------------------------------------------------------------------	platform_specific::platform_specific(platform_support& support,		pix_format_e format, bool flip_y) :		m_support(support),		m_ftype(RGBFB_NONE),		m_format(format),		m_bpp(0),		m_bitmap(0),		m_flip_y(flip_y),		m_width(0),		m_height(0),		m_window_obj(0),		m_window(0),		m_idcmp_hook(0),		m_input_flags(0),		m_dragging(false),		m_start_time(0.0),		m_last_key(0)	{		switch ( format )		{		case pix_format_gray8:			// Not supported.			break;		case pix_format_rgb555:			m_ftype = RGBFB_R5G5B5;			m_bpp = 15;			break;		case pix_format_rgb565:			m_ftype = RGBFB_R5G6B5;			m_bpp = 16;			break;		case pix_format_rgb24:			m_ftype = RGBFB_R8G8B8;			m_bpp = 24;			break;		case pix_format_bgr24:			m_ftype = RGBFB_B8G8R8;			m_bpp = 24;			break;		case pix_format_bgra32:			m_ftype = RGBFB_B8G8R8A8;			m_bpp = 32;			break;		case pix_format_abgr32:			m_ftype = RGBFB_A8B8G8R8;			m_bpp = 32;			break;		case pix_format_argb32:			m_ftype = RGBFB_A8R8G8B8;			m_bpp = 32;			break;        case pix_format_rgba32:			m_ftype = RGBFB_R8G8B8A8;			m_bpp = 32;			break;		}		for ( unsigned i = 0; i < platform_support::max_images; ++i )		{			m_img_bitmaps[i] = 0;		}	}	//------------------------------------------------------------------------	platform_specific::~platform_specific()	{		IIntuition->DisposeObject(m_window_obj);		IP96->p96FreeBitMap(m_bitmap);		for ( unsigned i = 0; i < platform_support::max_images; ++i )		{			IP96->p96FreeBitMap(m_img_bitmaps[i]);		}		if ( m_idcmp_hook != 0 )		{			IExec->FreeSysObject(ASOT_HOOK, m_idcmp_hook);		}	}	//------------------------------------------------------------------------	bool platform_specific::handle_input()	{		int16 code = 0;		uint32 result = 0;		Object* obj = reinterpret_cast<Object*>(m_window_obj);		while ( (result = IIntuition->IDoMethod(obj, WM_HANDLEINPUT,				&code)) != WMHI_LASTMSG )		{			switch ( result & WMHI_CLASSMASK )			{			case WMHI_CLOSEWINDOW:				return true;				break;			case WMHI_INTUITICK:				if ( !m_support.wait_mode() )				{					m_support.on_idle();				}				break;			case WMHI_NEWSIZE:				if ( make_bitmap() )				{					m_support.trans_affine_resizing(m_width, m_height);					m_support.on_resize(m_width, m_height);					m_support.force_redraw();				}				break;			}		}		return false;	}			//------------------------------------------------------------------------	bool platform_specific::load_img(const char* file, unsigned idx,		rendering_buffer* rbuf)	{		if ( m_img_bitmaps[idx] != 0 )		{			IP96->p96FreeBitMap(m_img_bitmaps[idx]);			m_img_bitmaps[idx] = 0;		}		bool result = false;		Object* picture = IDataTypes->NewDTObject(const_cast<STRPTR>(file),			DTA_GroupID, GID_PICTURE,			PDTA_DestMode, PMODE_V43,			PDTA_Remap, FALSE,			TAG_END);		if ( picture != 0 )		{			gpLayout layout;			layout.MethodID = DTM_PROCLAYOUT;			layout.gpl_GInfo = 0;			layout.gpl_Initial = 1;			ULONG loaded = IDataTypes->DoDTMethodA(picture, 0, 0,				reinterpret_cast<Msg>(&layout));			if ( loaded != 0 )			{				BitMap* src_bitmap = 0;				IDataTypes->GetDTAttrs(picture,					PDTA_ClassBitMap, &src_bitmap,					TAG_END);				bool supported = false;				RGBFTYPE ftype = static_cast<RGBFTYPE>(IP96->p96GetBitMapAttr(					src_bitmap, P96BMA_RGBFORMAT));				switch ( ftype )				{				case RGBFB_R8G8B8:					supported = true;					break;				default:					m_support.message("File uses unsupported graphics mode.");					break;				}				if ( supported )  {					uint16 width = IP96->p96GetBitMapAttr(src_bitmap,						P96BMA_WIDTH);					uint16 height = IP96->p96GetBitMapAttr(src_bitmap,						P96BMA_HEIGHT);					m_img_bitmaps[idx] = IP96->p96AllocBitMap(width, height,						m_bpp, BMF_USERPRIVATE, 0, m_ftype);					if ( m_img_bitmaps[idx] != 0 )					{						int8u* buf = reinterpret_cast<int8u*>(							IP96->p96GetBitMapAttr(m_img_bitmaps[idx],							P96BMA_MEMORY));						int bpr = IP96->p96GetBitMapAttr(m_img_bitmaps[idx],							P96BMA_BYTESPERROW);						int stride = (m_flip_y) ? -bpr : bpr;						rbuf->attach(buf, width, height, stride);						// P96 sets the alpha to zero so it can't be used to						// color convert true color modes.						if ( m_bpp == 32 )						{							RenderInfo ri;							int32 lock = IP96->p96LockBitMap(src_bitmap,								reinterpret_cast<uint8*>(&ri),								sizeof(RenderInfo));							rendering_buffer rbuf_src;							rbuf_src.attach(								reinterpret_cast<int8u*>(ri.Memory),								width, height, (m_flip_y) ?									-ri.BytesPerRow : ri.BytesPerRow);							switch ( m_format )							{							case pix_format_bgra32:								color_conv(rbuf, &rbuf_src,									color_conv_rgb24_to_bgra32());								break;							case pix_format_abgr32:								color_conv(rbuf, &rbuf_src,									color_conv_rgb24_to_abgr32());								break;							case pix_format_argb32:								color_conv(rbuf, &rbuf_src,									color_conv_rgb24_to_argb32());								break;							case pix_format_rgba32:								color_conv(rbuf, &rbuf_src,									color_conv_rgb24_to_rgba32());								break;							}							IP96->p96UnlockBitMap(src_bitmap, lock);						}						else						{							IGraphics->BltBitMap(src_bitmap, 0, 0,								m_img_bitmaps[idx], 0, 0, width, height,								ABC|ABNC, 0xFF, 0);						}						result = true;					}				}			}		}		IGraphics->WaitBlit();		IDataTypes->DisposeDTObject(picture);		return result;	}	//------------------------------------------------------------------------	bool platform_specific::create_img(unsigned idx, rendering_buffer* rbuf,		unsigned width, unsigned height)	{		if ( m_img_bitmaps[idx] != 0 )		{			IP96->p96FreeBitMap(m_img_bitmaps[idx]);			m_img_bitmaps[idx] = 0;		}		m_img_bitmaps[idx] = IP96->p96AllocBitMap(width, height,			m_bpp, BMF_USERPRIVATE, m_bitmap, m_ftype);		if ( m_img_bitmaps[idx] != 0 )		{			int8u* buf = reinterpret_cast<int8u*>(				IP96->p96GetBitMapAttr(m_img_bitmaps[idx],				P96BMA_MEMORY));			int bpr = IP96->p96GetBitMapAttr(m_img_bitmaps[idx],				P96BMA_BYTESPERROW);			int stride = (m_flip_y) ? -bpr : bpr;			rbuf->attach(buf, width, height, stride);			return true;		}		return false;	}	//------------------------------------------------------------------------	bool platform_specific::make_bitmap()	{		uint32 width = 0;		uint32 height = 0;		IIntuition->GetWindowAttrs(m_window,			WA_InnerWidth, &width,			WA_InnerHeight, &height,			TAG_END);		BitMap* bm = IP96->p96AllocBitMap(width, height, m_bpp,			BMF_USERPRIVATE|BMF_CLEAR, 0, m_ftype);		if ( bm == 0 )		{			return false;		}		int8u* buf = reinterpret_cast<int8u*>(			IP96->p96GetBitMapAttr(bm, P96BMA_MEMORY));		int bpr = IP96->p96GetBitMapAttr(bm, P96BMA_BYTESPERROW);		int stride = (m_flip_y) ? -bpr : bpr;		m_support.rbuf_window().attach(buf, width, height, stride);		if ( m_bitmap != 0 )		{			IP96->p96FreeBitMap(m_bitmap);			m_bitmap = 0;		}		m_bitmap = bm;		m_width = width;		m_height = height;		return true;	}	//------------------------------------------------------------------------	platform_support::platform_support(pix_format_e format, bool flip_y) :		m_specific(new platform_specific(*this, format, flip_y)),		m_format(format),		m_bpp(m_specific->m_bpp),		m_window_flags(0),		m_wait_mode(true),		m_flip_y(flip_y),		m_initial_width(10),		m_initial_height(10)	{		std::strncpy(m_caption, "Anti-Grain Geometry", 256);	}	//------------------------------------------------------------------------	platform_support::~platform_support()	{		delete m_specific;	}	//------------------------------------------------------------------------	void platform_support::caption(const char* cap)	{		std::strncpy(m_caption, cap, 256);		if ( m_specific->m_window != 0 )		{			const char* ignore = reinterpret_cast<const char*>(-1);			IIntuition->SetWindowAttr(m_specific->m_window,				WA_Title, m_caption, sizeof(char*));		}	}	//------------------------------------------------------------------------	void platform_support::start_timer()	{		timeval tv;		gettimeofday(&tv, 0);		m_specific->m_start_time = tv.tv_secs + tv.tv_micro/1e6;	}	//------------------------------------------------------------------------	double platform_support::elapsed_time() const	{		timeval tv;		gettimeofday(&tv, 0);		double end_time = tv.tv_secs + tv.tv_micro/1e6;		double elasped_seconds = end_time - m_specific->m_start_time;		double elasped_millis = elasped_seconds*1e3;		return elasped_millis;	}	//------------------------------------------------------------------------	void* platform_support::raw_display_handler()	{		return 0;	// Not available.	}	//------------------------------------------------------------------------	void platform_support::message(const char* msg)	{		APTR req = IIntuition->NewObject(RequesterClass, 0,			REQ_TitleText, "Anti-Grain Geometry",			REQ_Image, REQIMAGE_INFO,			REQ_BodyText, msg,			REQ_GadgetText, "_Ok",			TAG_END);		if ( req == 0 )		{			IDOS->Printf("Message: %s\n", msg);			return;		}		orRequest reqmsg;		reqmsg.MethodID = RM_OPENREQ;		reqmsg.or_Attrs = 0;		reqmsg.or_Window = m_specific->m_window;		reqmsg.or_Screen = 0;				IIntuition->IDoMethodA(reinterpret_cast<Object*>(req),			reinterpret_cast<Msg>(&reqmsg));		IIntuition->DisposeObject(req);	}	//------------------------------------------------------------------------	bool platform_support::init(unsigned width, unsigned height,		unsigned flags)	{		if( m_specific->m_ftype == RGBFB_NONE )		{			message("Unsupported mode requested.");			return false;		}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -