aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core
diff options
context:
space:
mode:
authorGravatar Mike Reed <reed@google.com>2017-01-10 11:58:39 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-01-10 17:31:58 +0000
commit356f7c2600ef54237fb8678cf63d5953f065b7da (patch)
tree419a3546f763b8cdbf5a37fb72905912bb987c37 /src/core
parentc0a7a0835905e02ba234ddc4bc2229e7806ba0ef (diff)
support external raster handles
draft CL for chrome: https://codereview.chromium.org/2618323005/ BUG=skia: Change-Id: I5dbcd700818776a9f62f1e10723d2efcc248dc44 Reviewed-on: https://skia-review.googlesource.com/6406 Reviewed-by: Florin Malita <fmalita@chromium.org> Commit-Queue: Mike Reed <reed@google.com>
Diffstat (limited to 'src/core')
-rw-r--r--src/core/SkBitmapDevice.cpp18
-rw-r--r--src/core/SkCanvas.cpp67
2 files changed, 78 insertions, 7 deletions
diff --git a/src/core/SkBitmapDevice.cpp b/src/core/SkBitmapDevice.cpp
index 814019059a..6d63ecf620 100644
--- a/src/core/SkBitmapDevice.cpp
+++ b/src/core/SkBitmapDevice.cpp
@@ -17,6 +17,7 @@
#include "SkPixelRef.h"
#include "SkPixmap.h"
#include "SkRasterClip.h"
+#include "SkRasterHandleAllocator.h"
#include "SkShader.h"
#include "SkSpecialImage.h"
#include "SkSurface.h"
@@ -79,21 +80,25 @@ SkBitmapDevice* SkBitmapDevice::Create(const SkImageInfo& info) {
return Create(info, SkSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType));
}
-SkBitmapDevice::SkBitmapDevice(const SkBitmap& bitmap, const SkSurfaceProps& surfaceProps)
+SkBitmapDevice::SkBitmapDevice(const SkBitmap& bitmap, const SkSurfaceProps& surfaceProps,
+ SkRasterHandleAllocator::Handle hndl)
: INHERITED(bitmap.info(), surfaceProps)
, fBitmap(bitmap)
+ , fRasterHandle(hndl)
{
SkASSERT(valid_for_bitmap_device(bitmap.info(), nullptr));
fBitmap.lockPixels();
}
SkBitmapDevice* SkBitmapDevice::Create(const SkImageInfo& origInfo,
- const SkSurfaceProps& surfaceProps) {
+ const SkSurfaceProps& surfaceProps,
+ SkRasterHandleAllocator* allocator) {
SkAlphaType newAT = origInfo.alphaType();
if (!valid_for_bitmap_device(origInfo, &newAT)) {
return nullptr;
}
+ SkRasterHandleAllocator::Handle hndl = nullptr;
const SkImageInfo info = origInfo.makeAlphaType(newAT);
SkBitmap bitmap;
@@ -101,6 +106,11 @@ SkBitmapDevice* SkBitmapDevice::Create(const SkImageInfo& origInfo,
if (!bitmap.setInfo(info)) {
return nullptr;
}
+ } else if (allocator) {
+ hndl = allocator->allocBitmap(info, &bitmap);
+ if (!hndl) {
+ return nullptr;
+ }
} else if (info.isOpaque()) {
// If this bitmap is opaque, we don't have any sensible default color,
// so we just return uninitialized pixels.
@@ -116,7 +126,7 @@ SkBitmapDevice* SkBitmapDevice::Create(const SkImageInfo& origInfo,
}
}
- return new SkBitmapDevice(bitmap, surfaceProps);
+ return new SkBitmapDevice(bitmap, surfaceProps, hndl);
}
void SkBitmapDevice::setNewSize(const SkISize& size) {
@@ -135,7 +145,7 @@ void SkBitmapDevice::replaceBitmapBackendForRasterSurface(const SkBitmap& bm) {
SkBaseDevice* SkBitmapDevice::onCreateDevice(const CreateInfo& cinfo, const SkPaint*) {
const SkSurfaceProps surfaceProps(this->surfaceProps().flags(), cinfo.fPixelGeometry);
- return SkBitmapDevice::Create(cinfo.fInfo, surfaceProps);
+ return SkBitmapDevice::Create(cinfo.fInfo, surfaceProps, cinfo.fAllocator);
}
const SkBitmap& SkBitmapDevice::onAccessBitmap() {
diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp
index cb76051add..4716053197 100644
--- a/src/core/SkCanvas.cpp
+++ b/src/core/SkCanvas.cpp
@@ -29,6 +29,7 @@
#include "SkPicture.h"
#include "SkRadialShadowMapShader.h"
#include "SkRasterClip.h"
+#include "SkRasterHandleAllocator.h"
#include "SkReadPixelsRec.h"
#include "SkRRect.h"
#include "SkShadowPaintFilterCanvas.h"
@@ -772,17 +773,21 @@ SkCanvas::SkCanvas(const SkBitmap& bitmap, const SkSurfaceProps& props)
this->init(device.get(), kDefault_InitFlags);
}
-SkCanvas::SkCanvas(const SkBitmap& bitmap)
+SkCanvas::SkCanvas(const SkBitmap& bitmap, std::unique_ptr<SkRasterHandleAllocator> alloc,
+ SkRasterHandleAllocator::Handle hndl)
: fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage))
, fProps(SkSurfaceProps::kLegacyFontHost_InitType)
+ , fAllocator(std::move(alloc))
, fConservativeRasterClip(false)
{
inc_canvas();
- sk_sp<SkBaseDevice> device(new SkBitmapDevice(bitmap, fProps));
+ sk_sp<SkBaseDevice> device(new SkBitmapDevice(bitmap, fProps, hndl));
this->init(device.get(), kDefault_InitFlags);
}
+SkCanvas::SkCanvas(const SkBitmap& bitmap) : SkCanvas(bitmap, nullptr, nullptr) {}
+
SkCanvas::~SkCanvas() {
// free up the contents of our deque
this->restoreToCount(1); // restore everything but the last
@@ -1260,7 +1265,8 @@ void SkCanvas::internalSaveLayer(const SaveLayerRec& rec, SaveLayerStrategy stra
(saveLayerFlags & kPreserveLCDText_SaveLayerFlag);
const SkBaseDevice::TileUsage usage = SkBaseDevice::kNever_TileUsage;
const SkBaseDevice::CreateInfo createInfo = SkBaseDevice::CreateInfo(info, usage, geo,
- preserveLCDText);
+ preserveLCDText,
+ fAllocator.get());
newDevice.reset(priorDevice->onCreateDevice(createInfo, paint));
if (!newDevice) {
return;
@@ -3404,3 +3410,58 @@ static_assert((int)SkRegion::kUnion_Op == (int)kUnion_SkClipOp, "")
static_assert((int)SkRegion::kXOR_Op == (int)kXOR_SkClipOp, "");
static_assert((int)SkRegion::kReverseDifference_Op == (int)kReverseDifference_SkClipOp, "");
static_assert((int)SkRegion::kReplace_Op == (int)kReplace_SkClipOp, "");
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+SkRasterHandleAllocator::Handle SkCanvas::accessTopRasterHandle() const {
+ if (fAllocator && fMCRec->fTopLayer->fDevice) {
+ const SkBaseDevice* dev = fMCRec->fTopLayer->fDevice;
+ SkRasterHandleAllocator::Handle handle = dev->getRasterHandle();
+ SkIPoint origin = dev->getOrigin();
+ SkMatrix ctm = this->getTotalMatrix();
+ ctm.preTranslate(SkIntToScalar(-origin.x()), SkIntToScalar(-origin.y()));
+
+ SkIRect clip = fMCRec->fRasterClip.getBounds();
+ clip.offset(-origin.x(), -origin.y());
+ if (clip.intersect(0, 0, dev->width(), dev->height())) {
+ clip.setEmpty();
+ }
+
+ fAllocator->updateHandle(handle, ctm, clip);
+ return handle;
+ }
+ return nullptr;
+}
+
+static bool install(SkBitmap* bm, const SkImageInfo& info,
+ const SkRasterHandleAllocator::Rec& rec) {
+ return bm->installPixels(info, rec.fPixels, rec.fRowBytes, nullptr,
+ rec.fReleaseProc, rec.fReleaseCtx);
+}
+
+SkRasterHandleAllocator::Handle SkRasterHandleAllocator::allocBitmap(const SkImageInfo& info,
+ SkBitmap* bm) {
+ SkRasterHandleAllocator::Rec rec;
+ if (!this->allocHandle(info, &rec) || !install(bm, info, rec)) {
+ return nullptr;
+ }
+ return rec.fHandle;
+}
+
+std::unique_ptr<SkCanvas>
+SkRasterHandleAllocator::MakeCanvas(std::unique_ptr<SkRasterHandleAllocator> alloc,
+ const SkImageInfo& info, const Rec* rec) {
+ if (!alloc || !supported_for_raster_canvas(info)) {
+ return nullptr;
+ }
+
+ SkBitmap bm;
+ Handle hndl;
+
+ if (rec) {
+ hndl = install(&bm, info, *rec) ? rec->fHandle : nullptr;
+ } else {
+ hndl = alloc->allocBitmap(info, &bm);
+ }
+ return hndl ? std::unique_ptr<SkCanvas>(new SkCanvas(bm, std::move(alloc), hndl)) : nullptr;
+}