use surface in SkView/SampleApp
BUG=skia: R=bsalomon@google.com, robertphillips@google.com Author: reed@google.com Review URL: https://codereview.chromium.org/580073003
This commit is contained in:
parent
9b222a5ddd
commit
0397e9f341
@ -21,8 +21,7 @@
|
||||
#endif
|
||||
//#define USE_GX_SCREEN
|
||||
|
||||
class SkCanvas;
|
||||
|
||||
class SkSurface;
|
||||
class SkOSMenu;
|
||||
|
||||
class SkWindow : public SkView {
|
||||
@ -59,7 +58,7 @@ public:
|
||||
void preConcat(const SkMatrix&);
|
||||
void postConcat(const SkMatrix&);
|
||||
|
||||
virtual SkCanvas* createCanvas();
|
||||
virtual SkSurface* createSurface();
|
||||
|
||||
virtual void onPDFSaved(const char title[], const char desc[],
|
||||
const char path[]) {}
|
||||
|
@ -271,17 +271,14 @@ public:
|
||||
fBackend = kNone_BackEndType;
|
||||
}
|
||||
|
||||
virtual SkCanvas* createCanvas(SampleWindow::DeviceType dType,
|
||||
SampleWindow* win) {
|
||||
virtual SkSurface* createSurface(SampleWindow::DeviceType dType,
|
||||
SampleWindow* win) SK_OVERRIDE {
|
||||
#if SK_SUPPORT_GPU
|
||||
if (IsGpuDeviceType(dType) && fCurContext) {
|
||||
SkAutoTUnref<SkBaseDevice> device(SkGpuDevice::Create(fCurRenderTarget));
|
||||
return new SkCanvas(device);
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
return NULL;
|
||||
return SkSurface::NewRenderTargetDirect(fCurRenderTarget);
|
||||
}
|
||||
#endif
|
||||
return NULL;
|
||||
}
|
||||
|
||||
virtual void publishCanvas(SampleWindow::DeviceType dType,
|
||||
|
@ -76,7 +76,7 @@ public:
|
||||
|
||||
// called before drawing. should install correct device
|
||||
// type on the canvas. Will skip drawing if returns false.
|
||||
virtual SkCanvas* createCanvas(DeviceType dType, SampleWindow* win) = 0;
|
||||
virtual SkSurface* createSurface(DeviceType dType, SampleWindow* win) = 0;
|
||||
|
||||
// called after drawing, should get the results onto the
|
||||
// screen.
|
||||
@ -100,18 +100,18 @@ public:
|
||||
SampleWindow(void* hwnd, int argc, char** argv, DeviceManager*);
|
||||
virtual ~SampleWindow();
|
||||
|
||||
virtual SkCanvas* createCanvas() SK_OVERRIDE {
|
||||
SkCanvas* canvas = NULL;
|
||||
virtual SkSurface* createSurface() SK_OVERRIDE {
|
||||
SkSurface* surface = NULL;
|
||||
if (fDevManager) {
|
||||
canvas = fDevManager->createCanvas(fDeviceType, this);
|
||||
surface = fDevManager->createSurface(fDeviceType, this);
|
||||
}
|
||||
if (NULL == canvas) {
|
||||
canvas = this->INHERITED::createCanvas();
|
||||
if (NULL == surface) {
|
||||
surface = this->INHERITED::createSurface();
|
||||
}
|
||||
return canvas;
|
||||
return surface;
|
||||
}
|
||||
|
||||
virtual void draw(SkCanvas* canvas);
|
||||
virtual void draw(SkCanvas*) SK_OVERRIDE;
|
||||
|
||||
void setDeviceType(DeviceType type);
|
||||
void toggleRendering();
|
||||
|
@ -24,12 +24,6 @@
|
||||
#include "SkOSFile.h"
|
||||
#include "SkStream.h"
|
||||
|
||||
#if SK_SUPPORT_GPU
|
||||
#include "SkGpuDevice.h"
|
||||
#else
|
||||
class GrContext;
|
||||
#endif
|
||||
|
||||
#define INT_SIZE 64
|
||||
#define SCALAR_SIZE SkIntToScalar(INT_SIZE)
|
||||
|
||||
|
@ -1,14 +1,14 @@
|
||||
|
||||
/*
|
||||
* Copyright 2011 Google Inc.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "SkWindow.h"
|
||||
#include "SkCanvas.h"
|
||||
#include "SkDevice.h"
|
||||
#include "SkOSMenu.h"
|
||||
#include "SkSurface.h"
|
||||
#include "SkSystemEventTypes.h"
|
||||
#include "SkTime.h"
|
||||
|
||||
@ -32,8 +32,9 @@ SkWindow::~SkWindow() {
|
||||
fMenus.deleteAll();
|
||||
}
|
||||
|
||||
SkCanvas* SkWindow::createCanvas() {
|
||||
return new SkCanvas(this->getBitmap());
|
||||
SkSurface* SkWindow::createSurface() {
|
||||
const SkBitmap& bm = this->getBitmap();
|
||||
return SkSurface::NewRasterDirect(bm.info(), bm.getPixels(), bm.rowBytes());
|
||||
}
|
||||
|
||||
void SkWindow::setMatrix(const SkMatrix& matrix) {
|
||||
@ -126,7 +127,8 @@ bool SkWindow::update(SkIRect* updateArea) {
|
||||
bm.setPixels(buffer);
|
||||
#endif
|
||||
|
||||
SkAutoTUnref<SkCanvas> canvas(this->createCanvas());
|
||||
SkAutoTUnref<SkSurface> surface(this->createSurface());
|
||||
SkCanvas* canvas = surface->getCanvas();
|
||||
|
||||
canvas->clipRegion(fDirtyRgn);
|
||||
if (updateArea)
|
||||
|
@ -1,4 +1,3 @@
|
||||
|
||||
/*
|
||||
* Copyright 2011 Google Inc.
|
||||
*
|
||||
@ -8,6 +7,7 @@
|
||||
|
||||
#import "SkNSView.h"
|
||||
#include "SkCanvas.h"
|
||||
#include "SkSurface.h"
|
||||
#include "SkCGUtils.h"
|
||||
#include "SkEvent.h"
|
||||
SK_COMPILE_ASSERT(SK_SUPPORT_GPU, not_implemented_for_non_gpu_build);
|
||||
@ -129,8 +129,8 @@ SK_COMPILE_ASSERT(SK_SUPPORT_GPU, not_implemented_for_non_gpu_build);
|
||||
- (void)drawSkia {
|
||||
fRedrawRequestPending = false;
|
||||
if (fWind) {
|
||||
SkAutoTUnref<SkCanvas> canvas(fWind->createCanvas());
|
||||
fWind->draw(canvas);
|
||||
SkAutoTUnref<SkSurface> surface(fWind->createSurface());
|
||||
fWind->draw(surface->getCanvas());
|
||||
#ifdef FORCE_REDRAW
|
||||
fWind->inval(NULL);
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user