make image drawing faster

This commit is contained in:
houzh 2024-02-29 10:34:01 +08:00
parent 5158f0561d
commit acefc45bd3
2 changed files with 10 additions and 1 deletions

View File

@ -369,7 +369,7 @@ void BitmapDrawable::draw(Canvas&canvas){
const float fx = dw / sw , fy = dh / sh;
const float alpha = mBitmapState->mBaseAlpha*mBitmapState->mAlpha/255.f;
const int angle_degrees = getRotateAngle(canvas);
const Cairo::SurfacePattern::Filter filterMode = (angle_degrees%90==0)&&(getOpacity()==PixelFormat::OPAQUE)?SurfacePattern::Filter::FAST:SurfacePattern::Filter::GOOD;
const Cairo::SurfacePattern::Filter filterMode = (angle_degrees%90==0)&&(getOpacity()==PixelFormat::OPAQUE)?SurfacePattern::Filter::NEAREST:SurfacePattern::Filter::BILINEAR;
canvas.rectangle(mBounds.left,mBounds.top,mBounds.width,mBounds.height);
canvas.clip();

View File

@ -30,9 +30,18 @@ NinePatch::NinePatch(Context*ctx,const std::string&resid){
NinePatch::~NinePatch() {
}
static int getRotateAngle(Canvas&canvas){
double xx, yx, xy, yy, x0, y0;
Cairo::Matrix ctx=canvas.get_matrix();
double radians = atan2(ctx.yy, ctx.xy);
return int(radians*180.f/M_PI);
}
void NinePatch::draw(Canvas& painter, int x, int y) {
const int angle_degrees = getRotateAngle(painter);
painter.save();
painter.translate(x,y);
const Cairo::SurfacePattern::Filter filterMode = (angle_degrees%90==0)&&(getOpacity()==PixelFormat::OPAQUE)?SurfacePattern::Filter::NEAREST:SurfacePattern::Filter::BILINEAR;
painter.set_source(mCachedImage,0,0);
painter.rectangle(0,0,mCachedImage->get_width(),mCachedImage->get_height());
painter.clip();