Skia drawing test

Source: Internet
Author: User
Tags skia

/***************************************. MK *************************************** *************/

Local_path: = $ (call my-DIR)
Include $ (clear_vars)
Local_prelink_module: = false
Local_src_files: = \
Ilivesearchservice. cpp \
Livesearchservice. cpp \
Commonconvertor. cpp \
Isystemcontrolservice. cpp \
Systemcontrolservice. cpp \
Iliveplayservice. cpp \
Liveplayservice. cpp \
Iepgservice. cpp \
Epgservice. cpp \
Isysteminfoservice. cpp \
Systeminfoservice. cpp \
Idvbupdateservice. cpp \
Dvbupdateservice. cpp \
Ilivebouquetservice. cpp \
Livebouquetservice. cpp \
Livedrawservice. cpp \

Local_shared_libraries: = \
Libui libcutils libutils libbinder libsonivox libicuuc libexpat \
Libdl \
Libandroid_runtime \
Libsurfaceflinger_client \
Libskia

Local_shared_libraries + = libstlport \

Local_shared_libraries + = libdm \

Local_module: = libnativedm

Local_module_tags: = ENG

Local_c_includes: = \
$ (Jni_h_include )\
Ccdt/frameworks/base/DVB/libdm \
$ (Top)/external/stlport \
$ (Top)/external/skia/include/core \
$ (Top)/external/skia/include/utils \
Ccdt/frameworks/base/DVB/libdm/src/DVB/dvbcore/iservice/epgreceiver \
Ccdt/frameworks/base/DVB/libdm/src/DVB/dvbcore/iservice/programsearch \
Ccdt/frameworks/base/DVB/libdm/src/DVB/dvbcore/iservice/servicefactory \
Ccdt/frameworks/base/DVB/libdm/src/DVB/dvbcore/iservice/systemcontrol \
Ccdt/frameworks/base/DVB/libdm/src/DVB/dvbcore/iservice/programplay \
Ccdt/frameworks/base/DVB/libdm/src/DVB/dvbcore/iservice/systeminfo \
Ccdt/frameworks/base/DVB/libdm/src/DVB/dvbcore/iservice/bouquetmonitor \
Ccdt/frameworks/base/DVB/libdm/src/DVB/dvbcore/iservice/otaloader \
Ccdt/frameworks/base/DVB/libdm/src/DVB/ddmanager \
Ccdt/frameworks/base/DVB/libdm/src/DVB/dvbcore/component/notification \
Ccdt/frameworks/base/DVB/libdm/src/DVB/dvbcore/component/tablefilter \
Ccdt/frameworks/base/DVB/libdm/src/DVB/dvbcore/component/sectionfilter \
Ccdt/frameworks/base/DVB/libdm/src/DVB/dvbcore/component/frontmonitor \
Ccdt/frameworks/base/DVB/libdm/src/DVB/dvbcore/component/tablesystem \
Ccdt/frameworks/base/DVB/libdm/src/include \
Ccdt/frameworks/base/DVB/libdm // src/DVB/dvbcore/include \
Ccdt/frameworks/base/DVB/libdm/src/DD/include \
Ccdt/frameworks/base/DVB/libdm/src/DVB/utils \

Include $ (build_shared_library)

/*************************************** ****. H *************************************** *********************/

# Ifndef livedrawservice_h
# Define livedrawservice_h

# Include <utils/Threads. h>
# Include <utils/string16.h>

# Include <surfaceflinger/surfacecomposerclient. h>
# Include <surfaceflinger/surface. h>
# Include <surfaceflinger/isurfacecomposer. h>

# Include <skcanvas. h>
# Include <skregion. h>
# Include <skbitmap. h>

