skia2/dm/DMGpuTask.cpp
commit-bot@chromium.org 15a1405999 Change device factories to take SkImageInfo instead of SkBitmap::Config
patch from issue 167033002

BUG=skia:
R=reed@google.com

Author: reed@chromium.org

Review URL: https://codereview.chromium.org/168653002

git-svn-id: http://skia.googlecode.com/svn/trunk@13463 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-02-16 00:59:25 +00:00

71 lines
2.1 KiB
C++

#include "DMGpuTask.h"
#include "DMExpectationsTask.h"
#include "DMUtil.h"
#include "DMWriteTask.h"
#include "SkCommandLineFlags.h"
#include "SkSurface.h"
#include "SkTLS.h"
namespace DM {
GpuTask::GpuTask(const char* name,
Reporter* reporter,
TaskRunner* taskRunner,
const Expectations& expectations,
skiagm::GMRegistry::Factory gmFactory,
SkColorType colorType,
GrContextFactory::GLContextType contextType,
int sampleCount)
: Task(reporter, taskRunner)
, fGM(gmFactory(NULL))
, fName(UnderJoin(fGM->shortName(), name))
, fExpectations(expectations)
, fColorType(colorType)
, fContextType(contextType)
, fSampleCount(sampleCount)
{}
static void* new_gr_context_factory() {
return SkNEW(GrContextFactory);
}
static void delete_gr_context_factory(void* factory) {
SkDELETE((GrContextFactory*) factory);
}
static GrContextFactory* get_gr_factory() {
return reinterpret_cast<GrContextFactory*>(SkTLS::Get(&new_gr_context_factory,
&delete_gr_context_factory));
}
void GpuTask::draw() {
GrContext* gr = get_gr_factory()->get(fContextType); // Will be owned by device.
SkImageInfo info = SkImageInfo::Make(SkScalarCeilToInt(fGM->width()),
SkScalarCeilToInt(fGM->height()),
fColorType, kPremul_SkAlphaType);
SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(gr, info, fSampleCount));
SkCanvas* canvas = surface->getCanvas();
canvas->concat(fGM->getInitialTransform());
fGM->draw(canvas);
canvas->flush();
SkBitmap bitmap;
bitmap.setConfig(info);
canvas->readPixels(&bitmap, 0, 0);
#if GR_CACHE_STATS
gr->printCacheStats();
#endif
this->spawnChild(SkNEW_ARGS(ExpectationsTask, (*this, fExpectations, bitmap)));
this->spawnChild(SkNEW_ARGS(WriteTask, (*this, bitmap)));
}
bool GpuTask::shouldSkip() const {
return SkToBool(fGM->getFlags() & skiagm::GM::kSkipGPU_Flag);
}
} // namespace DM