|
|
Created:
6 years, 10 months ago by reed1 Modified:
6 years, 10 months ago Reviewers:
mtklein CC:
skia-review_googlegroups.com Base URL:
https://skia.googlecode.com/svn/trunk Visibility:
Public. |
Descriptionchange benchmark to use surfaces instead of devices to specify its backends
BUG=skia:
R=mtklein@google.com
Committed: https://code.google.com/p/skia/source/detail?r=13297
Patch Set 1 #
Total comments: 3
Patch Set 2 : #Messages
Total messages: 12 (0 generated)
https://codereview.chromium.org/153133002/diff/1/bench/benchmain.cpp File bench/benchmain.cpp (right): https://codereview.chromium.org/153133002/diff/1/bench/benchmain.cpp#newcode97 bench/benchmain.cpp:97: static void saveFile(const char name[], const char config[], const char dir[], This would make a bit more conceptual sense if it took the const SkImage& instead of the source surface.
https://codereview.chromium.org/153133002/diff/1/bench/benchmain.cpp File bench/benchmain.cpp (right): https://codereview.chromium.org/153133002/diff/1/bench/benchmain.cpp#newcode97 bench/benchmain.cpp:97: static void saveFile(const char name[], const char config[], const char dir[], On 2014/02/03 21:34:43, mtklein wrote: > This would make a bit more conceptual sense if it took the const SkImage& > instead of the source surface. Not sure why. I am saving the state of the surface to a file. I *could* snapshot an image, or I *could* draw the surface into an offscreen bitmap, or ...
https://codereview.chromium.org/153133002/diff/1/bench/benchmain.cpp File bench/benchmain.cpp (right): https://codereview.chromium.org/153133002/diff/1/bench/benchmain.cpp#newcode97 bench/benchmain.cpp:97: static void saveFile(const char name[], const char config[], const char dir[], On 2014/02/03 21:39:48, reed1 wrote: > On 2014/02/03 21:34:43, mtklein wrote: > > This would make a bit more conceptual sense if it took the const SkImage& > > instead of the source surface. > > Not sure why. I am saving the state of the surface to a file. I *could* snapshot > an image, or I *could* draw the surface into an offscreen bitmap, or ... Yeah, that's sort of why it made more sense to me to take an SkImage. We can do almost anything to the surface that you pass in here, but there's less that can be done to a const SkImage.
lgtm
On 2014/02/03 21:47:32, mtklein wrote: > https://codereview.chromium.org/153133002/diff/1/bench/benchmain.cpp > File bench/benchmain.cpp (right): > > https://codereview.chromium.org/153133002/diff/1/bench/benchmain.cpp#newcode97 > bench/benchmain.cpp:97: static void saveFile(const char name[], const char > config[], const char dir[], > On 2014/02/03 21:39:48, reed1 wrote: > > On 2014/02/03 21:34:43, mtklein wrote: > > > This would make a bit more conceptual sense if it took the const SkImage& > > > instead of the source surface. > > > > Not sure why. I am saving the state of the surface to a file. I *could* > snapshot > > an image, or I *could* draw the surface into an offscreen bitmap, or ... > > Yeah, that's sort of why it made more sense to me to take an SkImage. We can do > almost anything to the surface that you pass in here, but there's less that can > be done to a const SkImage. Done
The CQ bit was checked by reed@google.com
CQ is trying da patch. Follow status at https://skia-tree-status.appspot.com/cq/reed@google.com/153133002/90001
The CQ bit was unchecked by commit-bot@chromium.org
Failed to apply patch for bench/benchmain.cpp: While running patch -p1 --forward --force --no-backup-if-mismatch; patching file bench/benchmain.cpp Hunk #1 FAILED at 13. Hunk #2 succeeded at 94 (offset 47 lines). Hunk #3 succeeded at 140 (offset 47 lines). Hunk #4 succeeded at 187 (offset 47 lines). Hunk #5 succeeded at 209 (offset 47 lines). Hunk #6 succeeded at 234 (offset 47 lines). Hunk #7 succeeded at 511 (offset 48 lines). Hunk #8 succeeded at 519 (offset 48 lines). Hunk #9 succeeded at 535 (offset 48 lines). Hunk #10 succeeded at 546 (offset 48 lines). Hunk #11 succeeded at 681 (offset 48 lines). 1 out of 11 hunks FAILED -- saving rejects to file bench/benchmain.cpp.rej Patch: bench/benchmain.cpp Index: bench/benchmain.cpp diff --git a/bench/benchmain.cpp b/bench/benchmain.cpp index 12c982037ea090bc72c62b9f9ad46ecc4691b644..4d158ee9244482f5442c8bec18e3481973639c92 100644 --- a/bench/benchmain.cpp +++ b/bench/benchmain.cpp @@ -13,12 +13,14 @@ #include "SkCanvas.h" #include "SkColorPriv.h" #include "SkCommandLineFlags.h" +#include "SkData.h" #include "SkDeferredCanvas.h" #include "SkGraphics.h" #include "SkImageEncoder.h" #include "SkOSFile.h" #include "SkPicture.h" #include "SkString.h" +#include "SkSurface.h" #if SK_SUPPORT_GPU #include "GrContext.h" @@ -47,14 +49,6 @@ static const char kDefaultsConfigStr[] = "defaults"; /////////////////////////////////////////////////////////////////////////////// -static void erase(SkBitmap& bm) { - if (bm.config() == SkBitmap::kA8_Config) { - bm.eraseColor(SK_ColorTRANSPARENT); - } else { - bm.eraseColor(SK_ColorWHITE); - } -} - class Iter { public: Iter() : fBench(BenchRegistry::Head()) {} @@ -101,30 +95,20 @@ static void make_filename(const char name[], SkString* path) { } static void saveFile(const char name[], const char config[], const char dir[], - const SkBitmap& bm) { - SkBitmap copy; - if (!bm.copyTo(©, SkBitmap::kARGB_8888_Config)) { + const SkImage* image) { + SkAutoTUnref<SkData> data(image->encode(SkImageEncoder::kPNG_Type, 100)); + if (NULL == data.get()) { return; } - if (bm.config() == SkBitmap::kA8_Config) { - // turn alpha into gray-scale - size_t size = copy.getSize() >> 2; - SkPMColor* p = copy.getAddr32(0, 0); - for (size_t i = 0; i < size; i++) { - int c = (*p >> SK_A32_SHIFT) & 0xFF; - c = 255 - c; - c |= (c << 24) | (c << 16) | (c << 8); - *p++ = c | (SK_A32_MASK << SK_A32_SHIFT); - } - } - SkString filename; make_filename(name, &filename); filename.appendf("_%s.png", config); SkString path = SkOSPath::SkPathJoin(dir, filename.c_str()); ::remove(path.c_str()); - SkImageEncoder::EncodeFile(path.c_str(), copy, SkImageEncoder::kPNG_Type, 100); + + SkFILEWStream stream(filename.c_str()); + stream.write(data->data(), data->size()); } static void performClip(SkCanvas* canvas, int w, int h) { @@ -158,31 +142,21 @@ static void performScale(SkCanvas* canvas, int w, int h) { canvas->translate(-x, -y); } -static SkBaseDevice* make_device(SkBitmap::Config config, const SkIPoint& size, - SkBenchmark::Backend backend, int sampleCount, GrContext* context) { - SkBaseDevice* device = NULL; - SkBitmap bitmap; - bitmap.setConfig(config, size.fX, size.fY); +static SkSurface* make_surface(SkColorType colorType, const SkIPoint& size, + SkBenchmark::Backend backend, int sampleCount, + GrContext* context) { + SkSurface* surface = NULL; + SkImageInfo info = SkImageInfo::Make(size.fX, size.fY, colorType, + kPremul_SkAlphaType); switch (backend) { case SkBenchmark::kRaster_Backend: - bitmap.allocPixels(); - erase(bitmap); - device = SkNEW_ARGS(SkBitmapDevice, (bitmap)); + surface = SkSurface::NewRaster(info); + surface->getCanvas()->clear(SK_ColorWHITE); break; #if SK_SUPPORT_GPU case SkBenchmark::kGPU_Backend: { - GrTextureDesc desc; - desc.fConfig = kSkia8888_GrPixelConfig; - desc.fFlags = kRenderTarget_GrTextureFlagBit; - desc.fWidth = size.fX; - desc.fHeight = size.fY; - desc.fSampleCnt = sampleCount; - SkAutoTUnref<GrTexture> texture(context->createUncachedTexture(desc, NULL, 0)); - if (!texture) { - return NULL; - } - device = SkNEW_ARGS(SkGpuDevice, (context, texture.get())); + surface = SkSurface::NewRenderTarget(context, info, sampleCount); break; } #endif @@ -190,7 +164,7 @@ static SkBaseDevice* make_device(SkBitmap::Config config, const SkIPoint& size, default: SkDEBUGFAIL("unsupported"); } - return device; + return surface; } #if SK_SUPPORT_GPU @@ -215,27 +189,27 @@ static const bool kIsDebug = false; #endif static const struct Config { - SkBitmap::Config config; + SkColorType fColorType; const char* name; int sampleCount; SkBenchmark::Backend backend; GLContextType contextType; bool runByDefault; } gConfigs[] = { - { SkBitmap::kNo_Config, "NONRENDERING", 0, SkBenchmark::kNonRendering_Backend, kNative, true}, - { SkBitmap::kARGB_8888_Config, "8888", 0, SkBenchmark::kRaster_Backend, kNative, true}, - { SkBitmap::kRGB_565_Config, "565", 0, SkBenchmark::kRaster_Backend, kNative, true}, + { kPMColor_SkColorType, "NONRENDERING", 0, SkBenchmark::kNonRendering_Backend, kNative, true}, + { kPMColor_SkColorType, "8888", 0, SkBenchmark::kRaster_Backend, kNative, true}, + { kRGB_565_SkColorType, "565", 0, SkBenchmark::kRaster_Backend, kNative, true}, #if SK_SUPPORT_GPU - { SkBitmap::kARGB_8888_Config, "GPU", 0, SkBenchmark::kGPU_Backend, kNative, true}, - { SkBitmap::kARGB_8888_Config, "MSAA4", 4, SkBenchmark::kGPU_Backend, kNative, false}, - { SkBitmap::kARGB_8888_Config, "MSAA16", 16, SkBenchmark::kGPU_Backend, kNative, false}, - { SkBitmap::kARGB_8888_Config, "NVPRMSAA4", 4, SkBenchmark::kGPU_Backend, kNVPR, true}, - { SkBitmap::kARGB_8888_Config, "NVPRMSAA16", 16, SkBenchmark::kGPU_Backend, kNVPR, false}, + { kPMColor_SkColorType, "GPU", 0, SkBenchmark::kGPU_Backend, kNative, true}, + { kPMColor_SkColorType, "MSAA4", 4, SkBenchmark::kGPU_Backend, kNative, false}, + { kPMColor_SkColorType, "MSAA16", 16, SkBenchmark::kGPU_Backend, kNative, false}, + { kPMColor_SkColorType, "NVPRMSAA4", 4, SkBenchmark::kGPU_Backend, kNVPR, true}, + { kPMColor_SkColorType, "NVPRMSAA16", 16, SkBenchmark::kGPU_Backend, kNVPR, false}, #if SK_ANGLE - { SkBitmap::kARGB_8888_Config, "ANGLE", 0, SkBenchmark::kGPU_Backend, kANGLE, true}, + { kPMColor_SkColorType, "ANGLE", 0, SkBenchmark::kGPU_Backend, kANGLE, true}, #endif // SK_ANGLE - { SkBitmap::kARGB_8888_Config, "Debug", 0, SkBenchmark::kGPU_Backend, kDebug, kIsDebug}, - { SkBitmap::kARGB_8888_Config, "NULLGPU", 0, SkBenchmark::kGPU_Backend, kNull, true}, + { kPMColor_SkColorType, "Debug", 0, SkBenchmark::kGPU_Backend, kDebug, kIsDebug}, + { kPMColor_SkColorType, "NULLGPU", 0, SkBenchmark::kGPU_Backend, kNull, true}, #endif // SK_SUPPORT_GPU }; @@ -491,7 +465,7 @@ int tool_main(int argc, char** argv) { glContext = gContextFactory.getGLContext(config.contextType); } #endif - SkAutoTUnref<SkBaseDevice> device; + SkAutoTUnref<SkCanvas> canvas; SkPicture recordFrom, recordTo; const SkIPoint dim = bench->getSize(); @@ -499,13 +473,14 @@ int tool_main(int argc, char** argv) { const SkPicture::RecordingFlags kRecordFlags = SkPicture::kUsePathBoundsForClip_RecordingFlag; + SkAutoTUnref<SkSurface> surface; if (SkBenchmark::kNonRendering_Backend != config.backend) { - device.reset(make_device(config.config, - dim, - config.backend, - config.sampleCount, - context)); - if (!device.get()) { + surface.reset(make_surface(config.fColorType, + dim, + config.backend, + config.sampleCount, + context)); + if (!surface.get()) { logger.logError(SkStringPrintf( "Device creation failure for config %s. Will skip.\n", config.name)); continue; @@ -514,7 +489,7 @@ int tool_main(int argc, char** argv) { switch(benchMode) { case kDeferredSilent_BenchMode: case kDeferred_BenchMode: - canvas.reset(SkDeferredCanvas::Create(device.get())); + canvas.reset(SkDeferredCanvas::Create(surface.get())); break; case kRecord_BenchMode: canvas.reset(SkRef(recordTo.beginRecording(dim.fX, dim.fY, kRecordFlags))); @@ -525,7 +500,7 @@ int tool_main(int argc, char** argv) { canvas.reset(SkRef(recordTo… (message too large)
CQ bit was unchecked on CL. Ignoring.
Message was sent while issue was closed.
Committed patchset #2 manually as r13297 (presubmit successful). |