Namespace Android {

Enum epixelformat {
Pixelformat_32bitrgba = pixel_format_rgba_8888, // 4x8-bit rgba
Pixelformat_32bitrgb0 = pixel_format_rgbx_8888, // 4x8-bit rgb0
Pixelformat_24bitrgb = pixel_format_rgb_888, // 3x8-bit RGB
Pixelformat_16bitrgb = pixel_format_rgb_565, // 16-bit RGB
Pixelformat_32bitbgra = pixel_format_bgra_8888, // 4x8-bit bgra
Pixelformat_16bitargb5551 = pixel_format_rgba_5551, // 16-bit argb
Pixelformat_16bitargb4444 = pixel_format_rgba_4444, // 16-bit argb
};

Enum ecolorconfig {
Colorconfig_kargb4444 = skbitmap: kargb_4444_config ,//! <16-bits per pixel, (see skcolorpriv. h for packing)
Colorconfig_kargb8888 = skbitmap: kargb_8888_config ,//! <32-bits per pixel, (see skcolorpriv. h for packing)
};

Class livedrawservice
{
Public:

Int open (INT canvasid, int X, int y, int W, int H, epixelformat mpixelformat, ecolorconfig rgbconfig );
Int close (INT canvasid );
Int closeall ();
Int drawbuffer (INT canvasid, void * picbuffer, int W, int H, int X, int y, int alphavalue, ecolorconfig rgbconfig );
Int clearcanvas (INT canvasid );
Int hidecanvas (INT canvasid );
Int showcanvas (INT canvasid );
Livedrawservice ();
~ Livedrawservice ();
};

Class dvbcanvasmanager
{
Public:
Sp <surfacecomposerclient> videoclient;
Sp <surfacecontrol> spsurctrl;
Surfacecontrol * surcontrl;
Sp <surface> Sur;
Skcanvas * canvas;
Skpaint * paint;
Int canvaswidth, canvasheight;
Ecolorconfig mcolorconfig;
Int drawbuffer (void * picbuffer, int W, int H, int X, int y, ecolorconfig rgbconfig, int alphavalue, bool isclearbefor );
Int clearcanvas ();
Int hidecanvas ();
Int showcanvas ();
Int getbytesperpixbyrgbconfig (ecolorconfig rgbconfig );

};

} // End namespace android
# Endif // livedrawservice_h

/************************************ CPP ** **************************************** *****/
# Include "livedrawservice. H"

# Include <stdlib. h>
# Include <stdio. h>
# Include <utils/log. h>

Using namespace android;

STD: Map <int, dvbcanvasmanager> allcanvasmap;
Int pid =-1;
Skcolor color [2] = {0xaf00ff00, 0xaf0000ff };
Int indexcolor = 1;

Livedrawservice: livedrawservice ()
{

PID = getpid ();
// Canvas 1
Int buffer [500*100];
For (INT I = 0; I <20000; I ++ ){
Buffer [I] = 0xff00ff00;
}
For (INT I = 20000; I <50000; I ++ ){
Buffer [I] = 0xff0000ff;
}
Open (1,500,150,300,500, pixelformat_32bitrgba, colorconfig_kargb8888 );
Drawbuffer (1, buffer, 500,100,-1, colorconfig_kargb8888 );

// Canvas 2
Int buffer2 [100*1000];
For (INT I = 0; I <50000; I ++ ){
Buffer2 [I] = 0xff00ff00;
}
For (INT I = 50000; I <100000; I ++ ){
Buffer2 [I] = 0xff0000ff;
}
Open (2,100,600,120, pixelformat_32bitrgba, colorconfig_kargb8888 );
Drawbuffer (2, buffer2, 1000,100, 0,-1, colorconfig_kargb8888 );

}

Livedrawservice ::~ Livedrawservice ()
{

}

