robertphillips 2016-04-20 15:57:27 -07:00 committed by Commit bot
parent 9bc22351b5
commit a814000cbb
4 changed files with 44 additions and 59 deletions

View File

@ -1220,6 +1220,7 @@ public:
///////////////////////////////////////////////////////////////////////////
protected:
/** After calling saveLayer(), there can be any number of devices that make
up the top-most drawing area. LayerIter can be used to iterate through
those devices. Note that the iterator is only valid until the next API
@ -1258,6 +1259,7 @@ public:
bool fDone;
};
public:
// don't call
GrRenderTarget* internal_private_accessTopLayerRenderTarget();
@ -1431,6 +1433,7 @@ private:
void doSave();
void checkForDeferredSave();
friend class CanvasTestingAccess; // for testing
friend class SkDrawIter; // needs setupDrawForLayerDevice()
friend class AutoDrawLooper;
friend class SkLua; // needs top layer size and offset

View File

@ -12,7 +12,6 @@
#include "SkCamera.h"
#include "SkColorFilter.h"
#include "SkColorPriv.h"
#include "SkDevice.h"
#include "SkGradientShader.h"
#include "SkImage.h"
#include "SkInterpolator.h"
@ -35,22 +34,6 @@ static void make_paint(SkPaint* paint, const SkMatrix& localMatrix) {
paint->setXfermodeMode(SkXfermode::kDstIn_Mode);
}
static void dump_layers(const char label[], SkCanvas* canvas) {
SkDebugf("Dump Layers(%s)\n", label);
SkCanvas::LayerIter iter(canvas, true);
int index = 0;
while (!iter.done()) {
SkImageInfo info = iter.device()->imageInfo();
const SkIRect& clip = iter.clip().getBounds();
SkDebugf("Layer[%d] bitmap [%d %d] X=%d Y=%d clip=[%d %d %d %d] alpha=%d\n", index++,
info.width(), info.height(), iter.x(), iter.y(),
clip.fLeft, clip.fTop, clip.fRight, clip.fBottom,
iter.paint().getAlpha());
iter.next();
}
}
// test drawing with strips of fading gradient above and below
static void test_fade(SkCanvas* canvas) {
SkAutoCanvasRestore ar(canvas, true);
@ -86,8 +69,6 @@ static void test_fade(SkCanvas* canvas) {
p.setAntiAlias(true);
canvas->drawOval(r, p);
dump_layers("inside layer alpha", canvas);
canvas->restore();
} else {
r.set(0, 0, SkIntToScalar(100), SkIntToScalar(100));
@ -100,8 +81,6 @@ static void test_fade(SkCanvas* canvas) {
// return;
dump_layers("outside layer alpha", canvas);
// now apply an effect
SkMatrix m;
m.setScale(SK_Scalar1, -SK_Scalar1);

View File

@ -46,7 +46,6 @@
#include "SkBitmap.h"
#include "SkCanvas.h"
#include "SkClipStack.h"
#include "SkDevice.h"
#include "SkDocument.h"
#include "SkMatrix.h"
#include "SkNWayCanvas.h"
@ -498,6 +497,40 @@ static void NestedSaveRestoreWithFlushTestStep(SkCanvas* canvas, const TestData&
}
TEST_STEP(NestedSaveRestoreWithFlush, NestedSaveRestoreWithFlushTestStep);
class CanvasTestingAccess {
public:
static bool SameState(const SkCanvas* canvas1, const SkCanvas* canvas2) {
SkCanvas::LayerIter layerIter1(const_cast<SkCanvas*>(canvas1), false);
SkCanvas::LayerIter layerIter2(const_cast<SkCanvas*>(canvas2), false);
while (!layerIter1.done() && !layerIter2.done()) {
if (layerIter1.matrix() != layerIter2.matrix()) {
return false;
}
if (layerIter1.clip() != layerIter2.clip()) {
return false;
}
if (layerIter1.paint() != layerIter2.paint()) {
return false;
}
if (layerIter1.x() != layerIter2.x()) {
return false;
}
if (layerIter1.y() != layerIter2.y()) {
return false;
}
layerIter1.next();
layerIter2.next();
}
if (!layerIter1.done()) {
return false;
}
if (!layerIter2.done()) {
return false;
}
return true;
}
};
static void AssertCanvasStatesEqual(skiatest::Reporter* reporter, const TestData& d,
const SkCanvas* canvas1, const SkCanvas* canvas2,
CanvasTestStep* testStep) {
@ -528,27 +561,9 @@ static void AssertCanvasStatesEqual(skiatest::Reporter* reporter, const TestData
canvas2->getTotalMatrix(), testStep->assertMessage());
REPORTER_ASSERT_MESSAGE(reporter, equal_clips(*canvas1, *canvas2), testStep->assertMessage());
SkCanvas::LayerIter layerIter1(const_cast<SkCanvas*>(canvas1), false);
SkCanvas::LayerIter layerIter2(const_cast<SkCanvas*>(canvas2), false);
while (!layerIter1.done() && !layerIter2.done()) {
REPORTER_ASSERT_MESSAGE(reporter, layerIter1.matrix() ==
layerIter2.matrix(), testStep->assertMessage());
REPORTER_ASSERT_MESSAGE(reporter, layerIter1.clip() ==
layerIter2.clip(), testStep->assertMessage());
REPORTER_ASSERT_MESSAGE(reporter, layerIter1.paint() ==
layerIter2.paint(), testStep->assertMessage());
REPORTER_ASSERT_MESSAGE(reporter, layerIter1.x() ==
layerIter2.x(), testStep->assertMessage());
REPORTER_ASSERT_MESSAGE(reporter, layerIter1.y() ==
layerIter2.y(), testStep->assertMessage());
layerIter1.next();
layerIter2.next();
}
REPORTER_ASSERT_MESSAGE(reporter, layerIter1.done(),
testStep->assertMessage());
REPORTER_ASSERT_MESSAGE(reporter, layerIter2.done(),
testStep->assertMessage());
REPORTER_ASSERT_MESSAGE(reporter,
CanvasTestingAccess::SameState(canvas1, canvas2),
testStep->assertMessage());
}
static void TestPdfDevice(skiatest::Reporter* reporter,

View File

@ -9,7 +9,6 @@
#define WrappedBenchmark_DEFINED
#include "Benchmark.h"
#include "SkDevice.h"
#include "SkSurface.h"
#include "GrContext.h"
#include "GrRenderTarget.h"
@ -113,26 +112,15 @@ private:
void onBlitToScreen(SkCanvas* canvas, int w, int h) override {
// We call copySurface directly on the underlying GPU surfaces for a more efficient blit.
GrRenderTarget* dst, *src;
GrRenderTarget* dst = canvas->internal_private_accessTopLayerRenderTarget();
SkASSERT(dst);
SkCanvas::LayerIter canvasIter(canvas, false);
SkAssertResult((dst = canvasIter.device()->accessRenderTarget()));
SkCanvas::LayerIter offscreenIter(fOffScreen->getCanvas(), false);
SkAssertResult((src = offscreenIter.device()->accessRenderTarget()));
GrRenderTarget* src = fOffScreen->getCanvas()->internal_private_accessTopLayerRenderTarget();
SkASSERT(src);
SkASSERT(dst->getContext() == src->getContext());
dst->getContext()->copySurface(dst, src, SkIRect::MakeWH(w, h), SkIPoint::Make(0, 0));
#ifdef SK_DEBUG
// This method should not be called while layers are saved.
canvasIter.next();
SkASSERT(canvasIter.done());
offscreenIter.next();
SkASSERT(offscreenIter.done());
#endif
}
int fNumSamples;