remove unused SkAutoROCanvasPixels
BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1550583002 TBR= Review URL: https://codereview.chromium.org/1550583002
This commit is contained in:
parent
0b70f45be8
commit
48eb08a790
@ -1,71 +0,0 @@
|
||||
/*
|
||||
* 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 "gm.h"
|
||||
#include "SkCanvas.h"
|
||||
#include "SkPath.h"
|
||||
#include "SkSurface.h"
|
||||
#include "SkPicture.h"
|
||||
|
||||
static void draw_content(SkCanvas* canvas) {
|
||||
SkImageInfo info = canvas->imageInfo();
|
||||
SkPaint paint;
|
||||
paint.setAntiAlias(true);
|
||||
canvas->drawCircle(SkScalarHalf(info.width()), SkScalarHalf(info.height()),
|
||||
SkScalarHalf(info.width()), paint);
|
||||
}
|
||||
|
||||
class PeekPixelsGM : public skiagm::GM {
|
||||
public:
|
||||
PeekPixelsGM() {}
|
||||
|
||||
protected:
|
||||
SkString onShortName() override {
|
||||
return SkString("peekpixels");
|
||||
}
|
||||
|
||||
SkISize onISize() override {
|
||||
return SkISize::Make(360, 120);
|
||||
}
|
||||
|
||||
void onDraw(SkCanvas* canvas) override {
|
||||
SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100);
|
||||
SkAutoTUnref<SkSurface> surface(canvas->newSurface(info));
|
||||
if (surface.get()) {
|
||||
SkCanvas* surfCanvas = surface->getCanvas();
|
||||
|
||||
draw_content(surfCanvas);
|
||||
SkBitmap bitmap;
|
||||
|
||||
// test peekPixels
|
||||
{
|
||||
SkImageInfo info;
|
||||
size_t rowBytes;
|
||||
const void* addr = surfCanvas->peekPixels(&info, &rowBytes);
|
||||
if (addr && bitmap.installPixels(info, const_cast<void*>(addr), rowBytes)) {
|
||||
canvas->drawBitmap(bitmap, 0, 0, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
// test ROCanvasPixels
|
||||
canvas->translate(120, 0);
|
||||
SkAutoROCanvasPixels ropixels(surfCanvas);
|
||||
if (ropixels.asROBitmap(&bitmap)) {
|
||||
canvas->drawBitmap(bitmap, 0, 0, nullptr);
|
||||
}
|
||||
|
||||
// test Surface
|
||||
canvas->translate(120, 0);
|
||||
surface->draw(canvas, 0, 0, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
typedef skiagm::GM INHERITED;
|
||||
};
|
||||
|
||||
DEF_GM(return new PeekPixelsGM;)
|
@ -1,13 +1,14 @@
|
||||
|
||||
/*
|
||||
* Copyright 2013 Google Inc.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "gm.h"
|
||||
#include "SkBitmap.h"
|
||||
#include "SkGradientShader.h"
|
||||
#include "SkSurface.h"
|
||||
#include "SkXfermode.h"
|
||||
#include "SkColorPriv.h"
|
||||
|
||||
@ -59,7 +60,7 @@ protected:
|
||||
0x80,
|
||||
};
|
||||
|
||||
SkAutoTUnref<SkCanvas> tempCanvas(this->possiblyCreateTempCanvas(canvas, kSize, kSize));
|
||||
SkAutoTUnref<SkSurface> tempSurface(this->possiblyCreateTempSurface(canvas, kSize, kSize));
|
||||
|
||||
int test = 0;
|
||||
int x = 0, y = 0;
|
||||
@ -82,7 +83,7 @@ protected:
|
||||
modePaint.setStyle(kStrokes[s].fStyle);
|
||||
modePaint.setStrokeWidth(kStrokes[s].fWidth);
|
||||
|
||||
this->drawMode(canvas, x, y, kSize, kSize, modePaint, tempCanvas.get());
|
||||
this->drawMode(canvas, x, y, kSize, kSize, modePaint, tempSurface);
|
||||
|
||||
++test;
|
||||
x += kSize + 10;
|
||||
@ -99,7 +100,7 @@ protected:
|
||||
modePaint.setStyle(kStrokes[s].fStyle);
|
||||
modePaint.setStrokeWidth(kStrokes[s].fWidth);
|
||||
|
||||
this->drawMode(canvas, x, y, kSize, kSize, modePaint, tempCanvas.get());
|
||||
this->drawMode(canvas, x, y, kSize, kSize, modePaint, tempSurface);
|
||||
|
||||
++test;
|
||||
x += kSize + 10;
|
||||
@ -121,37 +122,32 @@ private:
|
||||
* So when running on a GPU canvas we explicitly create a temporary canvas using a texture with
|
||||
* dimensions exactly matching the layer size.
|
||||
*/
|
||||
SkCanvas* possiblyCreateTempCanvas(SkCanvas* baseCanvas, int w, int h) {
|
||||
SkCanvas* tempCanvas = nullptr;
|
||||
SkSurface* possiblyCreateTempSurface(SkCanvas* baseCanvas, int w, int h) {
|
||||
#if SK_SUPPORT_GPU
|
||||
GrContext* context = baseCanvas->getGrContext();
|
||||
SkImageInfo baseInfo = baseCanvas->imageInfo();
|
||||
SkImageInfo info = SkImageInfo::Make(w, h, baseInfo.colorType(), baseInfo.alphaType(),
|
||||
baseInfo.profileType());
|
||||
SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(context, SkSurface::kNo_Budgeted,
|
||||
info, 0, nullptr));
|
||||
if (surface) {
|
||||
tempCanvas = SkRef(surface->getCanvas());
|
||||
}
|
||||
return SkSurface::NewRenderTarget(context, SkSurface::kNo_Budgeted, info, 0, nullptr);
|
||||
#else
|
||||
return nullptr;
|
||||
#endif
|
||||
return tempCanvas;
|
||||
}
|
||||
|
||||
void drawMode(SkCanvas* canvas,
|
||||
int x, int y, int w, int h,
|
||||
const SkPaint& modePaint, SkCanvas* layerCanvas) {
|
||||
const SkPaint& modePaint, SkSurface* surface) {
|
||||
canvas->save();
|
||||
|
||||
canvas->translate(SkIntToScalar(x), SkIntToScalar(y));
|
||||
|
||||
SkRect r = SkRect::MakeWH(SkIntToScalar(w), SkIntToScalar(h));
|
||||
|
||||
SkCanvas* modeCanvas;
|
||||
if (nullptr == layerCanvas) {
|
||||
if (nullptr == surface) {
|
||||
canvas->saveLayer(&r, nullptr);
|
||||
modeCanvas = canvas;
|
||||
} else {
|
||||
modeCanvas = layerCanvas;
|
||||
modeCanvas = surface->getCanvas();
|
||||
}
|
||||
|
||||
SkPaint bgPaint;
|
||||
@ -161,14 +157,10 @@ private:
|
||||
modeCanvas->drawRect(r, modePaint);
|
||||
modeCanvas = nullptr;
|
||||
|
||||
if (nullptr == layerCanvas) {
|
||||
if (nullptr == surface) {
|
||||
canvas->restore();
|
||||
} else {
|
||||
SkAutoROCanvasPixels ropixels(layerCanvas);
|
||||
SkBitmap bitmap;
|
||||
if (ropixels.asROBitmap(&bitmap)) {
|
||||
canvas->drawBitmap(bitmap, 0, 0);
|
||||
}
|
||||
surface->draw(canvas, 0, 0, nullptr);
|
||||
}
|
||||
|
||||
r.inset(-SK_ScalarHalf, -SK_ScalarHalf);
|
||||
|
@ -1554,49 +1554,6 @@ private:
|
||||
};
|
||||
#define SkAutoCanvasRestore(...) SK_REQUIRE_LOCAL_VAR(SkAutoCanvasRestore)
|
||||
|
||||
/**
|
||||
* If the caller wants read-only access to the pixels in a canvas, it can just
|
||||
* call canvas->peekPixels(), since that is the fastest way to "peek" at the
|
||||
* pixels on a raster-backed canvas.
|
||||
*
|
||||
* If the canvas has pixels, but they are not readily available to the CPU
|
||||
* (e.g. gpu-backed), then peekPixels() will fail, but readPixels() will
|
||||
* succeed (though be slower, since it will return a copy of the pixels).
|
||||
*
|
||||
* SkAutoROCanvasPixels encapsulates these two techniques, trying first to call
|
||||
* peekPixels() (for performance), but if that fails, calling readPixels() and
|
||||
* storing the copy locally.
|
||||
*
|
||||
* The caller must respect the restrictions associated with peekPixels(), since
|
||||
* that may have been called: The returned information is invalidated if...
|
||||
* - any API is called on the canvas (or its parent surface if present)
|
||||
* - the canvas goes out of scope
|
||||
*/
|
||||
class SkAutoROCanvasPixels : SkNoncopyable {
|
||||
public:
|
||||
SkAutoROCanvasPixels(SkCanvas* canvas);
|
||||
|
||||
// returns NULL on failure
|
||||
const void* addr() const { return fAddr; }
|
||||
|
||||
// undefined if addr() == NULL
|
||||
size_t rowBytes() const { return fRowBytes; }
|
||||
|
||||
// undefined if addr() == NULL
|
||||
const SkImageInfo& info() const { return fInfo; }
|
||||
|
||||
// helper that, if returns true, installs the pixels into the bitmap. Note
|
||||
// that the bitmap may reference the address returned by peekPixels(), so
|
||||
// the caller must respect the restrictions associated with peekPixels().
|
||||
bool asROBitmap(SkBitmap*) const;
|
||||
|
||||
private:
|
||||
SkBitmap fBitmap; // used if peekPixels() fails
|
||||
const void* fAddr; // NULL on failure
|
||||
SkImageInfo fInfo;
|
||||
size_t fRowBytes;
|
||||
};
|
||||
|
||||
#ifdef SK_SUPPORT_LEGACY_SAVEFLAGS
|
||||
static inline SkCanvas::SaveFlags operator|(const SkCanvas::SaveFlags lhs,
|
||||
const SkCanvas::SaveFlags rhs) {
|
||||
|
@ -1395,31 +1395,6 @@ bool SkCanvas::onAccessTopLayerPixels(SkPixmap* pmap) {
|
||||
return dev && dev->accessPixels(pmap);
|
||||
}
|
||||
|
||||
SkAutoROCanvasPixels::SkAutoROCanvasPixels(SkCanvas* canvas) {
|
||||
fAddr = canvas->peekPixels(&fInfo, &fRowBytes);
|
||||
if (nullptr == fAddr) {
|
||||
fInfo = canvas->imageInfo();
|
||||
if (kUnknown_SkColorType == fInfo.colorType() || !fBitmap.tryAllocPixels(fInfo)) {
|
||||
return; // failure, fAddr is nullptr
|
||||
}
|
||||
if (!canvas->readPixels(&fBitmap, 0, 0)) {
|
||||
return; // failure, fAddr is nullptr
|
||||
}
|
||||
fAddr = fBitmap.getPixels();
|
||||
fRowBytes = fBitmap.rowBytes();
|
||||
}
|
||||
SkASSERT(fAddr); // success
|
||||
}
|
||||
|
||||
bool SkAutoROCanvasPixels::asROBitmap(SkBitmap* bitmap) const {
|
||||
if (fAddr) {
|
||||
return bitmap->installPixels(fInfo, const_cast<void*>(fAddr), fRowBytes);
|
||||
} else {
|
||||
bitmap->reset();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void SkCanvas::internalDrawDevice(SkBaseDevice* srcDev, int x, int y,
|
||||
|
Loading…
Reference in New Issue
Block a user