106a57b5ac
It is safe to store raw pointers to these objects since they are both always accessed on the same thread we can safely invalidate their back pointers when needed. This allows us to remove a ref of Recorder on Device. Bug: skia:12794 Change-Id: Icb5e079f7e820824520d52e48012b447e714a9ee Reviewed-on: https://skia-review.googlesource.com/c/skia/+/494239 Reviewed-by: Robert Phillips <robertphillips@google.com> Reviewed-by: Michael Ludwig <michaelludwig@google.com> Commit-Queue: Greg Daniel <egdaniel@google.com>
124 lines
4.9 KiB
C++
124 lines
4.9 KiB
C++
/*
|
|
* Copyright 2021 Google LLC
|
|
*
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
* found in the LICENSE file.
|
|
*/
|
|
|
|
#include "tests/Test.h"
|
|
|
|
#include "experimental/graphite/include/BackendTexture.h"
|
|
#include "experimental/graphite/include/Context.h"
|
|
#include "experimental/graphite/include/Recorder.h"
|
|
#include "experimental/graphite/include/SkStuff.h"
|
|
#include "experimental/graphite/src/Caps.h"
|
|
#include "experimental/graphite/src/ContextPriv.h"
|
|
#include "experimental/graphite/src/Gpu.h"
|
|
#include "experimental/graphite/src/ResourceTypes.h"
|
|
|
|
#include "include/core/SkSurface.h"
|
|
|
|
using namespace skgpu;
|
|
|
|
namespace {
|
|
const SkISize kSize = {16, 16};
|
|
}
|
|
|
|
DEF_GRAPHITE_TEST_FOR_CONTEXTS(BackendTextureTest, reporter, context) {
|
|
auto caps = context->priv().gpu()->caps();
|
|
|
|
TextureInfo info = caps->getDefaultSampledTextureInfo(kRGBA_8888_SkColorType,
|
|
/*levelCount=*/1,
|
|
Protected::kNo,
|
|
Renderable::kNo);
|
|
REPORTER_ASSERT(reporter, info.isValid());
|
|
|
|
auto texture1 = context->createBackendTexture(kSize, info);
|
|
REPORTER_ASSERT(reporter, texture1.isValid());
|
|
|
|
// We make a copy to do the remaining tests so we still have texture1 to safely delete the
|
|
// backend object.
|
|
auto texture1Copy = texture1;
|
|
REPORTER_ASSERT(reporter, texture1Copy.isValid());
|
|
REPORTER_ASSERT(reporter, texture1 == texture1Copy);
|
|
|
|
auto texture2 = context->createBackendTexture(kSize, info);
|
|
REPORTER_ASSERT(reporter, texture2.isValid());
|
|
|
|
REPORTER_ASSERT(reporter, texture1Copy != texture2);
|
|
|
|
// Test state after assignment
|
|
texture1Copy = texture2;
|
|
REPORTER_ASSERT(reporter, texture1Copy.isValid());
|
|
REPORTER_ASSERT(reporter, texture1Copy == texture2);
|
|
|
|
BackendTexture invalidTexture;
|
|
REPORTER_ASSERT(reporter, !invalidTexture.isValid());
|
|
|
|
texture1Copy = invalidTexture;
|
|
REPORTER_ASSERT(reporter, !texture1Copy.isValid());
|
|
|
|
texture1Copy = texture1;
|
|
REPORTER_ASSERT(reporter, texture1Copy.isValid());
|
|
REPORTER_ASSERT(reporter, texture1 == texture1Copy);
|
|
|
|
context->deleteBackendTexture(texture1);
|
|
context->deleteBackendTexture(texture2);
|
|
}
|
|
|
|
// Tests the wrapping of a BackendTexture in an SkSurface
|
|
DEF_GRAPHITE_TEST_FOR_CONTEXTS(SurfaceBackendTextureTest, reporter, context) {
|
|
// TODO: Right now this just tests very basic combinations of surfaces. This should be expanded
|
|
// to conver a much broader set of things once we add more support in Graphite for different
|
|
// formats, color types, etc.
|
|
|
|
auto caps = context->priv().gpu()->caps();
|
|
sk_sp<Recorder> recorder = context->createRecorder();
|
|
|
|
TextureInfo info = caps->getDefaultSampledTextureInfo(kRGBA_8888_SkColorType,
|
|
/*levelCount=*/1,
|
|
Protected::kNo,
|
|
Renderable::kYes);
|
|
|
|
auto texture = context->createBackendTexture(kSize, info);
|
|
REPORTER_ASSERT(reporter, texture.isValid());
|
|
|
|
sk_sp<SkSurface> surface = MakeGraphiteFromBackendTexture(recorder.get(),
|
|
texture,
|
|
kRGBA_8888_SkColorType,
|
|
/*colorSpace=*/nullptr,
|
|
/*props=*/nullptr);
|
|
REPORTER_ASSERT(reporter, surface);
|
|
|
|
surface.reset();
|
|
|
|
// We should fail when trying to wrap the same texture in a surface with a non compatible
|
|
// color type.
|
|
surface = MakeGraphiteFromBackendTexture(recorder.get(),
|
|
texture,
|
|
kAlpha_8_SkColorType,
|
|
/*colorSpace=*/nullptr,
|
|
/*props=*/nullptr);
|
|
REPORTER_ASSERT(reporter, !surface);
|
|
|
|
context->deleteBackendTexture(texture);
|
|
|
|
// We should fail to make a wrap non renderable texture in a surface.
|
|
info = caps->getDefaultSampledTextureInfo(kRGBA_8888_SkColorType,
|
|
/*levelCount=*/1,
|
|
Protected::kNo,
|
|
Renderable::kNo);
|
|
texture = context->createBackendTexture(kSize, info);
|
|
REPORTER_ASSERT(reporter, texture.isValid());
|
|
|
|
surface = MakeGraphiteFromBackendTexture(recorder.get(),
|
|
texture,
|
|
kRGBA_8888_SkColorType,
|
|
/*colorSpace=*/nullptr,
|
|
/*props=*/nullptr);
|
|
|
|
REPORTER_ASSERT(reporter, !surface);
|
|
context->deleteBackendTexture(texture);
|
|
}
|
|
|