Add CopyFrameRect() gfxlib call; passing a NULL FRAME is valid; repair a few TFB_Image locking violations; assert on working with off-screen FRAMEs
git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@3487 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
@@ -404,6 +404,7 @@ extern FRAME SetRelFrameIndex (FRAME Frame, SIZE FrameOffs);
|
|||||||
extern FRAME SetEquFrameIndex (FRAME DstFrame, FRAME SrcFrame);
|
extern FRAME SetEquFrameIndex (FRAME DstFrame, FRAME SrcFrame);
|
||||||
extern FRAME IncFrameIndex (FRAME Frame);
|
extern FRAME IncFrameIndex (FRAME Frame);
|
||||||
extern FRAME DecFrameIndex (FRAME Frame);
|
extern FRAME DecFrameIndex (FRAME Frame);
|
||||||
|
extern DRAWABLE CopyFrameRect (FRAME Frame, const RECT *area);
|
||||||
extern DRAWABLE CloneFrame (FRAME Frame);
|
extern DRAWABLE CloneFrame (FRAME Frame);
|
||||||
extern DRAWABLE RotateFrame (FRAME Frame, int angle_deg);
|
extern DRAWABLE RotateFrame (FRAME Frame, int angle_deg);
|
||||||
extern DRAWABLE RescaleFrame (FRAME, int width, int height);
|
extern DRAWABLE RescaleFrame (FRAME, int width, int height);
|
||||||
|
|||||||
@@ -248,6 +248,11 @@ RotateFrame (FRAME Frame, int angle_deg)
|
|||||||
double d;
|
double d;
|
||||||
double angle = angle_deg * M_PI / 180;
|
double angle = angle_deg * M_PI / 180;
|
||||||
|
|
||||||
|
if (!Frame)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
assert (Frame->Type != SCREEN_DRAWABLE);
|
||||||
|
|
||||||
Drawable = request_drawable (1, RAM_DRAWABLE, WANT_PIXMAP, 0, 0);
|
Drawable = request_drawable (1, RAM_DRAWABLE, WANT_PIXMAP, 0, 0);
|
||||||
if (!Drawable)
|
if (!Drawable)
|
||||||
return 0;
|
return 0;
|
||||||
@@ -283,17 +288,44 @@ RotateFrame (FRAME Frame, int angle_deg)
|
|||||||
|
|
||||||
// color.a is ignored
|
// color.a is ignored
|
||||||
void
|
void
|
||||||
SetFrameTransparentColor (FRAME Frame, Color color)
|
SetFrameTransparentColor (FRAME frame, Color color)
|
||||||
{
|
{
|
||||||
TFB_DrawCanvas_SetTransparentColor (Frame->image->NormalImg, color,
|
TFB_Image *img;
|
||||||
FALSE);
|
|
||||||
|
if (!frame)
|
||||||
|
return;
|
||||||
|
|
||||||
|
assert (frame->Type != SCREEN_DRAWABLE);
|
||||||
|
|
||||||
|
img = frame->image;
|
||||||
|
LockMutex (img->mutex);
|
||||||
|
|
||||||
|
// TODO: This should defer to TFB_DrawImage instead
|
||||||
|
TFB_DrawCanvas_SetTransparentColor (img->NormalImg, color, FALSE);
|
||||||
|
|
||||||
|
UnlockMutex (img->mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
Color
|
Color
|
||||||
GetFramePixel (FRAME frame, POINT pixelPt)
|
GetFramePixel (FRAME frame, POINT pixelPt)
|
||||||
{
|
{
|
||||||
return TFB_DrawCanvas_GetPixel (frame->image->NormalImg,
|
TFB_Image *img;
|
||||||
pixelPt.x, pixelPt.y);
|
Color ret;
|
||||||
|
|
||||||
|
if (!frame)
|
||||||
|
return BUILD_COLOR_RGBA (0, 0, 0, 0);
|
||||||
|
|
||||||
|
assert (frame->Type != SCREEN_DRAWABLE);
|
||||||
|
|
||||||
|
img = frame->image;
|
||||||
|
LockMutex (img->mutex);
|
||||||
|
|
||||||
|
// TODO: This should defer to TFB_DrawImage instead
|
||||||
|
ret = TFB_DrawCanvas_GetPixel (img->NormalImg, pixelPt.x, pixelPt.y);
|
||||||
|
|
||||||
|
UnlockMutex (img->mutex);
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static FRAME
|
static FRAME
|
||||||
@@ -317,39 +349,53 @@ makeMatchingFrame (FRAME frame, int width, int height)
|
|||||||
return newFrame;
|
return newFrame;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Creates an new DRAWABLE containing a copy of specified FRAME's rect
|
||||||
|
// Source FRAME must not be a SCREEN_DRAWABLE
|
||||||
|
DRAWABLE
|
||||||
|
CopyFrameRect (FRAME frame, const RECT *area)
|
||||||
|
{
|
||||||
|
FRAME newFrame;
|
||||||
|
POINT nullPt = MAKE_POINT (0, 0);
|
||||||
|
|
||||||
|
if (!frame)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
assert (frame->Type != SCREEN_DRAWABLE);
|
||||||
|
|
||||||
|
newFrame = makeMatchingFrame (frame, area->extent.width,
|
||||||
|
area->extent.height);
|
||||||
|
if (!newFrame)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
TFB_DrawImage_CopyRect (frame->image, area, newFrame->image, nullPt);
|
||||||
|
|
||||||
|
return ReleaseDrawable (newFrame);
|
||||||
|
}
|
||||||
|
|
||||||
// Creates an new DRAWABLE mostly identical to specified FRAME
|
// Creates an new DRAWABLE mostly identical to specified FRAME
|
||||||
|
// Source FRAME must not be a SCREEN_DRAWABLE
|
||||||
DRAWABLE
|
DRAWABLE
|
||||||
CloneFrame (FRAME frame)
|
CloneFrame (FRAME frame)
|
||||||
{
|
{
|
||||||
FRAME newFrame;
|
FRAME newFrame;
|
||||||
TFB_Image *img;
|
|
||||||
TFB_Canvas src, dst;
|
|
||||||
RECT r;
|
RECT r;
|
||||||
|
|
||||||
if (!frame)
|
if (!frame)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
assert (frame->Type != SCREEN_DRAWABLE);
|
||||||
|
|
||||||
GetFrameRect (frame, &r);
|
GetFrameRect (frame, &r);
|
||||||
r.corner.x = 0;
|
r.corner.x = 0;
|
||||||
r.corner.y = 0;
|
r.corner.y = 0;
|
||||||
|
|
||||||
newFrame = makeMatchingFrame (frame, r.extent.width, r.extent.height);
|
newFrame = CaptureDrawable (CopyFrameRect (frame, &r));
|
||||||
if (!newFrame)
|
if (!newFrame)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
// copy the hot-spot
|
// copy the hot-spot
|
||||||
newFrame->HotSpot = frame->HotSpot;
|
newFrame->HotSpot = frame->HotSpot;
|
||||||
|
|
||||||
img = frame->image;
|
|
||||||
LockMutex (img->mutex);
|
|
||||||
|
|
||||||
// copy the pixels
|
|
||||||
src = img->NormalImg;
|
|
||||||
dst = newFrame->image->NormalImg;
|
|
||||||
TFB_DrawCanvas_CopyRect (src, &r, dst, MAKE_POINT (0, 0));
|
|
||||||
|
|
||||||
UnlockMutex (img->mutex);
|
|
||||||
|
|
||||||
return ReleaseDrawable (newFrame);
|
return ReleaseDrawable (newFrame);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -365,6 +411,8 @@ RescaleFrame (FRAME frame, int width, int height)
|
|||||||
if (!frame)
|
if (!frame)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
assert (frame->Type != SCREEN_DRAWABLE);
|
||||||
|
|
||||||
newFrame = makeMatchingFrame (frame, width, height);
|
newFrame = makeMatchingFrame (frame, width, height);
|
||||||
if (!newFrame)
|
if (!newFrame)
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -375,7 +423,8 @@ RescaleFrame (FRAME frame, int width, int height)
|
|||||||
|
|
||||||
img = frame->image;
|
img = frame->image;
|
||||||
LockMutex (img->mutex);
|
LockMutex (img->mutex);
|
||||||
|
// NOTE: We do not lock the target image because nothing has a
|
||||||
|
// reference to it yet!
|
||||||
src = img->NormalImg;
|
src = img->NormalImg;
|
||||||
dst = newFrame->image->NormalImg;
|
dst = newFrame->image->NormalImg;
|
||||||
TFB_DrawCanvas_Rescale_Nearest (src, dst, -1, NULL, NULL, NULL);
|
TFB_DrawCanvas_Rescale_Nearest (src, dst, -1, NULL, NULL, NULL);
|
||||||
@@ -393,6 +442,8 @@ ReadFramePixelColors (FRAME frame, Color *pixels, int width, int height)
|
|||||||
if (!frame)
|
if (!frame)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
|
assert (frame->Type != SCREEN_DRAWABLE);
|
||||||
|
|
||||||
// TODO: Do we need to lock the img->mutex here?
|
// TODO: Do we need to lock the img->mutex here?
|
||||||
img = frame->image;
|
img = frame->image;
|
||||||
return TFB_DrawCanvas_GetPixelColors (img->NormalImg, pixels,
|
return TFB_DrawCanvas_GetPixelColors (img->NormalImg, pixels,
|
||||||
@@ -408,6 +459,8 @@ WriteFramePixelColors (FRAME frame, const Color *pixels, int width, int height)
|
|||||||
if (!frame)
|
if (!frame)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
|
assert (frame->Type != SCREEN_DRAWABLE);
|
||||||
|
|
||||||
// TODO: Do we need to lock the img->mutex here?
|
// TODO: Do we need to lock the img->mutex here?
|
||||||
img = frame->image;
|
img = frame->image;
|
||||||
return TFB_DrawCanvas_SetPixelColors (img->NormalImg, pixels,
|
return TFB_DrawCanvas_SetPixelColors (img->NormalImg, pixels,
|
||||||
@@ -422,6 +475,8 @@ ReadFramePixelIndexes (FRAME frame, BYTE *pixels, int width, int height)
|
|||||||
if (!frame)
|
if (!frame)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
|
assert (frame->Type != SCREEN_DRAWABLE);
|
||||||
|
|
||||||
// TODO: Do we need to lock the img->mutex here?
|
// TODO: Do we need to lock the img->mutex here?
|
||||||
img = frame->image;
|
img = frame->image;
|
||||||
return TFB_DrawCanvas_GetPixelIndexes (img->NormalImg, pixels,
|
return TFB_DrawCanvas_GetPixelIndexes (img->NormalImg, pixels,
|
||||||
@@ -437,6 +492,8 @@ WriteFramePixelIndexes (FRAME frame, const BYTE *pixels, int width, int height)
|
|||||||
if (!frame)
|
if (!frame)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
|
assert (frame->Type != SCREEN_DRAWABLE);
|
||||||
|
|
||||||
// TODO: Do we need to lock the img->mutex here?
|
// TODO: Do we need to lock the img->mutex here?
|
||||||
img = frame->image;
|
img = frame->image;
|
||||||
return TFB_DrawCanvas_SetPixelIndexes (img->NormalImg, pixels,
|
return TFB_DrawCanvas_SetPixelIndexes (img->NormalImg, pixels,
|
||||||
|
|||||||
@@ -458,6 +458,27 @@ BOOLEAN
|
|||||||
TFB_DrawImage_Intersect (TFB_Image *img1, POINT img1org,
|
TFB_DrawImage_Intersect (TFB_Image *img1, POINT img1org,
|
||||||
TFB_Image *img2, POINT img2org, const RECT *interRect)
|
TFB_Image *img2, POINT img2org, const RECT *interRect)
|
||||||
{
|
{
|
||||||
return TFB_DrawCanvas_Intersect (img1->NormalImg, img1org,
|
BOOLEAN ret;
|
||||||
|
|
||||||
|
LockMutex (img1->mutex);
|
||||||
|
LockMutex (img2->mutex);
|
||||||
|
ret = TFB_DrawCanvas_Intersect (img1->NormalImg, img1org,
|
||||||
img2->NormalImg, img2org, interRect);
|
img2->NormalImg, img2org, interRect);
|
||||||
|
UnlockMutex (img2->mutex);
|
||||||
|
UnlockMutex (img1->mutex);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
TFB_DrawImage_CopyRect (TFB_Image *source, const RECT *srcRect,
|
||||||
|
TFB_Image *target, POINT dstPt)
|
||||||
|
{
|
||||||
|
LockMutex (source->mutex);
|
||||||
|
LockMutex (target->mutex);
|
||||||
|
TFB_DrawCanvas_CopyRect (source->NormalImg, srcRect,
|
||||||
|
target->NormalImg, dstPt);
|
||||||
|
target->dirty = TRUE;
|
||||||
|
UnlockMutex (target->mutex);
|
||||||
|
UnlockMutex (source->mutex);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -107,6 +107,8 @@ void TFB_DrawImage_Delete (TFB_Image *image);
|
|||||||
void TFB_DrawImage_FixScaling (TFB_Image *image, int target, int type);
|
void TFB_DrawImage_FixScaling (TFB_Image *image, int target, int type);
|
||||||
BOOLEAN TFB_DrawImage_Intersect (TFB_Image *img1, POINT img1org,
|
BOOLEAN TFB_DrawImage_Intersect (TFB_Image *img1, POINT img1org,
|
||||||
TFB_Image *img2, POINT img2org, const RECT *interRect);
|
TFB_Image *img2, POINT img2org, const RECT *interRect);
|
||||||
|
void TFB_DrawImage_CopyRect (TFB_Image *source, const RECT *srcRect,
|
||||||
|
TFB_Image *target, POINT dstPt);
|
||||||
|
|
||||||
void TFB_DrawImage_Line (int x1, int y1, int x2, int y2, Color color,
|
void TFB_DrawImage_Line (int x1, int y1, int x2, int y2, Color color,
|
||||||
DrawMode, TFB_Image *target);
|
DrawMode, TFB_Image *target);
|
||||||
|
|||||||
Reference in New Issue
Block a user