2016-05-11 17:09:18 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 2016 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef TestContext_DEFINED
|
|
|
|
#define TestContext_DEFINED
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkRefCnt.h"
|
|
|
|
#include "include/gpu/GrTypes.h"
|
|
|
|
#include "include/private/SkNoncopyable.h"
|
|
|
|
#include "include/private/SkTemplates.h"
|
|
|
|
#include "src/core/SkScopeExit.h"
|
|
|
|
#include "tools/gpu/FenceSync.h"
|
2016-05-11 17:09:18 +00:00
|
|
|
|
2017-07-13 19:07:54 +00:00
|
|
|
class GrContext;
|
|
|
|
struct GrContextOptions;
|
|
|
|
|
2016-05-11 17:09:18 +00:00
|
|
|
namespace sk_gpu_test {
|
2016-10-05 15:42:03 +00:00
|
|
|
|
|
|
|
class GpuTimer;
|
2020-02-21 20:46:27 +00:00
|
|
|
class FlushFinishTracker;
|
2016-10-05 15:42:03 +00:00
|
|
|
|
2016-05-11 17:09:18 +00:00
|
|
|
/**
|
|
|
|
* An offscreen 3D context. This class is intended for Skia's internal testing needs and not
|
|
|
|
* for general use.
|
|
|
|
*/
|
|
|
|
class TestContext : public SkNoncopyable {
|
|
|
|
public:
|
|
|
|
virtual ~TestContext();
|
|
|
|
|
2020-02-21 20:46:27 +00:00
|
|
|
bool fenceSyncSupport() const { return fFenceSupport; }
|
2016-05-11 17:09:18 +00:00
|
|
|
|
2016-10-05 15:42:03 +00:00
|
|
|
bool gpuTimingSupport() const { return fGpuTimer != nullptr; }
|
2016-11-03 18:40:50 +00:00
|
|
|
GpuTimer* gpuTimer() const { SkASSERT(fGpuTimer); return fGpuTimer.get(); }
|
2016-10-05 15:42:03 +00:00
|
|
|
|
2016-05-11 17:09:18 +00:00
|
|
|
bool getMaxGpuFrameLag(int *maxFrameLag) const {
|
2020-02-21 20:46:27 +00:00
|
|
|
if (!this->fenceSyncSupport()) {
|
2016-05-11 17:09:18 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
*maxFrameLag = kMaxFrameLag;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-02-13 17:59:19 +00:00
|
|
|
void makeNotCurrent() const;
|
2016-05-11 17:09:18 +00:00
|
|
|
void makeCurrent() const;
|
|
|
|
|
2017-11-17 14:25:23 +00:00
|
|
|
/**
|
|
|
|
* Like makeCurrent() but this returns an object that will restore the previous current
|
|
|
|
* context in its destructor. Useful to undo the effect making this current before returning to
|
|
|
|
* a caller that doesn't expect the current context to be changed underneath it.
|
|
|
|
*
|
|
|
|
* The returned object restores the current context of the same type (e.g. egl, glx, ...) in its
|
|
|
|
* destructor. It is undefined behavior if that context is destroyed before the destructor
|
|
|
|
* executes. If the concept of a current context doesn't make sense for this context type then
|
|
|
|
* the returned object's destructor is a no-op.
|
|
|
|
*/
|
|
|
|
SkScopeExit SK_WARN_UNUSED_RESULT makeCurrentAndAutoRestore() const;
|
|
|
|
|
2018-10-12 13:31:11 +00:00
|
|
|
virtual GrBackendApi backend() = 0;
|
2016-05-11 17:09:18 +00:00
|
|
|
|
2017-07-13 19:07:54 +00:00
|
|
|
virtual sk_sp<GrContext> makeGrContext(const GrContextOptions&);
|
|
|
|
|
2016-05-11 17:09:18 +00:00
|
|
|
/**
|
2020-02-21 20:46:27 +00:00
|
|
|
* This will flush work to the GPU. Additionally, if the platform supports fence syncs, we will
|
|
|
|
* add a finished callback to our flush call. We allow ourselves to have kMaxFrameLag number of
|
|
|
|
* unfinished flushes active on the GPU at a time. If we have 2 outstanding flushes then we will
|
|
|
|
* wait on the CPU until one has finished.
|
2016-05-11 17:09:18 +00:00
|
|
|
*/
|
2020-02-21 20:46:27 +00:00
|
|
|
void flushAndWaitOnSync(GrContext* context);
|
2016-05-11 17:09:18 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This notifies the context that we are deliberately testing abandoning
|
|
|
|
* the context. It is useful for debugging contexts that would otherwise
|
|
|
|
* test that GPU resources are properly deleted. It also allows a debugging
|
|
|
|
* context to test that further API calls are not made by Skia GPU code.
|
|
|
|
*/
|
|
|
|
virtual void testAbandon();
|
|
|
|
|
2016-05-11 18:55:36 +00:00
|
|
|
/** Wait until all GPU work is finished. */
|
|
|
|
virtual void finish() = 0;
|
|
|
|
|
2016-05-11 17:09:18 +00:00
|
|
|
protected:
|
2020-02-21 20:46:27 +00:00
|
|
|
bool fFenceSupport = false;
|
|
|
|
|
2016-11-03 18:40:50 +00:00
|
|
|
std::unique_ptr<GpuTimer> fGpuTimer;
|
2016-05-11 17:09:18 +00:00
|
|
|
|
|
|
|
TestContext();
|
|
|
|
|
|
|
|
/** This should destroy the 3D context. */
|
|
|
|
virtual void teardown();
|
|
|
|
|
2020-02-13 17:59:19 +00:00
|
|
|
virtual void onPlatformMakeNotCurrent() const = 0;
|
2016-05-11 17:09:18 +00:00
|
|
|
virtual void onPlatformMakeCurrent() const = 0;
|
2017-11-17 14:25:23 +00:00
|
|
|
/**
|
|
|
|
* Subclasses should implement such that the returned function will cause the current context
|
|
|
|
* of this type to be made current again when it is called. It should additionally be the
|
|
|
|
* case that if "this" is already current when this is called, then "this" is destroyed (thereby
|
|
|
|
* setting the null context as current), and then the std::function is called the null context
|
|
|
|
* should remain current.
|
|
|
|
*/
|
|
|
|
virtual std::function<void()> onPlatformGetAutoContextRestore() const = 0;
|
2016-05-11 17:09:18 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
enum {
|
|
|
|
kMaxFrameLag = 3
|
|
|
|
};
|
|
|
|
|
2020-02-21 20:46:27 +00:00
|
|
|
sk_sp<FlushFinishTracker> fFinishTrackers[kMaxFrameLag - 1];
|
|
|
|
int fCurrentFlushIdx = 0;
|
2016-05-11 17:09:18 +00:00
|
|
|
|
|
|
|
typedef SkNoncopyable INHERITED;
|
|
|
|
};
|
|
|
|
} // namespace sk_gpu_test
|
|
|
|
#endif
|