Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / skia / dm / DMGpuGMTask.cpp
1 #include "DMGpuGMTask.h"
2 #include "DMUtil.h"
3 #include "DMWriteTask.h"
4 #include "SkCommonFlags.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 static bool gAlreadyWarned[GrContextFactory::kGLContextTypeCnt][kGrGLStandardCnt];
26
27 void GpuGMTask::draw(GrContextFactory* grFactory) {
28     SkImageInfo info = SkImageInfo::Make(SkScalarCeilToInt(fGM->width()),
29                                          SkScalarCeilToInt(fGM->height()),
30                                          kN32_SkColorType,
31                                          kPremul_SkAlphaType);
32     SkAutoTUnref<SkSurface> surface(NewGpuSurface(grFactory, fContextType, fGpuAPI, info,
33                                                   fSampleCount));
34     if (!surface) {
35         if (!gAlreadyWarned[fContextType][fGpuAPI]) {
36             SkDebugf("FYI: couldn't create GPU context, type %d API %d.  Will skip.\n",
37                      fContextType, fGpuAPI);
38             gAlreadyWarned[fContextType][fGpuAPI] = true;
39         }
40         return;
41     }
42     SkCanvas* canvas = surface->getCanvas();
43     CanvasPreflight(canvas);
44
45     canvas->concat(fGM->getInitialTransform());
46     fGM->draw(canvas);
47     canvas->flush();
48 #if GR_CACHE_STATS && SK_SUPPORT_GPU
49     if (FLAGS_veryVerbose) {
50         grFactory->get(fContextType)->printCacheStats();
51     }
52 #endif
53
54     SkBitmap bitmap;
55     bitmap.setInfo(info);
56     canvas->readPixels(&bitmap, 0, 0);
57
58     this->spawnChild(SkNEW_ARGS(WriteTask, (*this, "GM", bitmap)));
59 }
60
61 bool GpuGMTask::shouldSkip() const {
62     return kGPUDisabled || SkToBool(fGM->getFlags() & skiagm::GM::kSkipGPU_Flag);
63 }
64
65 }  // namespace DM