GrGpu.h revision 67c18d6b5188a0497f6912a73d964c763d2f8f84
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 "GrGpuCommandBuffer.h" 12#include "GrProgramDesc.h" 13#include "GrSwizzle.h" 14#include "GrAllocator.h" 15#include "GrTextureProducer.h" 16#include "GrTypes.h" 17#include "GrXferProcessor.h" 18#include "SkPath.h" 19#include "SkTArray.h" 20#include <map> 21 22class GrBuffer; 23class GrContext; 24struct GrContextOptions; 25class GrGLContext; 26class GrMesh; 27class GrNonInstancedVertices; 28class GrPath; 29class GrPathRange; 30class GrPathRenderer; 31class GrPathRendererChain; 32class GrPathRendering; 33class GrPipeline; 34class GrPrimitiveProcessor; 35class GrRenderTarget; 36class GrStencilAttachment; 37class GrStencilSettings; 38class GrSurface; 39class GrTexture; 40 41namespace gr_instanced { class InstancedRendering; } 42 43class GrGpu : public SkRefCnt { 44public: 45 /** 46 * Create an instance of GrGpu that matches the specified backend. If the requested backend is 47 * not supported (at compile-time or run-time) this returns nullptr. The context will not be 48 * fully constructed and should not be used by GrGpu until after this function returns. 49 */ 50 static GrGpu* Create(GrBackend, GrBackendContext, const GrContextOptions&, GrContext* context); 51 52 //////////////////////////////////////////////////////////////////////////// 53 54 GrGpu(GrContext* context); 55 ~GrGpu() override; 56 57 GrContext* getContext() { return fContext; } 58 const GrContext* getContext() const { return fContext; } 59 60 /** 61 * Gets the capabilities of the draw target. 62 */ 63 const GrCaps* caps() const { return fCaps.get(); } 64 65 GrPathRendering* pathRendering() { return fPathRendering.get(); } 66 67 enum class DisconnectType { 68 // No cleanup should be attempted, immediately cease making backend API calls 69 kAbandon, 70 // Free allocated resources (not known by GrResourceCache) before returning and 71 // ensure no backend backend 3D API calls will be made after disconnect() returns. 72 kCleanup, 73 }; 74 75 // Called by GrContext when the underlying backend context is already or will be destroyed 76 // before GrContext. 77 virtual void disconnect(DisconnectType); 78 79 /** 80 * The GrGpu object normally assumes that no outsider is setting state 81 * within the underlying 3D API's context/device/whatever. This call informs 82 * the GrGpu that the state was modified and it shouldn't make assumptions 83 * about the state. 84 */ 85 void markContextDirty(uint32_t state = kAll_GrBackendState) { fResetBits |= state; } 86 87 /** 88 * Creates a texture object. If kRenderTarget_GrSurfaceFlag the texture can 89 * be used as a render target by calling GrTexture::asRenderTarget(). Not all 90 * pixel configs can be used as render targets. Support for configs as textures 91 * or render targets can be checked using GrCaps. 92 * 93 * @param desc describes the texture to be created. 94 * @param budgeted does this texture count against the resource cache budget? 95 * @param texels array of mipmap levels containing texel data to load. 96 * Each level begins with full-size palette data for paletted textures. 97 * For compressed formats the level contains the compressed pixel data. 98 * Otherwise, it contains width*height texels. If there is only one 99 * element and it contains nullptr fPixels, texture data is 100 * uninitialized. 101 * @return The texture object if successful, otherwise nullptr. 102 */ 103 GrTexture* createTexture(const GrSurfaceDesc& desc, SkBudgeted budgeted, 104 const SkTArray<GrMipLevel>& texels); 105 106 /** 107 * Simplified createTexture() interface for when there is no initial texel data to upload. 108 */ 109 GrTexture* createTexture(const GrSurfaceDesc& desc, SkBudgeted budgeted) { 110 return this->createTexture(desc, budgeted, SkTArray<GrMipLevel>()); 111 } 112 113 /** Simplified createTexture() interface for when there is only a base level */ 114 GrTexture* createTexture(const GrSurfaceDesc& desc, SkBudgeted budgeted, const void* level0Data, 115 size_t rowBytes) { 116 SkASSERT(level0Data); 117 GrMipLevel level = { level0Data, rowBytes }; 118 SkSTArray<1, GrMipLevel> array; 119 array.push_back() = level; 120 return this->createTexture(desc, budgeted, array); 121 } 122 123 /** 124 * Implements GrTextureProvider::wrapBackendTexture 125 */ 126 sk_sp<GrTexture> wrapBackendTexture(const GrBackendTextureDesc&, GrWrapOwnership); 127 128 /** 129 * Implements GrTextureProvider::wrapBackendRenderTarget 130 */ 131 sk_sp<GrRenderTarget> wrapBackendRenderTarget(const GrBackendRenderTargetDesc&,GrWrapOwnership); 132 133 /** 134 * Implements GrTextureProvider::wrapBackendTextureAsRenderTarget 135 */ 136 sk_sp<GrRenderTarget> wrapBackendTextureAsRenderTarget(const GrBackendTextureDesc&); 137 138 /** 139 * Creates a buffer in GPU memory. For a client-side buffer use GrBuffer::CreateCPUBacked. 140 * 141 * @param size size of buffer to create. 142 * @param intendedType hint to the graphics subsystem about what the buffer will be used for. 143 * @param accessPattern hint to the graphics subsystem about how the data will be accessed. 144 * @param data optional data with which to initialize the buffer. 145 * 146 * @return the buffer if successful, otherwise nullptr. 147 */ 148 GrBuffer* createBuffer(size_t size, GrBufferType intendedType, GrAccessPattern accessPattern, 149 const void* data = nullptr); 150 151 /** 152 * Creates an instanced rendering object if it is supported on this platform. 153 */ 154 gr_instanced::InstancedRendering* createInstancedRendering(); 155 156 /** 157 * Resolves MSAA. 158 */ 159 void resolveRenderTarget(GrRenderTarget* target); 160 161 /** Info struct returned by getReadPixelsInfo about performing intermediate draws before 162 reading pixels for performance or correctness. */ 163 struct ReadPixelTempDrawInfo { 164 /** If the GrGpu is requesting that the caller do a draw to an intermediate surface then 165 this is descriptor for the temp surface. The draw should always be a rect with 166 dst 0,0,w,h. */ 167 GrSurfaceDesc fTempSurfaceDesc; 168 /** Indicates whether there is a performance advantage to using an exact match texture 169 (in terms of width and height) for the intermediate texture instead of approximate. */ 170 SkBackingFit fTempSurfaceFit; 171 /** Swizzle to apply during the draw. This is used to compensate for either feature or 172 performance limitations in the underlying 3D API. */ 173 GrSwizzle fSwizzle; 174 /** The config that should be used to read from the temp surface after the draw. This may be 175 different than the original read config in order to compensate for swizzling. The 176 read data will effectively be in the original read config. */ 177 GrPixelConfig fReadConfig; 178 }; 179 180 /** Describes why an intermediate draw must/should be performed before readPixels. */ 181 enum DrawPreference { 182 /** On input means that the caller would proceed without draw if the GrGpu doesn't request 183 one. 184 On output means that the GrGpu is not requesting a draw. */ 185 kNoDraw_DrawPreference, 186 /** Means that the client would prefer a draw for performance of the readback but 187 can satisfy a straight readPixels call on the inputs without an intermediate draw. 188 getReadPixelsInfo will never set the draw preference to this value but may leave 189 it set. */ 190 kCallerPrefersDraw_DrawPreference, 191 /** On output means that GrGpu would prefer a draw for performance of the readback but 192 can satisfy a straight readPixels call on the inputs without an intermediate draw. The 193 caller of getReadPixelsInfo should never specify this on intput. */ 194 kGpuPrefersDraw_DrawPreference, 195 /** On input means that the caller requires a draw to do a transformation and there is no 196 CPU fallback. 197 On output means that GrGpu can only satisfy the readPixels request if the intermediate 198 draw is performed. 199 */ 200 kRequireDraw_DrawPreference 201 }; 202 203 /** 204 * Used to negotiate whether and how an intermediate draw should or must be performed before 205 * a readPixels call. If this returns false then GrGpu could not deduce an intermediate draw 206 * that would allow a successful readPixels call. The passed width, height, and rowBytes, 207 * must be non-zero and already reflect clipping to the src bounds. 208 */ 209 bool getReadPixelsInfo(GrSurface* srcSurface, int readWidth, int readHeight, size_t rowBytes, 210 GrPixelConfig readConfig, DrawPreference*, ReadPixelTempDrawInfo*); 211 212 /** Info struct returned by getWritePixelsInfo about performing an intermediate draw in order 213 to write pixels to a GrSurface for either performance or correctness reasons. */ 214 struct WritePixelTempDrawInfo { 215 /** If the GrGpu is requesting that the caller upload to an intermediate surface and draw 216 that to the dst then this is the descriptor for the intermediate surface. The caller 217 should upload the pixels such that the upper left pixel of the upload rect is at 0,0 in 218 the intermediate surface.*/ 219 GrSurfaceDesc fTempSurfaceDesc; 220 /** Swizzle to apply during the draw. This is used to compensate for either feature or 221 performance limitations in the underlying 3D API. */ 222 GrSwizzle fSwizzle; 223 /** The config that should be specified when uploading the *original* data to the temp 224 surface before the draw. This may be different than the original src data config in 225 order to compensate for swizzling that will occur when drawing. */ 226 GrPixelConfig fWriteConfig; 227 }; 228 229 /** 230 * Used to negotiate whether and how an intermediate surface should be used to write pixels to 231 * a GrSurface. If this returns false then GrGpu could not deduce an intermediate draw 232 * that would allow a successful transfer of the src pixels to the dst. The passed width, 233 * height, and rowBytes, must be non-zero and already reflect clipping to the dst bounds. 234 */ 235 bool getWritePixelsInfo(GrSurface* dstSurface, int width, int height, 236 GrPixelConfig srcConfig, DrawPreference*, WritePixelTempDrawInfo*); 237 238 /** 239 * Reads a rectangle of pixels from a render target. 240 * 241 * @param surface The surface to read from 242 * @param left left edge of the rectangle to read (inclusive) 243 * @param top top edge of the rectangle to read (inclusive) 244 * @param width width of rectangle to read in pixels. 245 * @param height height of rectangle to read in pixels. 246 * @param config the pixel config of the destination buffer 247 * @param buffer memory to read the rectangle into. 248 * @param rowBytes the number of bytes between consecutive rows. Zero 249 * means rows are tightly packed. 250 * @param invertY buffer should be populated bottom-to-top as opposed 251 * to top-to-bottom (skia's usual order) 252 * 253 * @return true if the read succeeded, false if not. The read can fail 254 * because of a unsupported pixel config or because no render 255 * target is currently set. 256 */ 257 bool readPixels(GrSurface* surface, 258 int left, int top, int width, int height, 259 GrPixelConfig config, void* buffer, size_t rowBytes); 260 261 /** 262 * Updates the pixels in a rectangle of a surface. 263 * 264 * @param surface The surface to write to. 265 * @param left left edge of the rectangle to write (inclusive) 266 * @param top top edge of the rectangle to write (inclusive) 267 * @param width width of rectangle to write in pixels. 268 * @param height height of rectangle to write in pixels. 269 * @param config the pixel config of the source buffer 270 * @param texels array of mipmap levels containing texture data 271 */ 272 bool writePixels(GrSurface* surface, 273 int left, int top, int width, int height, 274 GrPixelConfig config, 275 const SkTArray<GrMipLevel>& texels); 276 277 /** 278 * This function is a shim which creates a SkTArray<GrMipLevel> of size 1. 279 * It then calls writePixels with that SkTArray. 280 * 281 * @param buffer memory to read pixels from. 282 * @param rowBytes number of bytes between consecutive rows. Zero 283 * means rows are tightly packed. 284 */ 285 bool writePixels(GrSurface* surface, 286 int left, int top, int width, int height, 287 GrPixelConfig config, const void* buffer, 288 size_t rowBytes); 289 290 /** 291 * Updates the pixels in a rectangle of a surface using a buffer 292 * 293 * @param surface The surface to write to. 294 * @param left left edge of the rectangle to write (inclusive) 295 * @param top top edge of the rectangle to write (inclusive) 296 * @param width width of rectangle to write in pixels. 297 * @param height height of rectangle to write in pixels. 298 * @param config the pixel config of the source buffer 299 * @param transferBuffer GrBuffer to read pixels from (type must be "kCpuToGpu") 300 * @param offset offset from the start of the buffer 301 * @param rowBytes number of bytes between consecutive rows. Zero 302 * means rows are tightly packed. 303 */ 304 bool transferPixels(GrSurface* surface, 305 int left, int top, int width, int height, 306 GrPixelConfig config, GrBuffer* transferBuffer, 307 size_t offset, size_t rowBytes, GrFence* fence); 308 309 /** 310 * This is can be called before allocating a texture to be a dst for copySurface. This is only 311 * used for doing dst copies needed in blends, thus the src is always a GrRenderTarget. It will 312 * populate the origin, config, and flags fields of the desc such that copySurface can 313 * efficiently succeed. 314 */ 315 virtual bool initDescForDstCopy(const GrRenderTarget* src, GrSurfaceDesc* desc) const = 0; 316 317 // After the client interacts directly with the 3D context state the GrGpu 318 // must resync its internal state and assumptions about 3D context state. 319 // Each time this occurs the GrGpu bumps a timestamp. 320 // state of the 3D context 321 // At 10 resets / frame and 60fps a 64bit timestamp will overflow in about 322 // a billion years. 323 typedef uint64_t ResetTimestamp; 324 325 // This timestamp is always older than the current timestamp 326 static const ResetTimestamp kExpiredTimestamp = 0; 327 // Returns a timestamp based on the number of times the context was reset. 328 // This timestamp can be used to lazily detect when cached 3D context state 329 // is dirty. 330 ResetTimestamp getResetTimestamp() const { return fResetTimestamp; } 331 332 // Called to perform a surface to surface copy. Fallbacks to issuing a draw from the src to dst 333 // take place at the GrOpList level and this function implement faster copy paths. The rect 334 // and point are pre-clipped. The src rect and implied dst rect are guaranteed to be within the 335 // src/dst bounds and non-empty. 336 bool copySurface(GrSurface* dst, 337 GrSurface* src, 338 const SkIRect& srcRect, 339 const SkIPoint& dstPoint); 340 341 struct MultisampleSpecs { 342 MultisampleSpecs(uint8_t uniqueID, int effectiveSampleCnt, const SkPoint* locations) 343 : fUniqueID(uniqueID), 344 fEffectiveSampleCnt(effectiveSampleCnt), 345 fSampleLocations(locations) {} 346 347 // Nonzero ID that uniquely identifies these multisample specs. 348 uint8_t fUniqueID; 349 // The actual number of samples the GPU will run. NOTE: this value can be greater than the 350 // the render target's sample count. 351 int fEffectiveSampleCnt; 352 // If sample locations are supported, points to the subpixel locations at which the GPU will 353 // sample. Pixel center is at (.5, .5), and (0, 0) indicates the top left corner. 354 const SkPoint* fSampleLocations; 355 }; 356 357 // Finds a render target's multisample specs. The pipeline is only needed in case we need to 358 // flush the draw state prior to querying multisample info. The pipeline is not expected to 359 // affect the multisample information itself. 360 const MultisampleSpecs& queryMultisampleSpecs(const GrPipeline&); 361 362 // Finds the multisample specs with a given unique id. 363 const MultisampleSpecs& getMultisampleSpecs(uint8_t uniqueID) { 364 SkASSERT(uniqueID > 0 && uniqueID < fMultisampleSpecs.count()); 365 return fMultisampleSpecs[uniqueID]; 366 } 367 368 // Creates a GrGpuCommandBuffer in which the GrOpList can send draw commands to instead of 369 // directly to the Gpu object. This currently does not take a GrRenderTarget. The command buffer 370 // is expected to infer the render target from the first draw, clear, or discard. This is an 371 // awkward workaround that goes away after MDB is complete and the render target is known from 372 // the GrRenderTargetOpList. 373 virtual GrGpuCommandBuffer* createCommandBuffer( 374 const GrGpuCommandBuffer::LoadAndStoreInfo& colorInfo, 375 const GrGpuCommandBuffer::LoadAndStoreInfo& stencilInfo) = 0; 376 377 // Called by GrOpList when flushing. 378 // Provides a hook for post-flush actions (e.g. PLS reset and Vulkan command buffer submits). 379 virtual void finishOpList() {} 380 381 virtual GrFence SK_WARN_UNUSED_RESULT insertFence() const = 0; 382 virtual bool waitFence(GrFence, uint64_t timeout = 1000) const = 0; 383 virtual void deleteFence(GrFence) const = 0; 384 385 /////////////////////////////////////////////////////////////////////////// 386 // Debugging and Stats 387 388 class Stats { 389 public: 390#if GR_GPU_STATS 391 Stats() { this->reset(); } 392 393 void reset() { 394 fRenderTargetBinds = 0; 395 fShaderCompilations = 0; 396 fTextureCreates = 0; 397 fTextureUploads = 0; 398 fTransfersToTexture = 0; 399 fStencilAttachmentCreates = 0; 400 fNumDraws = 0; 401 fNumFailedDraws = 0; 402 } 403 404 int renderTargetBinds() const { return fRenderTargetBinds; } 405 void incRenderTargetBinds() { fRenderTargetBinds++; } 406 int shaderCompilations() const { return fShaderCompilations; } 407 void incShaderCompilations() { fShaderCompilations++; } 408 int textureCreates() const { return fTextureCreates; } 409 void incTextureCreates() { fTextureCreates++; } 410 int textureUploads() const { return fTextureUploads; } 411 void incTextureUploads() { fTextureUploads++; } 412 int transfersToTexture() const { return fTransfersToTexture; } 413 void incTransfersToTexture() { fTransfersToTexture++; } 414 void incStencilAttachmentCreates() { fStencilAttachmentCreates++; } 415 void incNumDraws() { fNumDraws++; } 416 void incNumFailedDraws() { ++fNumFailedDraws; } 417 void dump(SkString*); 418 void dumpKeyValuePairs(SkTArray<SkString>* keys, SkTArray<double>* values); 419 int numDraws() const { return fNumDraws; } 420 int numFailedDraws() const { return fNumFailedDraws; } 421 private: 422 int fRenderTargetBinds; 423 int fShaderCompilations; 424 int fTextureCreates; 425 int fTextureUploads; 426 int fTransfersToTexture; 427 int fStencilAttachmentCreates; 428 int fNumDraws; 429 int fNumFailedDraws; 430#else 431 void dump(SkString*) {} 432 void dumpKeyValuePairs(SkTArray<SkString>*, SkTArray<double>*) {} 433 void incRenderTargetBinds() {} 434 void incShaderCompilations() {} 435 void incTextureCreates() {} 436 void incTextureUploads() {} 437 void incTransfersToTexture() {} 438 void incStencilAttachmentCreates() {} 439 void incNumDraws() {} 440 void incNumFailedDraws() {} 441#endif 442 }; 443 444 Stats* stats() { return &fStats; } 445 446 /** Creates a texture directly in the backend API without wrapping it in a GrTexture. This is 447 only to be used for testing (particularly for testing the methods that import an externally 448 created texture into Skia. Must be matched with a call to deleteTestingOnlyTexture(). */ 449 virtual GrBackendObject createTestingOnlyBackendTexture(void* pixels, int w, int h, 450 GrPixelConfig config, 451 bool isRenderTarget = false) = 0; 452 /** Check a handle represents an actual texture in the backend API that has not been freed. */ 453 virtual bool isTestingOnlyBackendTexture(GrBackendObject) const = 0; 454 /** If ownership of the backend texture has been transferred pass true for abandonTexture. This 455 will do any necessary cleanup of the handle without freeing the texture in the backend 456 API. */ 457 virtual void deleteTestingOnlyBackendTexture(GrBackendObject, 458 bool abandonTexture = false) = 0; 459 460 // width and height may be larger than rt (if underlying API allows it). 461 // Returns nullptr if compatible sb could not be created, otherwise the caller owns the ref on 462 // the GrStencilAttachment. 463 virtual GrStencilAttachment* createStencilAttachmentForRenderTarget(const GrRenderTarget*, 464 int width, 465 int height) = 0; 466 // clears target's entire stencil buffer to 0 467 virtual void clearStencil(GrRenderTarget* target) = 0; 468 469 // draws an outline rectangle for debugging/visualization purposes. 470 virtual void drawDebugWireRect(GrRenderTarget*, const SkIRect&, GrColor) = 0; 471 472 // Determines whether a texture will need to be rescaled in order to be used with the 473 // GrSamplerParams. This variation is called when the caller will create a new texture using the 474 // texture provider from a non-texture src (cpu-backed image, ...). 475 bool makeCopyForTextureParams(int width, int height, const GrSamplerParams&, 476 GrTextureProducer::CopyParams*, SkScalar scaleAdjust[2]) const; 477 478 // Like the above but this variation should be called when the caller is not creating the 479 // original texture but rather was handed the original texture. It adds additional checks 480 // relevant to original textures that were created external to Skia via 481 // GrTextureProvider::wrap methods. 482 bool makeCopyForTextureParams(GrTexture* texture, const GrSamplerParams& params, 483 GrTextureProducer::CopyParams* copyParams, 484 SkScalar scaleAdjust[2]) const { 485 if (this->makeCopyForTextureParams(texture->width(), texture->height(), params, 486 copyParams, scaleAdjust)) { 487 return true; 488 } 489 return this->onMakeCopyForTextureParams(texture, params, copyParams, scaleAdjust); 490 } 491 492 // This is only to be used in GL-specific tests. 493 virtual const GrGLContext* glContextForTesting() const { return nullptr; } 494 495 // This is only to be used by testing code 496 virtual void resetShaderCacheForTesting() const {} 497 498 void handleDirtyContext() { 499 if (fResetBits) { 500 this->resetContext(); 501 } 502 } 503 504protected: 505 static void ElevateDrawPreference(GrGpu::DrawPreference* preference, 506 GrGpu::DrawPreference elevation) { 507 GR_STATIC_ASSERT(GrGpu::kCallerPrefersDraw_DrawPreference > GrGpu::kNoDraw_DrawPreference); 508 GR_STATIC_ASSERT(GrGpu::kGpuPrefersDraw_DrawPreference > 509 GrGpu::kCallerPrefersDraw_DrawPreference); 510 GR_STATIC_ASSERT(GrGpu::kRequireDraw_DrawPreference > 511 GrGpu::kGpuPrefersDraw_DrawPreference); 512 *preference = SkTMax(*preference, elevation); 513 } 514 515 // Handles cases where a surface will be updated without a call to flushRenderTarget 516 void didWriteToSurface(GrSurface* surface, const SkIRect* bounds, uint32_t mipLevels = 1) const; 517 518 Stats fStats; 519 std::unique_ptr<GrPathRendering> fPathRendering; 520 // Subclass must initialize this in its constructor. 521 sk_sp<const GrCaps> fCaps; 522 523 typedef SkTArray<SkPoint, true> SamplePattern; 524 525private: 526 // called when the 3D context state is unknown. Subclass should emit any 527 // assumed 3D context state and dirty any state cache. 528 virtual void onResetContext(uint32_t resetBits) = 0; 529 530 // Called before certain draws in order to guarantee coherent results from dst reads. 531 virtual void xferBarrier(GrRenderTarget*, GrXferBarrierType) = 0; 532 533 // overridden by backend-specific derived class to create objects. 534 // Texture size and sample size will have already been validated in base class before 535 // onCreateTexture/CompressedTexture are called. 536 virtual GrTexture* onCreateTexture(const GrSurfaceDesc& desc, 537 SkBudgeted budgeted, 538 const SkTArray<GrMipLevel>& texels) = 0; 539 virtual GrTexture* onCreateCompressedTexture(const GrSurfaceDesc& desc, 540 SkBudgeted budgeted, 541 const SkTArray<GrMipLevel>& texels) = 0; 542 543 virtual sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTextureDesc&, GrWrapOwnership) = 0; 544 virtual sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTargetDesc&, 545 GrWrapOwnership) = 0; 546 virtual sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTextureDesc&)=0; 547 virtual GrBuffer* onCreateBuffer(size_t size, GrBufferType intendedType, GrAccessPattern, 548 const void* data) = 0; 549 550 virtual gr_instanced::InstancedRendering* onCreateInstancedRendering() = 0; 551 552 virtual bool onMakeCopyForTextureParams(GrTexture* texture, const GrSamplerParams&, 553 GrTextureProducer::CopyParams*, 554 SkScalar scaleAdjust[2]) const { return false; } 555 556 virtual bool onGetReadPixelsInfo(GrSurface* srcSurface, int readWidth, int readHeight, 557 size_t rowBytes, GrPixelConfig readConfig, DrawPreference*, 558 ReadPixelTempDrawInfo*) = 0; 559 virtual bool onGetWritePixelsInfo(GrSurface* dstSurface, int width, int height, 560 GrPixelConfig srcConfig, DrawPreference*, 561 WritePixelTempDrawInfo*) = 0; 562 563 // overridden by backend-specific derived class to perform the surface read 564 virtual bool onReadPixels(GrSurface*, 565 int left, int top, 566 int width, int height, 567 GrPixelConfig, 568 void* buffer, 569 size_t rowBytes) = 0; 570 571 // overridden by backend-specific derived class to perform the surface write 572 virtual bool onWritePixels(GrSurface*, 573 int left, int top, int width, int height, 574 GrPixelConfig config, 575 const SkTArray<GrMipLevel>& texels) = 0; 576 577 // overridden by backend-specific derived class to perform the surface write 578 virtual bool onTransferPixels(GrSurface*, 579 int left, int top, int width, int height, 580 GrPixelConfig config, GrBuffer* transferBuffer, 581 size_t offset, size_t rowBytes) = 0; 582 583 // overridden by backend-specific derived class to perform the resolve 584 virtual void onResolveRenderTarget(GrRenderTarget* target) = 0; 585 586 // overridden by backend specific derived class to perform the copy surface 587 virtual bool onCopySurface(GrSurface* dst, 588 GrSurface* src, 589 const SkIRect& srcRect, 590 const SkIPoint& dstPoint) = 0; 591 592 // overridden by backend specific derived class to perform the multisample queries 593 virtual void onQueryMultisampleSpecs(GrRenderTarget*, const GrStencilSettings&, 594 int* effectiveSampleCnt, SamplePattern*) = 0; 595 596 void resetContext() { 597 this->onResetContext(fResetBits); 598 fResetBits = 0; 599 ++fResetTimestamp; 600 } 601 602 struct SamplePatternComparator { 603 bool operator()(const SamplePattern&, const SamplePattern&) const; 604 }; 605 606 typedef std::map<SamplePattern, uint8_t, SamplePatternComparator> MultisampleSpecsIdMap; 607 608 ResetTimestamp fResetTimestamp; 609 uint32_t fResetBits; 610 MultisampleSpecsIdMap fMultisampleSpecsIdMap; 611 SkSTArray<1, MultisampleSpecs, true> fMultisampleSpecs; 612 // The context owns us, not vice-versa, so this ptr is not ref'ed by Gpu. 613 GrContext* fContext; 614 615 friend class GrPathRendering; 616 friend class gr_instanced::InstancedRendering; 617 typedef SkRefCnt INHERITED; 618}; 619 620#endif 621