Add validation check to GrGpu::createTexture & minor SkGpuDevice cleanup
authorrobertphillips@google.com <robertphillips@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Wed, 31 Oct 2012 13:56:35 +0000 (13:56 +0000)
committerrobertphillips@google.com <robertphillips@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Wed, 31 Oct 2012 13:56:35 +0000 (13:56 +0000)
https://codereview.appspot.com/6821055/

git-svn-id: http://skia.googlecode.com/svn/trunk@6213 2bbb7eff-a529-9590-31e7-b0007b416f81

include/gpu/SkGpuDevice.h
src/gpu/GrGpu.cpp
src/gpu/SkGpuDevice.cpp

index a1d00ba35cced4c046aec0fe23b4f9bdd0182fd6..0a5f36e65bd8c3c79b6bdb68066d19ab8c133222 100644 (file)
@@ -29,11 +29,11 @@ class SK_API SkGpuDevice : public SkDevice {
 public:
     /**
      *  New device that will create an offscreen renderTarget based on the
-     *  config, width, height. The device's storage will not count against
-     *  the GrContext's texture cache budget. The device's pixels will be
-     *  uninitialized.
+     *  config, width, height, and sampleCount. The device's storage will not 
+     *  count against the GrContext's texture cache budget. The device's pixels 
+     *  will be uninitialized.
      */
-    SkGpuDevice(GrContext*, SkBitmap::Config, int width, int height);
+    SkGpuDevice(GrContext*, SkBitmap::Config, int width, int height, int sampleCount = 0);
 
     /**
      *  New device that will render to the specified renderTarget.
index 542c458d3f03d69a201639e76f0e7c35d1ddf9af..57eb0851521756509ce64fbabc2b492efe1bc583 100644 (file)
@@ -126,6 +126,10 @@ void GrGpu::unimpl(const char msg[]) {
 
 GrTexture* GrGpu::createTexture(const GrTextureDesc& desc,
                                 const void* srcData, size_t rowBytes) {
+    if (kUnknown_GrPixelConfig == desc.fConfig) {
+        return NULL;
+    }
+
     this->handleDirtyContext();
     GrTexture* tex = this->onCreateTexture(desc, srcData, rowBytes);
     if (NULL != tex &&
index 8f62e283ab8fe987add623587e3977f96e51bd31..b0f4ac188bbc0f788f6a6a0b9cf33abce2830b0c 100644 (file)
@@ -204,7 +204,8 @@ void SkGpuDevice::initFromRenderTarget(GrContext* context,
 SkGpuDevice::SkGpuDevice(GrContext* context,
                          SkBitmap::Config config,
                          int width,
-                         int height)
+                         int height,
+                         int sampleCount)
     : SkDevice(config, width, height, false /*isOpaque*/) {
 
     fDrawProcs = NULL;
@@ -218,14 +219,13 @@ SkGpuDevice::SkGpuDevice(GrContext* context,
     if (config != SkBitmap::kRGB_565_Config) {
         config = SkBitmap::kARGB_8888_Config;
     }
-    SkBitmap bm;
-    bm.setConfig(config, width, height);
 
     GrTextureDesc desc;
     desc.fFlags = kRenderTarget_GrTextureFlagBit;
     desc.fWidth = width;
     desc.fHeight = height;
-    desc.fConfig = SkBitmapConfig2GrPixelConfig(bm.config());
+    desc.fConfig = SkBitmapConfig2GrPixelConfig(config);
+    desc.fSampleCnt = sampleCount;
 
     SkAutoTUnref<GrTexture> texture(fContext->createUncachedTexture(desc, NULL, 0));