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