Ejemplo n.º 1
0
    kernel loadKernel(occa::device_v *dHandle,
                      const std::string &kernelName){
      infoID_t infoID;

      infoID.modelID    = dHandle->modelID();
      infoID.kernelName = kernelName;

      headerMutex.lock();
      const infoHeader_t &h = headerMap[infoID];
      headerMutex.unlock();

      const std::string hFilename = fileDatabase::getFilename(h.fileID);
      FILE *inFD = fopen(hFilename.c_str(), "rb");

      char *buffer = new char[h.contentBytes + 1];
      buffer[h.contentBytes] = '\0';

      fseek(inFD, h.contentOffset, SEEK_SET);

      ignoreResult( fread(buffer, sizeof(char), h.contentBytes, inFD) );

      fclose(inFD);

      kernel k = kernel(dHandle->loadKernelFromLibrary(buffer, kernelName));

      delete [] buffer;
      fclose(inFD);

      return k;
    }
Ejemplo n.º 2
0
DEF_FUZZ(PathMeasure, fuzz) {
    uint8_t bits;
    fuzz->next(&bits);
    SkScalar distance[6];
    for (auto index = 0; index < 6; ++index) {
        fuzz->next(&distance[index]);
    }
    SkPath path;
    BuildPath(fuzz, &path, SkPath::Verb::kDone_Verb);
    SkRect bounds = path.getBounds();
    SkScalar maxDim = SkTMax(bounds.width(), bounds.height());
    SkScalar resScale = maxDim / 1000;
    SkPathMeasure measure(path, bits & 1, resScale);
    SkPoint position;
    SkVector tangent;
    ignoreResult(measure.getPosTan(distance[0], &position, &tangent));
    SkPath dst;
    ignoreResult(measure.getSegment(distance[1], distance[2], &dst, (bits >> 1) & 1));
    ignoreResult(measure.nextContour());
    ignoreResult(measure.getPosTan(distance[3], &position, &tangent));
    ignoreResult(measure.getSegment(distance[4], distance[5], &dst, (bits >> 2) & 1));
}
Ejemplo n.º 3
0
    void save(const std::string &filename){
      headerMutex.lock();

      FILE *outFD = fopen(filename.c_str(), "wb");

      uint32_t headerCount = headerMap.size();

      if(headerCount == 0){
        headerMutex.unlock();
        return;
      }

      fwrite(&headerCount, sizeof(uint32_t), 1, outFD);

      cHeaderMapIterator it = headerMap.begin();

      const uint64_t headerOffset = headerCount * ((  sizeof(uint32_t)) +
                                                   (6*sizeof(uint64_t)));

      uint64_t contentOffsets = sizeof(headerCount) + headerOffset;

      for(uint32_t i = 0; i < headerCount; ++i){
        const infoHeader_t &h = it->second;

        fwrite(&(h.mode), sizeof(uint32_t), 1, outFD);

        fwrite(&(contentOffsets), sizeof(uint64_t), 1, outFD);
        fwrite(&(h.flagsBytes)  , sizeof(uint64_t), 1, outFD);
        contentOffsets += h.flagsBytes;

        fwrite(&(contentOffsets), sizeof(uint64_t), 1, outFD);
        fwrite(&(h.contentBytes), sizeof(uint64_t), 1, outFD);
        contentOffsets += h.contentBytes;

        fwrite(&(contentOffsets)   , sizeof(uint64_t), 1, outFD);
        fwrite(&(h.kernelNameBytes), sizeof(uint64_t), 1, outFD);
        contentOffsets += h.kernelNameBytes;

        ++it;
      }

      it = headerMap.begin();

      for(uint32_t i = 0; i < headerCount; ++i){
        const infoHeader_t &h = it->second;
        ++it;

        char *buffer = new char[std::max(h.flagsBytes,
                                         std::max(h.contentBytes,
                                                  h.kernelNameBytes))];

        if(0 <= h.fileID){
          const std::string hFilename = fileDatabase::getFilename(h.fileID);
          FILE *inFD = fopen(hFilename.c_str(), "rb");

          fseek(inFD, h.flagsOffset, SEEK_SET);
          ignoreResult( fread(buffer , sizeof(char), h.flagsBytes, inFD) );
          fwrite(buffer, sizeof(char), h.flagsBytes, outFD);

          ignoreResult( fread(buffer , sizeof(char), h.contentBytes, inFD) );
          fwrite(buffer, sizeof(char), h.contentBytes, outFD);

          ignoreResult( fread(buffer , sizeof(char), h.kernelNameBytes, inFD) );
          fwrite(buffer, sizeof(char), h.kernelNameBytes, outFD);

          fclose(inFD);

          delete [] buffer;
        }
        else{
          const char *c  = scratchPad.c_str();
          const char *c1 = c + h.flagsOffset;
          const char *c2 = c + h.contentOffset;
          const char *c3 = c + h.kernelNameOffset;

          fwrite(c1, sizeof(char), h.flagsBytes     , outFD);
          fwrite(c2, sizeof(char), h.contentBytes   , outFD);
          fwrite(c3, sizeof(char), h.kernelNameBytes, outFD);
        }
      }

      fclose(outFD);

      headerMutex.unlock();
    }