Home | History | Annotate | Download | only in dm
      1 #include "DMGpuGMTask.h"
      2 #include "DMUtil.h"
      3 #include "DMWriteTask.h"
      4 #include "SkCommandLineFlags.h"
      5 #include "SkSurface.h"
      6 #include "SkTLS.h"
      7 
      8 namespace DM {
      9 
     10 GpuGMTask::GpuGMTask(const char* config,
     11                      Reporter* reporter,
     12                      TaskRunner* taskRunner,
     13                      skiagm::GMRegistry::Factory gmFactory,
     14                      GrContextFactory::GLContextType contextType,
     15                      GrGLStandard gpuAPI,
     16                      int sampleCount)
     17     : GpuTask(reporter, taskRunner)
     18     , fGM(gmFactory(NULL))
     19     , fName(UnderJoin(fGM->getName(), config))
     20     , fContextType(contextType)
     21     , fGpuAPI(gpuAPI)
     22     , fSampleCount(sampleCount)
     23     {}
     24 
     25 void GpuGMTask::draw(GrContextFactory* grFactory) {
     26     SkImageInfo info = SkImageInfo::Make(SkScalarCeilToInt(fGM->width()),
     27                                          SkScalarCeilToInt(fGM->height()),
     28                                          kN32_SkColorType,
     29                                          kPremul_SkAlphaType);
     30     SkAutoTUnref<SkSurface> surface(NewGpuSurface(grFactory, fContextType, fGpuAPI, info,
     31                                                   fSampleCount));
     32     if (!surface) {
     33         this->fail("Could not create context for the config and the api.");
     34         return;
     35     }
     36     SkCanvas* canvas = surface->getCanvas();
     37     CanvasPreflight(canvas);
     38 
     39     canvas->concat(fGM->getInitialTransform());
     40     fGM->draw(canvas);
     41     canvas->flush();
     42 
     43     SkBitmap bitmap;
     44     bitmap.setInfo(info);
     45     canvas->readPixels(&bitmap, 0, 0);
     46 
     47     this->spawnChild(SkNEW_ARGS(WriteTask, (*this, "GM", bitmap)));
     48 }
     49 
     50 bool GpuGMTask::shouldSkip() const {
     51     return kGPUDisabled || SkToBool(fGM->getFlags() & skiagm::GM::kSkipGPU_Flag);
     52 }
     53 
     54 }  // namespace DM
     55