GrSurface.h revision 7d501ab502e861f2b2367b10a701b8449241558e
17d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com/* 27d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com * Copyright 2012 Google Inc. 37d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com * 47d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com * Use of this source code is governed by a BSD-style license that can be 57d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com * found in the LICENSE file. 67d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com */ 77d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com 87d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com 97d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com#ifndef GrSurface_DEFINED 107d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com#define GrSurface_DEFINED 117d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com 127d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com#include "GrTypes.h" 137d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com#include "GrResource.h" 147d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com 157d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.comclass GrTexture; 167d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.comclass GrRenderTarget; 177d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com 187d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.comclass GrSurface : public GrResource { 197d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.compublic: 207d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com SK_DECLARE_INST_COUNT(GrSurface); 217d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com 227d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com /** 237d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com * Retrieves the width of the surface. 247d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com * 257d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com * @return the width in texels 267d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com */ 277d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com int width() const { return fDesc.fWidth; } 287d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com 297d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com /** 307d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com * Retrieves the height of the surface. 317d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com * 327d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com * @return the height in texels 337d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com */ 347d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com int height() const { return fDesc.fHeight; } 357d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com 367d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com /** 377d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com * Retrieves the pixel config specified when the surface was created. 387d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com * For render targets this can be kUnknown_GrPixelConfig 397d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com * if client asked us to render to a target that has a pixel 407d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com * config that isn't equivalent with one of our configs. 417d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com */ 427d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com GrPixelConfig config() const { return fDesc.fConfig; } 437d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com 447d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com /** 457d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com * Return the descriptor describing the surface 467d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com */ 477d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com const GrTextureDesc& desc() const { return fDesc; } 487d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com 497d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com /** 507d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com * @return the texture associated with the surface, may be NULL. 517d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com */ 527d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com virtual GrTexture* asTexture() = 0; 537d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com virtual const GrTexture* asTexture() const = 0; 547d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com 557d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com /** 567d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com * @return the render target underlying this surface, may be NULL. 577d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com */ 587d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com virtual GrRenderTarget* asRenderTarget() = 0; 597d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com virtual const GrRenderTarget* asRenderTarget() const = 0; 607d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com 617d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com /** 627d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com * Reads a rectangle of pixels from the surface. 637d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com * @param left left edge of the rectangle to read (inclusive) 647d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com * @param top top edge of the rectangle to read (inclusive) 657d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com * @param width width of rectangle to read in pixels. 667d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com * @param height height of rectangle to read in pixels. 677d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com * @param config the pixel config of the destination buffer 687d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com * @param buffer memory to read the rectangle into. 697d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com * @param rowBytes number of bytes bewtween consecutive rows. Zero 707d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com * means rows are tightly packed. 717d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com * 727d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com * @return true if the read succeeded, false if not. The read can fail 737d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com * because of an unsupported pixel config. 747d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com */ 757d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com virtual bool readPixels(int left, int top, int width, int height, 767d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com GrPixelConfig config, void* buffer, 777d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com size_t rowBytes) = 0; 787d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com 797d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com /** 807d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com * Copy the src pixels [buffer, rowbytes, pixelconfig] into the surface 817d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com * at the specified rectangle. 827d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com * @param left left edge of the rectangle to write (inclusive) 837d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com * @param top top edge of the rectangle to write (inclusive) 847d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com * @param width width of rectangle to write in pixels. 857d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com * @param height height of rectangle to write in pixels. 867d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com * @param config the pixel config of the source buffer 877d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com * @param buffer memory to read the rectangle from. 887d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com * @param rowBytes number of bytes bewtween consecutive rows. Zero 897d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com * means rows are tightly packed. 907d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com */ 917d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com virtual void writePixels(int left, int top, int width, int height, 927d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com GrPixelConfig config, const void* buffer, 937d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com size_t rowBytes) = 0; 947d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com 957d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.comprotected: 967d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com GrTextureDesc fDesc; 977d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com 987d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com GrSurface(GrGpu* gpu, const GrTextureDesc& desc) 997d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com : INHERITED(gpu) 1007d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com , fDesc(desc) { 1017d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com } 1027d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com 1037d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.comprivate: 1047d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com typedef GrResource INHERITED; 1057d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com}; 1067d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com 1077d501ab502e861f2b2367b10a701b8449241558erobertphillips@google.com#endif // GrSurface_DEFINED 108