GrGpu.h revision 9ad1f92e2fceea33215c0f13cee42a679fb88d44
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 // Ensures that all queued up driver-level commands have been sent to the GPU. For example, on 386 // OpenGL, this calls glFlush. 387 virtual void flush() = 0; 388 389 /////////////////////////////////////////////////////////////////////////// 390 // Debugging and Stats 391 392 class Stats { 393 public: 394#if GR_GPU_STATS 395 Stats() { this->reset(); } 396 397 void reset() { 398 fRenderTargetBinds = 0; 399 fShaderCompilations = 0; 400 fTextureCreates = 0; 401 fTextureUploads = 0; 402 fTransfersToTexture = 0; 403 fStencilAttachmentCreates = 0; 404 fNumDraws = 0; 405 fNumFailedDraws = 0; 406 } 407 408 int renderTargetBinds() const { return fRenderTargetBinds; } 409 void incRenderTargetBinds() { fRenderTargetBinds++; } 410 int shaderCompilations() const { return fShaderCompilations; } 411 void incShaderCompilations() { fShaderCompilations++; } 412 int textureCreates() const { return fTextureCreates; } 413 void incTextureCreates() { fTextureCreates++; } 414 int textureUploads() const { return fTextureUploads; } 415 void incTextureUploads() { fTextureUploads++; } 416 int transfersToTexture() const { return fTransfersToTexture; } 417 void incTransfersToTexture() { fTransfersToTexture++; } 418 void incStencilAttachmentCreates() { fStencilAttachmentCreates++; } 419 void incNumDraws() { fNumDraws++; } 420 void incNumFailedDraws() { ++fNumFailedDraws; } 421 void dump(SkString*); 422 void dumpKeyValuePairs(SkTArray<SkString>* keys, SkTArray<double>* values); 423 int numDraws() const { return fNumDraws; } 424 int numFailedDraws() const { return fNumFailedDraws; } 425 private: 426 int fRenderTargetBinds; 427 int fShaderCompilations; 428 int fTextureCreates; 429 int fTextureUploads; 430 int fTransfersToTexture; 431 int fStencilAttachmentCreates; 432 int fNumDraws; 433 int fNumFailedDraws; 434#else 435 void dump(SkString*) {} 436 void dumpKeyValuePairs(SkTArray<SkString>*, SkTArray<double>*) {} 437 void incRenderTargetBinds() {} 438 void incShaderCompilations() {} 439 void incTextureCreates() {} 440 void incTextureUploads() {} 441 void incTransfersToTexture() {} 442 void incStencilAttachmentCreates() {} 443 void incNumDraws() {} 444 void incNumFailedDraws() {} 445#endif 446 }; 447 448 Stats* stats() { return &fStats; } 449 450 /** Creates a texture directly in the backend API without wrapping it in a GrTexture. This is 451 only to be used for testing (particularly for testing the methods that import an externally 452 created texture into Skia. Must be matched with a call to deleteTestingOnlyTexture(). */ 453 virtual GrBackendObject createTestingOnlyBackendTexture(void* pixels, int w, int h, 454 GrPixelConfig config, 455 bool isRenderTarget = false) = 0; 456 /** Check a handle represents an actual texture in the backend API that has not been freed. */ 457 virtual bool isTestingOnlyBackendTexture(GrBackendObject) const = 0; 458 /** If ownership of the backend texture has been transferred pass true for abandonTexture. This 459 will do any necessary cleanup of the handle without freeing the texture in the backend 460 API. */ 461 virtual void deleteTestingOnlyBackendTexture(GrBackendObject, 462 bool abandonTexture = false) = 0; 463 464 // width and height may be larger than rt (if underlying API allows it). 465 // Returns nullptr if compatible sb could not be created, otherwise the caller owns the ref on 466 // the GrStencilAttachment. 467 virtual GrStencilAttachment* createStencilAttachmentForRenderTarget(const GrRenderTarget*, 468 int width, 469 int height) = 0; 470 // clears target's entire stencil buffer to 0 471 virtual void clearStencil(GrRenderTarget* target) = 0; 472 473 // draws an outline rectangle for debugging/visualization purposes. 474 virtual void drawDebugWireRect(GrRenderTarget*, const SkIRect&, GrColor) = 0; 475 476 // Determines whether a texture will need to be rescaled in order to be used with the 477 // GrSamplerParams. This variation is called when the caller will create a new texture using the 478 // texture provider from a non-texture src (cpu-backed image, ...). 479 bool makeCopyForTextureParams(int width, int height, const GrSamplerParams&, 480 GrTextureProducer::CopyParams*, SkScalar scaleAdjust[2]) const; 481 482 // Like the above but this variation should be called when the caller is not creating the 483 // original texture but rather was handed the original texture. It adds additional checks 484 // relevant to original textures that were created external to Skia via 485 // GrTextureProvider::wrap methods. 486 bool makeCopyForTextureParams(GrTexture* texture, const GrSamplerParams& params, 487 GrTextureProducer::CopyParams* copyParams, 488 SkScalar scaleAdjust[2]) const { 489 if (this->makeCopyForTextureParams(texture->width(), texture->height(), params, 490 copyParams, scaleAdjust)) { 491 return true; 492 } 493 return this->onMakeCopyForTextureParams(texture, params, copyParams, scaleAdjust); 494 } 495 496 // This is only to be used in GL-specific tests. 497 virtual const GrGLContext* glContextForTesting() const { return nullptr; } 498 499 // This is only to be used by testing code 500 virtual void resetShaderCacheForTesting() const {} 501 502 void handleDirtyContext() { 503 if (fResetBits) { 504 this->resetContext(); 505 } 506 } 507 508protected: 509 static void ElevateDrawPreference(GrGpu::DrawPreference* preference, 510 GrGpu::DrawPreference elevation) { 511 GR_STATIC_ASSERT(GrGpu::kCallerPrefersDraw_DrawPreference > GrGpu::kNoDraw_DrawPreference); 512 GR_STATIC_ASSERT(GrGpu::kGpuPrefersDraw_DrawPreference > 513 GrGpu::kCallerPrefersDraw_DrawPreference); 514 GR_STATIC_ASSERT(GrGpu::kRequireDraw_DrawPreference > 515 GrGpu::kGpuPrefersDraw_DrawPreference); 516 *preference = SkTMax(*preference, elevation); 517 } 518 519 // Handles cases where a surface will be updated without a call to flushRenderTarget 520 void didWriteToSurface(GrSurface* surface, const SkIRect* bounds, 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 typedef SkTArray<SkPoint, true> SamplePattern; 528 529private: 530 // called when the 3D context state is unknown. Subclass should emit any 531 // assumed 3D context state and dirty any state cache. 532 virtual void onResetContext(uint32_t resetBits) = 0; 533 534 // Called before certain draws in order to guarantee coherent results from dst reads. 535 virtual void xferBarrier(GrRenderTarget*, GrXferBarrierType) = 0; 536 537 // overridden by backend-specific derived class to create objects. 538 // Texture size and sample size will have already been validated in base class before 539 // onCreateTexture/CompressedTexture are called. 540 virtual GrTexture* onCreateTexture(const GrSurfaceDesc& desc, 541 SkBudgeted budgeted, 542 const SkTArray<GrMipLevel>& texels) = 0; 543 virtual GrTexture* onCreateCompressedTexture(const GrSurfaceDesc& desc, 544 SkBudgeted budgeted, 545 const SkTArray<GrMipLevel>& texels) = 0; 546 547 virtual sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTextureDesc&, GrWrapOwnership) = 0; 548 virtual sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTargetDesc&, 549 GrWrapOwnership) = 0; 550 virtual sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTextureDesc&)=0; 551 virtual GrBuffer* onCreateBuffer(size_t size, GrBufferType intendedType, GrAccessPattern, 552 const void* data) = 0; 553 554 virtual gr_instanced::InstancedRendering* onCreateInstancedRendering() = 0; 555 556 virtual bool onMakeCopyForTextureParams(GrTexture* texture, const GrSamplerParams&, 557 GrTextureProducer::CopyParams*, 558 SkScalar scaleAdjust[2]) const { return false; } 559 560 virtual bool onGetReadPixelsInfo(GrSurface* srcSurface, int readWidth, int readHeight, 561 size_t rowBytes, GrPixelConfig readConfig, DrawPreference*, 562 ReadPixelTempDrawInfo*) = 0; 563 virtual bool onGetWritePixelsInfo(GrSurface* dstSurface, int width, int height, 564 GrPixelConfig srcConfig, DrawPreference*, 565 WritePixelTempDrawInfo*) = 0; 566 567 // overridden by backend-specific derived class to perform the surface read 568 virtual bool onReadPixels(GrSurface*, 569 int left, int top, 570 int width, int height, 571 GrPixelConfig, 572 void* buffer, 573 size_t rowBytes) = 0; 574 575 // overridden by backend-specific derived class to perform the surface write 576 virtual bool onWritePixels(GrSurface*, 577 int left, int top, int width, int height, 578 GrPixelConfig config, 579 const SkTArray<GrMipLevel>& texels) = 0; 580 581 // overridden by backend-specific derived class to perform the surface write 582 virtual bool onTransferPixels(GrSurface*, 583 int left, int top, int width, int height, 584 GrPixelConfig config, GrBuffer* transferBuffer, 585 size_t offset, size_t rowBytes) = 0; 586 587 // overridden by backend-specific derived class to perform the resolve 588 virtual void onResolveRenderTarget(GrRenderTarget* target) = 0; 589 590 // overridden by backend specific derived class to perform the copy surface 591 virtual bool onCopySurface(GrSurface* dst, 592 GrSurface* src, 593 const SkIRect& srcRect, 594 const SkIPoint& dstPoint) = 0; 595 596 // overridden by backend specific derived class to perform the multisample queries 597 virtual void onQueryMultisampleSpecs(GrRenderTarget*, const GrStencilSettings&, 598 int* effectiveSampleCnt, SamplePattern*) = 0; 599 600 void resetContext() { 601 this->onResetContext(fResetBits); 602 fResetBits = 0; 603 ++fResetTimestamp; 604 } 605 606 struct SamplePatternComparator { 607 bool operator()(const SamplePattern&, const SamplePattern&) const; 608 }; 609 610 typedef std::map<SamplePattern, uint8_t, SamplePatternComparator> MultisampleSpecsIdMap; 611 612 ResetTimestamp fResetTimestamp; 613 uint32_t fResetBits; 614 MultisampleSpecsIdMap fMultisampleSpecsIdMap; 615 SkSTArray<1, MultisampleSpecs, true> fMultisampleSpecs; 616 // The context owns us, not vice-versa, so this ptr is not ref'ed by Gpu. 617 GrContext* fContext; 618 619 friend class GrPathRendering; 620 friend class gr_instanced::InstancedRendering; 621 typedef SkRefCnt INHERITED; 622}; 623 624#endif 625