1 /* 2 * Copyright 2011 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #ifndef GrGpu_DEFINED 9 #define GrGpu_DEFINED 10 11 #include "include/core/SkPath.h" 12 #include "include/core/SkSurface.h" 13 #include "include/gpu/GrContext.h" 14 #include "include/gpu/GrTypes.h" 15 #include "include/private/SkTArray.h" 16 #include "src/gpu/GrAllocator.h" 17 #include "src/gpu/GrCaps.h" 18 #include "src/gpu/GrGpuCommandBuffer.h" 19 #include "src/gpu/GrProgramDesc.h" 20 #include "src/gpu/GrSamplePatternDictionary.h" 21 #include "src/gpu/GrSwizzle.h" 22 #include "src/gpu/GrTextureProducer.h" 23 #include "src/gpu/GrXferProcessor.h" 24 #include <map> 25 26 class GrBackendRenderTarget; 27 class GrBackendSemaphore; 28 class GrGpuBuffer; 29 class GrContext; 30 struct GrContextOptions; 31 class GrGLContext; 32 class GrMesh; 33 class GrPath; 34 class GrPathRenderer; 35 class GrPathRendererChain; 36 class GrPathRendering; 37 class GrPipeline; 38 class GrPrimitiveProcessor; 39 class GrRenderTarget; 40 class GrSemaphore; 41 class GrStencilAttachment; 42 class GrStencilSettings; 43 class GrSurface; 44 class GrTexture; 45 class SkJSONWriter; 46 47 class GrGpu : public SkRefCnt { 48 public: 49 GrGpu(GrContext* context); 50 ~GrGpu() override; 51 getContext()52 GrContext* getContext() { return fContext; } getContext()53 const GrContext* getContext() const { return fContext; } 54 setCurrentGrResourceTag(const GrGpuResourceTag tag)55 void setCurrentGrResourceTag(const GrGpuResourceTag tag) { 56 if (fContext) { 57 fContext->setCurrentGrResourceTag(tag); 58 } 59 } 60 61 /** 62 * Gets the capabilities of the draw target. 63 */ caps()64 const GrCaps* caps() const { return fCaps.get(); } refCaps()65 sk_sp<const GrCaps> refCaps() const { return fCaps; } 66 pathRendering()67 GrPathRendering* pathRendering() { return fPathRendering.get(); } 68 69 enum class DisconnectType { 70 // No cleanup should be attempted, immediately cease making backend API calls 71 kAbandon, 72 // Free allocated resources (not known by GrResourceCache) before returning and 73 // ensure no backend backend 3D API calls will be made after disconnect() returns. 74 kCleanup, 75 }; 76 77 // Called by GrContext when the underlying backend context is already or will be destroyed 78 // before GrContext. 79 virtual void disconnect(DisconnectType); 80 81 /** 82 * The GrGpu object normally assumes that no outsider is setting state 83 * within the underlying 3D API's context/device/whatever. This call informs 84 * the GrGpu that the state was modified and it shouldn't make assumptions 85 * about the state. 86 */ 87 void markContextDirty(uint32_t state = kAll_GrBackendState) { fResetBits |= state; } 88 89 /** 90 * Creates a texture object. If renderable is kYes then the returned texture can 91 * be used as a render target by calling GrTexture::asRenderTarget(). Not all 92 * pixel configs can be used as render targets. Support for configs as textures 93 * or render targets can be checked using GrCaps. 94 * 95 * @param desc describes the texture to be created. 96 * @param format the format for the texture (not currently used). 97 * @param renderable should the resulting texture be renderable 98 * @param renderTargetSampleCnt The number of samples to use for rendering if renderable is 99 * kYes. If renderable is kNo then this must be 1. 100 * @param budgeted does this texture count against the resource cache budget? 101 * @param isProtected should the texture be created as protected. 102 * @param texels array of mipmap levels containing texel data to load. 103 * If level i has pixels then it is assumed that its dimensions are 104 * max(1, floor(desc.fWidth / 2)) by max(1, floor(desc.fHeight / 2)). 105 * If texels[i].fPixels == nullptr for all i <= mipLevelCount or 106 * mipLevelCount is 0 then the texture's contents are uninitialized. 107 * If a level has non-null pixels, its row bytes must be a multiple of the 108 * config's bytes-per-pixel. The row bytes must be tight to the 109 * level width if !caps->writePixelsRowBytesSupport(). 110 * If mipLevelCount > 1 and texels[i].fPixels != nullptr for any i > 0 111 * then all levels must have non-null pixels. All levels must have 112 * non-null pixels if GrCaps::createTextureMustSpecifyAllLevels() is true. 113 * @param mipLevelCount the number of levels in 'texels'. May be 0, 1, or 114 * floor(max((log2(desc.fWidth), log2(desc.fHeight)))). It must be the 115 * latter if GrCaps::createTextureMustSpecifyAllLevels() is true. 116 * @return The texture object if successful, otherwise nullptr. 117 */ 118 sk_sp<GrTexture> createTexture(const GrSurfaceDesc& desc, const GrBackendFormat& format, 119 GrRenderable renderable, int renderTargetSampleCnt, SkBudgeted, 120 GrProtected isProtected, const GrMipLevel texels[], 121 int mipLevelCount); 122 123 /** 124 * Simplified createTexture() interface for when there is no initial texel data to upload. 125 */ 126 sk_sp<GrTexture> createTexture(const GrSurfaceDesc& desc, const GrBackendFormat& format, 127 GrRenderable renderable, int renderTargetSampleCnt, 128 SkBudgeted budgeted, GrProtected isProtected); 129 130 sk_sp<GrTexture> createCompressedTexture(int width, int height, const GrBackendFormat&, 131 SkImage::CompressionType, SkBudgeted, const void* data, 132 size_t dataSize); 133 134 /** 135 * Implements GrResourceProvider::wrapBackendTexture 136 */ 137 sk_sp<GrTexture> wrapBackendTexture(const GrBackendTexture&, GrColorType, 138 GrWrapOwnership, GrWrapCacheable, GrIOType); 139 140 /** 141 * Implements GrResourceProvider::wrapRenderableBackendTexture 142 */ 143 sk_sp<GrTexture> wrapRenderableBackendTexture(const GrBackendTexture&, int sampleCnt, 144 GrColorType, GrWrapOwnership, GrWrapCacheable); 145 146 /** 147 * Implements GrResourceProvider::wrapBackendRenderTarget 148 */ 149 sk_sp<GrRenderTarget> wrapBackendRenderTarget(const GrBackendRenderTarget&, 150 GrColorType colorType); 151 152 /** 153 * Implements GrResourceProvider::wrapBackendTextureAsRenderTarget 154 */ 155 sk_sp<GrRenderTarget> wrapBackendTextureAsRenderTarget(const GrBackendTexture&, 156 int sampleCnt, 157 GrColorType colorType); 158 159 /** 160 * Implements GrResourceProvider::wrapVulkanSecondaryCBAsRenderTarget 161 */ 162 sk_sp<GrRenderTarget> wrapVulkanSecondaryCBAsRenderTarget(const SkImageInfo&, 163 const GrVkDrawableInfo&); 164 165 /** 166 * Creates a buffer in GPU memory. For a client-side buffer use GrBuffer::CreateCPUBacked. 167 * 168 * @param size size of buffer to create. 169 * @param intendedType hint to the graphics subsystem about what the buffer will be used for. 170 * @param accessPattern hint to the graphics subsystem about how the data will be accessed. 171 * @param data optional data with which to initialize the buffer. 172 * 173 * @return the buffer if successful, otherwise nullptr. 174 */ 175 sk_sp<GrGpuBuffer> createBuffer(size_t size, GrGpuBufferType intendedType, 176 GrAccessPattern accessPattern, const void* data = nullptr); 177 178 /** 179 * Resolves MSAA. 180 */ 181 void resolveRenderTarget(GrRenderTarget*); 182 183 /** 184 * Uses the base of the texture to recompute the contents of the other levels. 185 */ 186 bool regenerateMipMapLevels(GrTexture*); 187 188 /** 189 * If the backend API has stateful texture bindings, this resets them back to defaults. 190 */ 191 void resetTextureBindings(); 192 193 /** 194 * Reads a rectangle of pixels from a render target. No sRGB/linear conversions are performed. 195 * 196 * @param surface The surface to read from 197 * @param left left edge of the rectangle to read (inclusive) 198 * @param top top edge of the rectangle to read (inclusive) 199 * @param width width of rectangle to read in pixels. 200 * @param height height of rectangle to read in pixels. 201 * @param surfaceColorType the color type for this use of the surface. 202 * @param dstColorType the color type of the destination buffer. 203 * @param buffer memory to read the rectangle into. 204 * @param rowBytes the number of bytes between consecutive rows. Must be a multiple of 205 * dstColorType's bytes-per-pixel. Must be tight to width if 206 * !caps->readPixelsRowBytesSupport(). 207 * 208 * @return true if the read succeeded, false if not. The read can fail 209 * because of the surface doesn't support reading, the color type 210 * is not allowed for the format of the surface or if the rectangle 211 * read is not contained in the surface. 212 */ 213 bool readPixels(GrSurface* surface, int left, int top, int width, int height, 214 GrColorType surfaceColorType, GrColorType dstColorType, void* buffer, 215 size_t rowBytes); 216 217 /** 218 * Updates the pixels in a rectangle of a surface. No sRGB/linear conversions are performed. 219 * 220 * @param surface The surface to write to. 221 * @param left left edge of the rectangle to write (inclusive) 222 * @param top top edge of the rectangle to write (inclusive) 223 * @param width width of rectangle to write in pixels. 224 * @param height height of rectangle to write in pixels. 225 * @param surfaceColorType the color type for this use of the surface. 226 * @param srcColorType the color type of the source buffer. 227 * @param texels array of mipmap levels containing texture data. Row bytes must be a 228 * multiple of srcColorType's bytes-per-pixel. Must be tight to level 229 * width if !caps->writePixelsRowBytesSupport(). 230 * @param mipLevelCount number of levels in 'texels' 231 * 232 * @return true if the write succeeded, false if not. The read can fail 233 * because of the surface doesn't support writing (e.g. read only), 234 * the color type is not allowed for the format of the surface or 235 * if the rectangle written is not contained in the surface. 236 */ 237 bool writePixels(GrSurface* surface, int left, int top, int width, int height, 238 GrColorType surfaceColorType, GrColorType srcColorType, 239 const GrMipLevel texels[], int mipLevelCount); 240 241 /** 242 * Helper for the case of a single level. 243 */ writePixels(GrSurface * surface,int left,int top,int width,int height,GrColorType surfaceColorType,GrColorType srcColorType,const void * buffer,size_t rowBytes)244 bool writePixels(GrSurface* surface, int left, int top, int width, int height, 245 GrColorType surfaceColorType, GrColorType srcColorType, const void* buffer, 246 size_t rowBytes) { 247 GrMipLevel mipLevel = {buffer, rowBytes}; 248 return this->writePixels(surface, left, top, width, height, surfaceColorType, srcColorType, 249 &mipLevel, 1); 250 } 251 252 /** 253 * Updates the pixels in a rectangle of a texture using a buffer. If the texture is MIP mapped, 254 * the base level is written to. 255 * 256 * @param texture The texture to write to. 257 * @param left left edge of the rectangle to write (inclusive) 258 * @param top top edge of the rectangle to write (inclusive) 259 * @param width width of rectangle to write in pixels. 260 * @param height height of rectangle to write in pixels. 261 * @param textureColorType the color type for this use of the surface. 262 * @param bufferColorType the color type of the transfer buffer's pixel data 263 * @param transferBuffer GrBuffer to read pixels from (type must be "kXferCpuToGpu") 264 * @param offset offset from the start of the buffer 265 * @param rowBytes number of bytes between consecutive rows in the buffer. Must be a 266 * multiple of bufferColorType's bytes-per-pixel. Must be tight to width 267 * if !caps->writePixelsRowBytesSupport(). 268 */ 269 bool transferPixelsTo(GrTexture* texture, int left, int top, int width, int height, 270 GrColorType textureColorType, GrColorType bufferColorType, 271 GrGpuBuffer* transferBuffer, size_t offset, size_t rowBytes); 272 273 /** 274 * Reads the pixels from a rectangle of a surface into a buffer. Use 275 * GrCaps::SupportedRead::fOffsetAlignmentForTransferBuffer to determine the requirements for 276 * the buffer offset alignment. If the surface is a MIP mapped texture, the base level is read. 277 * 278 * If successful the row bytes in the buffer is always: 279 * GrColorTypeBytesPerPixel(bufferColorType) * width 280 * 281 * Asserts that the caller has passed a properly aligned offset and that the buffer is 282 * large enough to hold the result 283 * 284 * @param surface The surface to read from. 285 * @param left left edge of the rectangle to read (inclusive) 286 * @param top top edge of the rectangle to read (inclusive) 287 * @param width width of rectangle to read in pixels. 288 * @param height height of rectangle to read in pixels. 289 * @param surfaceColorType the color type for this use of the surface. 290 * @param bufferColorType the color type of the transfer buffer's pixel data 291 * @param transferBuffer GrBuffer to write pixels to (type must be "kXferGpuToCpu") 292 * @param offset offset from the start of the buffer 293 */ 294 bool transferPixelsFrom(GrSurface* surface, int left, int top, int width, int height, 295 GrColorType surfaceColorType, GrColorType bufferColorType, 296 GrGpuBuffer* transferBuffer, size_t offset); 297 298 // Called to perform a surface to surface copy. Fallbacks to issuing a draw from the src to dst 299 // take place at the GrOpList level and this function implement faster copy paths. The rect 300 // and point are pre-clipped. The src rect and implied dst rect are guaranteed to be within the 301 // src/dst bounds and non-empty. They must also be in their exact device space coords, including 302 // already being transformed for origin if need be. If canDiscardOutsideDstRect is set to true 303 // then we don't need to preserve any data on the dst surface outside of the copy. 304 bool copySurface(GrSurface* dst, GrSurface* src, const SkIRect& srcRect, 305 const SkIPoint& dstPoint, bool canDiscardOutsideDstRect = false); 306 307 // Queries the per-pixel HW sample locations for the given render target, and then finds or 308 // assigns a key that uniquely identifies the sample pattern. The actual sample locations can be 309 // retrieved with retrieveSampleLocations(). 310 int findOrAssignSamplePatternKey(GrRenderTarget*); 311 312 // Retrieves the per-pixel HW sample locations for the given sample pattern key, and, as a 313 // by-product, the actual number of samples in use. (This may differ from the number of samples 314 // requested by the render target.) Sample locations are returned as 0..1 offsets relative to 315 // the top-left corner of the pixel. retrieveSampleLocations(int samplePatternKey)316 const SkTArray<SkPoint>& retrieveSampleLocations(int samplePatternKey) const { 317 return fSamplePatternDictionary.retrieveSampleLocations(samplePatternKey); 318 } 319 320 // Returns a GrGpuRTCommandBuffer which GrOpLists send draw commands to instead of directly 321 // to the Gpu object. The 'bounds' rect is the content rect of the destination. 322 virtual GrGpuRTCommandBuffer* getCommandBuffer( 323 GrRenderTarget*, GrSurfaceOrigin, const SkRect& bounds, 324 const GrGpuRTCommandBuffer::LoadAndStoreInfo&, 325 const GrGpuRTCommandBuffer::StencilLoadAndStoreInfo&) = 0; 326 327 // Returns a GrGpuTextureCommandBuffer which GrOpLists send texture commands to instead of 328 // directly to the Gpu object. 329 virtual GrGpuTextureCommandBuffer* getCommandBuffer(GrTexture*, GrSurfaceOrigin) = 0; 330 331 // Called by GrDrawingManager when flushing. 332 // Provides a hook for post-flush actions (e.g. Vulkan command buffer submits). This will also 333 // insert any numSemaphore semaphores on the gpu and set the backendSemaphores to match the 334 // inserted semaphores. 335 GrSemaphoresSubmitted finishFlush(GrSurfaceProxy*[], int n, 336 SkSurface::BackendSurfaceAccess access, const GrFlushInfo&, 337 const GrPrepareForExternalIORequests&); 338 339 virtual void submit(GrGpuCommandBuffer*) = 0; 340 341 virtual GrFence SK_WARN_UNUSED_RESULT insertFence() = 0; 342 virtual bool waitFence(GrFence, uint64_t timeout = 1000) = 0; 343 virtual void deleteFence(GrFence) const = 0; 344 345 virtual sk_sp<GrSemaphore> SK_WARN_UNUSED_RESULT makeSemaphore(bool isOwned = true) = 0; 346 virtual sk_sp<GrSemaphore> wrapBackendSemaphore(const GrBackendSemaphore& semaphore, 347 GrResourceProvider::SemaphoreWrapType wrapType, 348 GrWrapOwnership ownership) = 0; 349 virtual void insertSemaphore(sk_sp<GrSemaphore> semaphore) = 0; 350 virtual void waitSemaphore(sk_sp<GrSemaphore> semaphore) = 0; 351 352 virtual void checkFinishProcs() = 0; 353 354 /** 355 * Put this texture in a safe and known state for use across multiple GrContexts. Depending on 356 * the backend, this may return a GrSemaphore. If so, other contexts should wait on that 357 * semaphore before using this texture. 358 */ 359 virtual sk_sp<GrSemaphore> prepareTextureForCrossContextUsage(GrTexture*) = 0; 360 361 /////////////////////////////////////////////////////////////////////////// 362 // Debugging and Stats 363 364 class Stats { 365 public: 366 #if GR_GPU_STATS 367 Stats() = default; 368 reset()369 void reset() { *this = {}; } 370 renderTargetBinds()371 int renderTargetBinds() const { return fRenderTargetBinds; } incRenderTargetBinds()372 void incRenderTargetBinds() { fRenderTargetBinds++; } 373 shaderCompilations()374 int shaderCompilations() const { return fShaderCompilations; } incShaderCompilations()375 void incShaderCompilations() { fShaderCompilations++; } 376 textureCreates()377 int textureCreates() const { return fTextureCreates; } incTextureCreates()378 void incTextureCreates() { fTextureCreates++; } 379 textureUploads()380 int textureUploads() const { return fTextureUploads; } incTextureUploads()381 void incTextureUploads() { fTextureUploads++; } 382 transfersToTexture()383 int transfersToTexture() const { return fTransfersToTexture; } incTransfersToTexture()384 void incTransfersToTexture() { fTransfersToTexture++; } 385 transfersFromSurface()386 int transfersFromSurface() const { return fTransfersFromSurface; } incTransfersFromSurface()387 void incTransfersFromSurface() { fTransfersFromSurface++; } 388 stencilAttachmentCreates()389 int stencilAttachmentCreates() const { return fStencilAttachmentCreates; } incStencilAttachmentCreates()390 void incStencilAttachmentCreates() { fStencilAttachmentCreates++; } 391 numDraws()392 int numDraws() const { return fNumDraws; } incNumDraws()393 void incNumDraws() { fNumDraws++; } 394 numFailedDraws()395 int numFailedDraws() const { return fNumFailedDraws; } incNumFailedDraws()396 void incNumFailedDraws() { ++fNumFailedDraws; } 397 numFinishFlushes()398 int numFinishFlushes() const { return fNumFinishFlushes; } incNumFinishFlushes()399 void incNumFinishFlushes() { ++fNumFinishFlushes; } 400 numScratchTexturesReused()401 int numScratchTexturesReused() const { return fNumScratchTexturesReused; } incNumScratchTexturesReused()402 void incNumScratchTexturesReused() { ++fNumScratchTexturesReused; } 403 404 #if GR_TEST_UTILS 405 void dump(SkString*); 406 void dumpKeyValuePairs(SkTArray<SkString>* keys, SkTArray<double>* values); 407 #endif 408 private: 409 int fRenderTargetBinds = 0; 410 int fShaderCompilations = 0; 411 int fTextureCreates = 0; 412 int fTextureUploads = 0; 413 int fTransfersToTexture = 0; 414 int fTransfersFromSurface = 0; 415 int fStencilAttachmentCreates = 0; 416 int fNumDraws = 0; 417 int fNumFailedDraws = 0; 418 int fNumFinishFlushes = 0; 419 int fNumScratchTexturesReused = 0; 420 #else 421 422 #if GR_TEST_UTILS 423 void dump(SkString*) {} 424 void dumpKeyValuePairs(SkTArray<SkString>*, SkTArray<double>*) {} 425 #endif 426 void incRenderTargetBinds() {} 427 void incShaderCompilations() {} 428 void incTextureCreates() {} 429 void incTextureUploads() {} 430 void incTransfersToTexture() {} 431 void incStencilAttachmentCreates() {} 432 void incNumDraws() {} 433 void incNumFailedDraws() {} 434 void incNumFinishFlushes() {} 435 #endif 436 }; 437 stats()438 Stats* stats() { return &fStats; } 439 void dumpJSON(SkJSONWriter*) const; 440 441 /** 442 * Creates a texture directly in the backend API without wrapping it in a GrTexture. 443 * Must be matched with a call to deleteBackendTexture(). 444 * Right now, the color is ignored if pixel data is provided. 445 * In the future, if neither a color nor pixels are provided then the backend texture 446 * will be uninitialized. 447 */ 448 virtual GrBackendTexture createBackendTexture(int w, int h, const GrBackendFormat&, 449 GrMipMapped, GrRenderable, 450 const void* pixels, size_t rowBytes, 451 const SkColor4f* color, 452 GrProtected isProtected) = 0; 453 454 /** 455 * Frees a texture created by createBackendTexture(). If ownership of the backend 456 * texture has been transferred to a GrContext using adopt semantics this should not be called. 457 */ 458 virtual void deleteBackendTexture(const GrBackendTexture&) = 0; 459 460 #if GR_TEST_UTILS 461 /** Check a handle represents an actual texture in the backend API that has not been freed. */ 462 virtual bool isTestingOnlyBackendTexture(const GrBackendTexture&) const = 0; 463 464 virtual GrBackendRenderTarget createTestingOnlyBackendRenderTarget(int w, int h, 465 GrColorType) = 0; 466 467 virtual void deleteTestingOnlyBackendRenderTarget(const GrBackendRenderTarget&) = 0; 468 469 // This is only to be used in GL-specific tests. glContextForTesting()470 virtual const GrGLContext* glContextForTesting() const { return nullptr; } 471 472 // This is only to be used by testing code resetShaderCacheForTesting()473 virtual void resetShaderCacheForTesting() const {} 474 475 /** 476 * Flushes all work to the gpu and forces the GPU to wait until all the gpu work has completed. 477 * This is for testing purposes only. 478 */ 479 virtual void testingOnly_flushGpuAndSync() = 0; 480 #endif 481 482 // width and height may be larger than rt (if underlying API allows it). 483 // Returns nullptr if compatible sb could not be created, otherwise the caller owns the ref on 484 // the GrStencilAttachment. 485 virtual GrStencilAttachment* createStencilAttachmentForRenderTarget( 486 const GrRenderTarget*, int width, int height, int numStencilSamples) = 0; 487 488 // Determines whether a texture will need to be rescaled in order to be used with the 489 // GrSamplerState. 490 static bool IsACopyNeededForRepeatWrapMode(const GrCaps*, GrTextureProxy* texProxy, 491 int width, int height, 492 GrSamplerState::Filter, 493 GrTextureProducer::CopyParams*, 494 SkScalar scaleAdjust[2]); 495 496 // Determines whether a texture will need to be copied because the draw requires mips but the 497 // texutre doesn't have any. This call should be only checked if IsACopyNeededForTextureParams 498 // fails. If the previous call succeeds, then a copy should be done using those params and the 499 // mip mapping requirements will be handled there. 500 static bool IsACopyNeededForMips(const GrCaps* caps, const GrTextureProxy* texProxy, 501 GrSamplerState::Filter filter, 502 GrTextureProducer::CopyParams* copyParams); 503 handleDirtyContext()504 void handleDirtyContext() { 505 if (fResetBits) { 506 this->resetContext(); 507 } 508 } 509 510 /** 511 * Returns a key that represents the sampler that will be created for the passed in parameters. 512 * Currently this key is only used when we are building a vulkan pipeline with immutable 513 * samplers. In that case, we need our cache key to also contain this key. 514 * 515 * A return value of 0 indicates that the program/pipeline we are creating is not affected by 516 * the sampler. 517 */ getExtraSamplerKeyForProgram(const GrSamplerState &,const GrBackendFormat &)518 virtual uint32_t getExtraSamplerKeyForProgram(const GrSamplerState&, const GrBackendFormat&) { 519 return 0; 520 } 521 storeVkPipelineCacheData()522 virtual void storeVkPipelineCacheData() {} 523 524 protected: 525 // Handles cases where a surface will be updated without a call to flushRenderTarget. 526 void didWriteToSurface(GrSurface* surface, GrSurfaceOrigin origin, const SkIRect* bounds, 527 uint32_t mipLevels = 1) const; 528 529 Stats fStats; 530 std::unique_ptr<GrPathRendering> fPathRendering; 531 // Subclass must initialize this in its constructor. 532 sk_sp<const GrCaps> fCaps; 533 534 private: 535 // called when the 3D context state is unknown. Subclass should emit any 536 // assumed 3D context state and dirty any state cache. 537 virtual void onResetContext(uint32_t resetBits) = 0; 538 539 // Implementation of resetTextureBindings. onResetTextureBindings()540 virtual void onResetTextureBindings() {} 541 542 // Queries the effective number of samples in use by the hardware for the given render target, 543 // and queries the individual sample locations. 544 virtual void querySampleLocations(GrRenderTarget*, SkTArray<SkPoint>*) = 0; 545 546 // Called before certain draws in order to guarantee coherent results from dst reads. 547 virtual void xferBarrier(GrRenderTarget*, GrXferBarrierType) = 0; 548 549 // overridden by backend-specific derived class to create objects. 550 // Texture size and sample size will have already been validated in base class before 551 // onCreateTexture is called. 552 virtual sk_sp<GrTexture> onCreateTexture(const GrSurfaceDesc&, 553 const GrBackendFormat&, 554 GrRenderable, 555 int renderTargetSampleCnt, 556 SkBudgeted, GrProtected, 557 const GrMipLevel[], 558 int mipLevelCount) = 0; 559 virtual sk_sp<GrTexture> onCreateCompressedTexture(int width, int height, 560 const GrBackendFormat&, 561 SkImage::CompressionType, SkBudgeted, 562 const void* data) = 0; 563 virtual sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTexture&, GrColorType, 564 GrWrapOwnership, GrWrapCacheable, GrIOType) = 0; 565 virtual sk_sp<GrTexture> onWrapRenderableBackendTexture(const GrBackendTexture&, int sampleCnt, 566 GrColorType, GrWrapOwnership, 567 GrWrapCacheable) = 0; 568 virtual sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTarget&, 569 GrColorType) = 0; 570 virtual sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTexture&, 571 int sampleCnt, 572 GrColorType) = 0; 573 virtual sk_sp<GrRenderTarget> onWrapVulkanSecondaryCBAsRenderTarget(const SkImageInfo&, 574 const GrVkDrawableInfo&); 575 576 virtual sk_sp<GrGpuBuffer> onCreateBuffer(size_t size, GrGpuBufferType intendedType, 577 GrAccessPattern, const void* data) = 0; 578 579 // overridden by backend-specific derived class to perform the surface read 580 virtual bool onReadPixels(GrSurface*, int left, int top, int width, int height, 581 GrColorType surfaceColorType, GrColorType dstColorType, void* buffer, 582 size_t rowBytes) = 0; 583 584 // overridden by backend-specific derived class to perform the surface write 585 virtual bool onWritePixels(GrSurface*, int left, int top, int width, int height, 586 GrColorType surfaceColorType, GrColorType srcColorType, 587 const GrMipLevel texels[], int mipLevelCount) = 0; 588 589 // overridden by backend-specific derived class to perform the texture transfer 590 virtual bool onTransferPixelsTo(GrTexture*, int left, int top, int width, int height, 591 GrColorType textiueColorType, GrColorType bufferColorType, 592 GrGpuBuffer* transferBuffer, size_t offset, 593 size_t rowBytes) = 0; 594 // overridden by backend-specific derived class to perform the surface transfer 595 virtual bool onTransferPixelsFrom(GrSurface*, int left, int top, int width, int height, 596 GrColorType surfaceColorType, GrColorType bufferColorType, 597 GrGpuBuffer* transferBuffer, size_t offset) = 0; 598 599 // overridden by backend-specific derived class to perform the resolve 600 virtual void onResolveRenderTarget(GrRenderTarget* target) = 0; 601 602 // overridden by backend specific derived class to perform mip map level regeneration. 603 virtual bool onRegenerateMipMapLevels(GrTexture*) = 0; 604 605 // overridden by backend specific derived class to perform the copy surface 606 virtual bool onCopySurface(GrSurface* dst, GrSurface* src, const SkIRect& srcRect, 607 const SkIPoint& dstPoint, bool canDiscardOutsideDstRect) = 0; 608 609 virtual void onFinishFlush(GrSurfaceProxy*[], int n, SkSurface::BackendSurfaceAccess access, 610 const GrFlushInfo&, const GrPrepareForExternalIORequests&) = 0; 611 612 #ifdef SK_ENABLE_DUMP_GPU onDumpJSON(SkJSONWriter *)613 virtual void onDumpJSON(SkJSONWriter*) const {} 614 #endif 615 resetContext()616 void resetContext() { 617 this->onResetContext(fResetBits); 618 fResetBits = 0; 619 } 620 621 uint32_t fResetBits; 622 // The context owns us, not vice-versa, so this ptr is not ref'ed by Gpu. 623 GrContext* fContext; 624 GrSamplePatternDictionary fSamplePatternDictionary; 625 626 friend class GrPathRendering; 627 typedef SkRefCnt INHERITED; 628 }; 629 630 #endif 631