Skip to content

Commit 2e0c70d

Browse files
Adlai-HollerSkia Commit-Bot
authored andcommitted
Migrate texture update methods to GrDirectContext
Cut & paste job, but I did replace some cases of just calling inherited implementations with using-statements. There are other methods on this class that are using-statements and that pattern is cleaner. Change-Id: Ie369c643e44bdb8f82dfffcf45c1f65d48606899 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/325660 Reviewed-by: Brian Salomon <[email protected]> Reviewed-by: Robert Phillips <[email protected]> Commit-Queue: Brian Salomon <[email protected]> Auto-Submit: Adlai Holler <[email protected]>
1 parent 43a2d42 commit 2e0c70d

File tree

4 files changed

+139
-153
lines changed

4 files changed

+139
-153
lines changed

include/gpu/GrDirectContext.h

Lines changed: 64 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -370,9 +370,7 @@ class SK_API GrDirectContext : public GrContext {
370370
*
371371
* The caller should check that the returned format is valid.
372372
*/
373-
GrBackendFormat defaultBackendFormat(SkColorType ct, GrRenderable renderable) const {
374-
return INHERITED::defaultBackendFormat(ct, renderable);
375-
}
373+
using GrRecordingContext::defaultBackendFormat;
376374

377375
/**
378376
* The explicitly allocated backend texture API allows clients to use Skia to create backend
@@ -485,6 +483,69 @@ class SK_API GrDirectContext : public GrContext {
485483
return this->createBackendTexture(&srcData, 1, renderable, isProtected, finishedProc,
486484
finishedContext);
487485
}
486+
487+
/**
488+
* If possible, updates a backend texture to be filled to a particular color. The client should
489+
* check the return value to see if the update was successful. The client can pass in a
490+
* finishedProc to be notified when the data has been uploaded by the gpu and the texture can be
491+
* deleted. The client is required to call `submit` to send the upload work to the gpu.
492+
* The finishedProc will always get called even if we failed to update the GrBackendTexture.
493+
* For the Vulkan backend after a successful update the layout of the created VkImage will be:
494+
* VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL
495+
*/
496+
bool updateBackendTexture(const GrBackendTexture&,
497+
const SkColor4f& color,
498+
GrGpuFinishedProc finishedProc,
499+
GrGpuFinishedContext finishedContext);
500+
501+
/**
502+
* If possible, updates a backend texture to be filled to a particular color. The data in
503+
* GrBackendTexture and passed in color is interpreted with respect to the passed in
504+
* SkColorType. The client should check the return value to see if the update was successful.
505+
* The client can pass in a finishedProc to be notified when the data has been uploaded by the
506+
* gpu and the texture can be deleted. The client is required to call `submit` to send
507+
* the upload work to the gpu. The finishedProc will always get called even if we failed to
508+
* update the GrBackendTexture.
509+
* For the Vulkan backend after a successful update the layout of the created VkImage will be:
510+
* VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL
511+
*/
512+
bool updateBackendTexture(const GrBackendTexture&,
513+
SkColorType skColorType,
514+
const SkColor4f& color,
515+
GrGpuFinishedProc finishedProc,
516+
GrGpuFinishedContext finishedContext);
517+
518+
/**
519+
* If possible, updates a backend texture filled with the provided pixmap data. The client
520+
* should check the return value to see if the update was successful. The client can pass in a
521+
* finishedProc to be notified when the data has been uploaded by the gpu and the texture can be
522+
* deleted. The client is required to call `submit` to send the upload work to the gpu.
523+
* The finishedProc will always get called even if we failed to create the GrBackendTexture.
524+
* The backend texture must be compatible with the provided pixmap(s). Compatible, in this case,
525+
* means that the backend format is compatible with the base pixmap's colortype. The src data
526+
* can be deleted when this call returns.
527+
* If the backend texture is mip mapped, the data for all the mipmap levels must be provided.
528+
* In the mipmapped case all the colortypes of the provided pixmaps must be the same.
529+
* Additionally, all the miplevels must be sized correctly (please see
530+
* SkMipmap::ComputeLevelSize and ComputeLevelCount).
531+
* Note: the pixmap's alphatypes and colorspaces are ignored.
532+
* For the Vulkan backend after a successful update the layout of the created VkImage will be:
533+
* VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL
534+
*/
535+
bool updateBackendTexture(const GrBackendTexture&,
536+
const SkPixmap srcData[],
537+
int numLevels,
538+
GrGpuFinishedProc finishedProc,
539+
GrGpuFinishedContext finishedContext);
540+
541+
/**
542+
* Retrieve the GrBackendFormat for a given SkImage::CompressionType. This is
543+
* guaranteed to match the backend format used by the following
544+
* createCompressedBackendTexture methods that take a CompressionType.
545+
* The caller should check that the returned format is valid.
546+
*/
547+
using GrRecordingContext::compressedBackendFormat;
548+
488549
protected:
489550
GrDirectContext(GrBackendApi backend, const GrContextOptions& options);
490551

include/private/GrContext.h

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -57,69 +57,6 @@ class SK_API GrContext : public GrRecordingContext {
5757
public:
5858
~GrContext() override;
5959

60-
/**
61-
* If possible, updates a backend texture to be filled to a particular color. The client should
62-
* check the return value to see if the update was successful. The client can pass in a
63-
* finishedProc to be notified when the data has been uploaded by the gpu and the texture can be
64-
* deleted. The client is required to call GrContext::submit to send the upload work to the gpu.
65-
* The finishedProc will always get called even if we failed to update the GrBackendTexture.
66-
* For the Vulkan backend after a successful update the layout of the created VkImage will be:
67-
* VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL
68-
*/
69-
bool updateBackendTexture(const GrBackendTexture&,
70-
const SkColor4f& color,
71-
GrGpuFinishedProc finishedProc,
72-
GrGpuFinishedContext finishedContext);
73-
74-
/**
75-
* If possible, updates a backend texture to be filled to a particular color. The data in
76-
* GrBackendTexture and passed in color is interpreted with respect to the passed in
77-
* SkColorType. The client should check the return value to see if the update was successful.
78-
* The client can pass in a finishedProc to be notified when the data has been uploaded by the
79-
* gpu and the texture can be deleted. The client is required to call GrContext::submit to send
80-
* the upload work to the gpu. The finishedProc will always get called even if we failed to
81-
* update the GrBackendTexture.
82-
* For the Vulkan backend after a successful update the layout of the created VkImage will be:
83-
* VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL
84-
*/
85-
bool updateBackendTexture(const GrBackendTexture&,
86-
SkColorType skColorType,
87-
const SkColor4f& color,
88-
GrGpuFinishedProc finishedProc,
89-
GrGpuFinishedContext finishedContext);
90-
91-
/**
92-
* If possible, updates a backend texture filled with the provided pixmap data. The client
93-
* should check the return value to see if the update was successful. The client can pass in a
94-
* finishedProc to be notified when the data has been uploaded by the gpu and the texture can be
95-
* deleted. The client is required to call GrContext::submit to send the upload work to the gpu.
96-
* The finishedProc will always get called even if we failed to create the GrBackendTexture.
97-
* The backend texture must be compatible with the provided pixmap(s). Compatible, in this case,
98-
* means that the backend format is compatible with the base pixmap's colortype. The src data
99-
* can be deleted when this call returns.
100-
* If the backend texture is mip mapped, the data for all the mipmap levels must be provided.
101-
* In the mipmapped case all the colortypes of the provided pixmaps must be the same.
102-
* Additionally, all the miplevels must be sized correctly (please see
103-
* SkMipmap::ComputeLevelSize and ComputeLevelCount).
104-
* Note: the pixmap's alphatypes and colorspaces are ignored.
105-
* For the Vulkan backend after a successful update the layout of the created VkImage will be:
106-
* VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL
107-
*/
108-
bool updateBackendTexture(const GrBackendTexture&,
109-
const SkPixmap srcData[],
110-
int numLevels,
111-
GrGpuFinishedProc finishedProc,
112-
GrGpuFinishedContext finishedContext);
113-
114-
/**
115-
* Retrieve the GrBackendFormat for a given SkImage::CompressionType. This is
116-
* guaranteed to match the backend format used by the following
117-
* createCompressedsBackendTexture methods that take a CompressionType.
118-
* The caller should check that the returned format is valid.
119-
*/
120-
GrBackendFormat compressedBackendFormat(SkImage::CompressionType compression) const {
121-
return INHERITED::compressedBackendFormat(compression);
122-
}
12360

12461
/**
12562
*If possible, create a compressed backend texture initialized to a particular color. The

src/gpu/GrContext.cpp

Lines changed: 0 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -43,93 +43,6 @@ GrContext::GrContext(sk_sp<GrContextThreadSafeProxy> proxy) : INHERITED(std::mov
4343

4444
GrContext::~GrContext() = default;
4545

46-
bool GrContext::updateBackendTexture(const GrBackendTexture& backendTexture,
47-
const SkColor4f& color,
48-
GrGpuFinishedProc finishedProc,
49-
GrGpuFinishedContext finishedContext) {
50-
sk_sp<GrRefCntedCallback> finishedCallback;
51-
if (finishedProc) {
52-
finishedCallback.reset(new GrRefCntedCallback(finishedProc, finishedContext));
53-
}
54-
55-
if (!this->asDirectContext()) {
56-
return false;
57-
}
58-
59-
if (this->abandoned()) {
60-
return false;
61-
}
62-
63-
GrGpu::BackendTextureData data(color);
64-
return fGpu->updateBackendTexture(backendTexture, std::move(finishedCallback), &data);
65-
}
66-
67-
bool GrContext::updateBackendTexture(const GrBackendTexture& backendTexture,
68-
SkColorType skColorType,
69-
const SkColor4f& color,
70-
GrGpuFinishedProc finishedProc,
71-
GrGpuFinishedContext finishedContext) {
72-
sk_sp<GrRefCntedCallback> finishedCallback;
73-
if (finishedProc) {
74-
finishedCallback.reset(new GrRefCntedCallback(finishedProc, finishedContext));
75-
}
76-
77-
if (!this->asDirectContext()) {
78-
return false;
79-
}
80-
81-
if (this->abandoned()) {
82-
return false;
83-
}
84-
85-
GrBackendFormat format = backendTexture.getBackendFormat();
86-
GrColorType grColorType = SkColorTypeAndFormatToGrColorType(this->caps(), skColorType, format);
87-
88-
if (!this->caps()->areColorTypeAndFormatCompatible(grColorType, format)) {
89-
return false;
90-
}
91-
92-
GrSwizzle swizzle = this->caps()->getWriteSwizzle(format, grColorType);
93-
GrGpu::BackendTextureData data(swizzle.applyTo(color));
94-
95-
return fGpu->updateBackendTexture(backendTexture, std::move(finishedCallback), &data);
96-
}
97-
98-
bool GrContext::updateBackendTexture(const GrBackendTexture& backendTexture,
99-
const SkPixmap srcData[],
100-
int numLevels,
101-
GrGpuFinishedProc finishedProc,
102-
GrGpuFinishedContext finishedContext) {
103-
sk_sp<GrRefCntedCallback> finishedCallback;
104-
if (finishedProc) {
105-
finishedCallback.reset(new GrRefCntedCallback(finishedProc, finishedContext));
106-
}
107-
108-
if (!this->asDirectContext()) {
109-
return false;
110-
}
111-
112-
if (this->abandoned()) {
113-
return false;
114-
}
115-
116-
if (!srcData || numLevels <= 0) {
117-
return false;
118-
}
119-
120-
int numExpectedLevels = 1;
121-
if (backendTexture.hasMipmaps()) {
122-
numExpectedLevels = SkMipmap::ComputeLevelCount(backendTexture.width(),
123-
backendTexture.height()) + 1;
124-
}
125-
if (numLevels != numExpectedLevels) {
126-
return false;
127-
}
128-
129-
GrGpu::BackendTextureData data(srcData);
130-
return fGpu->updateBackendTexture(backendTexture, std::move(finishedCallback), &data);
131-
}
132-
13346
//////////////////////////////////////////////////////////////////////////////
13447

13548
static GrBackendTexture create_and_update_compressed_backend_texture(

src/gpu/GrDirectContext.cpp

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,81 @@ GrBackendTexture GrDirectContext::createBackendTexture(const SkPixmap srcData[],
602602
std::move(finishedCallback), &data);
603603
}
604604

605+
bool GrDirectContext::updateBackendTexture(const GrBackendTexture& backendTexture,
606+
const SkColor4f& color,
607+
GrGpuFinishedProc finishedProc,
608+
GrGpuFinishedContext finishedContext) {
609+
sk_sp<GrRefCntedCallback> finishedCallback;
610+
if (finishedProc) {
611+
finishedCallback.reset(new GrRefCntedCallback(finishedProc, finishedContext));
612+
}
613+
614+
if (this->abandoned()) {
615+
return false;
616+
}
617+
618+
GrGpu::BackendTextureData data(color);
619+
return fGpu->updateBackendTexture(backendTexture, std::move(finishedCallback), &data);
620+
}
621+
622+
bool GrDirectContext::updateBackendTexture(const GrBackendTexture& backendTexture,
623+
SkColorType skColorType,
624+
const SkColor4f& color,
625+
GrGpuFinishedProc finishedProc,
626+
GrGpuFinishedContext finishedContext) {
627+
sk_sp<GrRefCntedCallback> finishedCallback;
628+
if (finishedProc) {
629+
finishedCallback.reset(new GrRefCntedCallback(finishedProc, finishedContext));
630+
}
631+
632+
if (this->abandoned()) {
633+
return false;
634+
}
635+
636+
GrBackendFormat format = backendTexture.getBackendFormat();
637+
GrColorType grColorType = SkColorTypeAndFormatToGrColorType(this->caps(), skColorType, format);
638+
639+
if (!this->caps()->areColorTypeAndFormatCompatible(grColorType, format)) {
640+
return false;
641+
}
642+
643+
GrSwizzle swizzle = this->caps()->getWriteSwizzle(format, grColorType);
644+
GrGpu::BackendTextureData data(swizzle.applyTo(color));
645+
646+
return fGpu->updateBackendTexture(backendTexture, std::move(finishedCallback), &data);
647+
}
648+
649+
bool GrDirectContext::updateBackendTexture(const GrBackendTexture& backendTexture,
650+
const SkPixmap srcData[],
651+
int numLevels,
652+
GrGpuFinishedProc finishedProc,
653+
GrGpuFinishedContext finishedContext) {
654+
sk_sp<GrRefCntedCallback> finishedCallback;
655+
if (finishedProc) {
656+
finishedCallback.reset(new GrRefCntedCallback(finishedProc, finishedContext));
657+
}
658+
659+
if (this->abandoned()) {
660+
return false;
661+
}
662+
663+
if (!srcData || numLevels <= 0) {
664+
return false;
665+
}
666+
667+
int numExpectedLevels = 1;
668+
if (backendTexture.hasMipmaps()) {
669+
numExpectedLevels = SkMipmap::ComputeLevelCount(backendTexture.width(),
670+
backendTexture.height()) + 1;
671+
}
672+
if (numLevels != numExpectedLevels) {
673+
return false;
674+
}
675+
676+
GrGpu::BackendTextureData data(srcData);
677+
return fGpu->updateBackendTexture(backendTexture, std::move(finishedCallback), &data);
678+
}
679+
605680
#ifdef SK_GL
606681

607682
/*************************************************************************************************/

0 commit comments

Comments
 (0)