re-order some parts of the code so that the msg and rect are only allocated once.
[AROS.git] / workbench / libs / gallium / bltpiperesourcerastport.c
blobbb954a0c2493685ef0249bb19a604fd2ad468bcf
1 /*
2 Copyright © 2011-2019, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <graphics/rastport.h>
7 #include <hidd/gfx.h>
8 #include <proto/alib.h>
9 #include <proto/layers.h>
10 #include <proto/graphics.h>
11 #include "pipe/p_state.h"
12 #include <aros/debug.h>
14 #include "gallium_intern.h"
16 /*****************************************************************************
18 NAME */
20 AROS_LH9(void, BltPipeResourceRastPort,
22 /* SYNOPSIS */
23 AROS_LHA(PipeHandle_t, pipe, A0),
24 AROS_LHA(struct pipe_resource *, srcPipeResource, A1),
25 AROS_LHA(LONG , xSrc, D0),
26 AROS_LHA(LONG , ySrc, D1),
27 AROS_LHA(struct RastPort * , destRP, A2),
28 AROS_LHA(LONG , xDest, D2),
29 AROS_LHA(LONG , yDest, D3),
30 AROS_LHA(LONG , xSize, D4),
31 AROS_LHA(LONG , ySize, D5),
33 /* LOCATION */
34 struct Library *, GalliumBase, 9, Gallium)
36 /* FUNCTION
37 Copies part of pipe resource onto rast port. Clips output by using layers of
38 rastport.
40 INPUTS
41 srcPipeResource - Copy from this pipe resource.
42 xSrc, ySrc - This is the upper left corner of the area to copy.
43 destRP - Destination RastPort.
44 xDest, yDest - Upper left corner where to place the copy
45 xSize, ySize - The size of the area to copy
47 RESULT
49 BUGS
51 INTERNALS
53 HISTORY
55 *****************************************************************************/
57 AROS_LIBFUNC_INIT
59 struct Layer *L;
61 if (!pipe || !(L = destRP->Layer))
62 return;
64 if (!IsLayerVisible(L))
65 return;
67 struct Rectangle renderableLayerRect;
68 struct pHidd_Gallium_DisplayResource drmsg = {
69 mID : ((struct GalliumBase *)GalliumBase)->galliumMId_DisplayResource,
70 resource : srcPipeResource,
71 bitmap: destRP->BitMap,
73 struct Rectangle result;
74 struct ClipRect *CR;
75 BOOL copied = FALSE;
77 LockLayerRom(L);
79 renderableLayerRect.MinX = L->bounds.MinX + xDest;
80 renderableLayerRect.MaxX = L->bounds.MinX + xDest + xSize - 1;
81 renderableLayerRect.MinY = L->bounds.MinY + yDest;
82 renderableLayerRect.MaxY = L->bounds.MinY + yDest + ySize - 1;
83 if (renderableLayerRect.MinX < L->bounds.MinX)
84 renderableLayerRect.MinX = L->bounds.MinX;
85 if (renderableLayerRect.MaxX > L->bounds.MaxX)
86 renderableLayerRect.MaxX = L->bounds.MaxX;
87 if (renderableLayerRect.MinY < L->bounds.MinY)
88 renderableLayerRect.MinY = L->bounds.MinY;
89 if (renderableLayerRect.MaxY > L->bounds.MaxY)
90 renderableLayerRect.MaxY = L->bounds.MaxY;
92 /* Do not clip renderableLayerRect to screen rast port. CRs are already clipped and unclipped
93 layer coords are needed. */
95 CR = L->ClipRect;
97 for (;NULL != CR; CR = CR->Next)
99 D(bug("Cliprect (%d, %d, %d, %d), lobs=%p\n",
100 CR->bounds.MinX, CR->bounds.MinY, CR->bounds.MaxX, CR->bounds.MaxY,
101 CR->lobs);)
103 /* I assume this means the cliprect is visible */
104 if (NULL == CR->lobs)
106 if (AndRectRect(&renderableLayerRect, &CR->bounds, &result))
108 /* This clip rect intersects renderable layer rect */
109 drmsg.srcx = xSrc + result.MinX - L->bounds.MinX - xDest; /* x in the source buffer */
110 drmsg.srcy = ySrc + result.MinY - L->bounds.MinY - yDest; /* y in the source buffer */
111 drmsg.dstx = result.MinX; /* Absolute (on bitmap) X of dest blit */
112 drmsg.dsty = result.MinY; /* Absolute (on bitmap) Y of dest blit */
113 drmsg.width = result.MaxX - result.MinX + 1; /* width of the rect in source buffer */
114 drmsg.height = result.MaxY - result.MinY + 1; /* height of the rect in source buffer */
116 OOP_DoMethod((OOP_Object *)pipe, (OOP_Msg)&drmsg);
118 copied = TRUE;
123 /* Notify the bitmap about blitting */
124 if (copied)
126 struct pHidd_BitMap_UpdateRect urmsg = {
127 mID : ((struct GalliumBase *)GalliumBase)->galliumMId_UpdateRect,
128 x : renderableLayerRect.MinX,
129 y : renderableLayerRect.MinY,
130 width : renderableLayerRect.MaxX - renderableLayerRect.MinX + 1,
131 height : renderableLayerRect.MaxY - renderableLayerRect.MinY + 1
134 OOP_Object * bm = HIDD_BM_OBJ(destRP->BitMap);
135 OOP_DoMethod(bm, (OOP_Msg)&urmsg);
138 UnlockLayerRom(L);
140 AROS_LIBFUNC_EXIT