2012-11-06 21:29:16 +00:00
|
|
|
/*
|
2012-07-26 17:27:57 +00:00
|
|
|
* Copyright 2012 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef PictureRenderer_DEFINED
|
|
|
|
#define PictureRenderer_DEFINED
|
2012-11-02 21:28:12 +00:00
|
|
|
|
|
|
|
#include "SkCountdown.h"
|
2012-11-06 21:26:13 +00:00
|
|
|
#include "SkDrawFilter.h"
|
2012-08-23 20:53:25 +00:00
|
|
|
#include "SkMath.h"
|
2012-11-06 22:14:54 +00:00
|
|
|
#include "SkPaint.h"
|
2012-09-07 15:21:18 +00:00
|
|
|
#include "SkPicture.h"
|
2012-09-18 14:32:35 +00:00
|
|
|
#include "SkRect.h"
|
2012-07-26 17:27:57 +00:00
|
|
|
#include "SkRefCnt.h"
|
2012-11-02 21:28:12 +00:00
|
|
|
#include "SkRunnable.h"
|
2012-09-07 15:21:18 +00:00
|
|
|
#include "SkString.h"
|
2012-11-02 21:28:12 +00:00
|
|
|
#include "SkTDArray.h"
|
|
|
|
#include "SkThreadPool.h"
|
|
|
|
#include "SkTypes.h"
|
2012-07-26 17:27:57 +00:00
|
|
|
|
2012-08-20 15:03:33 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
#include "GrContextFactory.h"
|
|
|
|
#include "GrContext.h"
|
|
|
|
#endif
|
|
|
|
|
2012-07-26 17:27:57 +00:00
|
|
|
class SkBitmap;
|
|
|
|
class SkCanvas;
|
2012-08-20 15:03:29 +00:00
|
|
|
class SkGLContext;
|
2012-11-02 21:28:12 +00:00
|
|
|
class SkThread;
|
2012-07-26 17:27:57 +00:00
|
|
|
|
|
|
|
namespace sk_tools {
|
|
|
|
|
Provide an option to bench drawing individual tiles in bench_pictures.
Provides output like the following:
running bench [1236 12045] androidpolice.skp
tile_256x256: tile [0,0] out of [5,48]: msecs = 1.00
tile_256x256: tile [1,0] out of [5,48]: msecs = 1.50
tile_256x256: tile [2,0] out of [5,48]: msecs = 1.00
tile_256x256: tile [3,0] out of [5,48]: msecs = 1.50
tile_256x256: tile [4,0] out of [5,48]: msecs = 2.50
tile_256x256: tile [0,1] out of [5,48]: msecs = 2.00
tile_256x256: tile [1,1] out of [5,48]: msecs = 3.50
tile_256x256: tile [2,1] out of [5,48]: msecs = 3.50
tile_256x256: tile [3,1] out of [5,48]: msecs = 6.00
tile_256x256: tile [4,1] out of [5,48]: msecs = 2.50
tile_256x256: tile [0,2] out of [5,48]: msecs = 2.00
BUG=https://code.google.com/p/skia/issues/detail?id=1016
Review URL: https://codereview.appspot.com/6937047
git-svn-id: http://skia.googlecode.com/svn/trunk@6805 2bbb7eff-a529-9590-31e7-b0007b416f81
2012-12-13 22:09:28 +00:00
|
|
|
class TiledPictureRenderer;
|
|
|
|
|
2012-07-26 17:27:57 +00:00
|
|
|
class PictureRenderer : public SkRefCnt {
|
Provide an option to bench drawing individual tiles in bench_pictures.
Provides output like the following:
running bench [1236 12045] androidpolice.skp
tile_256x256: tile [0,0] out of [5,48]: msecs = 1.00
tile_256x256: tile [1,0] out of [5,48]: msecs = 1.50
tile_256x256: tile [2,0] out of [5,48]: msecs = 1.00
tile_256x256: tile [3,0] out of [5,48]: msecs = 1.50
tile_256x256: tile [4,0] out of [5,48]: msecs = 2.50
tile_256x256: tile [0,1] out of [5,48]: msecs = 2.00
tile_256x256: tile [1,1] out of [5,48]: msecs = 3.50
tile_256x256: tile [2,1] out of [5,48]: msecs = 3.50
tile_256x256: tile [3,1] out of [5,48]: msecs = 6.00
tile_256x256: tile [4,1] out of [5,48]: msecs = 2.50
tile_256x256: tile [0,2] out of [5,48]: msecs = 2.00
BUG=https://code.google.com/p/skia/issues/detail?id=1016
Review URL: https://codereview.appspot.com/6937047
git-svn-id: http://skia.googlecode.com/svn/trunk@6805 2bbb7eff-a529-9590-31e7-b0007b416f81
2012-12-13 22:09:28 +00:00
|
|
|
|
2012-07-26 17:27:57 +00:00
|
|
|
public:
|
2012-08-20 15:04:04 +00:00
|
|
|
enum SkDeviceTypes {
|
2013-02-08 19:38:21 +00:00
|
|
|
#if SK_ANGLE
|
|
|
|
kAngle_DeviceType,
|
|
|
|
#endif
|
2012-08-20 15:04:04 +00:00
|
|
|
kBitmap_DeviceType,
|
|
|
|
#if SK_SUPPORT_GPU
|
2013-02-08 19:38:21 +00:00
|
|
|
kGPU_DeviceType,
|
2012-08-20 15:04:04 +00:00
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
2012-11-02 18:11:49 +00:00
|
|
|
enum BBoxHierarchyType {
|
|
|
|
kNone_BBoxHierarchyType = 0,
|
|
|
|
kRTree_BBoxHierarchyType,
|
2012-11-06 18:58:43 +00:00
|
|
|
kTileGrid_BBoxHierarchyType,
|
2012-11-02 18:11:49 +00:00
|
|
|
};
|
|
|
|
|
2012-11-06 21:26:13 +00:00
|
|
|
// this uses SkPaint::Flags as a base and adds additional flags
|
|
|
|
enum DrawFilterFlags {
|
|
|
|
kNone_DrawFilterFlag = 0,
|
2012-11-07 16:42:17 +00:00
|
|
|
kBlur_DrawFilterFlag = 0x4000, // toggles between blur and no blur
|
2012-12-18 18:20:44 +00:00
|
|
|
kHinting_DrawFilterFlag = 0x8000, // toggles between no hinting and normal hinting
|
|
|
|
kSlightHinting_DrawFilterFlag = 0x10000, // toggles between slight and normal hinting
|
|
|
|
kAAClip_DrawFilterFlag = 0x20000, // toggles between soft and hard clip
|
2012-11-06 21:26:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
SK_COMPILE_ASSERT(!(kBlur_DrawFilterFlag & SkPaint::kAllFlags), blur_flag_must_be_greater);
|
|
|
|
SK_COMPILE_ASSERT(!(kHinting_DrawFilterFlag & SkPaint::kAllFlags),
|
|
|
|
hinting_flag_must_be_greater);
|
|
|
|
SK_COMPILE_ASSERT(!(kSlightHinting_DrawFilterFlag & SkPaint::kAllFlags),
|
|
|
|
slight_hinting_flag_must_be_greater);
|
|
|
|
|
2012-11-02 21:28:12 +00:00
|
|
|
/**
|
|
|
|
* Called with each new SkPicture to render.
|
|
|
|
*/
|
2012-08-07 17:11:33 +00:00
|
|
|
virtual void init(SkPicture* pict);
|
2012-09-07 15:21:18 +00:00
|
|
|
|
2012-12-13 21:40:48 +00:00
|
|
|
/**
|
|
|
|
* Set the viewport so that only the portion listed gets drawn.
|
|
|
|
*/
|
|
|
|
void setViewport(SkISize size) { fViewport = size; }
|
|
|
|
|
2012-12-17 19:25:54 +00:00
|
|
|
/**
|
|
|
|
* Set the scale factor at which draw the picture.
|
|
|
|
*/
|
|
|
|
void setScaleFactor(SkScalar scale) { fScaleFactor = scale; }
|
|
|
|
|
2012-09-07 15:21:18 +00:00
|
|
|
/**
|
|
|
|
* Perform any setup that should done prior to each iteration of render() which should not be
|
|
|
|
* timed.
|
|
|
|
*/
|
|
|
|
virtual void setup() {}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Perform work that is to be timed. Typically this is rendering, but is also used for recording
|
|
|
|
* and preparing picture for playback by the subclasses which do those.
|
2012-09-20 14:54:21 +00:00
|
|
|
* If path is non-null, subclass implementations should call write().
|
|
|
|
* @param path If non-null, also write the output to the file specified by path. path should
|
|
|
|
* have no extension; it will be added by write().
|
2012-10-26 13:26:55 +00:00
|
|
|
* @return bool True if rendering succeeded and, if path is non-null, the output was
|
|
|
|
* successfully written to a file.
|
2012-09-07 15:21:18 +00:00
|
|
|
*/
|
2012-12-18 22:24:03 +00:00
|
|
|
virtual bool render(const SkString* path, SkBitmap** out = NULL) = 0;
|
2012-09-07 15:21:18 +00:00
|
|
|
|
2012-11-02 21:28:12 +00:00
|
|
|
/**
|
|
|
|
* Called once finished with a particular SkPicture, before calling init again, and before
|
|
|
|
* being done with this Renderer.
|
|
|
|
*/
|
2012-08-07 17:11:33 +00:00
|
|
|
virtual void end();
|
2012-11-02 21:28:12 +00:00
|
|
|
|
Provide an option to bench drawing individual tiles in bench_pictures.
Provides output like the following:
running bench [1236 12045] androidpolice.skp
tile_256x256: tile [0,0] out of [5,48]: msecs = 1.00
tile_256x256: tile [1,0] out of [5,48]: msecs = 1.50
tile_256x256: tile [2,0] out of [5,48]: msecs = 1.00
tile_256x256: tile [3,0] out of [5,48]: msecs = 1.50
tile_256x256: tile [4,0] out of [5,48]: msecs = 2.50
tile_256x256: tile [0,1] out of [5,48]: msecs = 2.00
tile_256x256: tile [1,1] out of [5,48]: msecs = 3.50
tile_256x256: tile [2,1] out of [5,48]: msecs = 3.50
tile_256x256: tile [3,1] out of [5,48]: msecs = 6.00
tile_256x256: tile [4,1] out of [5,48]: msecs = 2.50
tile_256x256: tile [0,2] out of [5,48]: msecs = 2.00
BUG=https://code.google.com/p/skia/issues/detail?id=1016
Review URL: https://codereview.appspot.com/6937047
git-svn-id: http://skia.googlecode.com/svn/trunk@6805 2bbb7eff-a529-9590-31e7-b0007b416f81
2012-12-13 22:09:28 +00:00
|
|
|
/**
|
|
|
|
* If this PictureRenderer is actually a TiledPictureRender, return a pointer to this as a
|
|
|
|
* TiledPictureRender so its methods can be called.
|
|
|
|
*/
|
|
|
|
virtual TiledPictureRenderer* getTiledRenderer() { return NULL; }
|
|
|
|
|
Change the method for timing individual tiles in bench_pictures.
When timing individual tiles in bench_pictures, keep a timer running
across all repeats, and then take the average. The former method of
timing each iteration separately runs into precision errors on some
platforms.
Running on my Mac Pro with OSX 10.8, the cmsecs for the new method
and the old method are roughly the same when checking the CPU time.
When checking the wall time, the old method often gives me 0ms,
while the new method gives me a larger value. I don't think this
can be entirely attributed to rounding though, since on occasion I
see the old method showing a short time period (.05 - .15ms) while
the new method shows .15ms higher (which is in range for the
difference I'm seeing for other tiles where the old method reports
0ms).
Some other changes:
PictureRenderer::resetState now takes a boolean parameter. If called
with false, it will only do a flush, while if called with true, it
will also call finish.
resetState is now called with true everywhere except in between
iterations of drawing the same tile (when timing individual tiles).
render_pictures_main no longer calls resetState directly, since it
already calls end, which calls resetState.
BUG=http://code.google.com/p/skia/issues/detail?id=1066
Review URL: https://codereview.appspot.com/7101060
git-svn-id: http://skia.googlecode.com/svn/trunk@7424 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-01-28 20:40:24 +00:00
|
|
|
/**
|
|
|
|
* Resets the GPU's state. Does nothing if the backing is raster. For a GPU renderer, calls
|
|
|
|
* flush, and calls finish if callFinish is true.
|
|
|
|
* @param callFinish Whether to call finish.
|
|
|
|
*/
|
|
|
|
void resetState(bool callFinish);
|
2012-08-07 17:11:33 +00:00
|
|
|
|
2013-02-08 19:38:21 +00:00
|
|
|
/**
|
|
|
|
* Set the backend type. Returns true on success and false on failure.
|
|
|
|
*/
|
|
|
|
bool setDeviceType(SkDeviceTypes deviceType) {
|
2012-08-20 15:04:04 +00:00
|
|
|
fDeviceType = deviceType;
|
2013-02-08 19:38:21 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
// In case this function is called more than once
|
|
|
|
SkSafeUnref(fGrContext);
|
|
|
|
fGrContext = NULL;
|
|
|
|
// Set to Native so it will have an initial value.
|
|
|
|
GrContextFactory::GLContextType glContextType = GrContextFactory::kNative_GLContextType;
|
|
|
|
#endif
|
|
|
|
switch(deviceType) {
|
|
|
|
case kBitmap_DeviceType:
|
|
|
|
return true;
|
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
case kGPU_DeviceType:
|
|
|
|
// Already set to GrContextFactory::kNative_GLContextType, above.
|
|
|
|
break;
|
|
|
|
#if SK_ANGLE
|
|
|
|
case kAngle_DeviceType:
|
|
|
|
glContextType = GrContextFactory::kANGLE_GLContextType;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
// Invalid device type.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
fGrContext = fGrContextFactory.get(glContextType);
|
|
|
|
if (NULL == fGrContext) {
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
fGrContext->ref();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#endif
|
2012-08-20 15:03:41 +00:00
|
|
|
}
|
|
|
|
|
2012-11-07 16:42:17 +00:00
|
|
|
void setDrawFilters(DrawFilterFlags const * const filters, const SkString& configName) {
|
|
|
|
memcpy(fDrawFilters, filters, sizeof(fDrawFilters));
|
2012-11-06 21:26:13 +00:00
|
|
|
fDrawFiltersConfig = configName;
|
|
|
|
}
|
|
|
|
|
2012-11-02 18:11:49 +00:00
|
|
|
void setBBoxHierarchyType(BBoxHierarchyType bbhType) {
|
|
|
|
fBBoxHierarchyType = bbhType;
|
|
|
|
}
|
|
|
|
|
2012-11-06 18:58:43 +00:00
|
|
|
void setGridSize(int width, int height) {
|
|
|
|
fGridWidth = width;
|
|
|
|
fGridHeight = height;
|
|
|
|
}
|
|
|
|
|
2012-08-20 15:03:41 +00:00
|
|
|
bool isUsingBitmapDevice() {
|
2012-08-20 15:03:44 +00:00
|
|
|
return kBitmap_DeviceType == fDeviceType;
|
2012-08-20 15:03:29 +00:00
|
|
|
}
|
|
|
|
|
2012-09-07 15:21:18 +00:00
|
|
|
virtual SkString getPerIterTimeFormat() { return SkString("%.2f"); }
|
|
|
|
|
|
|
|
virtual SkString getNormalTimeFormat() { return SkString("%6.2f"); }
|
|
|
|
|
2012-11-02 22:01:26 +00:00
|
|
|
/**
|
|
|
|
* Reports the configuration of this PictureRenderer.
|
|
|
|
*/
|
|
|
|
SkString getConfigName() {
|
|
|
|
SkString config = this->getConfigNameInternal();
|
2012-12-13 22:07:08 +00:00
|
|
|
if (!fViewport.isEmpty()) {
|
|
|
|
config.appendf("_viewport_%ix%i", fViewport.width(), fViewport.height());
|
|
|
|
}
|
2012-11-02 22:01:26 +00:00
|
|
|
if (kRTree_BBoxHierarchyType == fBBoxHierarchyType) {
|
|
|
|
config.append("_rtree");
|
2012-11-06 18:58:43 +00:00
|
|
|
} else if (kTileGrid_BBoxHierarchyType == fBBoxHierarchyType) {
|
|
|
|
config.append("_grid");
|
2012-11-02 22:01:26 +00:00
|
|
|
}
|
2013-02-08 19:38:21 +00:00
|
|
|
switch (fDeviceType) {
|
2012-11-02 22:01:26 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
2013-02-08 19:38:21 +00:00
|
|
|
case kGPU_DeviceType:
|
|
|
|
config.append("_gpu");
|
|
|
|
break;
|
|
|
|
#if SK_ANGLE
|
|
|
|
case kAngle_DeviceType:
|
|
|
|
config.append("_angle");
|
|
|
|
break;
|
|
|
|
#endif
|
2012-11-02 22:01:26 +00:00
|
|
|
#endif
|
2013-02-08 19:38:21 +00:00
|
|
|
default:
|
|
|
|
// Assume that no extra info means bitmap.
|
|
|
|
break;
|
|
|
|
}
|
2012-11-06 21:26:13 +00:00
|
|
|
config.append(fDrawFiltersConfig.c_str());
|
2012-11-02 22:01:26 +00:00
|
|
|
return config;
|
|
|
|
}
|
|
|
|
|
2012-08-20 15:03:29 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
2012-08-20 15:03:41 +00:00
|
|
|
bool isUsingGpuDevice() {
|
2013-02-08 19:38:21 +00:00
|
|
|
switch (fDeviceType) {
|
|
|
|
case kGPU_DeviceType:
|
|
|
|
// fall through
|
|
|
|
#if SK_ANGLE
|
|
|
|
case kAngle_DeviceType:
|
|
|
|
#endif
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
2012-08-20 15:03:41 +00:00
|
|
|
}
|
2012-08-20 15:03:47 +00:00
|
|
|
|
|
|
|
SkGLContext* getGLContext() {
|
2013-02-08 19:38:21 +00:00
|
|
|
GrContextFactory::GLContextType glContextType
|
|
|
|
= GrContextFactory::kNull_GLContextType;
|
|
|
|
switch(fDeviceType) {
|
|
|
|
case kGPU_DeviceType:
|
|
|
|
glContextType = GrContextFactory::kNative_GLContextType;
|
|
|
|
break;
|
|
|
|
#if SK_ANGLE
|
|
|
|
case kAngle_DeviceType:
|
|
|
|
glContextType = GrContextFactory::kANGLE_GLContextType;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
return NULL;
|
2012-08-20 15:03:47 +00:00
|
|
|
}
|
2013-02-08 19:38:21 +00:00
|
|
|
return fGrContextFactory.getGLContext(glContextType);
|
2012-08-20 15:03:47 +00:00
|
|
|
}
|
2012-09-13 15:40:37 +00:00
|
|
|
|
|
|
|
GrContext* getGrContext() {
|
|
|
|
return fGrContext;
|
|
|
|
}
|
2012-08-20 15:03:29 +00:00
|
|
|
#endif
|
|
|
|
|
2012-08-20 15:03:36 +00:00
|
|
|
PictureRenderer()
|
2012-08-20 15:03:33 +00:00
|
|
|
: fPicture(NULL)
|
|
|
|
, fDeviceType(kBitmap_DeviceType)
|
2012-11-02 19:16:22 +00:00
|
|
|
, fBBoxHierarchyType(kNone_BBoxHierarchyType)
|
2012-11-06 18:58:43 +00:00
|
|
|
, fGridWidth(0)
|
|
|
|
, fGridHeight(0)
|
2012-08-20 15:03:33 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
2013-02-08 19:38:21 +00:00
|
|
|
, fGrContext(NULL)
|
2012-08-20 15:03:33 +00:00
|
|
|
#endif
|
2012-12-24 18:26:43 +00:00
|
|
|
, fScaleFactor(SK_Scalar1)
|
2012-11-07 16:42:17 +00:00
|
|
|
{
|
|
|
|
sk_bzero(fDrawFilters, sizeof(fDrawFilters));
|
2012-12-13 21:40:48 +00:00
|
|
|
fViewport.set(0, 0);
|
2012-11-07 16:42:17 +00:00
|
|
|
}
|
2012-08-20 15:03:33 +00:00
|
|
|
|
2013-02-08 19:38:21 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
virtual ~PictureRenderer() {
|
|
|
|
SkSafeUnref(fGrContext);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-08-07 17:11:33 +00:00
|
|
|
protected:
|
|
|
|
SkAutoTUnref<SkCanvas> fCanvas;
|
2012-12-13 21:40:48 +00:00
|
|
|
SkPicture* fPicture;
|
|
|
|
SkDeviceTypes fDeviceType;
|
|
|
|
BBoxHierarchyType fBBoxHierarchyType;
|
|
|
|
DrawFilterFlags fDrawFilters[SkDrawFilter::kTypeCount];
|
|
|
|
SkString fDrawFiltersConfig;
|
|
|
|
int fGridWidth, fGridHeight; // used when fBBoxHierarchyType is TileGrid
|
2012-08-20 15:03:33 +00:00
|
|
|
|
2012-12-13 21:40:48 +00:00
|
|
|
void buildBBoxHierarchy();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the total width that should be drawn. If the viewport width has been set greater than
|
|
|
|
* 0, this will be the minimum of the current SkPicture's width and the viewport's width.
|
|
|
|
*/
|
|
|
|
int getViewWidth();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the total height that should be drawn. If the viewport height has been set greater
|
|
|
|
* than 0, this will be the minimum of the current SkPicture's height and the viewport's height.
|
|
|
|
*/
|
|
|
|
int getViewHeight();
|
|
|
|
|
2012-12-17 19:25:54 +00:00
|
|
|
/**
|
|
|
|
* Scales the provided canvas to the scale factor set by setScaleFactor.
|
|
|
|
*/
|
|
|
|
void scaleToScaleFactor(SkCanvas*);
|
|
|
|
|
2012-12-13 21:40:48 +00:00
|
|
|
SkPicture* createPicture();
|
|
|
|
uint32_t recordFlags();
|
|
|
|
SkCanvas* setupCanvas();
|
|
|
|
virtual SkCanvas* setupCanvas(int width, int height);
|
|
|
|
|
2012-08-07 17:11:33 +00:00
|
|
|
private:
|
2012-12-13 21:40:48 +00:00
|
|
|
SkISize fViewport;
|
2012-12-17 19:25:54 +00:00
|
|
|
SkScalar fScaleFactor;
|
2013-02-08 19:38:21 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
GrContextFactory fGrContextFactory;
|
|
|
|
GrContext* fGrContext;
|
|
|
|
#endif
|
2012-12-13 21:40:48 +00:00
|
|
|
|
2012-11-02 22:01:26 +00:00
|
|
|
virtual SkString getConfigNameInternal() = 0;
|
|
|
|
|
2012-08-07 17:11:33 +00:00
|
|
|
typedef SkRefCnt INHERITED;
|
2012-07-26 17:27:57 +00:00
|
|
|
};
|
|
|
|
|
2012-09-07 15:21:18 +00:00
|
|
|
/**
|
|
|
|
* This class does not do any rendering, but its render function executes recording, which we want
|
|
|
|
* to time.
|
|
|
|
*/
|
|
|
|
class RecordPictureRenderer : public PictureRenderer {
|
2012-12-18 22:24:03 +00:00
|
|
|
virtual bool render(const SkString*, SkBitmap** out = NULL) SK_OVERRIDE;
|
2012-09-07 15:21:18 +00:00
|
|
|
|
|
|
|
virtual SkString getPerIterTimeFormat() SK_OVERRIDE { return SkString("%.4f"); }
|
|
|
|
|
|
|
|
virtual SkString getNormalTimeFormat() SK_OVERRIDE { return SkString("%6.4f"); }
|
2012-11-02 22:01:26 +00:00
|
|
|
|
2012-11-06 16:54:40 +00:00
|
|
|
protected:
|
|
|
|
virtual SkCanvas* setupCanvas(int width, int height) SK_OVERRIDE;
|
|
|
|
|
2012-11-02 22:01:26 +00:00
|
|
|
private:
|
|
|
|
virtual SkString getConfigNameInternal() SK_OVERRIDE;
|
2012-09-07 15:21:18 +00:00
|
|
|
};
|
|
|
|
|
2012-07-26 17:27:57 +00:00
|
|
|
class PipePictureRenderer : public PictureRenderer {
|
2012-08-01 17:53:29 +00:00
|
|
|
public:
|
2012-12-18 22:24:03 +00:00
|
|
|
virtual bool render(const SkString*, SkBitmap** out = NULL) SK_OVERRIDE;
|
2012-08-07 17:11:33 +00:00
|
|
|
|
|
|
|
private:
|
2012-11-02 22:01:26 +00:00
|
|
|
virtual SkString getConfigNameInternal() SK_OVERRIDE;
|
|
|
|
|
2012-08-07 17:11:33 +00:00
|
|
|
typedef PictureRenderer INHERITED;
|
2012-07-26 17:27:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class SimplePictureRenderer : public PictureRenderer {
|
2012-08-01 17:53:29 +00:00
|
|
|
public:
|
2012-11-02 18:11:49 +00:00
|
|
|
virtual void init(SkPicture* pict) SK_OVERRIDE;
|
|
|
|
|
2012-12-18 22:24:03 +00:00
|
|
|
virtual bool render(const SkString*, SkBitmap** out = NULL) SK_OVERRIDE;
|
2012-08-07 17:11:33 +00:00
|
|
|
|
|
|
|
private:
|
2012-11-02 22:01:26 +00:00
|
|
|
virtual SkString getConfigNameInternal() SK_OVERRIDE;
|
|
|
|
|
2012-08-07 17:11:33 +00:00
|
|
|
typedef PictureRenderer INHERITED;
|
2012-07-26 17:27:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class TiledPictureRenderer : public PictureRenderer {
|
|
|
|
public:
|
|
|
|
TiledPictureRenderer();
|
|
|
|
|
2012-08-07 17:11:33 +00:00
|
|
|
virtual void init(SkPicture* pict) SK_OVERRIDE;
|
2012-09-20 14:54:21 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Renders to tiles, rather than a single canvas. If a path is provided, a separate file is
|
|
|
|
* created for each tile, named "path0.png", "path1.png", etc.
|
|
|
|
* Multithreaded mode currently does not support writing to a file.
|
|
|
|
*/
|
2012-12-18 22:24:03 +00:00
|
|
|
virtual bool render(const SkString* path, SkBitmap** out = NULL) SK_OVERRIDE;
|
2012-09-20 14:54:21 +00:00
|
|
|
|
2012-08-07 17:11:33 +00:00
|
|
|
virtual void end() SK_OVERRIDE;
|
2012-07-26 17:27:57 +00:00
|
|
|
|
2012-07-27 20:09:26 +00:00
|
|
|
void setTileWidth(int width) {
|
|
|
|
fTileWidth = width;
|
|
|
|
}
|
|
|
|
|
|
|
|
int getTileWidth() const {
|
|
|
|
return fTileWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setTileHeight(int height) {
|
|
|
|
fTileHeight = height;
|
|
|
|
}
|
|
|
|
|
|
|
|
int getTileHeight() const {
|
|
|
|
return fTileHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setTileWidthPercentage(double percentage) {
|
|
|
|
fTileWidthPercentage = percentage;
|
|
|
|
}
|
|
|
|
|
2012-08-01 17:53:29 +00:00
|
|
|
double getTileWidthPercentage() const {
|
2012-07-27 20:09:26 +00:00
|
|
|
return fTileWidthPercentage;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setTileHeightPercentage(double percentage) {
|
|
|
|
fTileHeightPercentage = percentage;
|
|
|
|
}
|
|
|
|
|
2012-08-01 17:53:29 +00:00
|
|
|
double getTileHeightPercentage() const {
|
2012-07-27 20:09:26 +00:00
|
|
|
return fTileHeightPercentage;
|
|
|
|
}
|
|
|
|
|
2012-08-23 20:53:25 +00:00
|
|
|
void setTileMinPowerOf2Width(int width) {
|
|
|
|
SkASSERT(SkIsPow2(width) && width > 0);
|
|
|
|
if (!SkIsPow2(width) || width <= 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
fTileMinPowerOf2Width = width;
|
|
|
|
}
|
|
|
|
|
|
|
|
int getTileMinPowerOf2Width() const {
|
|
|
|
return fTileMinPowerOf2Width;
|
|
|
|
}
|
|
|
|
|
Provide an option to bench drawing individual tiles in bench_pictures.
Provides output like the following:
running bench [1236 12045] androidpolice.skp
tile_256x256: tile [0,0] out of [5,48]: msecs = 1.00
tile_256x256: tile [1,0] out of [5,48]: msecs = 1.50
tile_256x256: tile [2,0] out of [5,48]: msecs = 1.00
tile_256x256: tile [3,0] out of [5,48]: msecs = 1.50
tile_256x256: tile [4,0] out of [5,48]: msecs = 2.50
tile_256x256: tile [0,1] out of [5,48]: msecs = 2.00
tile_256x256: tile [1,1] out of [5,48]: msecs = 3.50
tile_256x256: tile [2,1] out of [5,48]: msecs = 3.50
tile_256x256: tile [3,1] out of [5,48]: msecs = 6.00
tile_256x256: tile [4,1] out of [5,48]: msecs = 2.50
tile_256x256: tile [0,2] out of [5,48]: msecs = 2.00
BUG=https://code.google.com/p/skia/issues/detail?id=1016
Review URL: https://codereview.appspot.com/6937047
git-svn-id: http://skia.googlecode.com/svn/trunk@6805 2bbb7eff-a529-9590-31e7-b0007b416f81
2012-12-13 22:09:28 +00:00
|
|
|
virtual TiledPictureRenderer* getTiledRenderer() SK_OVERRIDE { return this; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Report the number of tiles in the x and y directions. Must not be called before init.
|
|
|
|
* @param x Output parameter identifying the number of tiles in the x direction.
|
|
|
|
* @param y Output parameter identifying the number of tiles in the y direction.
|
|
|
|
* @return True if the tiles have been set up, and x and y are meaningful. If false, x and y are
|
|
|
|
* unmodified.
|
|
|
|
*/
|
|
|
|
bool tileDimensions(int& x, int&y);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Move to the next tile and return its indices. Must be called before calling drawCurrentTile
|
|
|
|
* for the first time.
|
|
|
|
* @param i Output parameter identifying the column of the next tile to be drawn on the next
|
|
|
|
* call to drawNextTile.
|
|
|
|
* @param j Output parameter identifying the row of the next tile to be drawn on the next call
|
|
|
|
* to drawNextTile.
|
|
|
|
* @param True if the tiles have been created and the next tile to be drawn by drawCurrentTile
|
|
|
|
* is within the range of tiles. If false, i and j are unmodified.
|
|
|
|
*/
|
|
|
|
bool nextTile(int& i, int& j);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Render one tile. This will draw the same tile each time it is called until nextTile is
|
|
|
|
* called. The tile rendered will depend on how many calls have been made to nextTile.
|
|
|
|
* It is an error to call this without first calling nextTile, or if nextTile returns false.
|
|
|
|
*/
|
|
|
|
void drawCurrentTile();
|
|
|
|
|
2012-11-02 21:28:12 +00:00
|
|
|
protected:
|
|
|
|
SkTDArray<SkRect> fTileRects;
|
2012-07-26 17:27:57 +00:00
|
|
|
|
2012-11-02 22:01:26 +00:00
|
|
|
virtual SkCanvas* setupCanvas(int width, int height) SK_OVERRIDE;
|
|
|
|
virtual SkString getConfigNameInternal() SK_OVERRIDE;
|
|
|
|
|
2012-07-26 17:27:57 +00:00
|
|
|
private:
|
Provide an option to bench drawing individual tiles in bench_pictures.
Provides output like the following:
running bench [1236 12045] androidpolice.skp
tile_256x256: tile [0,0] out of [5,48]: msecs = 1.00
tile_256x256: tile [1,0] out of [5,48]: msecs = 1.50
tile_256x256: tile [2,0] out of [5,48]: msecs = 1.00
tile_256x256: tile [3,0] out of [5,48]: msecs = 1.50
tile_256x256: tile [4,0] out of [5,48]: msecs = 2.50
tile_256x256: tile [0,1] out of [5,48]: msecs = 2.00
tile_256x256: tile [1,1] out of [5,48]: msecs = 3.50
tile_256x256: tile [2,1] out of [5,48]: msecs = 3.50
tile_256x256: tile [3,1] out of [5,48]: msecs = 6.00
tile_256x256: tile [4,1] out of [5,48]: msecs = 2.50
tile_256x256: tile [0,2] out of [5,48]: msecs = 2.00
BUG=https://code.google.com/p/skia/issues/detail?id=1016
Review URL: https://codereview.appspot.com/6937047
git-svn-id: http://skia.googlecode.com/svn/trunk@6805 2bbb7eff-a529-9590-31e7-b0007b416f81
2012-12-13 22:09:28 +00:00
|
|
|
int fTileWidth;
|
|
|
|
int fTileHeight;
|
|
|
|
double fTileWidthPercentage;
|
|
|
|
double fTileHeightPercentage;
|
|
|
|
int fTileMinPowerOf2Width;
|
|
|
|
|
|
|
|
// These variables are only used for timing individual tiles.
|
|
|
|
// Next tile to draw in fTileRects.
|
|
|
|
int fCurrentTileOffset;
|
|
|
|
// Number of tiles in the x direction.
|
|
|
|
int fTilesX;
|
|
|
|
// Number of tiles in the y direction.
|
|
|
|
int fTilesY;
|
2012-09-20 14:42:33 +00:00
|
|
|
|
2012-08-07 17:11:33 +00:00
|
|
|
void setupTiles();
|
2012-08-23 20:53:25 +00:00
|
|
|
void setupPowerOf2Tiles();
|
2012-08-07 17:11:33 +00:00
|
|
|
|
|
|
|
typedef PictureRenderer INHERITED;
|
2012-07-26 17:27:57 +00:00
|
|
|
};
|
|
|
|
|
2012-11-02 21:28:12 +00:00
|
|
|
class CloneData;
|
|
|
|
|
|
|
|
class MultiCorePictureRenderer : public TiledPictureRenderer {
|
|
|
|
public:
|
|
|
|
explicit MultiCorePictureRenderer(int threadCount);
|
|
|
|
|
|
|
|
~MultiCorePictureRenderer();
|
|
|
|
|
|
|
|
virtual void init(SkPicture* pict) SK_OVERRIDE;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Behaves like TiledPictureRenderer::render(), only using multiple threads.
|
|
|
|
*/
|
2012-12-18 22:24:03 +00:00
|
|
|
virtual bool render(const SkString* path, SkBitmap** out = NULL) SK_OVERRIDE;
|
2012-11-02 21:28:12 +00:00
|
|
|
|
|
|
|
virtual void end() SK_OVERRIDE;
|
|
|
|
|
|
|
|
private:
|
2012-11-02 22:01:26 +00:00
|
|
|
virtual SkString getConfigNameInternal() SK_OVERRIDE;
|
|
|
|
|
2012-11-02 21:28:12 +00:00
|
|
|
const int fNumThreads;
|
|
|
|
SkTDArray<SkCanvas*> fCanvasPool;
|
|
|
|
SkThreadPool fThreadPool;
|
|
|
|
SkPicture* fPictureClones;
|
|
|
|
CloneData** fCloneData;
|
|
|
|
SkCountdown fCountdown;
|
|
|
|
|
|
|
|
typedef TiledPictureRenderer INHERITED;
|
|
|
|
};
|
|
|
|
|
2012-09-07 15:21:18 +00:00
|
|
|
/**
|
|
|
|
* This class does not do any rendering, but its render function executes turning an SkPictureRecord
|
|
|
|
* into an SkPicturePlayback, which we want to time.
|
|
|
|
*/
|
|
|
|
class PlaybackCreationRenderer : public PictureRenderer {
|
|
|
|
public:
|
|
|
|
virtual void setup() SK_OVERRIDE;
|
|
|
|
|
2012-12-18 22:24:03 +00:00
|
|
|
virtual bool render(const SkString*, SkBitmap** out = NULL) SK_OVERRIDE;
|
2012-09-07 15:21:18 +00:00
|
|
|
|
|
|
|
virtual SkString getPerIterTimeFormat() SK_OVERRIDE { return SkString("%.4f"); }
|
|
|
|
|
|
|
|
virtual SkString getNormalTimeFormat() SK_OVERRIDE { return SkString("%6.4f"); }
|
|
|
|
|
|
|
|
private:
|
2012-11-02 18:11:49 +00:00
|
|
|
SkAutoTUnref<SkPicture> fReplayer;
|
2012-11-02 22:01:26 +00:00
|
|
|
|
|
|
|
virtual SkString getConfigNameInternal() SK_OVERRIDE;
|
|
|
|
|
2012-09-07 15:21:18 +00:00
|
|
|
typedef PictureRenderer INHERITED;
|
|
|
|
};
|
|
|
|
|
2012-11-29 21:00:39 +00:00
|
|
|
extern PictureRenderer* CreateGatherPixelRefsRenderer();
|
2012-12-10 16:05:09 +00:00
|
|
|
extern PictureRenderer* CreatePictureCloneRenderer();
|
2012-11-29 21:00:39 +00:00
|
|
|
|
2012-07-26 17:27:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // PictureRenderer_DEFINED
|