aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Jim Van Verth <jvanverth@google.com>2017-08-31 16:44:08 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-09-01 13:29:07 +0000
commitd74f3f2c0b03552b0ef60dc3fbf9e98d4ab754a2 (patch)
tree396fd57e2aeaf147f34522dc67e7d3a79baab812
parent10a4c591cacfd80776302bb745c63d906b813b1e (diff)
Move texture proxy allocation for atlas to constructor.
This is to set up for allocating additional texture proxies as needed. Change-Id: Ibc0480c30d8efd6ccf8278f6dbdd3bfa3ee2397d Reviewed-on: https://skia-review.googlesource.com/41744 Reviewed-by: Robert Phillips <robertphillips@google.com> Commit-Queue: Jim Van Verth <jvanverth@google.com>
-rw-r--r--src/gpu/GrDrawOpAtlas.cpp68
-rw-r--r--src/gpu/GrDrawOpAtlas.h6
2 files changed, 40 insertions, 34 deletions
diff --git a/src/gpu/GrDrawOpAtlas.cpp b/src/gpu/GrDrawOpAtlas.cpp
index 9b2afc774f..c962a6168d 100644
--- a/src/gpu/GrDrawOpAtlas.cpp
+++ b/src/gpu/GrDrawOpAtlas.cpp
@@ -19,35 +19,12 @@ std::unique_ptr<GrDrawOpAtlas> GrDrawOpAtlas::Make(GrContext* ctx, GrPixelConfig
int numPlotsX, int numPlotsY,
GrDrawOpAtlas::EvictionFunc func,
void* data) {
- GrSurfaceDesc desc;
- desc.fFlags = kNone_GrSurfaceFlags;
- desc.fOrigin = kTopLeft_GrSurfaceOrigin;
- desc.fWidth = width;
- desc.fHeight = height;
- desc.fConfig = config;
-
- // We don't want to flush the context so we claim we're in the middle of flushing so as to
- // guarantee we do not recieve a texture with pending IO
- // TODO: Determine how to avoid having to do this. (https://bug.skia.org/4156)
- static const uint32_t kFlags = GrResourceProvider::kNoPendingIO_Flag;
- sk_sp<GrTexture> texture(ctx->resourceProvider()->createApproxTexture(desc, kFlags));
- if (!texture) {
- return nullptr;
- }
-
- // MDB TODO: for now, wrap an instantiated texture. Having the deferred instantiation
- // possess the correct properties (e.g., no pendingIO) should fall out of the system but
- // should receive special attention.
- // Note: When switching over to the deferred proxy, use the kExact flag to create
- // the atlas and assert that the width & height are powers of 2.
- sk_sp<GrTextureProxy> proxy = GrSurfaceProxy::MakeWrapped(std::move(texture),
- kTopLeft_GrSurfaceOrigin);
- if (!proxy) {
+ std::unique_ptr<GrDrawOpAtlas> atlas(
+ new GrDrawOpAtlas(ctx, config, width, height, numPlotsX, numPlotsY));
+ if (!atlas->getProxy()) {
return nullptr;
}
- std::unique_ptr<GrDrawOpAtlas> atlas(
- new GrDrawOpAtlas(ctx, std::move(proxy), numPlotsX, numPlotsY));
atlas->registerEvictionCallback(func, data);
return atlas;
}
@@ -162,16 +139,41 @@ void GrDrawOpAtlas::Plot::resetRects() {
///////////////////////////////////////////////////////////////////////////////
-GrDrawOpAtlas::GrDrawOpAtlas(GrContext* context, sk_sp<GrTextureProxy> proxy,
+GrDrawOpAtlas::GrDrawOpAtlas(GrContext* context, GrPixelConfig config, int width, int height,
int numPlotsX, int numPlotsY)
: fContext(context)
- , fProxy(std::move(proxy))
+ , fProxy(nullptr)
+ , fPixelConfig(config)
+ , fTextureWidth(width)
+ , fTextureHeight(height)
, fAtlasGeneration(kInvalidAtlasGeneration + 1) {
- fPlotWidth = fProxy->width() / numPlotsX;
- fPlotHeight = fProxy->height() / numPlotsY;
+
+ GrSurfaceDesc desc;
+ desc.fFlags = kNone_GrSurfaceFlags;
+ desc.fOrigin = kTopLeft_GrSurfaceOrigin;
+ desc.fWidth = fTextureWidth;
+ desc.fHeight = fTextureHeight;
+ desc.fConfig = fPixelConfig;
+
+ // We don't want to flush the context so we claim we're in the middle of flushing so as to
+ // guarantee we do not recieve a texture with pending IO
+ // TODO: Determine how to avoid having to do this. (https://bug.skia.org/4156)
+ static const uint32_t kFlags = GrResourceProvider::kNoPendingIO_Flag;
+ sk_sp<GrTexture> texture(context->resourceProvider()->createApproxTexture(desc, kFlags));
+ if (texture) {
+ // MDB TODO: for now, wrap an instantiated texture. Having the deferred instantiation
+ // possess the correct properties (e.g., no pendingIO) should fall out of the system but
+ // should receive special attention.
+ // Note: When switching over to the deferred proxy, use the kExact flag to create
+ // the atlas and assert that the width & height are powers of 2.
+ fProxy = GrSurfaceProxy::MakeWrapped(std::move(texture), kTopLeft_GrSurfaceOrigin);
+ }
+
+ fPlotWidth = fTextureWidth / numPlotsX;
+ fPlotHeight = fTextureHeight / numPlotsY;
SkASSERT(numPlotsX * numPlotsY <= BulkUseTokenUpdater::kMaxPlots);
- SkASSERT(fPlotWidth * numPlotsX == fProxy->width());
- SkASSERT(fPlotHeight * numPlotsY == fProxy->height());
+ SkASSERT(fPlotWidth * numPlotsX == fTextureWidth);
+ SkASSERT(fPlotHeight * numPlotsY == fTextureHeight);
SkDEBUGCODE(fNumPlots = numPlotsX * numPlotsY;)
@@ -183,7 +185,7 @@ GrDrawOpAtlas::GrDrawOpAtlas(GrContext* context, sk_sp<GrTextureProxy> proxy,
for (int x = numPlotsX - 1, c = 0; x >= 0; --x, ++c) {
uint32_t index = r * numPlotsX + c;
currPlot->reset(
- new Plot(index, 1, x, y, fPlotWidth, fPlotHeight, fProxy->config()));
+ new Plot(index, 1, x, y, fPlotWidth, fPlotHeight, fPixelConfig));
// build LRU list
fPlotList.addToHead(currPlot->get());
diff --git a/src/gpu/GrDrawOpAtlas.h b/src/gpu/GrDrawOpAtlas.h
index 87bd6954f4..e2c050330e 100644
--- a/src/gpu/GrDrawOpAtlas.h
+++ b/src/gpu/GrDrawOpAtlas.h
@@ -176,7 +176,8 @@ public:
}
private:
- GrDrawOpAtlas(GrContext*, sk_sp<GrTextureProxy>, int numPlotsX, int numPlotsY);
+ GrDrawOpAtlas(GrContext*, GrPixelConfig config, int width, int height,
+ int numPlotsX, int numPlotsY);
/**
* The backing GrTexture for a GrDrawOpAtlas is broken into a spatial grid of Plots. The Plots
@@ -288,6 +289,9 @@ private:
GrContext* fContext;
sk_sp<GrTextureProxy> fProxy;
+ GrPixelConfig fPixelConfig;
+ int fTextureWidth;
+ int fTextureHeight;
int fPlotWidth;
int fPlotHeight;
SkDEBUGCODE(uint32_t fNumPlots;)