aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu
diff options
context:
space:
mode:
authorGravatar robertphillips <robertphillips@google.com>2014-09-17 07:50:47 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2014-09-17 07:50:47 -0700
commit4aa6dfc0b77af9ac298bb9d48991b72a2fec00b2 (patch)
tree17804f9ad13b494638eebaa7b42e2db44d02136c /src/gpu
parentb374d6a62c0259387d90cad74753d8bad9ee1bea (diff)
Separate replacement creation from layer discovery
This is a simple refactoring that sets the stage for eliminating GrReplacements::ReplacementInfo and splitting up EXPERIMENTAL_drawPicture to support multi picture draw. R=bsalomon@google.com Author: robertphillips@google.com Review URL: https://codereview.chromium.org/559603004
Diffstat (limited to 'src/gpu')
-rw-r--r--src/gpu/GrLayerCache.cpp10
-rw-r--r--src/gpu/GrLayerCache.h15
-rw-r--r--src/gpu/SkGpuDevice.cpp60
3 files changed, 54 insertions, 31 deletions
diff --git a/src/gpu/GrLayerCache.cpp b/src/gpu/GrLayerCache.cpp
index 8e61cb761e..11a97e4c66 100644
--- a/src/gpu/GrLayerCache.cpp
+++ b/src/gpu/GrLayerCache.cpp
@@ -120,10 +120,11 @@ void GrLayerCache::freeAll() {
GrCachedLayer* GrLayerCache::createLayer(uint32_t pictureID,
int start, int stop,
const SkIPoint& offset,
- const SkMatrix& ctm) {
+ const SkMatrix& ctm,
+ const SkPaint* paint) {
SkASSERT(pictureID != SK_InvalidGenID && start > 0 && stop > 0);
- GrCachedLayer* layer = SkNEW_ARGS(GrCachedLayer, (pictureID, start, stop, offset, ctm));
+ GrCachedLayer* layer = SkNEW_ARGS(GrCachedLayer, (pictureID, start, stop, offset, ctm, paint));
fLayerHash.add(layer);
return layer;
}
@@ -139,11 +140,12 @@ GrCachedLayer* GrLayerCache::findLayer(uint32_t pictureID,
GrCachedLayer* GrLayerCache::findLayerOrCreate(uint32_t pictureID,
int start, int stop,
const SkIPoint& offset,
- const SkMatrix& ctm) {
+ const SkMatrix& ctm,
+ const SkPaint* paint) {
SkASSERT(pictureID != SK_InvalidGenID && start > 0 && stop > 0);
GrCachedLayer* layer = fLayerHash.find(GrCachedLayer::Key(pictureID, start, stop, offset, ctm));
if (NULL == layer) {
- layer = this->createLayer(pictureID, start, stop, offset, ctm);
+ layer = this->createLayer(pictureID, start, stop, offset, ctm, paint);
}
return layer;
diff --git a/src/gpu/GrLayerCache.h b/src/gpu/GrLayerCache.h
index 15fa246c43..1fb4c1001c 100644
--- a/src/gpu/GrLayerCache.h
+++ b/src/gpu/GrLayerCache.h
@@ -98,8 +98,10 @@ public:
// GrCachedLayer proper
GrCachedLayer(uint32_t pictureID, int start, int stop,
- const SkIPoint& offset, const SkMatrix& ctm)
+ const SkIPoint& offset, const SkMatrix& ctm,
+ const SkPaint* paint)
: fKey(pictureID, start, stop, offset, ctm)
+ , fPaint(paint)
, fTexture(NULL)
, fRect(GrIRect16::MakeEmpty())
, fPlot(NULL)
@@ -122,6 +124,7 @@ public:
fRect = rect;
}
GrTexture* texture() { return fTexture; }
+ const SkPaint* paint() const { return fPaint; }
const GrIRect16& rect() const { return fRect; }
void setPlot(GrPlot* plot) {
@@ -141,6 +144,10 @@ public:
private:
const Key fKey;
+ // The paint used when dropping the layer down into the owning canvas.
+ // Can be NULL.
+ const SkPaint* fPaint;
+
// fTexture is a ref on the atlasing texture for atlased layers and a
// ref on a GrTexture for non-atlased textures.
GrTexture* fTexture;
@@ -184,7 +191,8 @@ public:
GrCachedLayer* findLayerOrCreate(uint32_t pictureID,
int start, int stop,
const SkIPoint& offset,
- const SkMatrix& ctm);
+ const SkMatrix& ctm,
+ const SkPaint* paint);
// Inform the cache that layer's cached image is now required.
// Return true if the layer must be re-rendered. Return false if the
@@ -238,7 +246,8 @@ private:
void initAtlas();
GrCachedLayer* createLayer(uint32_t pictureID, int start, int stop,
- const SkIPoint& offset, const SkMatrix& ctm);
+ const SkIPoint& offset, const SkMatrix& ctm,
+ const SkPaint* paint);
void purgeAll();
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp
index 0ec2b858c4..ebe3a56680 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -1842,6 +1842,34 @@ static void wrap_texture(GrTexture* texture, int width, int height, SkBitmap* re
result->setPixelRef(SkNEW_ARGS(SkGrPixelRef, (info, texture)))->unref();
}
+static void convert_layers_to_replacements(const SkTDArray<GrCachedLayer*>& layers,
+ GrReplacements* replacements) {
+ // TODO: just replace GrReplacements::ReplacementInfo with GrCachedLayer?
+ for (int i = 0; i < layers.count(); ++i) {
+ GrReplacements::ReplacementInfo* layerInfo = replacements->push();
+ layerInfo->fStart = layers[i]->start();
+ layerInfo->fStop = layers[i]->stop();
+ layerInfo->fPos = layers[i]->offset();;
+
+ SkBitmap bm;
+ wrap_texture(layers[i]->texture(),
+ !layers[i]->isAtlased() ? layers[i]->rect().width()
+ : layers[i]->texture()->width(),
+ !layers[i]->isAtlased() ? layers[i]->rect().height()
+ : layers[i]->texture()->height(),
+ &bm);
+ layerInfo->fImage = SkImage::NewTexture(bm);
+
+ // TODO: copy this?
+ layerInfo->fPaint = layers[i]->paint();
+
+ layerInfo->fSrcRect = SkIRect::MakeXYWH(layers[i]->rect().fLeft,
+ layers[i]->rect().fTop,
+ layers[i]->rect().width(),
+ layers[i]->rect().height());
+ }
+}
+
bool SkGpuDevice::EXPERIMENTAL_drawPicture(SkCanvas* mainCanvas, const SkPicture* picture,
const SkMatrix* matrix, const SkPaint* paint) {
// todo: should handle these natively
@@ -1875,8 +1903,6 @@ bool SkGpuDevice::EXPERIMENTAL_drawPicture(SkCanvas* mainCanvas, const SkPicture
return false;
}
- GrReplacements replacements;
-
SkTDArray<GrCachedLayer*> atlased, nonAtlased;
atlased.setReserve(gpuData->numSaveLayers());
@@ -1885,16 +1911,12 @@ bool SkGpuDevice::EXPERIMENTAL_drawPicture(SkCanvas* mainCanvas, const SkPicture
if (pullForward[i]) {
const GrAccelData::SaveLayerInfo& info = gpuData->saveLayerInfo(i);
- GrCachedLayer* layer = fContext->getLayerCache()->findLayerOrCreate(picture->uniqueID(),
+ GrCachedLayer* layer = fContext->getLayerCache()->findLayerOrCreate(picture->uniqueID(),
info.fSaveLayerOpID,
info.fRestoreOpID,
info.fOffset,
- info.fOriginXform);
-
- GrReplacements::ReplacementInfo* layerInfo = replacements.push();
- layerInfo->fStart = info.fSaveLayerOpID;
- layerInfo->fStop = info.fRestoreOpID;
- layerInfo->fPos = info.fOffset;
+ info.fOriginXform,
+ info.fPaint);
GrTextureDesc desc;
desc.fFlags = kRenderTarget_GrTextureFlagBit;
@@ -1909,21 +1931,6 @@ bool SkGpuDevice::EXPERIMENTAL_drawPicture(SkCanvas* mainCanvas, const SkPicture
continue;
}
- SkBitmap bm;
- wrap_texture(layer->texture(),
- !layer->isAtlased() ? desc.fWidth : layer->texture()->width(),
- !layer->isAtlased() ? desc.fHeight : layer->texture()->height(),
- &bm);
- layerInfo->fImage = SkImage::NewTexture(bm);
-
- SkASSERT(info.fPaint);
- layerInfo->fPaint = info.fPaint;
-
- layerInfo->fSrcRect = SkIRect::MakeXYWH(layer->rect().fLeft,
- layer->rect().fTop,
- layer->rect().width(),
- layer->rect().height());
-
if (needsRendering) {
if (layer->isAtlased()) {
*atlased.append() = layer;
@@ -1936,6 +1943,11 @@ bool SkGpuDevice::EXPERIMENTAL_drawPicture(SkCanvas* mainCanvas, const SkPicture
GrLayerHoister::DrawLayers(picture, atlased, nonAtlased);
+ GrReplacements replacements;
+
+ convert_layers_to_replacements(atlased, &replacements);
+ convert_layers_to_replacements(nonAtlased, &replacements);
+
// Render the entire picture using new layers
GrRecordReplaceDraw(*picture->fRecord, mainCanvas, picture->fBBH.get(), &replacements, NULL);