unsigned Texture2D::GetSizeInBytes() { ID3D11Texture2D *texture = GetTexture(); D3D11_TEXTURE2D_DESC desc; texture->GetDesc(&desc); return desc.Width * desc.Height * GetFormatSize(desc.Format) * desc.SampleDesc.Count; }
INT CmSurfaceManager::CreateSurface2DUP(UINT width, UINT height, CM_SURFACE_FORMAT format, void *pSysMem, CmSurface2DUP * &pSurface2D) { pSurface2D = NULL; UINT index = m_pCmDevice->ValidSurfaceIndexStart(); if (GetFreeSurfaceIndex(index) != CM_SUCCESS) { return CM_EXCEED_SURFACE_AMOUNT; } if (m_2DUPSurfaceCount >= m_max2DUPSurfaceCount) { CM_ASSERT(0); return CM_EXCEED_SURFACE_AMOUNT; } UINT handle = 0; INT result = AllocateSurface2DUP(width, height, format, pSysMem, handle); if (result != CM_SUCCESS) { CM_ASSERT(0); return result; } result = CmSurface2DUP::Create(index, handle, width, height, format, this, pSurface2D); if (result != CM_SUCCESS) { FreeSurface2DUP(handle); CM_ASSERT(0); return result; } m_SurfaceArray[index] = pSurface2D; m_2DUPSurfaceCount++; UINT sizeperpixel = 1; GetFormatSize(format, sizeperpixel); m_SurfaceSizes[index] = width * height * sizeperpixel; return CM_SUCCESS; }
INT CmSurfaceManager::UPDATE_PROFILE_FOR_2D_SURFACE(UINT index, UINT width, UINT height, CM_SURFACE_FORMAT format, BOOL reuse) { UINT size = 0; UINT sizeperpixel = 1; GetFormatSize(format, sizeperpixel); size = width * height * sizeperpixel; m_2DSurfaceAllCount++; m_2DSurfaceAllSize += size; if (reuse) { m_2DSurfaceReuseCount++; m_2DSurfaceReuseSize += size; } else { m_2DSurfaceCount++; m_SurfaceSizes[index] = size; } return CM_SUCCESS; }
short ValueToStr(char *Values,short DataFormat,char *ValDesc,short Datasize,short RowNum,short ColNum,char *EqName,char *Property,BOOL Formatting) { short ind,i,stroff; char Buffer[BUFFER_SIZE+1]; double value; short col,row,cl=-1; stroff=0;ValDesc[0]=0; if (strcmp(Property,(char *)"STAQ") && strcmp(Property,(char *)"STCC")) { if (DataFormat==CF_TEXT) { for (i=0;Values[i] && i<Datasize-1;i++) ValDesc[i]=Values[i]; ValDesc[i]=0; return cl; } for (row=0;row<RowNum;row++) { for (col=0;col<ColNum;col++) { ind=col+row*ColNum; ConvertFormat((void *)&Values[ind*GetFormatSize(DataFormat)],DataFormat, (void *)&value,CF_DOUBLE,1); if (!strcmp(Property,(char *)"STAQ") || !strcmp(Property,(char *)"STCC")) sprintf(Buffer,"%d",(short)value); else { if (Formatting) sprintf(Buffer,"%lg",value);else sprintf(Buffer,"%lf",value); } if ((stroff+strlen(Buffer))>=(USHORT)Datasize) return cl; strcpy(&ValDesc[stroff],(char *)Buffer); stroff=strlen(ValDesc); if (stroff) { if (col==ColNum-1) ValDesc[stroff++]='\n'; else ValDesc[stroff++]='\t'; ValDesc[stroff]=0; } } } } else { i=0; while (i<RPCNumEqpsRead && strcmp(RPCMod[i].EqpName,EqName)) i++; value=*(double *)Values; if (i>=RPCNumEqpsRead) { sprintf(Buffer,"%lg",value); strcpy(ValDesc,(char *)Buffer); return cl; } while (i<RPCNumEqpsRead && !strcmp(RPCMod[i].EqpName,EqName)) { if ((RPCMod[i].Weight & ((short)value)) || (!RPCMod[i].Weight && !(short)value)) { if ((strlen(ValDesc)+strlen(RPCMod[i].StatName)+3)>=(USHORT)Datasize) { if ((strlen(ValDesc)+4)<=(USHORT)Datasize) stroff=strlen(ValDesc); else stroff=strlen(ValDesc)-4; strcpy(&ValDesc[stroff],(char *)" ->"); return cl; } if (strlen((char *)&ValDesc[stroff])) strcat(ValDesc,(char *)" + "); else cl=i; strcat(ValDesc,RPCMod[i].StatName); } i++; } stroff=strlen(ValDesc); if (stroff) ValDesc[stroff++]=9;ValDesc[stroff]=0; } if (stroff && (ValDesc[stroff-1]=='\t' || ValDesc[stroff-1]=='\n')) ValDesc[stroff-1]=0; return cl; }
short RPCSend(WORD Param,ElemDataStruct *lParam,WORD connectionID) { char user[255]; short cc=0,x,eqsize,count,rwflag; ElemDataStruct *ElemPointer; char *ptrs,*ptrd; HeaderStruct RPCHeader; EqpInfoStruct EqpInfo; BOOL remove=FALSE; WORD wParam; wParam=Param; if (!wParam) { wParam = 1; remove = TRUE; } ElemPointer=lParam; eqsize = abs((short)wParam); rwflag = eqsize/(short)wParam; RPCHeader.TotalSize=sizeof(HeaderStruct)+sizeof(EqpInfoStruct)*eqsize; if (getenv("USER")!=NULL) strcpy(user,getenv("USER")); else strcpy(user,"COLLAPS"); strcpy(RPCHeader.UserName,user); RPCHeader.EqpSize=(short)wParam; RPCHeader.Protocol=1; if (rwflag<0) { RPCHeader.TotalSize=RPCHeader.TotalSize+ GetFormatSize(ElemPointer->DataFormat)*(ElemPointer->Size); } ptrd=(char *) sendBuffer; ptrs=(char *) &RPCHeader; for (count=0;count<sizeof(HeaderStruct);count++) ptrd[count]=ptrs[count]; for (x=0;x<sizeof(ElemPointer->ElemName);x++) EqpInfo.ElemName[x]=ElemPointer->ElemName[x]; for (x=0;x<sizeof(ElemPointer->EqName);x++) EqpInfo.EqpModName[x]=ElemPointer->EqName[x]; EqpInfo.EqpModNo=ElemPointer->EqNo; for (x=0;x<sizeof(ElemPointer->Property);x++) EqpInfo.Property[x]=ElemPointer->Property[x]; strcpy(EqpInfo.Cycle,ElemPointer->Cycle); EqpInfo.DataFormat=ElemPointer->DataFormat; EqpInfo.DataSize=ElemPointer->Size; ptrs=(char *)&EqpInfo; for (x=0;x<sizeof(EqpInfoStruct);x++) { if (count==NOD_BUF_SIZE) { if (cc=NetSend(connectionID,count),cc) goto error; count=0; } ptrd[count++]=ptrs[x]; } if (rwflag<0) { ptrs=(char *)ElemPointer->Values; if (ptrs==NULL) return out_of_memory; for (x=0;x<(ElemPointer->Size*GetFormatSize(ElemPointer->DataFormat));x++) { ptrd[count++]=ptrs[x]; if (count==NOD_BUF_SIZE) { if (cc=NetSend(connectionID,count),cc) goto error; count=0; } } } if (count) { if (cc=NetSend(connectionID,count),cc) goto error; } error: if (cc) { if (NetProt==tcp) closesocket(connectionID); } return cc; }
short SyncRPC(char *Name,char *Property,char *Cycle,short Size,void *Data,short Datasize,short DataFormat,short dummy) { ElemDataStruct Elem; USHORT i; short j,cc,dataindex,flag; char Buffer[BUFFER_SIZE+1],eqname[EQNAME_SIZE+1]; char *values; double value; char *ptr; WORD connectionID; flag=abs(Size)/Size; if (strlen(Name)>ELEM_NAME_SIZE) return non_existent_elem; for (i=0;i<strlen(Name);i++) Elem.ElemName[i]=toupper(Name[i]); Elem.ElemName[i]=0; dataindex = SearchDataBase(RPCDataElems,Elem.ElemName,"NAME"); CString data; data.Format("%d",dataindex); AfxMessageBox(data,MB_OK,0); if (dataindex < 0) { strcpy(Buffer,"DEFAULT"); /************************/ cc = non_existent_fec; goto out2; } else strcpy((char *)Buffer,RPCData[dataindex].FecName); Elem.Values = NULL; Elem.FecIndex = SearchDataBase(RPCFecElems,Buffer,"FECNAME"); if (Elem.FecIndex < 0) { if (dataindex < 0) cc = non_existent_elem; else cc = non_existent_fec; goto out; } if (strlen(Property)>PROPERTY_SIZE) return illegal_property; strcpy(Elem.Property,Property); for (i=strlen(Elem.Property);i<PROPERTY_SIZE+1;i++) Elem.Property[i]=0; if (dataindex<0) { eqname[0]=0;Elem.EqNo=0; } else { strcpy((char *)eqname,RPCData[dataindex].EqName); Elem.EqNo=RPCData[dataindex].EqNumber; } strcpy(Elem.EqName,eqname); for (i=strlen(Elem.EqName);i<EQNAME_SIZE+1;i++) Elem.EqName[i]=0; Elem.DataFormat=DataFormat; if (Cycle==NULL) Elem.Cycle[0]=0; else strcpy(Elem.Cycle,Cycle); Elem.Size=abs(Size); if (Size<0) { switch (Elem.DataFormat) { case CF_TEXT: ptr=(char *)Data; for (i=0;i<abs(Size) && *ptr;i++) { j=0; while (*ptr && *ptr!='\t' && *ptr!='\r' && *ptr!='\n') Buffer[j++]=*ptr++; Buffer[j]=0; while (*ptr=='\t' || *ptr=='\r' || *ptr=='\n') ptr++; cc=StrToValue((double *)&value,Buffer,(char *)eqname,(char *)Property); if (!cc) { if (!i) { if ((Elem.Values = (char *) malloc(GetFormatSize(CF_DOUBLE)*abs(Size)))==NULL) {cc=out_of_memory;goto out;} } values=(char *)&value; for (j=0;j<GetFormatSize(CF_DOUBLE);j++) Elem.Values[i*GetFormatSize(CF_DOUBLE)+j]=values[j]; Elem.DataFormat=CF_DOUBLE; } else { if (strlen((char *)Data)>=(USHORT)GetFormatSize(CF_TEXT)) {cc=dimension_error;goto out;} if ((Elem.Values = (char *) malloc(GetFormatSize(CF_TEXT)*abs(Size)))==NULL) {cc=out_of_memory;goto out;} strcpy(Elem.Values,(char *)Data); break; } } break; case CF_DOUBLE: case CF_FLOAT: case CF_SHORT: case CF_LONG: case CF_BYTE: if ((Elem.Values = (char *) malloc(GetFormatSize(CF_DOUBLE)*abs(Size)))==NULL) {cc=out_of_memory;goto out;} ConvertFormat(Data,DataFormat,(void *)Elem.Values,CF_DOUBLE,abs(Size)); Elem.DataFormat=CF_DOUBLE; break; default: cc=illegal_format;goto out; } } cc=RPCConnect(0,&Elem,&connectionID); if (cc) goto out; cc=RPCSend(flag,&Elem,connectionID); if (cc) goto out; RPCReceive(flag,&Elem,connectionID); cc=Elem.CompCode; if (flag>0 && !cc && Data!=NULL) { ptr=(char *)Data; if (DataFormat==CF_TEXT) { if (Elem.DataFormat==CF_TEXT) { for (i=0;i<Datasize && Elem.Values[i];i++) ptr[i]=Elem.Values[i]; ptr[i]=0; } else ValueToStr(Elem.Values,Elem.DataFormat,ptr,Datasize, 1,abs(Size),Elem.EqName,Elem.Property,TRUE); } else ConvertFormat((void *)Elem.Values,Elem.DataFormat,Data,DataFormat,abs(Size)); } if (cc<0 && Data!=NULL && DataFormat==CF_TEXT && Datasize>(short)strlen(Elem.Values)) { strcpy((char *)Data,Elem.Values); } out: if (Elem.Values!=NULL) free((void *)Elem.Values); out2: lasterror = cc; return cc; }