Int livedrawservice: open (INT canvasid, int X, int y, int W, int H, epixelformat mpixelformat, ecolorconfig mcolorconfig)
{
Logi ("% s in [x = % d, y = % d, W = % D, H = % d]" ,__ function __, X, Y, W, h );

STD: Map <int, dvbcanvasmanager >:: iterator itcanvas = allcanvasmap. Find (canvasid );

If (itcanvas = allcanvasmap. End () {// not exist open it
Logi ("open new canvas !! ");
Dvbcanvasmanager * onecanvasmanager = new dvbcanvasmanager ();
Onecanvasmanager-> videoclient = new surfacecomposerclient;
If (onecanvasmanager-> videoclient = NULL ){
Logi ("onecanvasmanager-> videoclient = NULL !! Return ");
}
Onecanvasmanager-> spsurctrl = onecanvasmanager-> videoclient-> createsurface (PID, 0, W, H, mpixelformat, 0 );
Onecanvasmanager-> surcontrl = onecanvasmanager-> spsurctrl. Get ();
Onecanvasmanager-> sur = onecanvasmanager-> surcontrl-> getsurface ();
Onecanvasmanager-> mcolorconfig = mcolorconfig;
Onecanvasmanager-> videoclient-> opentransaction (); // set surface value
Onecanvasmanager-> spsurctrl-> setsize (W, H );
Onecanvasmanager-> spsurctrl-> setposition (x, y );
Onecanvasmanager-> spsurctrl-> setlayer (1000000 );
Onecanvasmanager-> spsurctrl-> hide ();
Onecanvasmanager-> videoclient-> closetransaction (); // end Sets

Skbitmap * pbitmap = new skbitmap ();
Pbitmap-> setconfig (skbitmap: config) mcolorconfig, W, H );

Pbitmap-> allocpixels ();
Surface: surfaceinfo Info;

Onecanvasmanager-> sur-> lock (& info); // set surface to info, about X, Y, W, H lock surface to get data form it
Pbitmap-> setpixels (info. bits); // build bitmap from Info
Onecanvasmanager-> sur-> unlockandpost (); // release surface after get data

Onecanvasmanager-> canvas = new skcanvas (* pbitmap); // build canvas form bitmap
Onecanvasmanager-> canvaswidth = W;
Onecanvasmanager-> canvasheight = h;
Onecanvasmanager-> paint = new skpaint ();
Onecanvasmanager-> videoclient-> opentransaction ();
Onecanvasmanager-> spsurctrl-> show ();
Onecanvasmanager-> videoclient-> closetransaction ();

Allcanvasmap. insert (STD: make_pair (canvasid, * onecanvasmanager ));
Delete onecanvasmanager;
Logi ("open new canvas over !! ");
} Else {
Logi ("This canvasid is opened no need to open !! Canvasid = % d ", canvasid );
}
Return 1;
}

Int livedrawservice: Close (INT canvasid)
{
Allcanvasmap. Erase (canvasid );
Return 1;
}

Int livedrawservice: closeall ()
{
Allcanvasmap. Clear ();
Return 1;
}

