2012-08-20 21:02:49 +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.
|
|
|
|
*/
|
|
|
|
|
2012-07-26 17:27:57 +00:00
|
|
|
#include "PictureRenderer.h"
|
2012-08-31 16:15:22 +00:00
|
|
|
#include "picture_utils.h"
|
2012-07-26 17:27:57 +00:00
|
|
|
#include "SamplePipeControllers.h"
|
2013-12-13 20:52:36 +00:00
|
|
|
#include "SkBitmapHasher.h"
|
2012-07-26 17:27:57 +00:00
|
|
|
#include "SkCanvas.h"
|
2013-05-21 20:31:23 +00:00
|
|
|
#include "SkData.h"
|
2012-07-26 17:27:57 +00:00
|
|
|
#include "SkDevice.h"
|
2013-12-18 17:25:33 +00:00
|
|
|
#include "SkDiscardableMemoryPool.h"
|
2012-07-26 17:27:57 +00:00
|
|
|
#include "SkGPipe.h"
|
2012-08-31 16:15:22 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
2013-02-07 19:45:46 +00:00
|
|
|
#include "gl/GrGLDefines.h"
|
2012-08-31 16:15:22 +00:00
|
|
|
#include "SkGpuDevice.h"
|
|
|
|
#endif
|
|
|
|
#include "SkGraphics.h"
|
|
|
|
#include "SkImageEncoder.h"
|
2012-11-06 21:26:13 +00:00
|
|
|
#include "SkMaskFilter.h"
|
2012-08-23 15:24:13 +00:00
|
|
|
#include "SkMatrix.h"
|
2014-10-09 11:59:19 +00:00
|
|
|
#include "SkMultiPictureDraw.h"
|
2014-04-10 15:39:02 +00:00
|
|
|
#include "SkOSFile.h"
|
2015-06-15 18:48:16 +00:00
|
|
|
#include "SkPaintFilterCanvas.h"
|
2012-07-26 17:27:57 +00:00
|
|
|
#include "SkPicture.h"
|
2014-04-18 18:04:41 +00:00
|
|
|
#include "SkPictureRecorder.h"
|
2013-05-21 20:31:23 +00:00
|
|
|
#include "SkPictureUtils.h"
|
|
|
|
#include "SkPixelRef.h"
|
2014-12-11 18:53:58 +00:00
|
|
|
#include "SkPixelSerializer.h"
|
2012-08-23 15:24:13 +00:00
|
|
|
#include "SkScalar.h"
|
2012-11-07 17:52:48 +00:00
|
|
|
#include "SkStream.h"
|
2012-08-21 19:05:08 +00:00
|
|
|
#include "SkString.h"
|
2014-10-09 11:59:19 +00:00
|
|
|
#include "SkSurface.h"
|
2012-08-31 16:15:22 +00:00
|
|
|
#include "SkTemplates.h"
|
2012-07-26 17:27:57 +00:00
|
|
|
#include "SkTDArray.h"
|
2012-08-31 16:15:22 +00:00
|
|
|
#include "SkThreadUtils.h"
|
2012-07-26 17:27:57 +00:00
|
|
|
#include "SkTypes.h"
|
2015-03-23 12:46:51 +00:00
|
|
|
#include "sk_tool_utils.h"
|
2012-08-20 15:03:29 +00:00
|
|
|
|
2013-12-18 04:59:26 +00:00
|
|
|
static inline SkScalar scalar_log2(SkScalar x) {
|
2015-05-12 17:37:34 +00:00
|
|
|
static const SkScalar log2_conversion_factor = SkScalarInvert(SkScalarLog(2));
|
2013-12-18 07:01:56 +00:00
|
|
|
|
2013-12-18 04:59:26 +00:00
|
|
|
return SkScalarLog(x) * log2_conversion_factor;
|
|
|
|
}
|
|
|
|
|
2012-07-26 17:27:57 +00:00
|
|
|
namespace sk_tools {
|
|
|
|
|
|
|
|
enum {
|
|
|
|
kDefaultTileWidth = 256,
|
|
|
|
kDefaultTileHeight = 256
|
|
|
|
};
|
|
|
|
|
2014-08-26 21:07:04 +00:00
|
|
|
void PictureRenderer::init(const SkPicture* pict,
|
|
|
|
const SkString* writePath,
|
2014-07-07 20:46:35 +00:00
|
|
|
const SkString* mismatchPath,
|
2014-08-26 21:07:04 +00:00
|
|
|
const SkString* inputFilename,
|
2014-10-09 11:59:19 +00:00
|
|
|
bool useChecksumBasedFilenames,
|
|
|
|
bool useMultiPictureDraw) {
|
2014-05-15 15:10:48 +00:00
|
|
|
this->CopyString(&fWritePath, writePath);
|
|
|
|
this->CopyString(&fMismatchPath, mismatchPath);
|
2014-03-19 17:26:07 +00:00
|
|
|
this->CopyString(&fInputFilename, inputFilename);
|
|
|
|
fUseChecksumBasedFilenames = useChecksumBasedFilenames;
|
2014-10-09 11:59:19 +00:00
|
|
|
fUseMultiPictureDraw = useMultiPictureDraw;
|
2014-03-19 17:26:07 +00:00
|
|
|
|
2015-08-27 14:41:13 +00:00
|
|
|
SkASSERT(nullptr == fPicture);
|
|
|
|
SkASSERT(nullptr == fCanvas.get());
|
2014-09-05 20:34:00 +00:00
|
|
|
if (fPicture || fCanvas.get()) {
|
2012-08-07 17:11:33 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-08-27 14:41:13 +00:00
|
|
|
SkASSERT(pict != nullptr);
|
|
|
|
if (nullptr == pict) {
|
2012-08-07 17:11:33 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-10-01 19:28:49 +00:00
|
|
|
fPicture.reset(SkRef(pict));
|
2012-08-20 15:03:57 +00:00
|
|
|
fCanvas.reset(this->setupCanvas());
|
|
|
|
}
|
|
|
|
|
2014-03-19 17:26:07 +00:00
|
|
|
void PictureRenderer::CopyString(SkString* dest, const SkString* src) {
|
2014-09-05 20:34:00 +00:00
|
|
|
if (src) {
|
2014-03-19 17:26:07 +00:00
|
|
|
dest->set(*src);
|
|
|
|
} else {
|
|
|
|
dest->reset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-15 18:48:16 +00:00
|
|
|
class FlagsFilterCanvas : public SkPaintFilterCanvas {
|
2012-11-06 21:26:13 +00:00
|
|
|
public:
|
2015-06-15 18:48:16 +00:00
|
|
|
FlagsFilterCanvas(SkCanvas* canvas, PictureRenderer::DrawFilterFlags* flags)
|
|
|
|
: INHERITED(canvas->imageInfo().width(), canvas->imageInfo().height())
|
|
|
|
, fFlags(flags) {
|
|
|
|
this->addCanvas(canvas);
|
|
|
|
}
|
2012-11-06 21:26:13 +00:00
|
|
|
|
2015-06-15 18:48:16 +00:00
|
|
|
protected:
|
|
|
|
void onFilterPaint(SkPaint* paint, Type t) const override {
|
2012-11-06 21:26:13 +00:00
|
|
|
paint->setFlags(paint->getFlags() & ~fFlags[t] & SkPaint::kAllFlags);
|
2013-07-03 15:34:35 +00:00
|
|
|
if (PictureRenderer::kMaskFilter_DrawFilterFlag & fFlags[t]) {
|
2012-11-06 21:26:13 +00:00
|
|
|
SkMaskFilter* maskFilter = paint->getMaskFilter();
|
2014-09-05 20:34:00 +00:00
|
|
|
if (maskFilter) {
|
2015-08-27 14:41:13 +00:00
|
|
|
paint->setMaskFilter(nullptr);
|
2012-11-06 21:26:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (PictureRenderer::kHinting_DrawFilterFlag & fFlags[t]) {
|
|
|
|
paint->setHinting(SkPaint::kNo_Hinting);
|
|
|
|
} else if (PictureRenderer::kSlightHinting_DrawFilterFlag & fFlags[t]) {
|
|
|
|
paint->setHinting(SkPaint::kSlight_Hinting);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2015-06-15 18:48:16 +00:00
|
|
|
const PictureRenderer::DrawFilterFlags* fFlags;
|
2012-11-06 21:26:13 +00:00
|
|
|
|
2015-06-15 18:48:16 +00:00
|
|
|
typedef SkPaintFilterCanvas INHERITED;
|
|
|
|
};
|
2012-11-06 21:26:13 +00:00
|
|
|
|
2012-08-20 15:03:57 +00:00
|
|
|
SkCanvas* PictureRenderer::setupCanvas() {
|
2012-12-13 21:40:48 +00:00
|
|
|
const int width = this->getViewWidth();
|
|
|
|
const int height = this->getViewHeight();
|
|
|
|
return this->setupCanvas(width, height);
|
2012-08-20 15:03:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SkCanvas* PictureRenderer::setupCanvas(int width, int height) {
|
2015-06-15 18:48:16 +00:00
|
|
|
SkAutoTUnref<SkCanvas> canvas;
|
|
|
|
|
2012-08-20 15:03:29 +00:00
|
|
|
switch(fDeviceType) {
|
|
|
|
case kBitmap_DeviceType: {
|
|
|
|
SkBitmap bitmap;
|
2012-08-20 15:03:57 +00:00
|
|
|
sk_tools::setup_bitmap(&bitmap, width, height);
|
2015-08-26 20:07:48 +00:00
|
|
|
canvas.reset(new SkCanvas(bitmap));
|
2012-08-20 15:03:29 +00:00
|
|
|
}
|
2012-12-17 19:25:54 +00:00
|
|
|
break;
|
2012-08-20 15:03:29 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
2013-02-08 19:38:21 +00:00
|
|
|
#if SK_ANGLE
|
|
|
|
case kAngle_DeviceType:
|
|
|
|
// fall through
|
2014-01-06 18:37:24 +00:00
|
|
|
#endif
|
2015-08-27 17:38:39 +00:00
|
|
|
#if SK_COMMAND_BUFFER
|
|
|
|
case kCommandBuffer_DeviceType:
|
|
|
|
// fall through
|
|
|
|
#endif
|
2014-01-06 18:37:24 +00:00
|
|
|
#if SK_MESA
|
|
|
|
case kMesa_DeviceType:
|
|
|
|
// fall through
|
2013-02-08 19:38:21 +00:00
|
|
|
#endif
|
2014-03-07 18:41:14 +00:00
|
|
|
case kGPU_DeviceType:
|
|
|
|
case kNVPR_DeviceType: {
|
2013-04-10 17:27:30 +00:00
|
|
|
SkAutoTUnref<GrSurface> target;
|
2013-02-08 19:38:21 +00:00
|
|
|
if (fGrContext) {
|
|
|
|
// create a render target to back the device
|
2014-10-28 21:33:06 +00:00
|
|
|
GrSurfaceDesc desc;
|
2013-02-08 19:38:21 +00:00
|
|
|
desc.fConfig = kSkia8888_GrPixelConfig;
|
2014-10-28 21:33:06 +00:00
|
|
|
desc.fFlags = kRenderTarget_GrSurfaceFlag;
|
2013-02-08 19:38:21 +00:00
|
|
|
desc.fWidth = width;
|
|
|
|
desc.fHeight = height;
|
2013-05-02 12:39:37 +00:00
|
|
|
desc.fSampleCnt = fSampleCount;
|
2015-08-27 14:41:13 +00:00
|
|
|
target.reset(fGrContext->textureProvider()->createTexture(desc, false, nullptr, 0));
|
2013-02-08 19:38:21 +00:00
|
|
|
}
|
2015-01-16 15:32:33 +00:00
|
|
|
|
2015-08-31 19:39:41 +00:00
|
|
|
uint32_t flags = fUseDFText ? SkSurfaceProps::kUseDeviceIndependentFonts_Flag : 0;
|
2015-01-16 15:32:33 +00:00
|
|
|
SkSurfaceProps props(flags, SkSurfaceProps::kLegacyFontHost_InitType);
|
2015-06-23 21:38:48 +00:00
|
|
|
SkAutoTUnref<SkGpuDevice> device(
|
|
|
|
SkGpuDevice::Create(target->asRenderTarget(), &props,
|
|
|
|
SkGpuDevice::kUninit_InitContents));
|
2015-01-16 15:32:33 +00:00
|
|
|
if (!device) {
|
2015-08-27 14:41:13 +00:00
|
|
|
return nullptr;
|
2013-02-08 19:38:21 +00:00
|
|
|
}
|
2015-08-26 20:07:48 +00:00
|
|
|
canvas.reset(new SkCanvas(device));
|
2013-02-08 19:38:21 +00:00
|
|
|
break;
|
2012-08-20 15:03:29 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
SkASSERT(0);
|
2015-08-27 14:41:13 +00:00
|
|
|
return nullptr;
|
2012-08-20 15:03:29 +00:00
|
|
|
}
|
2015-06-15 18:48:16 +00:00
|
|
|
|
|
|
|
if (fHasDrawFilters) {
|
|
|
|
if (fDrawFilters[0] & PictureRenderer::kAAClip_DrawFilterFlag) {
|
|
|
|
canvas->setAllowSoftClip(false);
|
|
|
|
}
|
|
|
|
|
2015-08-26 20:07:48 +00:00
|
|
|
canvas.reset(new FlagsFilterCanvas(canvas.get(), fDrawFilters));
|
2015-06-15 18:48:16 +00:00
|
|
|
}
|
|
|
|
|
2012-12-17 19:25:54 +00:00
|
|
|
this->scaleToScaleFactor(canvas);
|
2014-01-15 14:51:25 +00:00
|
|
|
|
|
|
|
// Pictures often lie about their extent (i.e., claim to be 100x100 but
|
|
|
|
// only ever draw to 90x100). Clear here so the undrawn portion will have
|
|
|
|
// a consistent color
|
|
|
|
canvas->clear(SK_ColorTRANSPARENT);
|
2015-06-15 18:48:16 +00:00
|
|
|
return canvas.detach();
|
2012-12-17 19:25:54 +00:00
|
|
|
}
|
2012-08-20 15:03:57 +00:00
|
|
|
|
2012-12-17 19:25:54 +00:00
|
|
|
void PictureRenderer::scaleToScaleFactor(SkCanvas* canvas) {
|
2015-08-27 14:41:13 +00:00
|
|
|
SkASSERT(canvas != nullptr);
|
2012-12-17 19:25:54 +00:00
|
|
|
if (fScaleFactor != SK_Scalar1) {
|
|
|
|
canvas->scale(fScaleFactor, fScaleFactor);
|
|
|
|
}
|
2012-08-07 17:11:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PictureRenderer::end() {
|
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
|
|
|
this->resetState(true);
|
2015-08-27 14:41:13 +00:00
|
|
|
fPicture.reset(nullptr);
|
|
|
|
fCanvas.reset(nullptr);
|
2012-08-07 17:11:33 +00:00
|
|
|
}
|
|
|
|
|
2012-12-13 21:40:48 +00:00
|
|
|
int PictureRenderer::getViewWidth() {
|
2015-08-27 14:41:13 +00:00
|
|
|
SkASSERT(fPicture != nullptr);
|
2014-08-29 15:03:56 +00:00
|
|
|
int width = SkScalarCeilToInt(fPicture->cullRect().width() * fScaleFactor);
|
2012-12-13 21:40:48 +00:00
|
|
|
if (fViewport.width() > 0) {
|
|
|
|
width = SkMin32(width, fViewport.width());
|
|
|
|
}
|
|
|
|
return width;
|
|
|
|
}
|
|
|
|
|
|
|
|
int PictureRenderer::getViewHeight() {
|
2015-08-27 14:41:13 +00:00
|
|
|
SkASSERT(fPicture != nullptr);
|
2014-08-29 15:03:56 +00:00
|
|
|
int height = SkScalarCeilToInt(fPicture->cullRect().height() * fScaleFactor);
|
2012-12-13 21:40:48 +00:00
|
|
|
if (fViewport.height() > 0) {
|
|
|
|
height = SkMin32(height, fViewport.height());
|
|
|
|
}
|
|
|
|
return height;
|
|
|
|
}
|
|
|
|
|
2012-11-02 18:11:49 +00:00
|
|
|
/** Converts fPicture to a picture that uses a BBoxHierarchy.
|
|
|
|
* PictureRenderer subclasses that are used to test picture playback
|
|
|
|
* should call this method during init.
|
|
|
|
*/
|
|
|
|
void PictureRenderer::buildBBoxHierarchy() {
|
2014-09-05 20:34:00 +00:00
|
|
|
SkASSERT(fPicture);
|
|
|
|
if (kNone_BBoxHierarchyType != fBBoxHierarchyType && fPicture) {
|
2014-04-17 23:35:06 +00:00
|
|
|
SkAutoTDelete<SkBBHFactory> factory(this->getFactory());
|
|
|
|
SkPictureRecorder recorder;
|
2014-11-11 12:54:49 +00:00
|
|
|
uint32_t flags = this->recordFlags();
|
|
|
|
if (fUseMultiPictureDraw) {
|
|
|
|
flags |= SkPictureRecorder::kComputeSaveLayerInfo_RecordFlag;
|
|
|
|
}
|
2015-01-09 14:41:48 +00:00
|
|
|
SkCanvas* canvas = recorder.beginRecording(fPicture->cullRect().width(),
|
2014-08-29 15:03:56 +00:00
|
|
|
fPicture->cullRect().height(),
|
2014-04-17 23:35:06 +00:00
|
|
|
factory.get(),
|
2014-11-11 12:54:49 +00:00
|
|
|
flags);
|
2014-09-04 15:42:50 +00:00
|
|
|
fPicture->playback(canvas);
|
2014-04-13 19:09:42 +00:00
|
|
|
fPicture.reset(recorder.endRecording());
|
2012-11-02 18:11:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
void PictureRenderer::resetState(bool callFinish) {
|
2012-08-20 15:04:12 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
2014-10-09 12:24:15 +00:00
|
|
|
SkGLContext* glContext = this->getGLContext();
|
2015-08-27 14:41:13 +00:00
|
|
|
if (nullptr == glContext) {
|
2013-02-08 19:38:21 +00:00
|
|
|
SkASSERT(kBitmap_DeviceType == fDeviceType);
|
|
|
|
return;
|
|
|
|
}
|
2012-08-20 15:04:15 +00:00
|
|
|
|
2013-02-08 19:38:21 +00:00
|
|
|
fGrContext->flush();
|
2014-03-11 22:58:00 +00:00
|
|
|
glContext->swapBuffers();
|
2013-02-08 19:38:21 +00:00
|
|
|
if (callFinish) {
|
|
|
|
SK_GL(*glContext, Finish());
|
2012-08-20 15:03:47 +00:00
|
|
|
}
|
2012-08-20 15:04:12 +00:00
|
|
|
#endif
|
2012-08-20 15:03:47 +00:00
|
|
|
}
|
|
|
|
|
2013-12-18 17:25:33 +00:00
|
|
|
void PictureRenderer::purgeTextures() {
|
|
|
|
SkDiscardableMemoryPool* pool = SkGetGlobalDiscardableMemoryPool();
|
|
|
|
|
|
|
|
pool->dumpPool();
|
|
|
|
|
|
|
|
#if SK_SUPPORT_GPU
|
2014-10-09 12:24:15 +00:00
|
|
|
SkGLContext* glContext = this->getGLContext();
|
2015-08-27 14:41:13 +00:00
|
|
|
if (nullptr == glContext) {
|
2013-12-18 17:25:33 +00:00
|
|
|
SkASSERT(kBitmap_DeviceType == fDeviceType);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// resetState should've already done this
|
|
|
|
fGrContext->flush();
|
|
|
|
|
|
|
|
fGrContext->purgeAllUnlockedResources();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2012-09-18 14:32:35 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2012-11-06 16:54:40 +00:00
|
|
|
SkCanvas* RecordPictureRenderer::setupCanvas(int width, int height) {
|
|
|
|
// defer the canvas setup until the render step
|
2015-08-27 14:41:13 +00:00
|
|
|
return nullptr;
|
2012-11-06 16:54:40 +00:00
|
|
|
}
|
|
|
|
|
2014-03-19 17:26:07 +00:00
|
|
|
bool RecordPictureRenderer::render(SkBitmap** out) {
|
2014-04-17 23:35:06 +00:00
|
|
|
SkAutoTDelete<SkBBHFactory> factory(this->getFactory());
|
|
|
|
SkPictureRecorder recorder;
|
2015-01-09 14:41:48 +00:00
|
|
|
SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(this->getViewWidth()),
|
2014-08-29 15:03:56 +00:00
|
|
|
SkIntToScalar(this->getViewHeight()),
|
2014-04-17 23:35:06 +00:00
|
|
|
factory.get(),
|
2014-04-13 19:09:42 +00:00
|
|
|
this->recordFlags());
|
|
|
|
this->scaleToScaleFactor(canvas);
|
2014-09-04 15:42:50 +00:00
|
|
|
fPicture->playback(canvas);
|
2014-04-13 19:09:42 +00:00
|
|
|
SkAutoTUnref<SkPicture> picture(recorder.endRecording());
|
2014-05-15 15:10:48 +00:00
|
|
|
if (!fWritePath.isEmpty()) {
|
2012-11-07 17:52:48 +00:00
|
|
|
// Record the new picture as a new SKP with PNG encoded bitmaps.
|
2014-07-29 02:26:58 +00:00
|
|
|
SkString skpPath = SkOSPath::Join(fWritePath.c_str(), fInputFilename.c_str());
|
2012-11-07 17:52:48 +00:00
|
|
|
SkFILEWStream stream(skpPath.c_str());
|
2015-03-23 12:46:51 +00:00
|
|
|
sk_tool_utils::PngPixelSerializer serializer;
|
2014-12-11 18:53:58 +00:00
|
|
|
picture->serialize(&stream, &serializer);
|
2012-11-07 17:52:48 +00:00
|
|
|
return true;
|
|
|
|
}
|
2012-09-20 14:54:21 +00:00
|
|
|
return false;
|
2012-09-07 15:21:18 +00:00
|
|
|
}
|
|
|
|
|
2012-11-02 22:01:26 +00:00
|
|
|
SkString RecordPictureRenderer::getConfigNameInternal() {
|
|
|
|
return SkString("record");
|
|
|
|
}
|
|
|
|
|
2012-09-18 14:32:35 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2014-03-19 17:26:07 +00:00
|
|
|
bool PipePictureRenderer::render(SkBitmap** out) {
|
2015-08-27 14:41:13 +00:00
|
|
|
SkASSERT(fCanvas.get() != nullptr);
|
|
|
|
SkASSERT(fPicture != nullptr);
|
|
|
|
if (nullptr == fCanvas.get() || nullptr == fPicture) {
|
2012-09-20 14:54:21 +00:00
|
|
|
return false;
|
2012-08-07 17:11:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PipeController pipeController(fCanvas.get());
|
2012-07-26 17:27:57 +00:00
|
|
|
SkGPipeWriter writer;
|
|
|
|
SkCanvas* pipeCanvas = writer.startRecording(&pipeController);
|
2014-06-04 12:40:44 +00:00
|
|
|
pipeCanvas->drawPicture(fPicture);
|
2012-07-26 17:27:57 +00:00
|
|
|
writer.endRecording();
|
2012-09-07 15:21:18 +00:00
|
|
|
fCanvas->flush();
|
2014-09-05 20:34:00 +00:00
|
|
|
if (out) {
|
2015-08-26 20:07:48 +00:00
|
|
|
*out = new SkBitmap;
|
2015-01-09 14:41:48 +00:00
|
|
|
setup_bitmap(*out, SkScalarCeilToInt(fPicture->cullRect().width()),
|
2014-08-29 15:03:56 +00:00
|
|
|
SkScalarCeilToInt(fPicture->cullRect().height()));
|
2012-12-18 22:24:03 +00:00
|
|
|
fCanvas->readPixels(*out, 0, 0);
|
2012-12-19 02:01:38 +00:00
|
|
|
}
|
2015-10-20 21:29:10 +00:00
|
|
|
return true;
|
2012-07-26 17:27:57 +00:00
|
|
|
}
|
|
|
|
|
2012-11-02 22:01:26 +00:00
|
|
|
SkString PipePictureRenderer::getConfigNameInternal() {
|
|
|
|
return SkString("pipe");
|
|
|
|
}
|
|
|
|
|
2012-09-18 14:32:35 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2014-07-07 20:46:35 +00:00
|
|
|
void SimplePictureRenderer::init(const SkPicture* picture, const SkString* writePath,
|
2014-05-15 15:10:48 +00:00
|
|
|
const SkString* mismatchPath, const SkString* inputFilename,
|
2014-10-09 11:59:19 +00:00
|
|
|
bool useChecksumBasedFilenames, bool useMultiPictureDraw) {
|
2015-01-09 14:41:48 +00:00
|
|
|
INHERITED::init(picture, writePath, mismatchPath, inputFilename,
|
2014-10-09 11:59:19 +00:00
|
|
|
useChecksumBasedFilenames, useMultiPictureDraw);
|
2012-11-02 18:11:49 +00:00
|
|
|
this->buildBBoxHierarchy();
|
|
|
|
}
|
|
|
|
|
2014-03-19 17:26:07 +00:00
|
|
|
bool SimplePictureRenderer::render(SkBitmap** out) {
|
2015-08-27 14:41:13 +00:00
|
|
|
SkASSERT(fCanvas.get() != nullptr);
|
2014-09-05 20:34:00 +00:00
|
|
|
SkASSERT(fPicture);
|
2015-08-27 14:41:13 +00:00
|
|
|
if (nullptr == fCanvas.get() || nullptr == fPicture) {
|
2012-09-20 14:54:21 +00:00
|
|
|
return false;
|
2012-08-07 17:11:33 +00:00
|
|
|
}
|
|
|
|
|
2014-10-09 11:59:19 +00:00
|
|
|
if (fUseMultiPictureDraw) {
|
|
|
|
SkMultiPictureDraw mpd;
|
|
|
|
|
|
|
|
mpd.add(fCanvas, fPicture);
|
|
|
|
|
|
|
|
mpd.draw();
|
|
|
|
} else {
|
|
|
|
fCanvas->drawPicture(fPicture);
|
|
|
|
}
|
2012-09-07 15:21:18 +00:00
|
|
|
fCanvas->flush();
|
2014-09-05 20:34:00 +00:00
|
|
|
if (out) {
|
2015-08-26 20:07:48 +00:00
|
|
|
*out = new SkBitmap;
|
2015-01-09 14:41:48 +00:00
|
|
|
setup_bitmap(*out, SkScalarCeilToInt(fPicture->cullRect().width()),
|
2014-08-29 15:03:56 +00:00
|
|
|
SkScalarCeilToInt(fPicture->cullRect().height()));
|
2012-12-18 22:24:03 +00:00
|
|
|
fCanvas->readPixels(*out, 0, 0);
|
|
|
|
}
|
2015-10-20 21:29:10 +00:00
|
|
|
return true;
|
2012-07-26 17:27:57 +00:00
|
|
|
}
|
|
|
|
|
2012-11-02 22:01:26 +00:00
|
|
|
SkString SimplePictureRenderer::getConfigNameInternal() {
|
|
|
|
return SkString("simple");
|
|
|
|
}
|
|
|
|
|
2012-09-18 14:32:35 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2014-08-18 14:52:17 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
2015-05-22 21:01:46 +00:00
|
|
|
TiledPictureRenderer::TiledPictureRenderer(const GrContextOptions& opts)
|
2014-08-26 21:07:04 +00:00
|
|
|
: INHERITED(opts)
|
2014-08-18 14:52:17 +00:00
|
|
|
, fTileWidth(kDefaultTileWidth)
|
|
|
|
#else
|
2012-07-26 17:27:57 +00:00
|
|
|
TiledPictureRenderer::TiledPictureRenderer()
|
2012-11-02 21:28:12 +00:00
|
|
|
: fTileWidth(kDefaultTileWidth)
|
2014-08-18 14:52:17 +00:00
|
|
|
#endif
|
2012-08-29 17:35:07 +00:00
|
|
|
, fTileHeight(kDefaultTileHeight)
|
2012-09-10 19:01:38 +00:00
|
|
|
, fTileWidthPercentage(0.0)
|
2012-08-29 17:35:07 +00:00
|
|
|
, fTileHeightPercentage(0.0)
|
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
|
|
|
, fTileMinPowerOf2Width(0)
|
|
|
|
, fCurrentTileOffset(-1)
|
|
|
|
, fTilesX(0)
|
|
|
|
, fTilesY(0) { }
|
2012-07-26 17:27:57 +00:00
|
|
|
|
2014-07-07 20:46:35 +00:00
|
|
|
void TiledPictureRenderer::init(const SkPicture* pict, const SkString* writePath,
|
2014-05-15 15:10:48 +00:00
|
|
|
const SkString* mismatchPath, const SkString* inputFilename,
|
2014-10-09 11:59:19 +00:00
|
|
|
bool useChecksumBasedFilenames, bool useMultiPictureDraw) {
|
2014-09-05 20:34:00 +00:00
|
|
|
SkASSERT(pict);
|
2012-09-18 14:32:35 +00:00
|
|
|
SkASSERT(0 == fTileRects.count());
|
2015-08-27 14:41:13 +00:00
|
|
|
if (nullptr == pict || fTileRects.count() != 0) {
|
2012-08-07 17:11:33 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-09-18 14:32:35 +00:00
|
|
|
// Do not call INHERITED::init(), which would create a (potentially large) canvas which is not
|
|
|
|
// used by bench_pictures.
|
2015-10-01 19:28:49 +00:00
|
|
|
fPicture.reset(SkRef(pict));
|
2014-05-15 15:10:48 +00:00
|
|
|
this->CopyString(&fWritePath, writePath);
|
|
|
|
this->CopyString(&fMismatchPath, mismatchPath);
|
2014-03-19 17:26:07 +00:00
|
|
|
this->CopyString(&fInputFilename, inputFilename);
|
|
|
|
fUseChecksumBasedFilenames = useChecksumBasedFilenames;
|
2014-10-09 11:59:19 +00:00
|
|
|
fUseMultiPictureDraw = useMultiPictureDraw;
|
2012-11-02 21:28:12 +00:00
|
|
|
this->buildBBoxHierarchy();
|
2012-07-27 20:09:26 +00:00
|
|
|
|
|
|
|
if (fTileWidthPercentage > 0) {
|
2014-08-29 15:03:56 +00:00
|
|
|
fTileWidth = SkScalarCeilToInt(float(fTileWidthPercentage * fPicture->cullRect().width() / 100));
|
2012-07-27 20:09:26 +00:00
|
|
|
}
|
|
|
|
if (fTileHeightPercentage > 0) {
|
2014-08-29 15:03:56 +00:00
|
|
|
fTileHeight = SkScalarCeilToInt(float(fTileHeightPercentage * fPicture->cullRect().height() / 100));
|
2012-07-27 20:09:26 +00:00
|
|
|
}
|
|
|
|
|
2012-08-23 20:53:25 +00:00
|
|
|
if (fTileMinPowerOf2Width > 0) {
|
|
|
|
this->setupPowerOf2Tiles();
|
|
|
|
} else {
|
|
|
|
this->setupTiles();
|
|
|
|
}
|
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
|
|
|
fCanvas.reset(this->setupCanvas(fTileWidth, fTileHeight));
|
|
|
|
// Initialize to -1 so that the first call to nextTile will set this up to draw tile 0 on the
|
|
|
|
// first call to drawCurrentTile.
|
|
|
|
fCurrentTileOffset = -1;
|
2012-07-26 17:27:57 +00:00
|
|
|
}
|
|
|
|
|
2012-08-07 17:11:33 +00:00
|
|
|
void TiledPictureRenderer::end() {
|
2012-09-20 14:42:33 +00:00
|
|
|
fTileRects.reset();
|
2012-08-07 17:11:33 +00:00
|
|
|
this->INHERITED::end();
|
2012-07-26 17:27:57 +00:00
|
|
|
}
|
|
|
|
|
2012-08-07 17:11:33 +00:00
|
|
|
void TiledPictureRenderer::setupTiles() {
|
2012-12-13 21:40:48 +00:00
|
|
|
// Only use enough tiles to cover the viewport
|
|
|
|
const int width = this->getViewWidth();
|
|
|
|
const int height = this->getViewHeight();
|
|
|
|
|
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
|
|
|
fTilesX = fTilesY = 0;
|
2012-12-13 21:40:48 +00:00
|
|
|
for (int tile_y_start = 0; tile_y_start < height; tile_y_start += fTileHeight) {
|
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
|
|
|
fTilesY++;
|
2012-12-13 21:40:48 +00:00
|
|
|
for (int tile_x_start = 0; tile_x_start < width; tile_x_start += fTileWidth) {
|
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 (0 == tile_y_start) {
|
|
|
|
// Only count tiles in the X direction on the first pass.
|
|
|
|
fTilesX++;
|
|
|
|
}
|
2014-10-09 11:59:19 +00:00
|
|
|
*fTileRects.append() = SkIRect::MakeXYWH(tile_x_start, tile_y_start,
|
|
|
|
fTileWidth, fTileHeight);
|
2012-08-23 20:53:25 +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
|
|
|
bool TiledPictureRenderer::tileDimensions(int &x, int &y) {
|
2015-08-27 14:41:13 +00:00
|
|
|
if (fTileRects.count() == 0 || nullptr == fPicture) {
|
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
|
|
|
return false;
|
|
|
|
}
|
|
|
|
x = fTilesX;
|
|
|
|
y = fTilesY;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-08-23 20:53:25 +00:00
|
|
|
// The goal of the powers of two tiles is to minimize the amount of wasted tile
|
|
|
|
// space in the width-wise direction and then minimize the number of tiles. The
|
|
|
|
// constraints are that every tile must have a pixel width that is a power of
|
|
|
|
// two and also be of some minimal width (that is also a power of two).
|
|
|
|
//
|
2012-08-31 16:15:22 +00:00
|
|
|
// This is solved by first taking our picture size and rounding it up to the
|
2012-08-23 20:53:25 +00:00
|
|
|
// multiple of the minimal width. The binary representation of this rounded
|
|
|
|
// value gives us the tiles we need: a bit of value one means we need a tile of
|
|
|
|
// that size.
|
|
|
|
void TiledPictureRenderer::setupPowerOf2Tiles() {
|
2012-12-13 21:40:48 +00:00
|
|
|
// Only use enough tiles to cover the viewport
|
|
|
|
const int width = this->getViewWidth();
|
|
|
|
const int height = this->getViewHeight();
|
|
|
|
|
|
|
|
int rounded_value = width;
|
|
|
|
if (width % fTileMinPowerOf2Width != 0) {
|
|
|
|
rounded_value = width - (width % fTileMinPowerOf2Width) + fTileMinPowerOf2Width;
|
2012-08-23 20:53:25 +00:00
|
|
|
}
|
|
|
|
|
2013-12-18 04:59:26 +00:00
|
|
|
int num_bits = SkScalarCeilToInt(scalar_log2(SkIntToScalar(width)));
|
2012-08-23 20:53:25 +00:00
|
|
|
int largest_possible_tile_size = 1 << num_bits;
|
|
|
|
|
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
|
|
|
fTilesX = fTilesY = 0;
|
2012-08-23 20:53:25 +00:00
|
|
|
// The tile height is constant for a particular picture.
|
2012-12-13 21:40:48 +00:00
|
|
|
for (int tile_y_start = 0; tile_y_start < height; tile_y_start += fTileHeight) {
|
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
|
|
|
fTilesY++;
|
2012-08-23 20:53:25 +00:00
|
|
|
int tile_x_start = 0;
|
|
|
|
int current_width = largest_possible_tile_size;
|
2012-09-18 14:32:35 +00:00
|
|
|
// Set fTileWidth to be the width of the widest tile, so that each canvas is large enough
|
|
|
|
// to draw each tile.
|
|
|
|
fTileWidth = current_width;
|
2012-08-23 20:53:25 +00:00
|
|
|
|
|
|
|
while (current_width >= fTileMinPowerOf2Width) {
|
|
|
|
// It is very important this is a bitwise AND.
|
|
|
|
if (current_width & rounded_value) {
|
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 (0 == tile_y_start) {
|
|
|
|
// Only count tiles in the X direction on the first pass.
|
|
|
|
fTilesX++;
|
|
|
|
}
|
2014-10-09 11:59:19 +00:00
|
|
|
*fTileRects.append() = SkIRect::MakeXYWH(tile_x_start, tile_y_start,
|
|
|
|
current_width, fTileHeight);
|
2012-08-23 20:53:25 +00:00
|
|
|
tile_x_start += current_width;
|
|
|
|
}
|
|
|
|
|
|
|
|
current_width >>= 1;
|
2012-07-26 17:27:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-20 14:42:33 +00:00
|
|
|
/**
|
2014-03-16 19:46:36 +00:00
|
|
|
* Draw the specified picture to the canvas translated to rectangle provided, so that this mini
|
2012-09-20 14:42:33 +00:00
|
|
|
* canvas represents the rectangle's portion of the overall picture.
|
|
|
|
* Saves and restores so that the initial clip and matrix return to their state before this function
|
|
|
|
* is called.
|
|
|
|
*/
|
2014-08-26 21:07:04 +00:00
|
|
|
static void draw_tile_to_canvas(SkCanvas* canvas,
|
2014-10-09 11:59:19 +00:00
|
|
|
const SkIRect& tileRect,
|
2014-07-07 20:46:35 +00:00
|
|
|
const SkPicture* picture) {
|
2012-09-20 14:42:33 +00:00
|
|
|
int saveCount = canvas->save();
|
2012-12-17 19:25:54 +00:00
|
|
|
// Translate so that we draw the correct portion of the picture.
|
|
|
|
// Perform a postTranslate so that the scaleFactor does not interfere with the positioning.
|
|
|
|
SkMatrix mat(canvas->getTotalMatrix());
|
2014-10-09 11:59:19 +00:00
|
|
|
mat.postTranslate(-SkIntToScalar(tileRect.fLeft), -SkIntToScalar(tileRect.fTop));
|
2012-12-17 19:25:54 +00:00
|
|
|
canvas->setMatrix(mat);
|
2014-11-28 15:42:16 +00:00
|
|
|
canvas->clipRect(SkRect::Make(tileRect));
|
2014-10-20 15:45:57 +00:00
|
|
|
canvas->clear(SK_ColorTRANSPARENT); // Not every picture covers the entirety of every tile
|
2014-06-04 12:40:44 +00:00
|
|
|
canvas->drawPicture(picture);
|
2012-09-20 14:42:33 +00:00
|
|
|
canvas->restoreToCount(saveCount);
|
|
|
|
canvas->flush();
|
2012-07-26 17:27:57 +00:00
|
|
|
}
|
|
|
|
|
2012-09-20 14:42:33 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2013-12-13 20:52:36 +00:00
|
|
|
/**
|
|
|
|
* Copies the entirety of the src bitmap (typically a tile) into a portion of the dst bitmap.
|
|
|
|
* If the src bitmap is too large to fit within the dst bitmap after the x and y
|
|
|
|
* offsets have been applied, any excess will be ignored (so only the top-left portion of the
|
|
|
|
* src bitmap will be copied).
|
|
|
|
*
|
|
|
|
* @param src source bitmap
|
|
|
|
* @param dst destination bitmap
|
|
|
|
* @param xOffset x-offset within destination bitmap
|
|
|
|
* @param yOffset y-offset within destination bitmap
|
|
|
|
*/
|
|
|
|
static void bitmapCopyAtOffset(const SkBitmap& src, SkBitmap* dst,
|
|
|
|
int xOffset, int yOffset) {
|
|
|
|
for (int y = 0; y <src.height() && y + yOffset < dst->height() ; y++) {
|
|
|
|
for (int x = 0; x < src.width() && x + xOffset < dst->width() ; x++) {
|
|
|
|
*dst->getAddr32(xOffset + x, yOffset + y) = *src.getAddr32(x, y);
|
2012-12-18 22:24:03 +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
|
|
|
bool TiledPictureRenderer::nextTile(int &i, int &j) {
|
|
|
|
if (++fCurrentTileOffset < fTileRects.count()) {
|
|
|
|
i = fCurrentTileOffset % fTilesX;
|
|
|
|
j = fCurrentTileOffset / fTilesX;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TiledPictureRenderer::drawCurrentTile() {
|
|
|
|
SkASSERT(fCurrentTileOffset >= 0 && fCurrentTileOffset < fTileRects.count());
|
2014-03-16 19:46:36 +00:00
|
|
|
draw_tile_to_canvas(fCanvas, fTileRects[fCurrentTileOffset], fPicture);
|
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
|
|
|
}
|
|
|
|
|
2015-01-09 14:41:48 +00:00
|
|
|
bool TiledPictureRenderer::postRender(SkCanvas* canvas, const SkIRect& tileRect,
|
2014-10-09 11:59:19 +00:00
|
|
|
SkBitmap* tempBM, SkBitmap** out,
|
|
|
|
int tileNumber) {
|
|
|
|
bool success = true;
|
|
|
|
|
|
|
|
if (out) {
|
|
|
|
if (canvas->readPixels(tempBM, 0, 0)) {
|
|
|
|
// Add this tile to the entire bitmap.
|
|
|
|
bitmapCopyAtOffset(*tempBM, *out, tileRect.left(), tileRect.top());
|
|
|
|
} else {
|
|
|
|
success = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
2014-03-19 17:26:07 +00:00
|
|
|
bool TiledPictureRenderer::render(SkBitmap** out) {
|
2015-08-27 14:41:13 +00:00
|
|
|
SkASSERT(fPicture != nullptr);
|
|
|
|
if (nullptr == fPicture) {
|
2012-11-02 21:28:12 +00:00
|
|
|
return false;
|
2012-09-20 14:42:33 +00:00
|
|
|
}
|
|
|
|
|
2012-12-18 22:24:03 +00:00
|
|
|
SkBitmap bitmap;
|
2014-10-09 11:59:19 +00:00
|
|
|
if (out) {
|
2015-08-26 20:07:48 +00:00
|
|
|
*out = new SkBitmap;
|
2015-01-09 14:41:48 +00:00
|
|
|
setup_bitmap(*out, SkScalarCeilToInt(fPicture->cullRect().width()),
|
2014-08-29 15:03:56 +00:00
|
|
|
SkScalarCeilToInt(fPicture->cullRect().height()));
|
2012-12-18 22:24:03 +00:00
|
|
|
setup_bitmap(&bitmap, fTileWidth, fTileHeight);
|
|
|
|
}
|
2012-11-02 21:28:12 +00:00
|
|
|
bool success = true;
|
2014-10-09 11:59:19 +00:00
|
|
|
|
|
|
|
if (fUseMultiPictureDraw) {
|
|
|
|
SkMultiPictureDraw mpd;
|
|
|
|
SkTDArray<SkSurface*> surfaces;
|
|
|
|
surfaces.setReserve(fTileRects.count());
|
|
|
|
|
|
|
|
// Create a separate SkSurface/SkCanvas for each tile along with a
|
|
|
|
// translated version of the skp (to mimic Chrome's behavior) and
|
|
|
|
// feed all such pairs to the MultiPictureDraw.
|
|
|
|
for (int i = 0; i < fTileRects.count(); ++i) {
|
|
|
|
SkImageInfo ii = fCanvas->imageInfo().makeWH(fTileRects[i].width(),
|
|
|
|
fTileRects[i].height());
|
|
|
|
*surfaces.append() = fCanvas->newSurface(ii);
|
|
|
|
surfaces[i]->getCanvas()->setMatrix(fCanvas->getTotalMatrix());
|
|
|
|
|
|
|
|
SkPictureRecorder recorder;
|
2014-11-11 12:54:49 +00:00
|
|
|
SkRTreeFactory bbhFactory;
|
|
|
|
|
2014-10-09 11:59:19 +00:00
|
|
|
SkCanvas* c = recorder.beginRecording(SkIntToScalar(fTileRects[i].width()),
|
2014-11-11 12:54:49 +00:00
|
|
|
SkIntToScalar(fTileRects[i].height()),
|
|
|
|
&bbhFactory,
|
|
|
|
SkPictureRecorder::kComputeSaveLayerInfo_RecordFlag);
|
2014-10-09 11:59:19 +00:00
|
|
|
c->save();
|
|
|
|
SkMatrix mat;
|
|
|
|
mat.setTranslate(-SkIntToScalar(fTileRects[i].fLeft),
|
|
|
|
-SkIntToScalar(fTileRects[i].fTop));
|
|
|
|
c->setMatrix(mat);
|
|
|
|
c->drawPicture(fPicture);
|
|
|
|
c->restore();
|
|
|
|
|
|
|
|
SkAutoTUnref<SkPicture> xlatedPicture(recorder.endRecording());
|
|
|
|
|
|
|
|
mpd.add(surfaces[i]->getCanvas(), xlatedPicture);
|
2014-05-22 00:36:05 +00:00
|
|
|
}
|
2014-10-09 11:59:19 +00:00
|
|
|
|
|
|
|
// Render all the buffered SkCanvases/SkPictures
|
|
|
|
mpd.draw();
|
|
|
|
|
|
|
|
// Sort out the results and cleanup the allocated surfaces
|
|
|
|
for (int i = 0; i < fTileRects.count(); ++i) {
|
|
|
|
success &= this->postRender(surfaces[i]->getCanvas(), fTileRects[i], &bitmap, out, i);
|
|
|
|
surfaces[i]->unref();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (int i = 0; i < fTileRects.count(); ++i) {
|
|
|
|
draw_tile_to_canvas(fCanvas, fTileRects[i], fPicture);
|
|
|
|
success &= this->postRender(fCanvas, fTileRects[i], &bitmap, out, i);
|
2012-12-18 22:24:03 +00:00
|
|
|
}
|
2012-09-20 14:42:33 +00:00
|
|
|
}
|
2014-10-09 11:59:19 +00:00
|
|
|
|
2012-11-02 21:28:12 +00:00
|
|
|
return success;
|
2012-09-20 14:42:33 +00:00
|
|
|
}
|
2012-08-31 16:15:22 +00:00
|
|
|
|
2012-11-02 21:28:12 +00:00
|
|
|
SkCanvas* TiledPictureRenderer::setupCanvas(int width, int height) {
|
|
|
|
SkCanvas* canvas = this->INHERITED::setupCanvas(width, height);
|
2014-09-05 20:34:00 +00:00
|
|
|
SkASSERT(fPicture);
|
2012-12-17 19:25:54 +00:00
|
|
|
// Clip the tile to an area that is completely inside both the SkPicture and the viewport. This
|
|
|
|
// is mostly important for tiles on the right and bottom edges as they may go over this area and
|
|
|
|
// the picture may have some commands that draw outside of this area and so should not actually
|
|
|
|
// be written.
|
|
|
|
// Uses a clipRegion so that it will be unaffected by the scale factor, which may have been set
|
|
|
|
// by INHERITED::setupCanvas.
|
|
|
|
SkRegion clipRegion;
|
|
|
|
clipRegion.setRect(0, 0, this->getViewWidth(), this->getViewHeight());
|
|
|
|
canvas->clipRegion(clipRegion);
|
2012-11-02 21:28:12 +00:00
|
|
|
return canvas;
|
|
|
|
}
|
2012-11-02 22:01:26 +00:00
|
|
|
|
|
|
|
SkString TiledPictureRenderer::getConfigNameInternal() {
|
|
|
|
SkString name;
|
|
|
|
if (fTileMinPowerOf2Width > 0) {
|
|
|
|
name.append("pow2tile_");
|
|
|
|
name.appendf("%i", fTileMinPowerOf2Width);
|
|
|
|
} else {
|
|
|
|
name.append("tile_");
|
|
|
|
if (fTileWidthPercentage > 0) {
|
|
|
|
name.appendf("%.f%%", fTileWidthPercentage);
|
|
|
|
} else {
|
|
|
|
name.appendf("%i", fTileWidth);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
name.append("x");
|
|
|
|
if (fTileHeightPercentage > 0) {
|
|
|
|
name.appendf("%.f%%", fTileHeightPercentage);
|
|
|
|
} else {
|
|
|
|
name.appendf("%i", fTileHeight);
|
|
|
|
}
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
2012-08-31 16:15:22 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2012-09-07 15:21:18 +00:00
|
|
|
void PlaybackCreationRenderer::setup() {
|
2014-04-17 23:35:06 +00:00
|
|
|
SkAutoTDelete<SkBBHFactory> factory(this->getFactory());
|
2015-08-26 20:07:48 +00:00
|
|
|
fRecorder.reset(new SkPictureRecorder);
|
2015-01-09 14:41:48 +00:00
|
|
|
SkCanvas* canvas = fRecorder->beginRecording(SkIntToScalar(this->getViewWidth()),
|
2014-08-29 15:03:56 +00:00
|
|
|
SkIntToScalar(this->getViewHeight()),
|
2014-04-17 23:35:06 +00:00
|
|
|
factory.get(),
|
2014-04-13 19:09:42 +00:00
|
|
|
this->recordFlags());
|
|
|
|
this->scaleToScaleFactor(canvas);
|
2014-06-04 12:40:44 +00:00
|
|
|
canvas->drawPicture(fPicture);
|
2012-09-07 15:21:18 +00:00
|
|
|
}
|
|
|
|
|
2014-03-19 17:26:07 +00:00
|
|
|
bool PlaybackCreationRenderer::render(SkBitmap** out) {
|
2014-04-13 19:09:42 +00:00
|
|
|
fPicture.reset(fRecorder->endRecording());
|
2012-09-20 14:54:21 +00:00
|
|
|
// Since this class does not actually render, return false.
|
|
|
|
return false;
|
2012-07-26 17:27:57 +00:00
|
|
|
}
|
|
|
|
|
2012-11-02 22:01:26 +00:00
|
|
|
SkString PlaybackCreationRenderer::getConfigNameInternal() {
|
|
|
|
return SkString("playback_creation");
|
|
|
|
}
|
|
|
|
|
2012-11-02 18:11:49 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// SkPicture variants for each BBoxHierarchy type
|
|
|
|
|
2014-04-17 23:35:06 +00:00
|
|
|
SkBBHFactory* PictureRenderer::getFactory() {
|
2012-11-02 18:11:49 +00:00
|
|
|
switch (fBBoxHierarchyType) {
|
|
|
|
case kNone_BBoxHierarchyType:
|
2015-08-27 14:41:13 +00:00
|
|
|
return nullptr;
|
2012-11-02 18:11:49 +00:00
|
|
|
case kRTree_BBoxHierarchyType:
|
2015-08-26 20:07:48 +00:00
|
|
|
return new SkRTreeFactory;
|
2012-11-02 18:11:49 +00:00
|
|
|
}
|
|
|
|
SkASSERT(0); // invalid bbhType
|
2015-08-27 14:41:13 +00:00
|
|
|
return nullptr;
|
2012-07-26 17:27:57 +00:00
|
|
|
}
|
2012-11-02 18:11:49 +00:00
|
|
|
|
|
|
|
} // namespace sk_tools
|