add DeferredCanvas mode to SampleApp
BUG=skia: Review URL: https://codereview.chromium.org/1129603002
This commit is contained in:
parent
af242958a5
commit
beedb81a7f
@ -15,6 +15,7 @@
|
||||
#include "SkCanvas.h"
|
||||
#include "SkCommandLineFlags.h"
|
||||
#include "SkData.h"
|
||||
#include "SkDeferredCanvas.h"
|
||||
#include "SkDevice.h"
|
||||
#include "SkDocument.h"
|
||||
#include "SkGPipe.h"
|
||||
@ -181,10 +182,9 @@ public:
|
||||
|
||||
#if SK_SUPPORT_GPU
|
||||
switch (win->getDeviceType()) {
|
||||
case kRaster_DeviceType:
|
||||
// fallthrough
|
||||
case kPicture_DeviceType:
|
||||
// fallthrough
|
||||
case kRaster_DeviceType: // fallthrough
|
||||
case kPicture_DeviceType: // fallthrough
|
||||
case kDeferred_DeviceType: // fallthrough
|
||||
case kGPU_DeviceType:
|
||||
// all these guys use the native backend
|
||||
fBackend = kNativeGL_BackEndType;
|
||||
@ -210,10 +210,9 @@ public:
|
||||
SkASSERT(NULL == fCurIntf);
|
||||
SkAutoTUnref<const GrGLInterface> glInterface;
|
||||
switch (win->getDeviceType()) {
|
||||
case kRaster_DeviceType:
|
||||
// fallthrough
|
||||
case kPicture_DeviceType:
|
||||
// fallthrough
|
||||
case kRaster_DeviceType: // fallthrough
|
||||
case kPicture_DeviceType: // fallthrough
|
||||
case kDeferred_DeviceType: // fallthrough
|
||||
case kGPU_DeviceType:
|
||||
// all these guys use the native interface
|
||||
glInterface.reset(GrGLCreateNativeInterface());
|
||||
@ -673,7 +672,8 @@ static inline SampleWindow::DeviceType cycle_devicetype(SampleWindow::DeviceType
|
||||
SampleWindow::kANGLE_DeviceType,
|
||||
#endif // SK_ANGLE
|
||||
#endif // SK_SUPPORT_GPU
|
||||
SampleWindow::kRaster_DeviceType
|
||||
SampleWindow::kDeferred_DeviceType,
|
||||
SampleWindow::kRaster_DeviceType,
|
||||
};
|
||||
SK_COMPILE_ASSERT(SK_ARRAY_COUNT(gCT) == SampleWindow::kDeviceTypeCnt, array_size_mismatch);
|
||||
return gCT[ct];
|
||||
@ -829,7 +829,7 @@ SampleWindow::SampleWindow(void* hwnd, int argc, char** argv, DeviceManager* dev
|
||||
int itemID;
|
||||
|
||||
itemID =fAppMenu->appendList("Device Type", "Device Type", sinkID, 0,
|
||||
"Raster", "Picture", "OpenGL",
|
||||
"Raster", "Picture", "OpenGL", "Deferred",
|
||||
#if SK_ANGLE
|
||||
"ANGLE",
|
||||
#endif
|
||||
@ -1196,6 +1196,12 @@ SkCanvas* SampleWindow::beforeChildren(SkCanvas* canvas) {
|
||||
canvas = fPDFDocument->beginPage(this->width(), this->height());
|
||||
} else if (kPicture_DeviceType == fDeviceType) {
|
||||
canvas = fRecorder.beginRecording(9999, 9999, NULL, 0);
|
||||
} else if (kDeferred_DeviceType == fDeviceType) {
|
||||
fDeferredSurface.reset(canvas->newSurface(canvas->imageInfo()));
|
||||
if (fDeferredSurface.get()) {
|
||||
fDeferredCanvas.reset(SkDeferredCanvas::Create(fDeferredSurface));
|
||||
canvas = fDeferredCanvas;
|
||||
}
|
||||
} else {
|
||||
canvas = this->INHERITED::beforeChildren(canvas);
|
||||
}
|
||||
@ -1284,6 +1290,13 @@ void SampleWindow::afterChildren(SkCanvas* orig) {
|
||||
} else {
|
||||
picture->playback(orig);
|
||||
}
|
||||
} else if (kDeferred_DeviceType == fDeviceType) {
|
||||
SkAutoTUnref<SkImage> image(fDeferredCanvas->newImageSnapshot());
|
||||
if (image) {
|
||||
orig->drawImage(image, 0, 0, NULL);
|
||||
}
|
||||
fDeferredCanvas.reset(NULL);
|
||||
fDeferredSurface.reset(NULL);
|
||||
}
|
||||
|
||||
// Do this after presentGL and other finishing, rather than in afterChild
|
||||
@ -1858,6 +1871,7 @@ static const char* gDeviceTypePrefix[] = {
|
||||
"angle: ",
|
||||
#endif // SK_ANGLE
|
||||
#endif // SK_SUPPORT_GPU
|
||||
"deferred: ",
|
||||
};
|
||||
SK_COMPILE_ASSERT(SK_ARRAY_COUNT(gDeviceTypePrefix) == SampleWindow::kDeviceTypeCnt,
|
||||
array_size_mismatch);
|
||||
|
@ -22,6 +22,7 @@ class GrRenderTarget;
|
||||
|
||||
class SkCanvas;
|
||||
class SkData;
|
||||
class SkDeferredCanvas;
|
||||
class SkDocument;
|
||||
class SkEvent;
|
||||
class SkTypeface;
|
||||
@ -39,7 +40,7 @@ public:
|
||||
kANGLE_DeviceType,
|
||||
#endif // SK_ANGLE
|
||||
#endif // SK_SUPPORT_GPU
|
||||
|
||||
kDeferred_DeviceType,
|
||||
kDeviceTypeCnt
|
||||
};
|
||||
|
||||
@ -161,6 +162,8 @@ private:
|
||||
int fCurrIndex;
|
||||
|
||||
SkPictureRecorder fRecorder;
|
||||
SkAutoTDelete<SkSurface> fDeferredSurface;
|
||||
SkAutoTDelete<SkDeferredCanvas> fDeferredCanvas;
|
||||
SkPath fClipPath;
|
||||
|
||||
SkTouchGesture fGesture;
|
||||
|
Loading…
Reference in New Issue
Block a user