/*******************
* Livedrawservice draw Buffer
********************/
Int livedrawservice: drawbuffer (INT canvasid, void * picbuffer, int W, int H, int X, int y, int alphavalue, ecolorconfig rgbconfig)
{
Logi ("% s in canvasid = % d !! ",__ Function __, canvasid );
STD: Map <int, dvbcanvasmanager >:: iterator itcanvas = allcanvasmap. Find (canvasid );

If (itcanvas = allcanvasmap. End () {// not exist return
Logi ("% s in, canvasid = % d not getcanvas !! ",__ Function __, canvasid );
Return-1;
} Else {
Return (* itcanvas). Second. drawbuffer (picbuffer, W, H, X, Y, rgbconfig, alphavalue, true );
}
Return-1;
}

Int livedrawservice: clearcanvas (INT canvasid)
{
Logi ("% s in canvasid = % d !! ",__ Function __, canvasid );
STD: Map <int, dvbcanvasmanager >:: iterator itcanvas = allcanvasmap. Find (canvasid );
If (itcanvas = allcanvasmap. End () {// not exist return
Logi ("% s in, canvasid = % d not getcanvas !! ",__ Function __, canvasid );
Return-1;
} Else {
Return (* itcanvas). Second. clearcanvas ();
}
}

Int livedrawservice: hidecanvas (INT canvasid)
{
Logi ("% s in canvasid = % d !! ",__ Function __, canvasid );
STD: Map <int, dvbcanvasmanager >:: iterator itcanvas = allcanvasmap. Find (canvasid );
If (itcanvas = allcanvasmap. End () {// not exist return
Logi ("% s in, canvasid = % d not getcanvas !! ",__ Function __, canvasid );
Return-1;
} Else {
Return (* itcanvas). Second. hidecanvas ();
}
}

Int livedrawservice: showcanvas (INT canvasid)
{
Logi ("% s in canvasid = % d !! ",__ Function __, canvasid );
STD: Map <int, dvbcanvasmanager >:: iterator itcanvas = allcanvasmap. Find (canvasid );
If (itcanvas = allcanvasmap. End () {// not exist return
Logi ("% s in, canvasid = % d not getcanvas !! ",__ Function __, canvasid );
Return-1;
} Else {
Return (* itcanvas). Second. showcanvas ();
}
}

/*******************
* Draw Buffer
********************/
Int dvbcanvasmanager: drawbuffer (void * picbuffer, int W, int H, int X, int y, ecolorconfig rgbconfig, int alphavalue, bool isclearbefor)
{
Logi ("% s in !! [W = % D, H = % d, x = % d, y = % d] ",__ function __, W, H, x, y );
If (SUR! = NULL & canvas! = NULL & spsurctrl! = NULL ){

If (surface: isvalid (SUR )){
If (isclearbefor ){
Clearcanvas ();
}

Skbitmap * pbitmap = new skbitmap ();
Pbitmap-> setconfig (skbitmap: config) rgbconfig, W, H, w * getbytesperpixbyrgbconfig (rgbconfig); // w * pbitmap-> bytesperpixel ()
Pbitmap-> allocpixels ();
Pbitmap-> setpixels (picbuffer );

If (alphavalue> 0 ){
Paint-> setalpha (alphavalue );
}

Skirect * mskirectsrc = new skirect ();
Mskirectsrc-> set (0, 0, W, H );

Skrect * mskrectdest = new skrect ();
Mskrectdest-> set (X, Y, x + W, Y + H );

Canvas-> drawbitmaprect (* pbitmap, mskirectsrc, * mskrectdest, paint );

Videoclient-> opentransaction ();
Surcontrl-> show ();
Videoclient-> closetransaction ();

Delete pbitmap;
Delete mskirectsrc;
Delete mskrectdest;
} Else {
Logi ("surface unvalide !! ");
}
Logi ("% s draw success !! ",__ Function __);
Return 1;
} Else {
Logi ("% s: Sur = NULL or canvas = NULL or spsurctrl = NULL !! ",__ Function __);
}
Return-1;
}

Int dvbcanvasmanager: clearcanvas ()
{
Logi ("% s in !! ",__ Function __);
If (SUR! = NULL & canvas! = NULL & spsurctrl! = NULL ){
Canvas-> drawcolor (0x00ffffff); // not work, the color is over old
/*
Skbitmap * pbitmap = new skbitmap ();
Pbitmap-> setconfig (skbitmap: config) mcolorconfig, canvaswidth, canvasheight, canvaswidth * getbytesperpixbyrgbconfig (mcolorconfig); // w * pbitmap-> bytesperpixel ()
Pbitmap-> allocpixels ();
Pbitmap-> eraseargb (0, 0, 0 );
Canvas-> drawbitmap (* pbitmap, 0, 0 );
*/
Logi ("% s over !! ",__ Function __);
} Else {
Logi ("% s: Sur = NULL or canvas = NULL or spsurctrl = NULL !! ",__ Function __);
}
Return 1;
}

Int dvbcanvasmanager: hidecanvas ()
{
Logi ("% s in !! ",__ Function __);
If (SUR! = NULL & canvas! = NULL & spsurctrl! = NULL ){
Videoclient-> opentransaction ();
Surcontrl-> hide ();
Videoclient-> closetransaction ();
} Else {
Logi ("% s: Sur = NULL or canvas = NULL or spsurctrl = NULL !! ",__ Function __);
}
Return 1;
}

Int dvbcanvasmanager: showcanvas ()
{
Logi ("% s in !! ",__ Function __);
If (SUR! = NULL & canvas! = NULL & spsurctrl! = NULL ){
Videoclient-> opentransaction ();
Surcontrl-> show ();
Videoclient-> closetransaction ();
} Else {
Logi ("% s: Sur = NULL or canvas = NULL or spsurctrl = NULL !! ",__ Function __);
}
Return 1;
}

Int dvbcanvasmanager: getbytesperpixbyrgbconfig (ecolorconfig rgbconfig)
{
Int bytes = 2;
Switch (rgbconfig)
{
Case colorconfig_kargb4444:
{
Bytes = 2;
}
Break;
Case colorconfig_kargb8888:
{
Bytes = 4;
}
Break;
Default:
Break;
}
Return bytes;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.