aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Robert Phillips <robertphillips@google.com>2017-11-30 08:46:03 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-11-30 14:16:32 +0000
commit8def8bffe98ee58af6c088f3ab6e4a41f32b732f (patch)
treec79c5c8d5cedbce45cbf0bc0eb39d41b500f47bc
parent1c8092ac64dc4d9fd140d7fd46fa52163fe26569 (diff)
Add a GrContextThreadSafeProxy to SkSurfaceCharacterization
Ganesh will require access to the GrCaps to make rendering decisions. Change-Id: I6dee42a3f0dc638f052706b8d1ea6e02b589e062 Reviewed-on: https://skia-review.googlesource.com/77681 Reviewed-by: Brian Salomon <bsalomon@google.com> Commit-Queue: Robert Phillips <robertphillips@google.com>
-rw-r--r--gm/fontcache.cpp2
-rw-r--r--include/core/SkDeferredDisplayListRecorder.h4
-rw-r--r--include/gpu/GrContext.h3
-rw-r--r--include/private/SkDeferredDisplayList.h3
-rw-r--r--include/private/SkSurfaceCharacterization.h61
-rw-r--r--src/core/SkDeferredDisplayListRecorder.cpp2
-rw-r--r--src/image/SkSurface_Gpu.cpp8
7 files changed, 64 insertions, 19 deletions
diff --git a/gm/fontcache.cpp b/gm/fontcache.cpp
index b93cc3f031..ce919e9df5 100644
--- a/gm/fontcache.cpp
+++ b/gm/fontcache.cpp
@@ -51,6 +51,7 @@ protected:
void onDraw(SkCanvas* canvas) override {
canvas->clear(SK_ColorLTGRAY);
this->drawText(canvas);
+#if SK_SUPPORT_GPU
// Debugging tool for GPU.
static const bool kShowAtlas = false;
if (kShowAtlas) {
@@ -59,6 +60,7 @@ protected:
canvas->drawImage(img, 0, 0);
}
}
+#endif
}
private:
diff --git a/include/core/SkDeferredDisplayListRecorder.h b/include/core/SkDeferredDisplayListRecorder.h
index 185adfa99b..63934a1857 100644
--- a/include/core/SkDeferredDisplayListRecorder.h
+++ b/include/core/SkDeferredDisplayListRecorder.h
@@ -18,7 +18,7 @@ class SkSurface; // TODO: remove
/*
* This class is intended to be used as:
- * Get an SkSurfaceCharacterization from the ultimate intended gpu-backed destination SkSurface
+ * Get an SkSurfaceCharacterization representing the intended gpu-backed destination SkSurface
* Create one of these (an SkDDLMaker) on the stack
* Get the canvas and render into it
* Snap off and hold on to an SkDeferredDisplayList
@@ -44,7 +44,7 @@ public:
std::unique_ptr<SkDeferredDisplayList> detach();
private:
- SkSurfaceCharacterization fCharacterization;
+ const SkSurfaceCharacterization fCharacterization;
sk_sp<SkSurface> fSurface; // temporary until we have a real implementation
};
diff --git a/include/gpu/GrContext.h b/include/gpu/GrContext.h
index 41d00a6802..7b87b0a879 100644
--- a/include/gpu/GrContext.h
+++ b/include/gpu/GrContext.h
@@ -420,6 +420,9 @@ private:
* proxy does not access the 3D API (e.g. OpenGL) that backs the generating GrContext.
*/
class GrContextThreadSafeProxy : public SkRefCnt {
+public:
+ bool matches(GrContext* context) const { return context->uniqueID() == fContextUniqueID; }
+
private:
GrContextThreadSafeProxy(sk_sp<const GrCaps> caps, uint32_t uniqueID)
: fCaps(std::move(caps))
diff --git a/include/private/SkDeferredDisplayList.h b/include/private/SkDeferredDisplayList.h
index 37e792ff20..30c2518bdc 100644
--- a/include/private/SkDeferredDisplayList.h
+++ b/include/private/SkDeferredDisplayList.h
@@ -10,7 +10,8 @@
#include "SkSurfaceCharacterization.h"
-class SkImage; // TODO: rm this
+class SkImage; // TODO: rm this since it is just for the temporary placeholder implementation
+class SkSurface;
/*
* This class contains pre-processed gpu operations that can be replayed into
diff --git a/include/private/SkSurfaceCharacterization.h b/include/private/SkSurfaceCharacterization.h
index f3acb01236..9f0faf33f4 100644
--- a/include/private/SkSurfaceCharacterization.h
+++ b/include/private/SkSurfaceCharacterization.h
@@ -10,10 +10,17 @@
#include "GrTypes.h"
-class SkSurface;
+#if SK_SUPPORT_GPU
-// This class captures all the pertinent data about an SkSurface required
-// to perform cpu-preprocessing for gpu-rendering.
+class GrContextThreadSafeProxy;
+
+/** \class SkSurfaceCharacterization
+ A surface characterization contains all the information Ganesh requires to makes its internal
+ rendering decisions. When passed into a SkDeferredDisplayListRecorder it will copy the
+ data and pass it on to the SkDeferredDisplayList if/when it is created. Note that both of
+ those objects (the Recorder and the DisplayList) will take a ref on the
+ GrContextThreadSafeProxy object.
+*/
class SkSurfaceCharacterization {
public:
SkSurfaceCharacterization()
@@ -24,31 +31,57 @@ public:
, fSampleCnt(0) {
}
+ SkSurfaceCharacterization(SkSurfaceCharacterization&&) = default;
+ SkSurfaceCharacterization& operator=(SkSurfaceCharacterization&&) = default;
+
+ SkSurfaceCharacterization(const SkSurfaceCharacterization&) = default;
+ SkSurfaceCharacterization& operator=(const SkSurfaceCharacterization& other) = default;
+
+ GrSurfaceOrigin origin() const { return fOrigin; }
+ int width() const { return fWidth; }
+ int height() const { return fHeight; }
+ GrPixelConfig config() const { return fConfig; }
+ int sampleCount() const { return fSampleCnt; }
+ GrContextThreadSafeProxy* contextInfo() const { return fContextInfo.get(); }
+
+private:
+ friend class SkSurface_Gpu; // for 'set'
+
void set(GrSurfaceOrigin origin,
int width, int height,
GrPixelConfig config,
- int sampleCnt) {
+ int sampleCnt,
+ sk_sp<GrContextThreadSafeProxy> contextInfo) {
fOrigin = origin;
fWidth = width;
fHeight = height;
fConfig = config;
fSampleCnt = sampleCnt;
+ fContextInfo = contextInfo;
}
- GrSurfaceOrigin origin() const { return fOrigin; }
+ GrSurfaceOrigin fOrigin;
+ int fWidth;
+ int fHeight;
+ GrPixelConfig fConfig;
+ int fSampleCnt;
+ sk_sp<GrContextThreadSafeProxy> fContextInfo;
+};
+
+#else// !SK_SUPPORT_GPU
+
+class SkSurfaceCharacterization {
+public:
+ SkSurfaceCharacterization() : fWidth(0), fHeight(0) { }
+
int width() const { return fWidth; }
int height() const { return fHeight; }
- GrPixelConfig config() const { return fConfig; }
- int sampleCount() const { return fSampleCnt; }
private:
- GrSurfaceOrigin fOrigin;
- int fWidth;
- int fHeight;
- GrPixelConfig fConfig;
- int fSampleCnt;
- // TODO: need to include caps!
- // Maybe use GrContextThreadSafeProxy (it has the caps & the unique Context ID already)
+ int fWidth;
+ int fHeight;
};
#endif
+
+#endif
diff --git a/src/core/SkDeferredDisplayListRecorder.cpp b/src/core/SkDeferredDisplayListRecorder.cpp
index c47a79a77d..18e516ab31 100644
--- a/src/core/SkDeferredDisplayListRecorder.cpp
+++ b/src/core/SkDeferredDisplayListRecorder.cpp
@@ -7,6 +7,8 @@
#include "SkDeferredDisplayListRecorder.h"
+#include "GrContext.h"
+
#include "SkCanvas.h" // TODO: remove
#include "SkDeferredDisplayList.h"
#include "SkSurface.h" // TODO: remove
diff --git a/src/image/SkSurface_Gpu.cpp b/src/image/SkSurface_Gpu.cpp
index 891f03709b..3d19762cd4 100644
--- a/src/image/SkSurface_Gpu.cpp
+++ b/src/image/SkSurface_Gpu.cpp
@@ -162,18 +162,22 @@ bool SkSurface_Gpu::onWait(int numSemaphores, const GrBackendSemaphore* waitSema
bool SkSurface_Gpu::onCharacterize(SkSurfaceCharacterization* data) const {
GrRenderTargetContext* rtc = fDevice->accessRenderTargetContext();
+ GrContext* ctx = fDevice->context();
data->set(rtc->origin(), rtc->width(), rtc->height(), rtc->colorSpaceInfo().config(),
- rtc->numColorSamples());
+ rtc->numColorSamples(), ctx->threadSafeProxy());
+
return true;
}
bool SkSurface_Gpu::isCompatible(const SkSurfaceCharacterization& data) const {
GrRenderTargetContext* rtc = fDevice->accessRenderTargetContext();
+ GrContext* ctx = fDevice->context();
return data.origin() == rtc->origin() && data.width() == rtc->width() &&
data.height() == rtc->height() && data.config() == rtc->colorSpaceInfo().config() &&
- data.sampleCount() == rtc->numColorSamples();
+ data.sampleCount() == rtc->numColorSamples() &&
+ data.contextInfo() && data.contextInfo()->matches(ctx);
}
void SkSurface_Gpu::onDraw(SkDeferredDisplayList* dl) {