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